Created
August 21, 2015 09:01
-
-
Save eugeneai/9ba855fa7eb25325766b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/env python2 | |
import os, os.path | |
import pprint | |
import pickle | |
def gpg_move(): | |
f=open("find_gpg.log") | |
for orig in f: | |
orig = orig.strip() | |
path = os.path.normpath(orig) | |
path = path.split(os.sep) | |
filename = path[-1] | |
path = path[:-1] | |
name,ext = os.path.splitext(filename) | |
path.append(name) | |
restored=os.sep.join(path) | |
vault=restored+".vault" | |
os.system ("mv '%s' '%s'" % (vault, restored)) | |
os.system ("rm '%s'" % orig) | |
#break | |
print ("ok gpg") | |
def rest_vault(): | |
f=open('find.log') | |
for orig in f: | |
orig=orig.strip() | |
#print (orig) | |
break | |
BTREE={} | |
FTREE={} | |
def store_dr(p, c, path, d): | |
n=d | |
for r in path: | |
n=n.setdefault(r,{}) | |
st=os.stat(p) | |
mtime=st.st_mtime | |
n.setdefault('stat',mtime) | |
n.setdefault('name',c) | |
return mtime | |
def store_d(p, d): | |
p=p.strip() | |
if p.endswith('.vault'): | |
c=p[:-6] | |
else: | |
c=p | |
path=c | |
path=path.split(os.sep) | |
filename = path[-1] | |
path = path[:-1] | |
name,ext = os.path.splitext(filename) | |
path.append(name) | |
if ext: | |
path.append(ext) | |
else: | |
print ("NOEXT", p) | |
return False, path | |
path.reverse() | |
store_dr(p, c, path, d) | |
return True, path | |
def load_content(cname, d): | |
""" | |
""" | |
f=open(cname) | |
for rec in f: | |
rc,path = store_d(rec, d) | |
if not rc: | |
continue | |
#print (rec) | |
#break | |
#pprint.pprint (d) | |
def is_alternate(f): | |
if 'stat' in f: | |
return False, f | |
if len(f)>1: | |
return True, f | |
for _,v in f.items(): | |
return is_alternate(v) | |
def merge_recs(b,f,c): | |
idx=len(c) | |
if idx<2: | |
return True # Contunue search | |
alt, bd = is_alternate(b) | |
afd, fd = is_alternate(f) | |
if not alt: | |
#print ("B:",alt, bd) | |
#print ("F:",fd) | |
if afd: | |
###print (fd) | |
#print ("Polysource") | |
#print (fd) | |
#print (bd) | |
#print (c) | |
#print () | |
return True # Multiple vault copies | |
else: | |
target = fd['name'] | |
source = bd['name'] | |
if os.path.exists(target): | |
#print ("Exists \"%s\"" % target) | |
pass | |
else: | |
print ("Restore: '%s'" % target) | |
#source=source.replace("'","_apo_") | |
#target=target.replace("'","_apo_") | |
CMD="cp -n \"%s\" \"%s\"" % (source,target) | |
print (CMD) | |
rs = os.system (CMD) | |
if rs == 0: | |
os.system ("rm '%s.vault'" % target) | |
return True | |
else: | |
print ("Polytarget") | |
#print ("B:",alt, bd) | |
#print ("F:",fd) | |
#pprint.pprint (c) | |
return True # Multiple backup copies | |
def merge_trees(B, F, c=None): | |
if c==None: | |
c=[] | |
for k,vf in F.items(): | |
try: | |
vb=B[k] | |
except KeyError: | |
vb=None | |
if vb==None: | |
rc=merge_recs(B, F, c) | |
if not rc: | |
return rc | |
continue | |
c.append(k) | |
rc=merge_trees(vb, vf,c) | |
c.pop() | |
if not rc: | |
return rc | |
return True | |
if __name__=="__main__": | |
print () | |
# gpg_move() | |
# print ('Load BTREE') | |
# load_content('backup.log',BTREE) | |
# pickle.dump(BTREE,open("btree.dat","wb")) | |
# print ('Load FTREE') | |
# load_content('find.log', FTREE) | |
# pickle.dump(FTREE,open("ftree.dat","wb")) | |
print ('Load trees.') | |
BTREE=pickle.load(open('btree.dat','rb')) | |
FTREE=pickle.load(open('ftree.dat','rb')) | |
print ('Done.') | |
merge_trees(BTREE, FTREE) | |
print ('ok') | |
quit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment