Commit 301e1281 authored by Cristiano Urban's avatar Cristiano Urban
Browse files

Added MD5 checksum read functionality + added content_MD5 field in db_connector.py.

parent 37317ab1
Loading
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -16,6 +16,23 @@ class Checksum(object):
    def setFileBufferSize(fileBufferSize):
        self.fileBufferSize = fileBufferSize
        
    def fileIsValid(self, absFilePath):
        if not self.md5FileSuffix in absFilePath:
            return True
        else:
            return False
        
    def getMD5(self, absFilePath):        
        if self.fileIsValid(absFilePath):
            md5FileName = os.path.dirname(absFilePath) + self.md5FileSuffix
            md5File = open(md5FileName, "r")
            for row in md5File:
                md5sum = row.split("  ./")[0]
                fileName = row.split("  ./")[1].rstrip()
                if fileName == os.path.basename(absFilePath):
                    return md5sum
        return None

    def md5sum(self, filePath):
        md5Hash = hashlib.md5()
        with open(filePath, "rb") as f:
+2 −2
Original line number Diff line number Diff line
@@ -35,8 +35,8 @@ class DbConnector(object):
            self.cursor.execute("SELECT get_ltree_path(%s)", (parentOSPath,))
            parentLtreePath = self.cursor.fetchone()[0]
            #print(f"parentLtreePath: {parentLtreePath}, type: {type(parentLtreePath)}")
            self.cursor.execute("INSERT INTO Node(parent_path, name, type, owner_id, creator_id) VALUES (%s, %s, %s, %s, %s);", 
                                (parentLtreePath, node.name, node.type, node.ownerID, node.creatorID))
            self.cursor.execute("INSERT INTO Node(parent_path, name, type, owner_id, creator_id, content_md5) VALUES (%s, %s, %s, %s, %s, %s);", 
                                (parentLtreePath, node.name, node.type, node.ownerID, node.creatorID, node.contentMD5,))
            self.conn.commit()

    def selectNode(self):
+7 −5
Original line number Diff line number Diff line
@@ -134,10 +134,12 @@ class StorePreprocessor(object):
        for flist in files:
            for file in flist:
                print(f"FILE: {file}")
                if self.md5calc.fileIsValid(file):
                    dnode = Node(os.path.basename(file), "data")
                    dnode.setParentPath(os.path.dirname(file))
                    dnode.setOwnerID("3354")
                    dnode.setCreatorID("3354")
                    dnode.setContentMD5(self.md5calc.getMD5(file))                
                    self.dbConn.insertNode(dnode, dnode.parentPath)

        self.dbConn.disconnect()