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

Seperator problem fixed

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: 4333
SVN UUID:     67feda4a-a26e-11df-9d6e-31afc202ad0c
parent fb76bad1
......@@ -38,6 +38,7 @@ import getopt
import os
import sys
import re
import logging
import csfile
__version__ = "V0.1"
......@@ -62,7 +63,8 @@ class Usage(Error):
usage_text = "Version: "+__version__+"\nLicense: "+__license__+ \
"\n"+__subversion__+"\nAuthor: "+__author__+ """
Usage: csbackgen [-v|--verbose] [-e REGEX [-e REGEX [...]]]
[-R|--notrecursive] [-d|--debug] [-f|--followlinks] PATH
[-R|--notrecursive] [-d|--debug] [-f|--followlinks]
[-l|--log] PATH
or: csbackgen -h|--help\n"""
sys.stderr.write("csbackgen: " + self.msg + "\n")
sys.stderr.write(usage_text)
......@@ -75,7 +77,8 @@ def help():
help_text = "Version: "+__version__+"\nLicense: "+__license__+"\n"+ \
__subversion__+"\nAuthor: "+__author__+"""
Usage: csbackgen [-v|--verbose] [-e REGEX [-e REGEX [...]]]
[-R|--notrecursive] [-d|--debug] [-f|--followlinks] PATH
[-R|--notrecursive] [-d|--debug] [-f|--followlinks]
[-l|--log] PATH
or: csbackgen -h|--help
-------------------------------------------------------------------------------
-v|--verbose Be verbose.
......@@ -86,6 +89,7 @@ def help():
-d|--debug Debug mode. Be really verbose.
-f|--followlinks Follow symbolic links. Only available if option -R is not
set. Note that this option can lead to infinite recursion.
-l|--log Log status to ~/.csback/log
PATH Path to generate checksumfile for.
-------------------------------------------------------------------------------
csbackgen.py will either generate a checksumfile if still no checksumfile is
......@@ -94,27 +98,6 @@ the not yet registered files to the current checksumfile. In the latter case
csbackgen.py is working in its update mode.\n"""
sys.stdout.write(help_text)
# -----------------------------------------------------------------------------
def getSubDirectories(path, regexes, followLinks=False):
"""
To generate a list of subdirectories of path using os.walk(). Note that path
itself was not appended to the list.
"""
subDirs = set()
try:
# collect subdirectories
for root, dirs, files in os.walk(path, True, None, followLinks):
for dir in dirs:
subDirs.add(os.path.join(root, dir))
# exclude directories matching regexes
for regex in regexes:
matching = set(dir for dir in subDirs if None != re.match(regex, dir))
subDirs -= matching
except OSError as err:
raise Error("[Errno "+str(err.errno)+"] "+err.strerror+": "+err.filename)
else:
return subDirs
# -----------------------------------------------------------------------------
def main(argv=None):
if argv is None:
......@@ -149,25 +132,28 @@ def main(argv=None):
else:
raise Usage("Unhandled option chosen.")
if 1 == len(args):
inputpath = str(args[0])
inputpath = str(args[0]).rstrip(os.sep)+os.sep
else:
raise Usage("Invalid argument.")
if notRecursive:
if verbose or debugMode:
sys.stdout.write("csbackgen.py: Generating checksumfile in: '"+ \
path+"'\n")
inputpath+"'\n")
csfile.CsFile(inputpath).update(regexes)
else:
if verbose or debugMode:
sys.stdout.write("csbackgen.py: Collecting subdirectories.\n")
directories = [inputpath]
directories.extend(getSubDirectories(inputpath, regexes, \
directories.extend(csfile.getSubDirectories(inputpath, regexes, \
followLinks))
print(directories)
if verbose or debugMode:
sys.stdout.write( \
"csbackgen.py: Generating checksumfiles in subdirectories.\n")
for dir in directories:
csfile.CsFile(dir).update(regexes)
except Usage as err:
err.display()
return 2
......
......@@ -43,6 +43,7 @@ import os
import re
import sys
import hashlib
import logging
from datetime import datetime
__version__ = "V0.1"
......@@ -57,6 +58,30 @@ __copyright__ = "Copyright (c) 2012 by Daniel Armbruster"
chunkSize = 1024 * 128 # 128kB
debugMode = False
# -----------------------------------------------------------------------------
# functions
def getSubDirectories(path, regexes, followLinks=False):
"""
To generate a list of subdirectories of path using os.walk(). Note that path
itself was not appended to the list.
"""
subDirs = set()
try:
# collect subdirectories
for root, dirs, files in os.walk(path, True, None, followLinks):
for dir in dirs:
subDirs.add(os.path.join(root, dir))
# exclude directories matching regexes
for regex in regexes:
matching = set(dir for dir in subDirs if None != re.match(regex, dir))
subDirs -= matching
except OSError as err:
raise CsFileError("[Errno "+str(err.errno)+"] "+err.strerror+": " \
+err.filename)
else:
return subDirs
# -----------------------------------------------------------------------------
class CsFileError(Exception):
"""
......@@ -206,15 +231,18 @@ class CsFile:
csline = CsLine(file, self.__hashfunc)
csline.generate(chunkSize)
cslines.append(csline)
print(csline)
self.append(cslines)
def check(self, srcDir=''):
def check(self, srcDir='', beTolerant=False):
"""
Check a checksum file which means:
1. read checksum file
2, calculate checksum of file which is located in srcDir and check results
3. write the result to the checksum file
If the third argument (beTolerant) is set True the checking process will be
successful, too, if a file listed in a checksumfile is not available
anymore.
"""
if debugMode:
CsReport(220, "Start checking checksums.").display()
......
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