|
|
|
@ -1,8 +1,31 @@ |
|
|
|
#!/usr/bin/python |
|
|
|
import sqlite3 |
|
|
|
import functools |
|
|
|
def hash_file(path,hash_if_less,sample): |
|
|
|
return _imohash(path,hash_if_less,sample) |
|
|
|
|
|
|
|
def hashify(top,hashfunc): |
|
|
|
old_dir = os.getcwd() |
|
|
|
os.chdir(top) |
|
|
|
ret = [] |
|
|
|
for root,dirs,files in os.walk('.'): |
|
|
|
try: |
|
|
|
for file in files: |
|
|
|
filepath = os.path.join(root,file) |
|
|
|
hash = hashfunc(filepath) |
|
|
|
ret.append( |
|
|
|
( |
|
|
|
filepath, |
|
|
|
hash |
|
|
|
) |
|
|
|
) |
|
|
|
except PermissionError: |
|
|
|
print('Access denied:',root) |
|
|
|
except Exception as e: |
|
|
|
print(e,file) |
|
|
|
os.chdir(old_dir) |
|
|
|
return ret |
|
|
|
|
|
|
|
def __init_database__(con): |
|
|
|
cur = con.cursor() |
|
|
|
cur.execute('''CREATE TABLE IF NOT EXISTS `PATHS` ( |
|
|
|
@ -19,6 +42,11 @@ class fs: |
|
|
|
self.top=top |
|
|
|
self.hash_threshold=hash_threshold |
|
|
|
self.sample_size=sample_size |
|
|
|
self.hashfunc = functools.partial( |
|
|
|
hashfile, |
|
|
|
hash_if_less=self.hash_threshold, |
|
|
|
sample=self.sample |
|
|
|
) |
|
|
|
if db_path is None: |
|
|
|
self.db_path = 'fs.db' |
|
|
|
else: |
|
|
|
@ -26,6 +54,8 @@ class fs: |
|
|
|
self.con = sqlite3.connect(self.db_path) |
|
|
|
__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() |
|
|
|
@ -43,7 +73,7 @@ class fs: |
|
|
|
pass |
|
|
|
|
|
|
|
def backup(self,other): |
|
|
|
pass |
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
|
import os |
|
|
|
test = fs(os.getcwd()) |