Implenmentet some logging, argparse still missing.

This commit is contained in:
Milan Oberkirch 2013-06-08 03:27:27 +02:00
parent f6a3e951ea
commit dc8360efd8

View file

@ -3,7 +3,7 @@
Copyright (2013) Milan Oberkirch.
Permission is hereby granted, free of charge, to any person (except persons
working on behalf of the military, military organisations or organisations
working on behalf of the military, a military organizations or organizations
promoting or manufacturing firearms or explosive weapons) obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
@ -49,10 +49,18 @@ class PackageFileCollector:
'/': 'misc'
}
_log_handler_formatter = logging.Formatter('%(levelname)s: %(message)s')
_log_handler = logging.StreamHandler()
_log = logging.getLogger(__name__)
__current_target_directory_key = "//"
def __init__(self, package_name, target_directory='./package-collector/',
directory_mappings=None):
directory_mappings=None, log_level=logging.DEBUG):
self._log_handler.setFormatter(self._log_handler_formatter)
self._log.addHandler(self._log_handler)
self._log_handler.setLevel(log_level)
self.package_name = package_name
if target_directory[-1] != os.sep:
target_directory += os.sep
@ -115,13 +123,13 @@ class PackageFileCollector:
elif os.path.isfile(file):
os.symlink(file, self.__get_current_target_file(file))
elif os.path.islink(file):
logging.warn('"' + file + '" seems to be a dead link.'
' It will not be included.')
self._log.warn('This is a dead link, which will not be '
'included: "' + file + '"')
elif not os.path.exists(file):
logging.error('No such file or directory (or not'
' enough permission): "' + file + '".')
self._log.error('No such file or directory (or not'
' enough permissions): "' + file + '".')
else:
logging.error('Cannot access "' + file + '".')
self._log.error('Cannot access "' + file + '".')
return 1