|
a/src/mediaserver/cdplugins/uprcl/uprclinit.py |
|
b/src/mediaserver/cdplugins/uprcl/uprclinit.py |
|
... |
|
... |
38 |
g_rcldocs = []
|
38 |
g_rcldocs = []
|
39 |
g_pathprefix = ""
|
39 |
g_pathprefix = ""
|
40 |
g_httphp = ""
|
40 |
g_httphp = ""
|
41 |
g_dblock = ReadWriteLock()
|
41 |
g_dblock = ReadWriteLock()
|
42 |
g_rclconfdir = ""
|
42 |
g_rclconfdir = ""
|
|
|
43 |
g_friendlyname = "UpMpd-mediaserver"
|
43 |
|
44 |
|
44 |
# Create or update Recoll index, then read and process the data.
|
45 |
# Create or update Recoll index, then read and process the data.
|
45 |
def _update_index():
|
46 |
def _update_index():
|
46 |
uplog("Creating/updating index in %s for %s" % (g_rclconfdir, g_rcltopdirs))
|
47 |
uplog("Creating/updating index in %s for %s" % (g_rclconfdir, g_rcltopdirs))
|
47 |
|
48 |
|
|
... |
|
... |
52 |
# lock).
|
53 |
# lock).
|
53 |
global g_initrunning
|
54 |
global g_initrunning
|
54 |
g_dblock.acquire_write()
|
55 |
g_dblock.acquire_write()
|
55 |
g_initrunning = True
|
56 |
g_initrunning = True
|
56 |
g_dblock.release_write()
|
57 |
g_dblock.release_write()
|
57 |
|
58 |
uplog("_update_index: initrunning set")
|
|
|
59 |
|
|
|
60 |
try:
|
58 |
start = timer()
|
61 |
start = timer()
|
59 |
uprclindex.runindexer(g_rclconfdir, g_rcltopdirs)
|
62 |
uprclindex.runindexer(g_rclconfdir, g_rcltopdirs)
|
60 |
# Wait for indexer
|
63 |
# Wait for indexer
|
61 |
while not uprclindex.indexerdone():
|
64 |
while not uprclindex.indexerdone():
|
62 |
time.sleep(.5)
|
65 |
time.sleep(.5)
|
63 |
fin = timer()
|
66 |
fin = timer()
|
64 |
uplog("Indexing took %.2f Seconds" % (fin - start))
|
67 |
uplog("Indexing took %.2f Seconds" % (fin - start))
|
65 |
|
68 |
|
66 |
global g_rcldocs
|
69 |
global g_rcldocs
|
67 |
g_rcldocs = uprclfolders.inittree(g_rclconfdir, g_httphp, g_pathprefix)
|
70 |
g_rcldocs = uprclfolders.inittree(g_rclconfdir, g_httphp, g_pathprefix)
|
68 |
uprcltags.recolltosql(g_rcldocs)
|
71 |
uprcltags.recolltosql(g_rcldocs)
|
69 |
uprcluntagged.recoll2untagged(g_rcldocs)
|
72 |
uprcluntagged.recoll2untagged(g_rcldocs)
|
70 |
|
73 |
finally:
|
71 |
g_dblock.acquire_write()
|
74 |
g_dblock.acquire_write()
|
72 |
g_initrunning = False
|
75 |
g_initrunning = False
|
73 |
g_dblock.release_write()
|
76 |
g_dblock.release_write()
|
74 |
|
77 |
|
75 |
|
78 |
|
76 |
# This runs in a thread because of the possibly long index initialization.
|
79 |
# This runs in a thread because of the possibly long index initialization.
|
77 |
def _uprcl_init_worker():
|
80 |
def _uprcl_init_worker():
|
78 |
|
81 |
|
|
... |
|
... |
87 |
raise Exception("No UPMPD_PATHPREFIX in environment")
|
90 |
raise Exception("No UPMPD_PATHPREFIX in environment")
|
88 |
g_pathprefix = os.environ["UPMPD_PATHPREFIX"]
|
91 |
g_pathprefix = os.environ["UPMPD_PATHPREFIX"]
|
89 |
if "UPMPD_CONFIG" not in os.environ:
|
92 |
if "UPMPD_CONFIG" not in os.environ:
|
90 |
raise Exception("No UPMPD_CONFIG in environment")
|
93 |
raise Exception("No UPMPD_CONFIG in environment")
|
91 |
upconfig = conftree.ConfSimple(os.environ["UPMPD_CONFIG"])
|
94 |
upconfig = conftree.ConfSimple(os.environ["UPMPD_CONFIG"])
|
|
|
95 |
|
|
|
96 |
global g_friendlyname
|
|
|
97 |
tmp = upconfig.get("friendlyname")
|
|
|
98 |
if tmp:
|
|
|
99 |
g_friendlyname = tmp + "-mediaserver"
|
92 |
|
100 |
|
93 |
global g_httphp
|
101 |
global g_httphp
|
94 |
g_httphp = upconfig.get("uprclhostport")
|
102 |
g_httphp = upconfig.get("uprclhostport")
|
95 |
if g_httphp is None:
|
103 |
if g_httphp is None:
|
96 |
ip = findmyip()
|
104 |
ip = findmyip()
|
|
... |
|
... |
180 |
if g_initrunning:
|
188 |
if g_initrunning:
|
181 |
return False
|
189 |
return False
|
182 |
else:
|
190 |
else:
|
183 |
return True
|
191 |
return True
|
184 |
|
192 |
|
|
|
193 |
def updaterunning():
|
|
|
194 |
return g_initrunning
|
|
|
195 |
|
185 |
def start_update():
|
196 |
def start_update():
|
|
|
197 |
try:
|
186 |
if not ready():
|
198 |
if not ready():
|
|
|
199 |
return
|
|
|
200 |
idxthread = threading.Thread(target=_update_index)
|
|
|
201 |
idxthread.daemon = True
|
|
|
202 |
finally:
|
|
|
203 |
# We need to release the reader lock before starting the index
|
|
|
204 |
# update operation (which needs a writer lock), so there is a
|
|
|
205 |
# small window for mischief. I would be concerned if this was
|
|
|
206 |
# a highly concurrent or critical app, but here, not so
|
|
|
207 |
# much...
|
187 |
g_dblock.release_read()
|
208 |
g_dblock.release_read()
|
188 |
return
|
|
|
189 |
idxthread = threading.Thread(target=_update_index)
|
|
|
190 |
idxthread.daemon = True
|
|
|
191 |
# We need to release the reader lock before starting the index
|
|
|
192 |
# update operation, so that there is a small window for
|
|
|
193 |
# mischief. I would be concerned if this was a highly concurrent
|
|
|
194 |
# or critical app, but here, not so much...
|
|
|
195 |
g_dblock.release_read()
|
|
|
196 |
idxthread.start()
|
209 |
idxthread.start()
|
197 |
|
210 |
|