-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathjbrout.py
executable file
·263 lines (211 loc) · 7.43 KB
/
jbrout.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
#!/usr/bin/python3 -u
# -*- coding: utf-8 -*-
# ###########################################################################
# #
# # Copyright (C) 2005-2019 manatlan manatlan[at]gmail(dot)com
# #
# # This program is free software; you can redistribute it and/or modify
# # it under the terms of the GNU General Public License as published
# # by the Free Software Foundation; version 2 only.
# #
# # This program is distributed in the hope that it will be useful,
# # but WITHOUT ANY WARRANTY; without even the implied warranty of
# # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# # GNU General Public License for more details.
# #
# ###########################################################################
import os,sys,asyncio
import guy,vbuild
from jbapi import JBrout
__version__="0.2.2"
class jbrout:
""" RPC methods exposed in the front, see self.<method>() in js """
def getFolders(self):
return self.api.getFolders()
def getTags(self):
return self.api.getTags()
def getYears(self):
ll=self.api.selectFromFolder("/",True)
ma = 11111111
mi = 99999999
for i in ll:
a = int(i["date"][:8])
ma = max(a, ma)
mi = min(a, mi)
f=lambda yyyymmdd: yyyymmdd[0:4]+"-"+yyyymmdd[4:6]+"-"+yyyymmdd[6:8]
return dict(years=sorted(list({i["date"][:4] for i in ll} )), min=f(str(mi)),max=f(str(ma)))
async def refreshFolder(self,folder):
g=self.api.addFolder(folder)
nb=next(g)
await self.emit("set-working","0/%s"%nb)
last=None
for i in g:
await asyncio.sleep(0.00001)
if type(i)==dict:
await self.emit("set-working",None)
last=i
else:
await self.emit("set-working","%s/%s"%(i+1,nb))
return last
def removeFolder(self,folder):
f=self.api.selectFolderNode(folder)
f.remove()
def albumComment(self,folder,value=None): # getter & setter
f=self.api.selectFolderNode(folder)
if value is None: # getter
return f.comment
else: # setter
return f.setComment(value)
def albumExpand(self,folder,bool):
f=self.api.selectFolderNode(folder)
f.setExpand(bool)
def catExpand(self,cat,bool):
c=self.api.selectCatNode(cat)
if c:
c.setExpand(bool)
def selectFromFolder(self,folder,all=False):
return self.api.selectFromFolder(folder,all)
def selectFromBasket(self):
return self.api.selectFromBasket()
def selectFromTags(self,tags):
if tags:
return self.api.selectFromTags(tags)
else:
return []
def selectYear(self,yyyy):
return self.api.selectYear(yyyy)
def selectYearMonth(self,yyyymm):
return self.api.selectYearMonth(yyyymm)
def photoRebuildThumbnail(self,path):
p=self.api.selectPhotoNode(path)
p.rebuildThumbnail()
def photoRotateRight(self,path):
p=self.api.selectPhotoNode(path)
p.rotate("R")
def photoRotateLeft(self,path):
p=self.api.selectPhotoNode(path)
p.rotate("L")
def photoComment(self,path,txt):
p=self.api.selectPhotoNode(path)
p.setComment(txt)
def removeBasket(self):
self.api.clearBasket()
def photoBasket(self,path,bool):
p=self.api.selectPhotoNode(path)
if bool:
p.addToBasket()
else:
p.removeFromBasket()
def tagsAddTag(self,cat,txt):
c=self.api.selectCatNode(cat)
if c:
return c.addTag(txt.strip())
def tagsAddCat(self,cat,txt):
c=self.api.selectCatNode(cat)
if c:
return c.addCatg(txt.strip())
def tagsDelTag(self,txt):
t=self.api.selectTagNode(txt)
if t:
t.remove()
return True
def tagsDelCat(self,txt):
c=self.api.selectCatNode(cat)
if c:
c.remove()
return True
def tagMoveToCat(self,tag,cat):
t1=self.api.selectTagNode(tag)
c2=self.api.selectCatNode(cat)
if t1 and c2:
t1.moveToCatg(c2)
return True
def catMoveToCat(self,cat1,cat2):
c1=self.api.selectCatNode(cat1)
c2=self.api.selectCatNode(cat2)
if c1 and c2:
c1.moveToCatg(c2)
return True
def catRename(self,cat1,cat2):
c1=self.api.selectCatNode(cat1)
if c1:
return c1.rename(cat2)
def photoAddTags(self, path, tags):
assert type(tags) == list
p=self.api.selectPhotoNode(path)
return p.addTags(tags)
def photoDelTag(self, path, tag):
p=self.api.selectPhotoNode(path)
return p.delTag(tag)
def photoClearTags(self,path):
p=self.api.selectPhotoNode(path)
return p.clearTags()
def cfgGet(self,k,default=None):
cfg=self.api.getConf()
return cfg.get(k,default)
def cfgSet(self,k,v):
cfg=self.api.getConf()
cfg[k]=v
def dir(self,path):
np=lambda x: os.path.realpath(os.path.join(path,x))
ll=[ dict(name="..",isdir=True, path=np("..")) ]
try:
l=[dict(name=i,isdir=os.path.isdir( np(i) ),path=np(i)) for i in os.listdir(path) if not i.startswith(".")]
folders=[i for i in l if i["isdir"]]
files=[i for i in l if not i["isdir"] and (os.path.splitext(i["name"])[1][1:].lower() in self.api.supportedFormats) ]
folders.sort(key=lambda x: x["name"].lower())
files.sort(key=lambda x: x["name"].lower())
ll.extend( folders )
ll.extend( files )
except PermissionError:
pass
return ll
class index(guy.Guy,jbrout):
""" guy tech class (with tech stuff) """
size=(1024,780)
def __init__(self,api):
self.api=api
guy.Guy.__init__(self)
def render(self,path): #here is the magic
# load your template (from web folder)
with open( os.path.join(path,"static","index.html") ) as fid:
content=fid.read()
# load all vue/sfc components
v=vbuild.render( os.path.join(path,"static/*.vue") )
# and inject them in your template
return content.replace("<!-- HERE -->",str(v))
async def getPic(web,path,idx):
i=web.instance.api.selectPhotoNode(path)
if idx is not None:
info=dict(
tags=i.tags,
comment=i.comment,
rating=i.rating,
resolution=i.resolution,
real=i.real
)
await web.instance.emit("set-info",idx,path,info)
return i
@guy.http("/thumb/(.+)")
async def requestThumb(web,path): #override to hook others web requests
path=path.replace(":",".") # see patchUrl() is js
idx=web.get_argument('idx', None)
i=await getPic(web,path,idx)
web.write( i.getThumb() )
@guy.http("/image/(.+)")
async def requestImage(web,path): #override to hook others web requests
path=path.replace(":",".") # see patchUrl() is js
idx=web.get_argument('idx', None)
i=await getPic(web,path,idx)
web.write( i.getImage() )
def main():
cwd = os.path.dirname(__file__)
#~ with JBrout(os.path.expanduser("~/.local/share/jbrout")) as api: #copy of the original jbrout
#~ w=index(api=api)
#~ w.run()
#~ quit()
with JBrout(os.path.join(cwd,"tempconf")) as api:
w=index(api=api)
w.run()
if __name__=="__main__":
main()