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

dry-run mode implemented (increased verbosity)

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: 5312
SVN UUID:     67feda4a-a26e-11df-9d6e-31afc202ad0c
parent 0519eb57
......@@ -37,6 +37,7 @@
# 17/01/2012 V0.5 implemented file selection regarding time
# 24/02/2013 V0.6 make use of reimplemented directory lock module
# 28/02/2013 V0.7 improve error handling; use error codes
# 26/10/2013 V0.8 dry-run flag introduced
#
# =============================================================================
......@@ -51,18 +52,18 @@ import csbacklog
import pidlock
import csbackErrorCodes as eCodes
__version__ = "V0.7"
__version__ = "V0.8"
__subversion__ = "$Id$"
__license__ = "GPLv2+"
__author__ = "Daniel Armbruster"
__copyright__ = "Copyright (c) 2012 by Daniel Armbruster"
__copyright__ = "Copyright (c) 2013 by Daniel Armbruster"
# -----------------------------------------------------------------------------
# variables
# ---------
USAGE_TEXT = "Version: "+__version__+"\nLicense: "+__license__+ \
"\n"+__subversion__+"\nAuthor: "+__author__+ """
Usage: csbackgen [-v|--verbose] [-e REGEX [-e REGEX [...]]]
Usage: csbackgen [-v|--verbose] [-e REGEX [-e REGEX [...]]] [-n|--dry-run]
[-R|--notrecursive] [-d|--debug] [-f|--followlinks]
[-t|--target DIR] [-l|--logging] [-H|--hash ARG]
[-L|--lock] [-D|--daystart] [--atime N] [--mtime N]
......@@ -101,6 +102,7 @@ def help():
option avoids checksumfile access problems which might
occur. If not enabeled csbackchk will not care about
locked directories.
-n|--dry-run Perform a trial run with no changes made.
-D|--daystart Measure times (for --amin, --atime, --cmin, --ctime,
--mmin, and --mtime) from the beginning of today rather
than from 24 hours ago.
......@@ -180,14 +182,15 @@ def main(argv=None):
argv = sys.argv
try:
try:
opts, args = getopt.getopt(argv[1:], "vhe:Rdft:lLH:D", ["help",
opts, args = getopt.getopt(argv[1:], "vhe:Rdft:lLH:Dn", ["help",
"verbose", "notrecursive", "debug", "followlinks", "target=", \
"logging", "hash=", "lock", "daystart", "amin=", "atime=", \
"cmin=", "ctime=", "mmin=", "mtime="])
"cmin=", "ctime=", "mmin=", "mtime=", "dry-run"])
except getopt.GetoptError as err:
raise Usage(err.msg, eCodes.GLOBAL_UsageError)
verbose = False
debugMode = False
dryRunMode = False
notRecursive = False
followlinks = False
regexes = []
......@@ -208,6 +211,8 @@ def main(argv=None):
notRecursive = True
elif opt in ("-e"):
regexes.append(arg)
elif opt in ("-n", "--dry-run"):
dryRunMode = True
elif opt in ("-d", "--debug"):
debugMode = True
console.setLevel(logging.DEBUG)
......@@ -263,6 +268,9 @@ def main(argv=None):
eCodes.GLOBAL_InvalidCmdlineArgs)
# major part
if dryRunMode:
logger.getLogger().info("Perform a trial run with no changes made.")
logger.getLogger().debug("Start collecting subdirectories ...")
dirs = [srcpath]
# if no target path for checksumfiles had been passed generate the and
......@@ -287,8 +295,7 @@ def main(argv=None):
targetdirs.extend([dir.replace(dirs[0],targetDirectory,1) \
for dir in dirs[1:]])
# create a list of tuples now so that each target directory has its
# corresponding source directory
# create a list of tuples: (target directory, source directory)
pathes = list(zip(targetdirs, dirs))
logger.getLogger().debug("Directories arranged.")
......@@ -304,10 +311,10 @@ def main(argv=None):
if pidLock:
lock = pidlock.Lock(path[0])
checksumfile.update(regexes)
checksumfile.update(regexes, dryRunMode)
lock.release(os.getpid())
else:
checksumfile.update(regexes)
checksumfile.update(regexes, dryRunMode)
logger.getLogger().info( \
"Finished updating checksumfile in '{0}'.".format(path[0]))
......
......@@ -45,6 +45,7 @@
# CsLine.check() function (provide no logging anymore)
# 12/03/2013 V0.6.1 BUG in CsFile.check() function fixed
# 14/03/2013 V0.6.2 make use with statement
# 26/10/2013 V0.6.3 increase verbosity in debug mode (CsFile.update())
#
# =============================================================================
""" CsFile module to handle checksumfiles. """
......@@ -211,7 +212,7 @@ class CsFile:
else:
self.logger.debug("Finished appending to checksumfile '%s'", path)
def update(self, regexes=[]):
def update(self, regexes=[], dryRunMode=False):
"""
Update a checksum file. Also includes appending of not registered files to
checksum file in current directory.
......@@ -234,6 +235,7 @@ class CsFile:
newfiles = set(file for file in newFiles \
if not os.path.islink(os.path.join(self.srcdir, file)))
# exclude files matching time selection
excludedFiles = set()
try:
self.logger.debug("Excluding files matching time selection.")
if self.__timeDict['hasaTimes']:
......@@ -246,6 +248,7 @@ class CsFile:
datetime.fromtimestamp(os.stat(os.path.join(self.srcdir, \
file)).st_atime) < pair[1])
newFiles -= matching
excludedFiles.update(matching)
if self.__timeDict['hascTimes']:
cExcludes = CsTimeProcessor(self.__timeDict['cmin'], \
self.__timeDict['ctime'], self.__timeDict['daystart']).getResult()
......@@ -256,6 +259,7 @@ class CsFile:
datetime.fromtimestamp(os.stat(os.path.join(self.srcdir, \
file)).st_ctime) < pair[1])
newFiles -= matching
excludedFiles.update(matching)
if self.__timeDict['hasmTimes']:
mExcludes = CsTimeProcessor(self.__timeDict['mmin'], \
self.__timeDict['mtime'], self.__timeDict['daystart']).getResult()
......@@ -266,6 +270,7 @@ class CsFile:
datetime.fromtimestamp(os.stat(os.path.join(self.srcdir, \
file)).st_mtime) < pair[1])
newFiles -= matching
excludedFiles.update(matching)
except KeyError:
self.logger.debug( \
"KeyError while excluding files matching times selection.")
......@@ -285,6 +290,7 @@ class CsFile:
matching = set(file for file in newFiles \
if None != re.match(regex, file))
newFiles -= matching
excludedFiles.update(matching)
regexes.remove(BASENAME+CSSUFFIX)
regexes.append(BASENAME+RESULTSUFFIX)
regexes.remove(BASENAME+RESULTSUFFIX+r'\.[1-2]')
......@@ -292,15 +298,27 @@ class CsFile:
# exclude registered files
self.logger.debug("Excluding already registered files.")
newFiles -= registeredFiles
# generate cslines of newFiles
cslines = []
excludedFiles.update(registeredFiles)
# increase verbosity in debug mode
if len(excludedFiles):
self.logger.debug("List of excluded files:")
for file in excludedFiles:
self.logger.debug("{0}".format(file))
if len(newFiles):
self.logger.debug("A checksum will be generated for the following files:")
for file in newFiles:
csline = CsLine(file, self.srcdir, self.__hashfunc)
csline.generate(chunkSize)
cslines.append(csline)
self.append(cslines)
path = os.path.join(self.filedir, BASENAME+CSSUFFIX)
self.logger.debug("Update of checksumfile '%s' finished.", path)
self.logger.debug("{0}".format(file))
if not dryRunMode:
# generate cslines of newFiles
cslines = []
for file in newFiles:
csline = CsLine(file, self.srcdir, self.__hashfunc)
csline.generate(chunkSize)
cslines.append(csline)
self.append(cslines)
path = os.path.join(self.filedir, BASENAME+CSSUFFIX)
self.logger.debug("Update of checksumfile '%s' finished.", path)
def check(self, regexes, beTolerant=False):
"""
......
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