difflib
This commit is contained in:
parent
9af0458960
commit
6483f11b06
@ -1,3 +1,9 @@
|
||||
[snapshot]
|
||||
|
||||
dump_filename .snapshot.json.gz
|
||||
dump_path /home/luca/
|
||||
|
||||
|
||||
[sync]
|
||||
remote_folder /home/notanamber/notes
|
||||
local_folder /home/luca/sharednotes_dev
|
||||
|
@ -1,10 +1,45 @@
|
||||
# from tools import parse_conf as _parse_conf
|
||||
|
||||
DEFAULT_MANAGER_CONF = './conf/manager.conf'
|
||||
|
||||
class Manager():
|
||||
|
||||
def __init__(conf):
|
||||
self.conf = conf
|
||||
def __init__(task: int=0, conf: dict={}):
|
||||
if task:
|
||||
## get conf from task table
|
||||
## usually at ~/.syncdir.sync, a line is a task
|
||||
## c00092bca01e2b580d84ac04b5dcab05 p2185521 w1693995892 STOPPED /home/luca/sharednotes/ notanamber@myvps:/home/notanamber/notes/
|
||||
pass
|
||||
if conf:
|
||||
self.conf = conf
|
||||
return
|
||||
|
||||
def mirror():
|
||||
pass
|
||||
self.check_conf()
|
||||
|
||||
# conf_file = conf_file or DEFAULT_MANAGER_CONF
|
||||
# self.conf = _parse_conf.read_conf(conf_file)
|
||||
|
||||
def check_conf():
|
||||
local_path = self.conf.get('local_path')
|
||||
if not local_path:
|
||||
raise Exception('No local path specified')
|
||||
remote_path = self.conf.get('remote_path')
|
||||
if not remote_path:
|
||||
raise Exception('No remote path specified')
|
||||
|
||||
def mirror(dry_run=True):
|
||||
'''
|
||||
do an itial rsync
|
||||
|
||||
rsync -i -aPu --progress --out-format="%i ${GREEN}%n%L${ENDCOLOR} %''b" --log-file=$logfile -e ssh $otheropts $src $dest
|
||||
|
||||
Note:
|
||||
- if local_path don't exists it is created
|
||||
- if already exists can be a good idea to report it to user!
|
||||
'''
|
||||
|
||||
local_path = self.conf['local_path']
|
||||
remote_path = self.conf['remote_path']
|
||||
|
||||
def start_sync():
|
||||
self.mirror()
|
||||
|
BIN
src/lib/diff/__pycache__/mdiff.cpython-39.pyc
Normal file
BIN
src/lib/diff/__pycache__/mdiff.cpython-39.pyc
Normal file
Binary file not shown.
64
src/lib/diff/mdiff.py
Normal file
64
src/lib/diff/mdiff.py
Normal file
@ -0,0 +1,64 @@
|
||||
# import hashlib
|
||||
|
||||
def compute_diff(path_filea, path_fileb):
|
||||
'''
|
||||
- a
|
||||
|
||||
hhhh
|
||||
iiii
|
||||
jjjj
|
||||
eee
|
||||
|
||||
|
||||
|
||||
- b
|
||||
|
||||
nnnn
|
||||
llll
|
||||
jjjjj
|
||||
eee
|
||||
|
||||
'''
|
||||
with open(path_filea, 'r') as fa:
|
||||
alines = fa.readlines()
|
||||
with open(path_fileb, 'r') as fb:
|
||||
blines = fb.readlines()
|
||||
|
||||
diff_block = []
|
||||
same_block = []
|
||||
|
||||
out = []
|
||||
### compute
|
||||
while (alines or blines):
|
||||
aline = alines.pop(0) if alines else ''
|
||||
bline = blines.pop(0) if blines else ''
|
||||
|
||||
if aline == bline:
|
||||
if diff_block:
|
||||
out.append(diff_block)
|
||||
diff_block = []
|
||||
|
||||
if same_block: same_block.append(aline)
|
||||
else: same_block = [aline]
|
||||
|
||||
continue
|
||||
|
||||
## aline != bline
|
||||
if same_block:
|
||||
out.append(same_block)
|
||||
same_block = []
|
||||
|
||||
if diff_block:
|
||||
diff_block[0].append(aline)
|
||||
diff_block[1].append(bline)
|
||||
else:
|
||||
diff_block = [[aline], [bline]]
|
||||
|
||||
|
||||
if diff_block: out.append(diff_block)
|
||||
if same_block: out.append(same_block)
|
||||
|
||||
return out
|
||||
|
||||
def merge_diff(txt_diff, outfile):
|
||||
pass
|
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user