-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsyncdb.py
More file actions
22 lines (19 loc) · 746 Bytes
/
syncdb.py
File metadata and controls
22 lines (19 loc) · 746 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import os
import logging
from util import dryfunc, SyncherException
import util
import undo
import settings
def remove(filetoversionpath):
with open(settings.syncdbpath, 'r') as db:
before = db.read()
dbwithfileremoved = before.replace(filetoversionpath + os.linesep, "")
with open(settings.syncdbpath, 'w') as db:
dryfunc(settings.dry, db.write, dbwithfileremoved)
logging.info("removed %s from db", filetoversionpath)
undo.push(add, filetoversionpath)
def add(filetoversionpath):
with open(settings.syncdbpath, 'a') as db:
dryfunc(settings.dry, db.write, filetoversionpath + os.linesep)
logging.info("appended %s to db", filetoversionpath)
undo.push(remove, filetoversionpath)