|
a/src/mediaserver/cdplugins/uprcl/uprclfolders.py |
|
b/src/mediaserver/cdplugins/uprcl/uprclfolders.py |
|
... |
|
... |
17 |
import os
|
17 |
import os
|
18 |
import shlex
|
18 |
import shlex
|
19 |
import urllib
|
19 |
import urllib
|
20 |
import sys
|
20 |
import sys
|
21 |
|
21 |
|
22 |
from uprclutils import *
|
22 |
from uprclutils import uplog, docarturi, audiomtypes, rcldirentry, \
|
23 |
|
23 |
rcldoctoentry, cmpentries
|
24 |
from recoll import recoll
|
24 |
from recoll import recoll
|
25 |
from recoll import rclconfig
|
25 |
from recoll import rclconfig
|
26 |
|
26 |
|
27 |
g_myprefix = '0$uprcl$folders'
|
27 |
g_foldersIdPrefix = '0$uprcl$folders'
|
28 |
|
28 |
|
29 |
# Debug : limit processed recoll entries for speed
|
29 |
# Debug : limit processed recoll entries for speed
|
30 |
g_maxrecollcnt = 0
|
30 |
g_maxrecollcnt = 1000
|
31 |
|
31 |
|
32 |
# Internal init: create the directory tree (folders view) from the doc
|
32 |
# Internal init: create the directory tree (folders view) from the doc
|
33 |
# array by splitting the url in each doc.
|
33 |
# array by splitting the url in each doc.
|
34 |
#
|
34 |
#
|
35 |
# The dirvec vector has one entry for each directory. Each entry is a
|
35 |
# The dirvec vector has one entry for each directory. Each entry is a
|
|
... |
|
... |
190 |
# Browsing the initialized [folders] hierarchy
|
190 |
# Browsing the initialized [folders] hierarchy
|
191 |
|
191 |
|
192 |
|
192 |
|
193 |
# Extract dirvec index from objid, according to the way we generate them.
|
193 |
# Extract dirvec index from objid, according to the way we generate them.
|
194 |
def _objidtodiridx(pid):
|
194 |
def _objidtodiridx(pid):
|
195 |
if not pid.startswith(g_myprefix):
|
195 |
if not pid.startswith(g_foldersIdPrefix):
|
196 |
raise Exception("folders.browse: bad pid %s" % pid)
|
196 |
raise Exception("folders.browse: bad pid %s" % pid)
|
197 |
|
197 |
|
198 |
if len(g_alldocs) == 0:
|
198 |
if len(g_alldocs) == 0:
|
199 |
raise Exception("folders:browse: no docs")
|
199 |
raise Exception("folders:browse: no docs")
|
200 |
|
200 |
|
201 |
diridx = pid[len(g_myprefix):]
|
201 |
diridx = pid[len(g_foldersIdPrefix):]
|
202 |
if not diridx:
|
202 |
if not diridx:
|
203 |
diridx = 0
|
203 |
diridx = 0
|
204 |
else:
|
204 |
else:
|
205 |
if diridx[1] != 'd':
|
205 |
if diridx[1] != 'd':
|
206 |
raise Exception("folders:browse: called on non dir objid %s" % pid)
|
206 |
raise Exception("folders:browse: called on non dir objid %s" % pid)
|
|
... |
|
... |
210 |
raise Exception("folders:browse: bad pid %s" % pid)
|
210 |
raise Exception("folders:browse: bad pid %s" % pid)
|
211 |
|
211 |
|
212 |
return diridx
|
212 |
return diridx
|
213 |
|
213 |
|
214 |
|
214 |
|
|
|
215 |
# Tell the top module what entries we define in the root
|
215 |
def rootentries(pid):
|
216 |
def rootentries(pid):
|
216 |
return [rcldirentry(pid + 'folders', pid, '[folders]'),]
|
217 |
return [rcldirentry(pid + 'folders', pid, '[folders]'),]
|
217 |
|
218 |
|
218 |
|
219 |
|
219 |
# Look all docs inside directory, and return the cover art we find.
|
220 |
# Look all non-directory docs inside directory, and return the cover
|
|
|
221 |
# art we find.
|
220 |
def arturifordir(diridx):
|
222 |
def _arturifordir(diridx):
|
221 |
for nm,ids in g_dirvec[diridx].iteritems():
|
223 |
for nm,ids in g_dirvec[diridx].iteritems():
|
222 |
if ids[1] >= 0:
|
224 |
if ids[1] >= 0:
|
223 |
doc = g_alldocs[ids[1]]
|
225 |
doc = g_alldocs[ids[1]]
|
224 |
if doc.mtype != 'inode/directory' and doc.albumarturi:
|
226 |
if doc.mtype != 'inode/directory' and doc.albumarturi:
|
225 |
return doc.albumarturi
|
227 |
return doc.albumarturi
|
226 |
|
228 |
|
227 |
|
229 |
|
228 |
# Browse method
|
230 |
# Folder hierarchy browse method.
|
229 |
# objid is like folders$index
|
231 |
# objid is like folders$index
|
230 |
# flag is meta or children.
|
232 |
# flag is meta or children.
|
|
|
233 |
# httphp and pathprefix are used to generate URIs
|
231 |
def browse(pid, flag, httphp, pathprefix):
|
234 |
def browse(pid, flag, httphp, pathprefix):
|
232 |
|
235 |
|
233 |
diridx = _objidtodiridx(pid)
|
236 |
diridx = _objidtodiridx(pid)
|
234 |
|
237 |
|
235 |
# If there is only one entry in root, skip it. This means that 0
|
238 |
# If there is only one entry in root, skip it. This means that 0
|
|
... |
|
... |
241 |
entries = []
|
244 |
entries = []
|
242 |
|
245 |
|
243 |
# The basename call is just for diridx==0 (topdirs). Remove it if
|
246 |
# The basename call is just for diridx==0 (topdirs). Remove it if
|
244 |
# this proves a performance issue
|
247 |
# this proves a performance issue
|
245 |
for nm,ids in g_dirvec[diridx].iteritems():
|
248 |
for nm,ids in g_dirvec[diridx].iteritems():
|
246 |
uplog("folders:browse: got nm %s" % printable(nm))
|
|
|
247 |
if nm == "..":
|
249 |
if nm == "..":
|
248 |
continue
|
250 |
continue
|
249 |
thisdiridx = ids[0]
|
251 |
thisdiridx = ids[0]
|
250 |
thisdocidx = ids[1]
|
252 |
thisdocidx = ids[1]
|
251 |
if thisdocidx >= 0:
|
253 |
if thisdocidx >= 0:
|
|
... |
|
... |
256 |
|
258 |
|
257 |
if thisdiridx >= 0:
|
259 |
if thisdiridx >= 0:
|
258 |
# Skip empty directories
|
260 |
# Skip empty directories
|
259 |
if len(dirvec[thisdiridx]) == 1:
|
261 |
if len(dirvec[thisdiridx]) == 1:
|
260 |
continue
|
262 |
continue
|
261 |
id = g_myprefix + '$' + 'd' + str(thisdiridx)
|
263 |
id = g_foldersIdPrefix + '$' + 'd' + str(thisdiridx)
|
262 |
if doc and doc.albumarturi:
|
264 |
if doc and doc.albumarturi:
|
263 |
arturi = doc.albumarturi
|
265 |
arturi = doc.albumarturi
|
264 |
else:
|
266 |
else:
|
265 |
arturi = arturifordir(thisdiridx)
|
267 |
arturi = _arturifordir(thisdiridx)
|
266 |
entries.append(rcldirentry(id, pid, os.path.basename(nm),
|
268 |
entries.append(rcldirentry(id, pid, os.path.basename(nm),
|
267 |
arturi=arturi))
|
269 |
arturi=arturi))
|
268 |
else:
|
270 |
else:
|
269 |
# Not a directory. docidx had better been set
|
271 |
# Not a directory. docidx had better been set
|
270 |
if thisdocidx == -1:
|
272 |
if thisdocidx == -1:
|
271 |
uplog("folders:docidx -1 for non-dir entry %s"%nm)
|
273 |
uplog("folders:docidx -1 for non-dir entry %s"%nm)
|
272 |
continue
|
274 |
continue
|
273 |
doc = g_alldocs[thisdocidx]
|
275 |
doc = g_alldocs[thisdocidx]
|
274 |
id = g_myprefix + '$i' + str(thisdocidx)
|
276 |
id = g_foldersIdPrefix + '$i' + str(thisdocidx)
|
275 |
e = rcldoctoentry(id, pid, httphp, pathprefix, doc)
|
277 |
e = rcldoctoentry(id, pid, httphp, pathprefix, doc)
|
276 |
if e:
|
278 |
if e:
|
277 |
entries.append(e)
|
279 |
entries.append(e)
|
278 |
|
280 |
|
279 |
return sorted(entries, cmp=cmpentries)
|
281 |
return sorted(entries, cmp=cmpentries)
|
280 |
|
282 |
|
281 |
# return path for objid, which has to be a container. This is good old pwd
|
283 |
# Return path for objid, which has to be a container.This is good old
|
|
|
284 |
# pwd... It is called from the search module for generating a dir:
|
|
|
285 |
# recoll filtering directive.
|
282 |
def dirpath(objid):
|
286 |
def dirpath(objid):
|
283 |
|
|
|
284 |
# We may get called from search, on the top dir (above [folders]). Return
|
287 |
# We may get called from search, on the top dir (above [folders]). Return
|
285 |
# empty in this case
|
288 |
# empty in this case
|
286 |
try:
|
289 |
try:
|
287 |
diridx = _objidtodiridx(objid)
|
290 |
diridx = _objidtodiridx(objid)
|
288 |
except:
|
291 |
except:
|