Browse Source

Added some functions replacing for loop statements

restore_refactor
Raphael Roberts 7 years ago
parent
commit
229a84d34e
  1. 1
      backup.py
  2. 24
      restore.py

1
backup.py

@ -39,7 +39,6 @@ def hashify(top):
imohash = _imohash(filepath)
real_hash = None
if imohash in imo_hashes:
print(filepath)
real_hash = file_hash(filepath)
else:
imo_hashes.add(imohash)

24
restore.py

@ -7,11 +7,27 @@ import sqlite3
import time
import time
def create_temp():
def create_temp_dir():
name= 'fsb{}'.format(hex(time.time_ns())[2:])
os.mkdir(name)
return name
def copy_file_temp(path):
name= 'fsb{}'.format(hex(time.time_ns())[2:])
os.copy(path,name)
return name
def super_rename(src,dst):
parent =
if not o
def create_hash_lookup(top):
hashes = hasifiy(top)
ret = {}
for _hash in hashes:
path,*two_hashes = _hash
ret.setdefault(two_hashes,[]).append(path)
return ret
def lookup(cur,imohash,realhash=None):
if realhash is not None:
cur.execute('SELECT path FROM paths where blake=?',[realhash])
@ -23,9 +39,11 @@ def lookup(cur,imohash,realhash=None):
def restore(database,source,destination):
con=sqlite3.connect(database)
cur=con.cursor()
temp = create_temp()
temp = create_hash_lookup(source)
hashes = hashify(source)
for path,imohash,realhash in hashes:
for _hashes,paths in hashes.items():
search_results = lookup(cur,*_hashes)
ppath = os.path.join(source,path)
qpath=lookup(cur,imohash,realhash)
qpath=os.path.join(temp,qpath)

Loading…
Cancel
Save