Commit ac95ff4e authored by Cristiano Urban's avatar Cristiano Urban
Browse files

Added basic exception handling + minor changes.

parent ccb63962
Loading
Loading
Loading
Loading
+21 −11
Original line number Diff line number Diff line
@@ -35,12 +35,18 @@ class Checksum(object):
        """
        if self.fileIsValid(absFilePath):
            md5FileName = os.path.dirname(absFilePath) + self.md5FileSuffix
            try:
                md5File = open(md5FileName, "r")
            except IOError:
                raise
            else:
                for row in md5File:
                    md5sum = row.split("  ./")[0]
                    fileName = row.split("  ./")[1].rstrip()
                    if fileName == os.path.basename(absFilePath):
                        md5File.close()
                        return md5sum
                md5File.close()        
        return None

    def md5sum(self, filePath):
@@ -62,7 +68,11 @@ class Checksum(object):
            md5FilePath = os.path.abspath(parent) + '/' + cwd + self.md5FileSuffix
            if not os.path.exists(md5FilePath):
                if not files == []:
                    try:
                        md5file = open(md5FilePath, 'w')
                    except IOError:
                        raise
                    else:
                        for file in files:
                            filePath = os.path.abspath(folder) + '/' + file
                            md5file.write(self.md5sum(filePath) + "  ./" + file + '\n')