|
a/src/mediaserver/cdplugins/uprcl/uprclinit.py |
|
b/src/mediaserver/cdplugins/uprcl/uprclinit.py |
|
... |
|
... |
22 |
import subprocess
|
22 |
import subprocess
|
23 |
import time
|
23 |
import time
|
24 |
from timeit import default_timer as timer
|
24 |
from timeit import default_timer as timer
|
25 |
|
25 |
|
26 |
from rwlock import ReadWriteLock
|
26 |
from rwlock import ReadWriteLock
|
27 |
import uprclfolders
|
27 |
|
28 |
import uprcltags
|
28 |
from uprclfolders import Folders
|
29 |
import uprcluntagged
|
29 |
from uprcluntagged import Untagged
|
|
|
30 |
from uprcltags import Tagged
|
30 |
import uprclsearch
|
31 |
import uprclsearch
|
31 |
import uprclindex
|
32 |
import uprclindex
|
32 |
from uprclhttp import runbottle
|
33 |
from uprclhttp import runbottle
|
33 |
|
34 |
|
34 |
from upmplgutils import uplog
|
35 |
from upmplgutils import uplog
|
35 |
from uprclutils import findmyip, stringToStrings
|
36 |
from uprclutils import findmyip, stringToStrings
|
36 |
|
37 |
|
|
|
38 |
# Once initialization (not on imports)
|
37 |
try:
|
39 |
try:
|
38 |
_s = g_httphp
|
40 |
_s = g_httphp
|
39 |
except:
|
41 |
except:
|
40 |
# The recoll documents
|
42 |
# The recoll documents
|
41 |
g_rcldocs = []
|
|
|
42 |
g_pathprefix = ""
|
43 |
g_pathprefix = ""
|
43 |
g_httphp = ""
|
44 |
g_httphp = ""
|
44 |
g_dblock = ReadWriteLock()
|
45 |
g_dblock = ReadWriteLock()
|
45 |
g_rclconfdir = ""
|
46 |
g_rclconfdir = ""
|
46 |
g_friendlyname = "UpMpd-mediaserver"
|
47 |
g_friendlyname = "UpMpd-mediaserver"
|
47 |
|
48 |
g_trees = {}
|
|
|
49 |
|
48 |
# Create or update Recoll index, then read and process the data.
|
50 |
# Create or update Recoll index, then read and process the data. This
|
|
|
51 |
# runs in the separate uprcl_init_worker thread, and signals
|
|
|
52 |
# startup/completion by setting/unsetting the g_initrunning flag
|
49 |
def _update_index():
|
53 |
def _update_index():
|
50 |
uplog("Creating/updating index in %s for %s" % (g_rclconfdir, g_rcltopdirs))
|
54 |
uplog("Creating/updating index in %s for %s" % (g_rclconfdir, g_rcltopdirs))
|
51 |
|
55 |
|
52 |
# We take the writer lock, making sure that no browse/search
|
56 |
# We take the writer lock, making sure that no browse/search
|
53 |
# thread are active, then set the busy flag and release the
|
57 |
# thread are active, then set the busy flag and release the
|
54 |
# lock. This allows future browse operations to signal the
|
58 |
# lock. This allows future browse operations to signal the
|
55 |
# condition to the user instead of blocking (if we kept the write
|
59 |
# condition to the user instead of blocking (if we kept the write
|
56 |
# lock).
|
60 |
# lock).
|
57 |
global g_initrunning
|
61 |
global g_initrunning, g_trees
|
58 |
g_dblock.acquire_write()
|
62 |
g_dblock.acquire_write()
|
59 |
g_initrunning = True
|
63 |
g_initrunning = True
|
60 |
g_dblock.release_write()
|
64 |
g_dblock.release_write()
|
61 |
uplog("_update_index: initrunning set")
|
65 |
uplog("_update_index: initrunning set")
|
62 |
|
66 |
|
|
... |
|
... |
67 |
while not uprclindex.indexerdone():
|
71 |
while not uprclindex.indexerdone():
|
68 |
time.sleep(.5)
|
72 |
time.sleep(.5)
|
69 |
fin = timer()
|
73 |
fin = timer()
|
70 |
uplog("Indexing took %.2f Seconds" % (fin - start))
|
74 |
uplog("Indexing took %.2f Seconds" % (fin - start))
|
71 |
|
75 |
|
72 |
global g_rcldocs
|
|
|
73 |
g_rcldocs = uprclfolders.inittree(g_rclconfdir, g_httphp, g_pathprefix)
|
76 |
folders = Folders(g_rclconfdir, g_httphp, g_pathprefix)
|
74 |
uprcltags.recolltosql(g_rcldocs)
|
77 |
untagged = Untagged(folders.rcldocs(), g_httphp, g_pathprefix)
|
75 |
uprcluntagged.recoll2untagged(g_rcldocs)
|
78 |
tagged = Tagged(folders.rcldocs(), g_httphp, g_pathprefix)
|
|
|
79 |
newtrees = {}
|
|
|
80 |
newtrees['folders'] = folders
|
|
|
81 |
newtrees['untagged'] = untagged
|
|
|
82 |
newtrees['tags'] = tagged
|
|
|
83 |
g_trees = newtrees
|
76 |
finally:
|
84 |
finally:
|
77 |
g_dblock.acquire_write()
|
85 |
g_dblock.acquire_write()
|
78 |
g_initrunning = False
|
86 |
g_initrunning = False
|
79 |
g_dblock.release_write()
|
87 |
g_dblock.release_write()
|
80 |
|
88 |
|