def oracle(self, end_offset, begin_offset=None, mode="plain", scope=""): """ Builds the oracle shell command and calls it, returning it's output as a string. """ file_path = self.view.file_name() output_format = "plain" pos = "#" + str(end_offset) if begin_offset is not None: pos = "#%i,#%i" % (begin_offset, end_offset) oracle = sh.which("oracle") if oracle: args = [ "-pos=" + file_path + ":" + pos, "-format=" + output_format, mode ] if scope: args.append(scope) shcmd = gs.lst(oracle, args) print(" ".join(shcmd)) cmd = sh.Command(shcmd) cr = cmd.run() if cr.exc: _print('error loading env vars: %s' % cr.exc) return cr.out, cr.err return
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
def install(aso_install_vesion, force_install, _reinstall=False): global INSTALL_EXE if not _reinstall and _inst_state() != "": gs.notify( DOMAIN, 'Installation aborted. Install command already called for GoSublime %s.' % INSTALL_VERSION) return '' INSTALL_EXE = INSTALL_EXE.replace('_%s.exe' % about.DEFAULT_GO_VERSION, '_%s.exe' % sh.GO_VERSION) about.MARGO_EXE = INSTALL_EXE is_update = about.VERSION != INSTALL_VERSION gs.set_attr(_inst_name(), 'busy') init_start = time.time() if not _reinstall and not is_update and not force_install and _bins_exist( ) and aso_install_vesion == INSTALL_VERSION: m_out = 'no' else: gs.notify('GoSublime', 'Installing MarGo') start = time.time() cmd = sh.Command([ 'go', 'build', '-tags', 'gosublime' if ext_main_file() else '', '-v', '-o', INSTALL_EXE, 'gosublime/cmd/margo', ]) cmd.wd = gs.home_dir_path('bin') cmd.env = { 'CGO_ENABLED': '0', 'GOBIN': '', 'GOPATH': install_gopath(), } ev.debug('%s.build' % DOMAIN, { 'cmd': cmd.cmd_lst, 'cwd': cmd.wd, }) cr = cmd.run() m_out = 'cmd: `%s`\nstdout: `\n%s\n`\nstderr: `\n%s\n`\nexception: `%s`' % ( cr.cmd_lst, cr.out.strip(), cr.err.strip(), cr.exc, ) if cr.ok and _bins_exist(): def f(): gs.aso().set('install_version', INSTALL_VERSION) gs.save_aso() sublime.set_timeout(f, 0) else: err_prefix = 'MarGo build failed' gs.error(DOMAIN, '%s\n%s' % (err_prefix, m_out)) sl = [('GoSublime error', '\n'.join(( err_prefix, 'This is possibly a bug or miss-configuration of your environment.', 'For more help, please file an issue with the following build output', 'at: https://github.com/DisposaBoy/GoSublime/issues/new', 'or alternatively, you may send an email to: [email protected]', '\n', m_out, )))] sl.extend(sanity_check({}, False)) gs.show_output('GoSublime', '\n'.join(sanity_check_sl(sl))) gs.set_attr(_inst_name(), 'done') if is_update: gs.show_output( 'GoSublime-source', '\n'.join([ 'GoSublime source has been updated.', 'New version: `%s`, current version: `%s`' % (INSTALL_VERSION, about.VERSION), 'Please restart Sublime Text to complete the update.', ])) else: e = sh.env() a = [ 'GoSublime init %s (%0.3fs)' % (INSTALL_VERSION, time.time() - init_start), ] sl = [('install margo', m_out)] sl.extend(sanity_check(e)) a.extend(sanity_check_sl(sl)) gs.println(*a) missing = [k for k in ('GOROOT', 'GOPATH') if not e.get(k)] if missing: missing_message = '\n'.join([ 'Missing required environment variables: %s' % ' '.join(missing), 'See the `Quirks` section of USAGE.md for info', ]) cb = lambda ok: gs.show_output( DOMAIN, missing_message, merge_domain=True, print_output=False) gs.error(DOMAIN, missing_message) gs.focus(gs.dist_path('USAGE.md'), focus_pat='^Quirks', cb=cb) killSrv() start = time.time() # acall('ping', {}, lambda res, err: gs.println('MarGo Ready %0.3fs' % (time.time() - start))) report_x = lambda: gs.println( "GoSublime: Exception while cleaning up old binaries", gs.traceback()) try: bin_dirs = [ gs.home_path('bin'), ] l = [] for d in bin_dirs: try: for fn in os.listdir(d): if fn != INSTALL_EXE and about.MARGO_EXE_PAT.match(fn): l.append(os.path.join(d, fn)) except Exception: pass for fn in l: try: gs.println("GoSublime: removing old binary: `%s'" % fn) os.remove(fn) except Exception: report_x() except Exception: report_x() return m_out