|
|
|
@ -1,25 +1,40 @@ |
|
|
|
#/usr/bin/python |
|
|
|
#!/usr/bin/python |
|
|
|
import sqlite3 |
|
|
|
def hash_file(path,hash_if_less,sample): |
|
|
|
return _imohash(path,hash_if_less,sample) |
|
|
|
|
|
|
|
def __init_database__(path): |
|
|
|
con = sqlite3.connect(path) |
|
|
|
def __init_database__(con): |
|
|
|
cur = con.cursor() |
|
|
|
#cur.execute('CREATE TABLE IF NOT EXISTS `paths` (`path` TEXT, `imohash` BLOB, `blake` BLOB, UNIQUE(`path`, `imohash`, `blake`));') |
|
|
|
|
|
|
|
cur.execute('''CREATE TABLE IF NOT EXISTS `PATHS` ( |
|
|
|
`PATH` TEXT, |
|
|
|
`HASH` BLOB, |
|
|
|
`ID` INTEGER)''') |
|
|
|
cur.execute('''CREATE TABLE IF NOT EXISTS `BACKUPS` ( |
|
|
|
`ID` INTEGER, |
|
|
|
`HASH_THRESHOLD` INTEGER, |
|
|
|
`SAMPLE_SIZE` INTEGER)''') |
|
|
|
con.commit() |
|
|
|
|
|
|
|
class fs: |
|
|
|
def __init__(self,top,db_path=None,hash_threshold=1024**2,sample=128*1024): |
|
|
|
def __init__(self,top,db_path=None,hash_threshold=1024**2,sample_size=128*1024,id=None): |
|
|
|
self.top=top |
|
|
|
self.hash_threshold=hash_threshold |
|
|
|
if db_path is not None: |
|
|
|
self.sample_size=sample_size |
|
|
|
if db_path is None: |
|
|
|
self.db_path = 'fs.db' |
|
|
|
else: |
|
|
|
self.db_path=db_path |
|
|
|
self.con = sqlite3.connect(self.db_path) |
|
|
|
__init_database__(self.con) |
|
|
|
self.cur = self.con.cursor() |
|
|
|
if id is None: |
|
|
|
self.cur.execute('SELECT MAX(id) FROM backups') |
|
|
|
id=self.cur.fetchone() |
|
|
|
if id[0] is None: |
|
|
|
self.id = 0 |
|
|
|
else: |
|
|
|
self.id = id[0]+1 |
|
|
|
else: |
|
|
|
self.db_path = 'fs.db' |
|
|
|
|
|
|
|
def from_db(self,top,db_path,_id=0): |
|
|
|
pass |
|
|
|
self.id = id |
|
|
|
|
|
|
|
def write_to_db(self): |
|
|
|
pass |
|
|
|
@ -29,3 +44,6 @@ class fs: |
|
|
|
|
|
|
|
def backup(self,other): |
|
|
|
pass |
|
|
|
if __name__ == "__main__": |
|
|
|
import os |
|
|
|
test = fs(os.getcwd()) |