-
Notifications
You must be signed in to change notification settings - Fork 2
/
sync.py
executable file
·81 lines (53 loc) · 1.8 KB
/
sync.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/python
import arlalow
import pprint
import os
import sqlite3
import stat
import sys
from util import *
from afsutil import *
from syncutil import dosync, readbasefiles, getbasefilesdict
if len(sys.argv) != 2:
print >> sys.stderr, "usage:", sys.argv[0], "<local directory>"
sys.exit(1)
basepath = sys.argv[1]
conn = sqlite3.connect(basepath + "/.afssync/db.sqlite")
conn.row_factory = sqlite3.Row
cursor = conn.cursor()
cursor.execute('select volume, cell from config where seq = 1')
(volume, cell) = cursor.fetchone()
print "Initializing"
arlalow.init()
fs = fileserver(cell, volume)
wholetree = fs.traverse_remote_tree(fs.rootfid, "")
print "Fetched tree"
def allFileEntriesFromTree(tree):
if "children" in tree:
return [{"name": tree.get("name"), "fid":tree.get("fid"), "path":tree.get("path"), "parent":tree.get("parent")}] + [e for f in tree["children"] for e in allFileEntriesFromTree(f)]
else:
return [tree]
serverfiles = allFileEntriesFromTree(wholetree)
#print serverfiles
status = fs.getstatusforfids([e["fid"] for e in serverfiles])
for e in serverfiles:
e["status"] = status[e["fid"]]
readbasefiles(cursor)
localfiles = [e for e in getlocalfiles(basepath) if not e["path"].startswith("/.afssync/")]
#print localfiles
#print
#print "local"
localfilesdict = dict([(e["path"], e) for e in localfiles])
#print localfilesdict.keys()
#print
#print "server"
serverfilesdict = dict([(e["path"], e) for e in serverfiles])
#print serverfilesdict.keys()
allfiles = sorted(set(localfilesdict.keys()) | set(getbasefilesdict().keys()) | set(serverfilesdict.keys()))
try:
dosync(conn, cursor, allfiles, fs, localfilesdict, serverfilesdict, getbasefilesdict(), basepath)
finally:
arlalow.giveupallcallbacks(fs.fsconn)
#while 1:
# print "sleep"
# arlalow.sleep()