Commit 4c69b099 authored by Daniel Armbruster's avatar Daniel Armbruster Committed by thomas.forbriger
Browse files

Smaller improvements

This is a legacy commit from before 2015-05-18.
It may be incomplete as well as inconsistent.
See COPYING.legacy and README.history for details.


SVN Path:     http://gpitrsvn.gpi.uni-karlsruhe.de/repos/TFSoftware/trunk
SVN Revision: 4339
SVN UUID:     67feda4a-a26e-11df-9d6e-31afc202ad0c
parent 91e90641
......@@ -85,7 +85,7 @@ def help():
-v|--verbose Be verbose.
-h|--help Display this help.
-e REGEX While checking a checksumfile exclude files matching
REGEX.
REGEX(s).
-R|--notrecursive Do not search in subdirectories of PATH.
-d|--debug Debug mode. Be really verbose.
-f|--followlinks Follow symbolic links. Only available if option -R is not
......@@ -108,25 +108,26 @@ def help():
def main(argv=None):
# configure logger
logInfo = {'hostname': os.uname()[1], \
'user': str(pwd.getpwuid(os.getuid()).pw_name) \
'user': pwd.getpwuid(os.getuid()).pw_name, \
'pid': os.getpid()}
csfile.__logInfo = logInfo
csfile.moduleLoggerName = 'csbackchk.csfile'
logger = logging.LoggerAdapter(logging.getLogger('csbackchk'), logInfo)
csfile.csfileLogInfo = logInfo
csfile.csfileLoggerName = 'csbackgen.csfile'
log = logging.getLogger('csbackgen')
logger = logging.LoggerAdapter(log, logInfo)
logging.basicConfig(level=logging.DEBUG, \
format='%(asctime)-15s %(hostname)-10s %(name)-15s[%(pid)-8s]: \
(%(user)-8s) %(levelname)-8s %(message)s')
format='%(asctime)-15s %(hostname)-6s %(name)-8s[%(pid)s]: \
(%(user)-4s) %(levelname)-8s %(message)s')
console = logging.StreamHandler()
formatter = logging.Formatter( \
'%(name)-15s [%(lineno)d]: %(levelname)-15s %(message)s')
'%(name)-8s [%(lineno)d]: %(levelname)-8s %(message)s')
console.setFormatter(formatter)
if argv is None:
argv = sys.argv
try:
try:
opts, args = getopt.getopt(argv[1:], "vhe:Rdftl", ["help", "verbose", \
"notrecursive", "debug", "followlinks", "tolerant", "log"])
opts, args = getopt.getopt(argv[1:], "vhe:Rdft", ["help", "verbose", \
"notrecursive", "debug", "followlinks", "tolerant"])
except getopt.GetoptError as err:
raise Usage(err.msg)
verbose = False
......
......@@ -85,7 +85,7 @@ def help():
-v|--verbose Be verbose.
-h|--help Display this help.
-e REGEX While generating a checksumfile exclude files matching
REGEX.
REGEX(s).
-R|--notrecursive Do not generate checksumfiles for subdirectories.
-d|--debug Debug mode. Be really verbose.
-f|--followlinks Follow symbolic links. Only available if option -R is not
......@@ -167,17 +167,15 @@ def main(argv=None):
raise Usage("Target directory not a valid directory.")
# major part
if notRecursive:
logger.info("Generating checksumfile in: %s", inputpath)
csfile.CsFile(targetDirectory, srcpath=inputpath).update(regexes)
else:
directories = [inputpath]
if not notRecursive:
logger.info("Collecting subdirectories.")
directories = [inputpath]
directories.extend(csfile.getSubDirectories(inputpath, regexes, \
followLinks))
logger.info("Generating checksumfiles in subdirectories.")
for dir in directories:
csfile.CsFile(targetDirectory, srcpath=dir).update(regexes)
for dir in directories:
logger.info("Update files in directory: %s to checksumfile: %s.cs", dir, \
targetDirectory)
csfile.CsFile(targetDirectory, srcpath=dir).update(regexes)
except Usage as err:
err.display()
......@@ -186,7 +184,7 @@ def main(argv=None):
err.display()
return 2
else:
logger.info("Checksumfile(s) updated.")
logger.info("Checksumfile updated.")
return 0
......
......@@ -102,7 +102,7 @@ class CsFileError(Exception):
class CsFile:
"""
Provides an interface to handle a csback checksumfile. A checksumfile
possesses the ability to take the files generating the checksums for from a
possesses the ability to take the files for generating the checksums from a
different sourcdirectory which can be configured with the srcpath variable.
"""
def __init__(self, filedir, srcpath, hashfunc='sha256'):
......@@ -116,7 +116,7 @@ class CsFile:
def read(self):
"""
Read a checksum file.
Read a checksumfile.
"""
if not os.access(self.filedir, os.F_OK):
raise CsFileError(122, "Invalid directory path.")
......@@ -235,9 +235,9 @@ class CsFile:
be successful, too, if a file listed in a checksumfile is not available
anymore. Then the status of the checksum line will be set to 'warning'.
Note that this function does not perform a check if there unregistered files
in the directory. Adding checksum lines to the checksumfile is done by the
update function.
Note that this function does not perform a check if there are unregistered
files in the directory. Adding checksum lines to the checksumfile has to be
done by the update function.
"""
self.logger.debug("Start checking checksums.")
self.read()
......@@ -350,6 +350,7 @@ class CsLine:
# checks
if checksum == self.checksum:
self.statusLastCheck = 'ok'
self.logger.debug("Check of file: %s was successful.", src)
else:
self.logger.critical("File %s has no integrity anymore.", src)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment