Switch to unified view

a/src/mediaserver/cdplugins/uprcl/uprclfolders.py b/src/mediaserver/cdplugins/uprcl/uprclfolders.py
...
...
25
from recoll import rclconfig
25
from recoll import rclconfig
26
26
27
g_myprefix = '0$uprcl$folders'
27
g_myprefix = '0$uprcl$folders'
28
28
29
# Debug : limit processed recoll entries for speed
29
# Debug : limit processed recoll entries for speed
30
g_maxrecollcnt = 5000
30
g_maxrecollcnt = 0
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
...
...
49
    dirvec.append({})
49
    dirvec.append({})
50
    dirvec[fathidx][nm] = (len(dirvec) - 1, docidx)
50
    dirvec[fathidx][nm] = (len(dirvec) - 1, docidx)
51
    dirvec[-1][".."] = (fathidx, -1)
51
    dirvec[-1][".."] = (fathidx, -1)
52
    return len(dirvec) - 1
52
    return len(dirvec) - 1
53
53
54
def _rcl2folders(docs, confdir):
54
def _rcl2folders(docs, confdir, httphp, pathprefix):
55
    global dirvec
55
    global dirvec
56
    dirvec = []
56
    dirvec = []
57
57
58
    rclconf = rclconfig.RclConfig(confdir)
58
    rclconf = rclconfig.RclConfig(confdir)
59
    topdirs = [os.path.expanduser(d) for d in
59
    topdirs = [os.path.expanduser(d) for d in
...
...
70
    # Walk the doc list and update the directory tree according to the
70
    # Walk the doc list and update the directory tree according to the
71
    # url (create intermediary directories if needed, create leaf
71
    # url (create intermediary directories if needed, create leaf
72
    # entry
72
    # entry
73
    for docidx in range(len(docs)):
73
    for docidx in range(len(docs)):
74
        doc = docs[docidx]
74
        doc = docs[docidx]
75
75
            
76
        # No need to include non-audio types in the visible
76
        # No need to include non-audio types in the visible tree.
77
        # tree.
78
        # TBD: We'll have to do some processing on image types though
79
        # (will go before these lines)
80
        if doc.mtype not in audiomtypes:
77
        if doc.mtype not in audiomtypes:
81
            continue
78
            continue
79
80
        if doc.mtype != 'inode/directory':
81
            arturi = docarturi(doc, httphp, pathprefix)
82
            if arturi:
83
                # The uri is quoted, so it's ascii and we can just store
84
                # it as a doc attribute
85
                doc.albumarturi = arturi
82
86
83
        url = doc.getbinurl()
87
        url = doc.getbinurl()
84
        url = url[7:]
88
        url = url[7:]
85
        try:
89
        try:
86
            decoded = url.decode('utf-8')
90
            decoded = url.decode('utf-8')
...
...
120
            if elt in dirvec[fathidx]:
124
            if elt in dirvec[fathidx]:
121
                # This path element was already seen
125
                # This path element was already seen
122
                # If this is the last entry in the path, maybe update
126
                # If this is the last entry in the path, maybe update
123
                # the doc idx (previous entries were created for
127
                # the doc idx (previous entries were created for
124
                # intermediate elements without a Doc).
128
                # intermediate elements without a Doc).
125
                #uplog("NEED TO UPDATE DOC")
129
                if idx == len(path) -1:
126
                dirvec[fathidx][elt] = (dirvec[fathidx][elt][0], docidx)
130
                    dirvec[fathidx][elt] = (dirvec[fathidx][elt][0], docidx)
127
                # Update fathidx for next iteration
131
                # Update fathidx for next iteration
128
                fathidx = dirvec[fathidx][elt][0]
132
                fathidx = dirvec[fathidx][elt][0]
129
            else:
133
            else:
130
                # Element has no entry in father directory (hence no
134
                # Element has no entry in father directory (hence no
131
                # dirvec entry either).
135
                # dirvec entry either).
...
...
170
    uplog("Retrieved %d docs" % (totcnt,))
174
    uplog("Retrieved %d docs" % (totcnt,))
171
    return allthedocs
175
    return allthedocs
172
176
173
177
174
# Initialize (read recoll data and build tree)
178
# Initialize (read recoll data and build tree)
175
def inittree(confdir):
179
def inittree(confdir, httphp, pathprefix):
176
    global g_alldocs, g_dirvec
180
    global g_alldocs, g_dirvec
177
    
181
    
178
    g_alldocs = _fetchalldocs(confdir)
182
    g_alldocs = _fetchalldocs(confdir)
179
    g_dirvec = _rcl2folders(g_alldocs, confdir)
183
    g_dirvec = _rcl2folders(g_alldocs, confdir, httphp, pathprefix)
180
    return g_alldocs
184
    return g_alldocs
181
185
186
187
188
##############
189
# Browsing the initialized [folders] hierarchy
190
191
192
# Extract dirvec index from objid, according to the way we generate them.
182
def _objidtodiridx(pid):
193
def _objidtodiridx(pid):
183
    if not pid.startswith(g_myprefix):
194
    if not pid.startswith(g_myprefix):
184
        raise Exception("folders.browse: bad pid %s" % pid)
195
        raise Exception("folders.browse: bad pid %s" % pid)
185
196
186
    if len(g_alldocs) == 0:
197
    if len(g_alldocs) == 0:
...
...
197
    if diridx >= len(g_dirvec):
208
    if diridx >= len(g_dirvec):
198
        raise Exception("folders:browse: bad pid %s" % pid)
209
        raise Exception("folders:browse: bad pid %s" % pid)
199
210
200
    return diridx
211
    return diridx
201
212
213
202
def rootentries(pid):
214
def rootentries(pid):
203
    return [rcldirentry(pid + 'folders', pid, '[folders]'),]
215
    return [rcldirentry(pid + 'folders', pid, '[folders]'),]
216
217
218
# Look all docs inside directory, and return the cover art we find.
219
def arturifordir(diridx):
220
    for nm,ids in g_dirvec[diridx].iteritems():
221
        if ids[1] >= 0:
222
            doc = g_alldocs[ids[1]]
223
            if doc.mtype != 'inode/directory' and doc.albumarturi:
224
                return doc.albumarturi
225
              
204
226
205
# Browse method
227
# Browse method
206
# objid is like folders$index
228
# objid is like folders$index
207
# flag is meta or children. 
229
# flag is meta or children. 
208
def browse(pid, flag, httphp, pathprefix):
230
def browse(pid, flag, httphp, pathprefix):
...
...
228
        if thisdiridx >= 0:
250
        if thisdiridx >= 0:
229
            # Skip empty directories
251
            # Skip empty directories
230
            if len(dirvec[thisdiridx]) == 1:
252
            if len(dirvec[thisdiridx]) == 1:
231
                continue
253
                continue
232
            id = g_myprefix + '$' + 'd' + str(thisdiridx)
254
            id = g_myprefix + '$' + 'd' + str(thisdiridx)
255
            arturi = arturifordir(thisdiridx)
233
            entries.append(rcldirentry(id, pid, os.path.basename(nm)))
256
            entries.append(rcldirentry(id, pid, os.path.basename(nm),
257
                                       arturi=arturi))
234
        else:
258
        else:
235
            # Not a directory. docidx had better been set
259
            # Not a directory. docidx had better been set
236
            if thisdocidx == -1:
260
            if thisdocidx == -1:
237
                uplog("folders:docidx -1 for non-dir entry %s"%nm)
261
                uplog("folders:docidx -1 for non-dir entry %s"%nm)
238
                continue
262
                continue