Ejemplo n.º 1
0
 def test_database(self):
     db = Database(":memory:")
     db.init_tables()
     db.store(FileInfo.from_file("tests/test.txt"))
     db.store(FileInfo.from_file("tests/symlink.lnk"))
     fileinfo = db.get_by_path(os.path.abspath("tests/test.txt"))
     self.assertEqual(fileinfo.path, os.path.abspath("tests/test.txt"))
Ejemplo n.º 2
0
def generate_fileinfos(path,
                       relative=False,
                       prefix=None,
                       onerror=None,
                       checksums=False):
    for p in generate_files(path=path, onerror=onerror):
        try:
            fileinfo = FileInfo.from_file(p,
                                          checksums=checksums,
                                          relative=relative)
            if prefix is not None:
                fileinfo.path = os.path.join(prefix, fileinfo.path)

            yield fileinfo

        except:
            if onerror is not None:
                onerror(sys.exc_info()[1])
Ejemplo n.º 3
0
def main():
    fileinfos = []
    with zipfile.ZipFile(sys.argv[1], 'r') as zp:
        for entry in zp.infolist():
            # print(entry, entry.filename, entry.date_time, entry.flag_bits, entry.CRC, entry.file_size)
            info = FileInfo(entry.filename)
            info.kind = 'file'
            info.size = entry.file_size
            info.blob = BlobInfo(entry.file_size, crc32=entry.CRC)
            info.mtime = int(datetime.datetime(*entry.date_time).timestamp()) * 10**9

            fileinfos.append(info)

    for info in fileinfos:
        print(info.json())
Ejemplo n.º 4
0
    def get_by_path(self, path):
        cur = self.con.cursor()
        cur.execute("SELECT * FROM fileinfo WHERE path = ?", (path,))
        rows = cur.fetchall()
        if len(rows) > 1:
            raise Exception("duplicates in database")
        elif len(rows) == 0:
            return None
        else:
            row = rows[0]
            fileinfo = FileInfo(path)

            # rowid = row[0]
            fileinfo.kind = row[1]
            fileinfo.path = row[2]
            fileinfo.dev = row[3]
            fileinfo.ino = row[4]
            fileinfo.mode = row[5]
            fileinfo.nlink = row[6]
            fileinfo.uid = row[7]
            fileinfo.gid = row[8]
            fileinfo.rdev = row[9]
            fileinfo.size = row[10]
            fileinfo.blksize = row[11]
            fileinfo.blocks = row[12]
            fileinfo.atime = row[13]
            fileinfo.ctime = row[14]
            fileinfo.mtime = row[15]
            fileinfo.time = row[16]

            return fileinfo
Ejemplo n.º 5
0
 def test_from_file(self):
     fileinfo = FileInfo.from_file("tests/test.txt")
     self.assertEqual(11, fileinfo.size)
     self.assertEqual("6df4d50a41a5d20bc4faad8a6f09aa8f", fileinfo.blob.md5)
     self.assertEqual("bc9faaae1e35d52f3dea9651da12cd36627b8403", fileinfo.blob.sha1)