-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsync.py
44 lines (35 loc) · 1.35 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
from one import *
import json, argparse
import logging
log = logging.getLogger(__name__)
tokenfile = '.ubuntuonetokens'
def load_tokens(username, password):
try:
with open(tokenfile) as f:
data = json.loads(f.read())
except IOError as e:
try:
data = acquire_token(username, password )
except Unauthorized, e:
print(e)
raise SystemExit
jsondata = json.dumps(data)
with open(tokenfile, 'wb') as f:
f.write(jsondata)
consumer, token = make_tokens(data)
return consumer, token
def main():
parser = argparse.ArgumentParser(description='Sync files from ubuntu, you only need to provide your username and password once.',
epilog="Copyright 2012 Tauri-Tec Ltd http://www.tauri-tec.com")
parser.add_argument('--username', type=str, action='store', dest='username',
help='Ubuntu One username')
parser.add_argument('--password', type=str, action='store', dest='password',
help='Ubuntu One password')
args = parser.parse_args()
consumer, token = load_tokens(args.username, args.password)
#iterate over tree starting here:
list_files(consumer, token, '/~/Ubuntu One/')
#fetches all your purchased music
#fetch_children(consumer, token, '/~/.ubuntuone/Purchased from Ubuntu One')
if __name__ == "__main__":
main()