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

Bug 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: 4332
SVN UUID:     67feda4a-a26e-11df-9d6e-31afc202ad0c
parent 7c36b144
......@@ -100,16 +100,16 @@ 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 = []
subDirs = set()
try:
# collect subdirectories
for root, dirs, files in os.walk(path, True, None, followLinks):
for dir in dirs:
subDirs.append(os.path.join(root, dir))
subDirs.add(os.path.join(root, dir))
# exclude directories matching regexes
if [] != regexes:
subDirs = [dir for dir in subDirs for regex in regexes \
if None == re.match(str(regex),dir)]
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:
......@@ -121,7 +121,7 @@ def main(argv=None):
argv = sys.argv
try:
try:
opts, args = getopt.getopt(argv[1:], "vhe:Rdf", ["help", "verbose",\
opts, args = getopt.getopt(argv[1:], "vhe:Rdf", ["help", "verbose", \
"notrecursive", "debug", "followlinks"])
except getopt.GetoptError as err:
raise Usage(err.msg)
......
......@@ -187,13 +187,17 @@ class CsFile:
if debugMode:
CsReport(188, "Fetching files not registered yet.").display()
registeredFiles = set(csline.path for csline in self.__cslines)
# fetch files (pathes) excluding those matching regexes
regexes.append(self.__filename)
newFiles = set([os.path.join(self.__filepath, file) \
for file in os.listdir(self.__filepath) \
if os.path.isfile(os.path.join(self.__filepath,file)) \
for regex in regexes if None == re.match(regex, file)])
regexes.remove(self.__filename)
# fetch files (pathes)
newFiles = os.listdir(self.__filepath)
newFiles = set(os.path.join(self.__filepath, file) for file in newFiles \
if os.path.isfile(os.path.join(self.__filepath, file)))
# exclude files matching regexes
regexes.append(os.path.join(self.__filepath,self.__filename))
for regex in regexes:
matching = set(file for file in newFiles \
if None != re.match(regex, file))
newFiles -= matching
regexes.remove(os.path.join(self.__filepath,self.__filename))
# exclude registered files
newFiles -= registeredFiles
# generate cslines of newFiles
......@@ -213,19 +217,19 @@ class CsFile:
3. write the result to the checksum file
"""
if debugMode:
CsReport(216, "Start checking checksums.").display()
CsReport(220, "Start checking checksums.").display()
self.read()
if 0 == len(self.__cslines) and debugMode:
CsReport(219, "CSFILE does not contain any lines.").display()
CsReport(223, "CSFILE does not contain any lines.").display()
for csline in self.__cslines:
if not len(srcDir):
if debugMode:
CsReport(223, "Performing check of file with file itself.").display()
CsReport(227, "Performing check of file with file itself.").display()
csline.check()
else:
filename = csline.path.split(os.sep)[-1]
if debugMode:
CsReport(228, "Performing check of file with source: "+ \
CsReport(232, "Performing check of file with source: "+ \
srcDir+os.sep+filename).display()
csline.check(srcDir+os.sep+filename)
self.write()
......@@ -266,7 +270,7 @@ class CsLine:
self.dateLastCheck = ''
self.statusLastCheck = ''
else:
CsFileError(269, "Invalid argument")
CsFileError(273, "Invalid argument")
def generate(self, chunkSize):
"""
......@@ -274,7 +278,7 @@ class CsLine:
result is a fully configured checksum line.
"""
if debugMode:
CsReport(277, "Calculating checksum for file: "+self.path).display()
CsReport(281, "Calculating checksum for file: "+self.path).display()
# generate checksum
try:
hashfunc = hashlib.new(self.hashfunc)
......@@ -286,7 +290,7 @@ class CsLine:
data = file.read(blockSize)
self.checksum = hashfunc.hexdigest()
except IOError as err:
raise CsFileError(289, "[Errno "+str(err.errno)+"] "+err.strerror+": " \
raise CsFileError(293, "[Errno "+str(err.errno)+"] "+err.strerror+": " \
+err.filename)
else:
file.close()
......@@ -321,13 +325,13 @@ class CsLine:
checksum = hashfunc.hexdigest()
except IOError as err:
# Maybe better to avoid Exception here and just put the status to notice
raise CsFileError(324, "[Errno "+str(err.errno)+"] "+err.strerror+": " \
raise CsFileError(328, "[Errno "+str(err.errno)+"] "+err.strerror+": " \
+err.filename)
else:
file.close()
# checks
if not len(self.checksum):
raise CsFileError(330, "Caclulation of checksum was not successful.")
raise CsFileError(334, "Caclulation of checksum was not successful.")
if checksum == self.checksum:
self.statusLastCheck = 'ok'
else:
......
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