def cmd_margo_reinstall(view, edit, args, wd, rkey): def cb(): gs.del_attr(mg9._inst_name()) out = mg9.install('', True, True) gs.notify(DOMAIN, 'MarGo re-installed done') push_output(view, rkey, out) gsq.launch(DOMAIN, cb)
def _send(): while True: try: try: method, arg, cb = gs.mg9_send_q.get() proc = gs.attr(PROC_ATTR_NAME) if not proc or proc.poll() is not None: killSrv() maybe_install() if not gs.checked(DOMAIN, 'launch _recv'): gsq.launch(DOMAIN, _recv) proc, _, err = gsshell.proc([_margo_bin(), '-poll=30'], stderr=gs.LOGFILE ,env={ 'XDG_CONFIG_HOME': gs.home_path(), }) gs.set_attr(PROC_ATTR_NAME, proc) if not proc: gs.notice(DOMAIN, 'Cannot start MarGo: %s' % err) try: cb({}, 'Abort. Cannot start MarGo') except: pass continue gsq.launch(DOMAIN, lambda: _read_stdout(proc)) req = Request(f=cb, method=method) gs.set_attr(REQUEST_PREFIX+req.token, req) gs.debug(DOMAIN, 'margo request: method: %s, token: %s' % (req.method, req.token)) header, _ = gs.json_encode({'method': method, 'token': req.token}) body, _ = gs.json_encode(arg) ln = '%s %s\n' % (header, body) if gs.PY3K: proc.stdin.write(bytes(ln, 'UTF-8')) else: proc.stdin.write(ln) except Exception: killSrv() gs.println(gs.traceback()) except Exception: gs.println(gs.traceback()) break
def _send(): while True: try: try: method, arg, cb = gs.mg9_send_q.get() proc = gs.attr(PROC_ATTR_NAME) if not proc or proc.poll() is not None: killSrv() if _inst_state() != "busy": maybe_install() while _inst_state() == "busy": time.sleep(0.100) mg_bin = _margo_bin() cmd = [ mg_bin, '-oom', gs.setting('margo_oom', 0), '-poll', 30, '-tag', TAG, ] c = sh.Command(cmd) c.stderr = gs.LOGFILE c.env = { 'GOGC': 10, 'XDG_CONFIG_HOME': gs.home_path(), } pr = c.proc() if pr.ok: proc = pr.p err = '' else: proc = None err = 'Exception: %s' % pr.exc if err or not proc or proc.poll() is not None: killSrv() _call(cb, {}, 'Abort. Cannot start MarGo: %s' % err) continue gs.set_attr(PROC_ATTR_NAME, proc) gsq.launch(DOMAIN, lambda: _read_stdout(proc)) req = Request(f=cb, method=method) gs.set_attr(REQUEST_PREFIX+req.token, req) header, err = gs.json_encode(req.header()) if err: _cb_err(cb, 'Failed to construct ipc header: %s' % err) continue body, err = gs.json_encode(arg) if err: _cb_err(cb, 'Failed to construct ipc body: %s' % err) continue ev.debug(DOMAIN, 'margo request: %s ' % header) ln = '%s %s\n' % (header, body) try: if gs.PY3K: proc.stdin.write(bytes(ln, 'UTF-8')) else: proc.stdin.write(ln) except Exception as ex: _cb_err(cb, 'Cannot talk to MarGo: %s' % err) killSrv() gs.println(gs.traceback()) except Exception: killSrv() gs.println(gs.traceback()) except Exception: gs.println(gs.traceback()) break
pass try: p.stdin.close() except Exception: pass def on(token, cb): req = Request(f=cb, token=token) gs.set_attr(REQUEST_PREFIX+req.token, req) def _dump(res, err): gs.println(json.dumps({ 'res': res, 'err': err, }, sort_keys=True, indent=2)) if not gs.checked(DOMAIN, 'launch ipc threads'): gsq.launch(DOMAIN, _send) gsq.launch(DOMAIN, _recv) def on_mg_msg(res, err): msg = res.get('message', '') if msg: print('GoSublime: MarGo: %s' % msg) gs.notify('MarGo', msg) return True on('margo.message', on_mg_msg)
def _send(): while True: try: try: method, arg, cb = gs.mg9_send_q.get() proc = gs.attr(PROC_ATTR_NAME) if not proc or proc.poll() is not None: killSrv() if _inst_state() != "busy": maybe_install() while _inst_state() == "busy": time.sleep(0.100) mg_bin = _margo_bin() cmd = [ mg_bin, '-oom', gs.setting('margo_oom', 0), '-poll', 30, '-tag', TAG, ] c = sh.Command(cmd) c.stderr = gs.LOGFILE c.env = { 'GOGC': 10, 'XDG_CONFIG_HOME': gs.home_path(), } pr = c.proc() if pr.ok: proc = pr.p err = '' else: proc = None err = 'Exception: %s' % pr.exc if err or not proc or proc.poll() is not None: killSrv() _call(cb, {}, 'Abort. Cannot start MarGo: %s' % err) continue gs.set_attr(PROC_ATTR_NAME, proc) gsq.launch(DOMAIN, lambda: _read_stdout(proc)) req = Request(f=cb, method=method) gs.set_attr(REQUEST_PREFIX + req.token, req) header, err = gs.json_encode(req.header()) if err: _cb_err(cb, 'Failed to construct ipc header: %s' % err) continue body, err = gs.json_encode(arg) if err: _cb_err(cb, 'Failed to construct ipc body: %s' % err) continue ev.debug(DOMAIN, 'margo request: %s ' % header) ln = '%s %s\n' % (header, body) try: if gs.PY3K: proc.stdin.write(bytes(ln, 'UTF-8')) else: proc.stdin.write(ln) except Exception as ex: _cb_err(cb, 'Cannot talk to MarGo: %s' % err) killSrv() gs.println(gs.traceback()) except Exception: killSrv() gs.println(gs.traceback()) except Exception: gs.println(gs.traceback()) break
pass def on(token, cb): req = Request(f=cb, token=token) gs.set_attr(REQUEST_PREFIX + req.token, req) def _dump(res, err): gs.println(json.dumps({ 'res': res, 'err': err, }, sort_keys=True, indent=2)) if not gs.checked(DOMAIN, 'launch ipc threads'): gsq.launch(DOMAIN, _send) gsq.launch(DOMAIN, _recv) def on_mg_msg(res, err): msg = res.get('message', '') if msg: print('GoSublime: MarGo: %s' % msg) gs.notify('MarGo', msg) return True on('margo.message', on_mg_msg)
def _send(): while True: try: try: method, arg, cb = gs.mg9_send_q.get() proc = gs.attr(PROC_ATTR_NAME) if not proc or proc.poll() is not None: killSrv() if gs.attr(_inst_name(), '') != "busy": maybe_install() if not gs.checked(DOMAIN, 'launch _recv'): gsq.launch(DOMAIN, _recv) while gs.attr(_inst_name(), '') == "busy": time.sleep(0.100) mg_bin = _margo_bin() cmd = [ mg_bin, '-oom', gs.setting('margo_oom', 0), '-poll', 30, '-tag', TAG, ] if os.path.exists(mg_bin): proc, _, err = gsshell.proc(cmd, stderr=gs.LOGFILE ,env={ 'GOGC': 10, 'XDG_CONFIG_HOME': gs.home_path(), }) else: proc = None err = "Can't find the MarGo binary at `%s`" % mg_bin if err or not proc or proc.poll() is not None: killSrv() gs.notice(DOMAIN, 'Cannot start MarGo:\n%s' % err) try: cb({}, 'Abort. Cannot start MarGo') except: pass continue gs.set_attr(PROC_ATTR_NAME, proc) gsq.launch(DOMAIN, lambda: _read_stdout(proc)) req = Request(f=cb, method=method) gs.set_attr(REQUEST_PREFIX+req.token, req) header, err = gs.json_encode(req.header()) if err: _cb_err(cb, 'Failed to construct ipc header: %s' % err) continue body, err = gs.json_encode(arg) if err: _cb_err(cb, 'Failed to construct ipc body: %s' % err) continue ev.debug(DOMAIN, 'margo request: %s ' % header) ln = '%s %s\n' % (header, body) try: if gs.PY3K: proc.stdin.write(bytes(ln, 'UTF-8')) else: proc.stdin.write(ln) except Exception as ex: _cb_err(cb, 'Cannot talk to MarGo: %s' % err) killSrv() gs.println(gs.traceback()) except Exception: killSrv() gs.println(gs.traceback()) except Exception: gs.println(gs.traceback()) break
def acall(method, arg, cb): if not gs.checked(DOMAIN, 'launch _send'): gsq.launch(DOMAIN, _send) gs.mg9_send_q.put((method, arg, cb))
def _send(): while True: try: try: method, arg, cb = gs.mg9_send_q.get() proc = gs.attr(PROC_ATTR_NAME) if not proc or proc.poll() is not None: killSrv() if gs.attr(INSTALL_ATTR_NAME) != "busy": maybe_install() if not gs.checked(DOMAIN, 'launch _recv'): gsq.launch(DOMAIN, _recv) while gs.attr(INSTALL_ATTR_NAME) == "busy": time.sleep(0.100) proc, _, err = gsshell.proc([_margo_bin(), '-poll', 30, '-tag', TAG], stderr=gs.LOGFILE ,env={ 'XDG_CONFIG_HOME': gs.home_path(), }) gs.set_attr(PROC_ATTR_NAME, proc) if not proc: gs.notice(DOMAIN, 'Cannot start MarGo: %s' % err) try: cb({}, 'Abort. Cannot start MarGo') except: pass continue gsq.launch(DOMAIN, lambda: _read_stdout(proc)) req = Request(f=cb, method=method) gs.set_attr(REQUEST_PREFIX+req.token, req) header, err = gs.json_encode(req.header()) if err: _cb_err('Failed to construct ipc header: ' % err) continue body, err = gs.json_encode(arg) if err: _cb_err(cb, 'Failed to construct ipc body: ' % err) continue gs.debug(DOMAIN, 'margo request: %s ' % header) ln = '%s %s\n' % (header, body) if gs.PY3K: proc.stdin.write(bytes(ln, 'UTF-8')) else: proc.stdin.write(ln) except Exception: killSrv() gs.println(gs.traceback()) except Exception: gs.println(gs.traceback()) break
def _send(): """Polls the mg9_send_q queue, sending requests to margo. If the margo process is not running _send() starts it and sets the PROC_ATTR_NAME attr. """ # TODO: REFACTOR. while True: try: try: method, arg, cb = gs.mg9_send_q.get() # CEV: proc should be the margo process. proc = gs.attr(PROC_ATTR_NAME) # CEV: Looks like this starts/restarts the margo process. if not proc or proc.poll() is not None: killSrv() if _inst_state() != "busy": maybe_install() # TODO: Improve the handling of install state. while _inst_state() == "busy": time.sleep(0.100) # Margo path and command line options. mg_bin = _margo_bin() cmd = [ mg_bin, "-oom", gs.setting("margo_oom", 0), "-poll", 30, "-tag", TAG, ] c = sh.Command(cmd) c.stderr = gs.LOGFILE c.env = {"GOGC": 10, "XDG_CONFIG_HOME": gs.home_path()} pr = c.proc() if pr.ok: proc = pr.p err = "" else: proc = None err = "Exception: %s" % pr.exc if err or not proc or proc.poll() is not None: killSrv() _call(cb, {}, "Abort. Cannot start MarGo: %s" % err) continue # Set the process name gs.set_attr(PROC_ATTR_NAME, proc) # Launch stdout feed. gsq.launch(DOMAIN, lambda: _read_stdout(proc)) req = Request(f=cb, method=method) gs.set_attr(REQUEST_PREFIX + req.token, req) header, err = gs.json_encode(req.header()) if err: _cb_err(cb, "Failed to construct ipc header: %s" % err) continue body, err = gs.json_encode(arg) if err: _cb_err(cb, "Failed to construct ipc body: %s" % err) continue ev.debug(DOMAIN, "margo request: %s " % header) ln = "%s %s\n" % (header, body) try: if gs.PY3K: proc.stdin.write(bytes(ln, "UTF-8")) else: proc.stdin.write(ln) except Exception as ex: _cb_err(cb, "Cannot talk to MarGo: %s" % err) killSrv() gs.println(gs.traceback()) except Exception: killSrv() gs.println(gs.traceback()) except Exception: gs.println(gs.traceback()) break
def _send(): while True: try: try: method, arg, cb = gs.mg9_send_q.get() proc = gs.attr(PROC_ATTR_NAME) if not proc or proc.poll() is not None: killSrv() if gs.attr(_inst_name(), "") != "busy": maybe_install() if not gs.checked(DOMAIN, "launch _recv"): gsq.launch(DOMAIN, _recv) while gs.attr(_inst_name(), "") == "busy": time.sleep(0.100) mg_bin = _margo_bin() cmd = [mg_bin, "-oom", gs.setting("margo_oom", 0), "-poll", 30, "-tag", TAG] if os.path.exists(mg_bin): c = sh.Command(cmd) c.stderr = gs.LOGFILE c.env = {"GOGC": 10, "XDG_CONFIG_HOME": gs.home_path()} pr = c.proc() if pr.ok: proc = pr.p err = "" else: proc = None err = "Cannot start MarGo: %s" % pr.exc else: proc = None err = "Can't find the MarGo binary at `%s`" % mg_bin if err or not proc or proc.poll() is not None: killSrv() gs.notice(DOMAIN, "Cannot start MarGo:\n%s" % err) try: cb({}, "Abort. Cannot start MarGo") except: pass continue gs.set_attr(PROC_ATTR_NAME, proc) gsq.launch(DOMAIN, lambda: _read_stdout(proc)) req = Request(f=cb, method=method) gs.set_attr(REQUEST_PREFIX + req.token, req) header, err = gs.json_encode(req.header()) if err: _cb_err(cb, "Failed to construct ipc header: %s" % err) continue body, err = gs.json_encode(arg) if err: _cb_err(cb, "Failed to construct ipc body: %s" % err) continue ev.debug(DOMAIN, "margo request: %s " % header) ln = "%s %s\n" % (header, body) try: if gs.PY3K: proc.stdin.write(bytes(ln, "UTF-8")) else: proc.stdin.write(ln) except Exception as ex: _cb_err(cb, "Cannot talk to MarGo: %s" % err) killSrv() gs.println(gs.traceback()) except Exception: killSrv() gs.println(gs.traceback()) except Exception: gs.println(gs.traceback()) break
def _send(): while True: try: try: method, arg, cb = gs.mg9_send_q.get() proc = gs.attr(PROC_ATTR_NAME) if not proc or proc.poll() is not None: killSrv() if gs.attr(INSTALL_ATTR_NAME) != "busy": maybe_install() if not gs.checked(DOMAIN, 'launch _recv'): gsq.launch(DOMAIN, _recv) while gs.attr(INSTALL_ATTR_NAME) == "busy": time.sleep(0.100) proc, _, err = gsshell.proc( [_margo_bin(), '-poll', 30, '-tag', TAG], stderr=gs.LOGFILE, env={ 'XDG_CONFIG_HOME': gs.home_path(), }) gs.set_attr(PROC_ATTR_NAME, proc) if not proc: gs.notice(DOMAIN, 'Cannot start MarGo: %s' % err) try: cb({}, 'Abort. Cannot start MarGo') except: pass continue gsq.launch(DOMAIN, lambda: _read_stdout(proc)) req = Request(f=cb, method=method) gs.set_attr(REQUEST_PREFIX + req.token, req) header, err = gs.json_encode(req.header()) if err: _cb_err('Failed to construct ipc header: ' % err) continue body, err = gs.json_encode(arg) if err: _cb_err(cb, 'Failed to construct ipc body: ' % err) continue gs.debug(DOMAIN, 'margo request: %s ' % header) ln = '%s %s\n' % (header, body) if gs.PY3K: proc.stdin.write(bytes(ln, 'UTF-8')) else: proc.stdin.write(ln) except Exception: killSrv() gs.println(gs.traceback()) except Exception: gs.println(gs.traceback()) break