def __init__(self, userdata, db=None): assert not running('Zotero'), 'Zotero is running' self.timeout = 60 if os.path.exists(EXPORTED): shutil.rmtree(EXPORTED) os.makedirs(EXPORTED) self.userdata = userdata self.password = str(uuid.uuid4()) self.id = self.userdata.get('zotero', 'zotero') if self.id == 'zotero': self.port = 23119 elif self.id == 'jurism': self.port = 24119 else: raise ValueError(f'Unexpected client "{self.userdata.zotero}"') self.zotero = self.id == 'zotero' self.jurism = self.id == 'jurism' with open(os.path.join(ROOT, 'gen/translators.json')) as f: self.translators = json.load(f, object_hook=Munch) if self.userdata.get('kill', 'true') == 'true': atexit.register(self.shutdown) self.preferences = Preferences(self) self.start(db)
def __init__(self, userdata): assert not running('Zotero'), 'Zotero is running' self.userdata = userdata self.password = str(uuid.uuid4()) self.id = self.userdata.get('zotero', 'zotero') if self.id == 'zotero': self.port = 23119 elif self.id == 'jurism': self.port = 24119 else: raise ValueError(f'Unexpected client "{self.userdata.zotero}"') self.zotero = self.id == 'zotero' self.jurism = self.id == 'jurism' self.timeout = int(self.userdata.get('timeout', 60)) with open(os.path.join(ROOT, 'gen/translators.json')) as f: self.translators = json.load(f, object_hook=Munch) if self.userdata.get('kill', 'true') == 'true': atexit.register(self.shutdown) self.start()
def __init__(self, userdata): assert not running('Zotero'), 'Zotero is running' self.fixtures_loaded = set() self.fixtures_loaded_log = userdata.get('loaded') self.client = userdata.get('client', 'zotero') self.beta = userdata.get('beta') == 'true' self.password = str(uuid.uuid4()) self.import_at_start = os.environ.get('ZOTERO_IMPORT', None) self.config = Config(userdata) self.proc = None if os.path.exists(EXPORTED): shutil.rmtree(EXPORTED) os.makedirs(EXPORTED) if self.client == 'zotero': self.port = 23119 elif self.client == 'jurism': self.port = 24119 else: raise ValueError(f'Unexpected client "{self.client}"') self.zotero = self.client == 'zotero' self.jurism = self.client == 'jurism' with open(os.path.join(ROOT, 'gen/translators.json')) as f: self.translators = json.load(f, object_hook=Munch) if userdata.get('kill', 'true') == 'true': atexit.register(self.shutdown) self.testing = userdata.get('testing', 'true') == 'true' if userdata.get('workers', 'true') == 'true': self.workers = 1 else: self.workers = 0 self.preferences = Preferences(self) self.redir = '>' self.start() self.redir = '>>'
def shutdown(self): if self.proc is None: return # graceful shutdown try: self.execute(""" const appStartup = Components.classes['@mozilla.org/toolkit/app-startup;1'].getService(Components.interfaces.nsIAppStartup); appStartup.quit(Components.interfaces.nsIAppStartup.eAttemptQuit); """) except: pass def on_terminate(proc): utils.print("process {} terminated with exit code {}".format( proc, proc.returncode)) zotero = psutil.Process(self.proc.pid) alive = zotero.children(recursive=True) alive.append(zotero) for p in alive: try: p.terminate() except psutil.NoSuchProcess: pass gone, alive = psutil.wait_procs(alive, timeout=5, callback=on_terminate) if alive: for p in alive: utils.print("process {} survived SIGTERM; trying SIGKILL" % p) try: p.kill() except psutil.NoSuchProcess: pass gone, alive = psutil.wait_procs(alive, timeout=5, callback=on_terminate) if alive: for p in alive: utils.print("process {} survived SIGKILL; giving up" % p) self.proc = None assert not running('Zotero')
def shutdown(self): if self.proc is None: return # graceful shutdown try: self.execute(""" const appStartup = Components.classes['@mozilla.org/toolkit/app-startup;1'].getService(Components.interfaces.nsIAppStartup); appStartup.quit(Components.interfaces.nsIAppStartup.eAttemptQuit); """) except: pass stopped = False for _ in redo.retrier(attempts=5, sleeptime=1): stopped = not running(self.proc.pid) if stopped: break zotero = psutil.Process(self.proc.pid) for proc in zotero.children(recursive=True): proc.kill() zotero.kill()
def shutdown(self): if self.proc is None: return # graceful shutdown try: self.execute(""" const appStartup = Components.classes['@mozilla.org/toolkit/app-startup;1'].getService(Components.interfaces.nsIAppStartup); appStartup.quit(Components.interfaces.nsIAppStartup.eAttemptQuit); """) except: pass stopped = False for _ in redo.retrier(attempts=5,sleeptime=1): stopped = not running(self.proc.pid) if stopped: break zotero = psutil.Process(self.proc.pid) for proc in zotero.children(recursive=True): proc.kill() zotero.kill()
def __init__(self, userdata): assert not running('Zotero'), 'Zotero is running' self.userdata = userdata self.id = self.userdata.get('zotero', 'zotero') if self.id == 'zotero': self.port = 23119 elif self.id == 'jurism': self.port = 24119 else: raise ValueError(f'Unexpected client "{self.userdata.zotero}"') self.zotero = self.id == 'zotero' self.jurism = self.id == 'jurism' self.timeout = int(self.userdata.get('timeout', 60)) with open(os.path.join(ROOT, 'gen/translators.json')) as f: self.translators = json.load(f, object_hook=Munch) if self.userdata.get('kill', 'true') == 'true': atexit.register(self.shutdown) self.start()