forked from M-Labs/artiq
master: handle logging while scanning repository
This commit is contained in:
parent
aa2acb9137
commit
3a06e22b67
|
@ -69,7 +69,7 @@ def main():
|
||||||
scheduler.start()
|
scheduler.start()
|
||||||
atexit.register(lambda: loop.run_until_complete(scheduler.stop()))
|
atexit.register(lambda: loop.run_until_complete(scheduler.stop()))
|
||||||
|
|
||||||
repository = Repository()
|
repository = Repository(log.log)
|
||||||
repository.scan_async()
|
repository.scan_async()
|
||||||
|
|
||||||
server_control = Server({
|
server_control = Server({
|
||||||
|
|
|
@ -10,13 +10,13 @@ logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def _scan_experiments():
|
def _scan_experiments(log):
|
||||||
r = dict()
|
r = dict()
|
||||||
for f in os.listdir("repository"):
|
for f in os.listdir("repository"):
|
||||||
if f.endswith(".py"):
|
if f.endswith(".py"):
|
||||||
try:
|
try:
|
||||||
full_name = os.path.join("repository", f)
|
full_name = os.path.join("repository", f)
|
||||||
worker = Worker()
|
worker = Worker({"log": lambda message: log("scan", message)})
|
||||||
try:
|
try:
|
||||||
description = yield from worker.examine(full_name)
|
description = yield from worker.examine(full_name)
|
||||||
finally:
|
finally:
|
||||||
|
@ -52,16 +52,17 @@ def _sync_explist(target, source):
|
||||||
|
|
||||||
|
|
||||||
class Repository:
|
class Repository:
|
||||||
def __init__(self):
|
def __init__(self, log_fn):
|
||||||
self.explist = Notifier(dict())
|
self.explist = Notifier(dict())
|
||||||
self._scanning = False
|
self._scanning = False
|
||||||
|
self.log_fn = log_fn
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def scan(self):
|
def scan(self):
|
||||||
if self._scanning:
|
if self._scanning:
|
||||||
return
|
return
|
||||||
self._scanning = True
|
self._scanning = True
|
||||||
new_explist = yield from _scan_experiments()
|
new_explist = yield from _scan_experiments(self.log_fn)
|
||||||
_sync_explist(self.explist, new_explist)
|
_sync_explist(self.explist, new_explist)
|
||||||
self._scanning = False
|
self._scanning = False
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue