forked from bordaigorl/remy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathremycli.py
100 lines (79 loc) · 2.34 KB
/
remycli.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import remy
from remy.remarkable.metadata import *
from remy.remarkable.filesource import LocalFileSource
# from fuzzywuzzy import process
# highest = process.extractOne(str2Match,strOptions)
where = "/Users/bordaigorl/Documents/reMarkable/backup/latest"
templ = "/Users/bordaigorl/Work/Code/reMarkable/built-in/2.1/templates"
def filter_by_field(f, v, docs):
return filter(lambda k: docs[k][f] == v, docs)
def list_folder(docs, uid='', exact=True):
if not exact:
uid = docs.matchId(uid)
if not docs.isFolder(uid):
print("NOT A FOLDER!")
return
folder = docs.get(uid)
print("FOLDERS")
for k in folder.folders:
print(' {0:<20} {1}'.format(docs.get(k).name(), k))
print("FILES")
for k in folder.files:
print(' {0:<20} {1}'.format(docs.get(k).name(), k))
def list_path(docs, path=''):
uid = docs.uidFromPath(path)
if uid:
if not docs.isFolder(uid):
print("The path is the document with id '{}'.".format(uid))
else:
list_folder(docs, uid)
else:
print("Not found!")
def list_trash(docs):
folders = []
files = []
lw = 20
for uid in docs.trash:
p = docs.pathOf(uid,trashToo=True)
if p is None:
p = "UNKNOWN"
else:
p = '/' + ('/'.join(p))
lw = max(lw,len(p))
if docs.get(uid).type == FOLDER_TYPE:
folders.append((uid, p))
elif docs.get(uid).type == DOCUMENT_TYPE:
files.append((uid, p))
print(lw)
print("FOLDERS")
for k, p in folders:
print((' {path}/{visibleName:<'+str(lw+2)+'} {uid}').format(path=p,name=docs.get(k).name(),uid=k))
print("FILES")
for k, p in files:
print((' {path}/{visibleName:<'+str(lw+2)+'} {uid}').format(path=p,name=docs.get(k).name(),uid=k))
_test_pwd = None
def load(where=where, templ=templ):
global _test_pwd
docs = RemarkableIndex(LocalFileSource("Backup", where, templ))
_test_pwd = [ROOT_ID, docs]
list_folder(docs)
return docs
def ls(path=None):
uid, docs = _test_pwd
if path:
uid = docs.uidFromPath(path, start=uid, delim="/")
list_folder(docs, uid)
def pwd():
uid, docs = _test_pwd
print(docs.nameOf(uid), uid)
def cd(path):
global _test_pwd
uid, docs = _test_pwd
f = docs.uidFromPath(path, start=uid, delim="/")
if f is None:
print("Path not found!")
elif docs.isFolder(f):
_test_pwd[0] = f
list_folder(docs, f)
else:
print("Path points to a file %s!" % f)