From baeaaf9371fcfdc0f87c0830bbf42d926f4ac736 Mon Sep 17 00:00:00 2001 From: rlbr Date: Thu, 6 Dec 2018 13:15:08 -0600 Subject: [PATCH] tested backup and write_to_db --- fs_class.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/fs_class.py b/fs_class.py index 8ff1a89..aa09383 100755 --- a/fs_class.py +++ b/fs_class.py @@ -1,6 +1,7 @@ #!/usr/bin/python import sqlite3 import functools +from imohash import hashfile as _imohash def hash_file(path,hash_if_less,sample): return _imohash(path,hash_if_less,sample) @@ -42,10 +43,12 @@ class fs: self.top=top self.hash_threshold=hash_threshold self.sample_size=sample_size + + self.hash_files = {} self.hashfunc = functools.partial( - hashfile, + hash_file, hash_if_less=self.hash_threshold, - sample=self.sample + sample=self.sample_size ) if db_path is None: self.db_path = 'fs.db' @@ -55,7 +58,6 @@ class fs: __init_database__(self.con) self.cur = self.con.cursor() - self.hash_files = {} if id is None: self.cur.execute('SELECT MAX(id) FROM backups') id=self.cur.fetchone() @@ -68,22 +70,24 @@ class fs: def write_to_db(self): '''stores self.hash_files in database, along with a backup id and hash_func parameters''' - for hash,files in self.hash_files.item() + for hash,files in self.hash_files.items(): for file in files: - self.cur.execue('INSERT INTO paths VALUES (?,?)',[hash,file]) + self.cur.execute('INSERT INTO paths VALUES (?,?,?)',[hash,file,self.id]) self.con.commit() def morph(self,other): '''renames/copies all files in self.top to match other''' pass - def backup(self,other): + def backup(self): '''fills in self.hash_file {hash:[filepaths]}''' paths = hashify(self.top,self.hashfunc) for filepath,hash in paths: - self.hash_file.setdefault(hash,[]).append(filepath) + self.hash_files.setdefault(hash,[]).append(filepath) if __name__ == "__main__": import os test = fs(os.getcwd()) + test.backup() + test.write_to_db()