Parent: [33d283] (diff)

Child: [0a7d1e] (diff)

Download this file

uprcluntagged.py    95 lines (77 with data), 2.7 kB

 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
#
# Copyright (C) 2017 J.F.Dockes
#
# 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, either version 3 of the License, or
# (at your option) any later version.
#
# 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.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import os
import shlex
import urllib
import sys
from uprclutils import uplog, rcldoctoentry, rcldirentry, cmpentries
untg_prefix = '0$uprcl$untagged'
def recoll2untagged(docs):
global g_utidx, g_rcldocs
g_rcldocs = docs
g_utidx = [-1]
for docidx in range(len(docs)):
doc = docs[docidx]
if doc.mtype == 'inode/directory':
continue
url = doc.getbinurl()
url = url[7:]
try:
decoded = url.decode('utf-8')
except:
decoded = urllib.quote(url).decode('utf-8')
tt = doc.title
if not tt:
g_utidx.append(docidx)
def _objidtoidx(pid):
if not pid.startswith(untg_prefix):
raise Exception("untagged.browse: bad pid %s" % pid)
if len(g_rcldocs) == 0:
raise Exception("untagged:browse: no docs")
idx = pid[len(untg_prefix):]
if not idx:
idx = 0
else:
if idx[1] != 'u':
raise Exception("untagged:browse: called on bad objid %s" % pid)
idx = int(idx[2:])
if idx >= len(g_utidx):
raise Exception("untagged:browse: bad pid %s" % pid)
return idx
def rootentries(pid):
return [rcldirentry(pid + 'untagged', pid, '[untagged]'),]
# Browse method
# objid is like untagged$*u<index>
# flag is meta or children.
def browse(pid, flag, httphp, pathprefix):
idx = _objidtoidx(pid)
entries = []
if idx == 0:
# Browsing root
for i in range(len(g_utidx))[1:]:
doc = g_rcldocs[g_utidx[i]]
id = untg_prefix + '$u' + str(i)
e = rcldoctoentry(id, pid, httphp, pathprefix, doc)
if e:
entries.append(e)
else:
# Non root: only items in there. flag needs to be 'meta'
doc = g_rcldocs[thisdocidx]
id = untg_prefix + '$u' + str(idx)
e = rcldoctoentry(id, pid, httphp, pathprefix, doc)
if e:
entries.append(e)
return sorted(entries, cmp=cmpentries)