def f(res, err): if err: gs.notify(DOMAIN, err) return decls = res.get('file_decls', []) for d in res.get('pkg_decls', []): if not vfn or d['fn'] != vfn: decls.append(d) for d in decls: dname = (d['repr'] or d['name']) trailer = [] trailer.extend(GOOS_PAT.findall(d['fn'])) trailer.extend(GOARCH_PAT.findall(d['fn'])) if trailer: trailer = ' (%s)' % ', '.join(trailer) else: trailer = '' d['ent'] = '%s %s%s' % (d['kind'], dname, trailer) ents = [] decls.sort(key=lambda d: d['ent']) for d in decls: ents.append(d['ent']) def cb(i, win): if i >= 0: d = decls[i] gs.focus(d['fn'], d['row'], d['col'], win) if ents: gs.show_quick_panel(ents, cb) else: gs.show_quick_panel([['', 'No declarations found']])
def act_on_path(view, path): if URL_PATH_PAT.match(path): if path.lower().startswith('gs.packages://'): path = os.path.join(sublime.packages_path(), path[14:]) else: try: if not URL_SCHEME_PAT.match(path): path = 'http://%s' % path gs.notify(DOMAIN, 'open url: %s' % path) webbrowser.open_new_tab(path) return True except Exception: gs.error_traceback(DOMAIN) return False wd = view.settings().get('9o.wd') or active_wd() m = SPLIT_FN_POS_PAT.match(path) path = gs.apath((m.group(1) if m else path), wd) row = max(0, int(m.group(2)) - 1 if (m and m.group(2)) else 0) col = max(0, int(m.group(3)) - 1 if (m and m.group(3)) else 0) if os.path.exists(path): gs.focus(path, row, col, win=view.window()) return True else: gs.notify(DOMAIN, "Invalid path `%s'" % path) return False
def on_mg_msg(res, err): msg = res.get('message', '') if msg: print('GoSublime: MarGo: %s' % msg) gs.notify('MarGo', msg) return True
def _install(maybe=False): if _inst_state() != "": return start = time.time() gs.set_attr(_inst_name(), 'busy') m_out = build_mg() gs.set_attr(_inst_name(), 'done') if m_out == 'ok': ev.margo_ready() gs.notify('GoSublime', 'ready') if maybe: return e = sh.env() a = [ 'GoSublime init %s (%0.3fs)' % (INSTALL_VERSION, time.time() - start), ] sl = [('install margo', m_out)] sl.extend(sanity_check(e)) a.extend(sanity_check_sl(sl)) gs.println(*a) _check_env(e) killSrv() _cleanup()
def act_on_path(view, path): is_vfn = gs.VFN_ID_PAT.match(path) row = 0 col = 0 if not is_vfn: if URL_PATH_PAT.match(path): if path.lower().startswith('gs.packages://'): path = os.path.join(sublime.packages_path(), path[14:]) else: try: if not URL_SCHEME_PAT.match(path): path = 'http://%s' % path gs.notify(DOMAIN, 'open url: %s' % path) webbrowser.open_new_tab(path) return True except Exception: gs.error_traceback(DOMAIN) return False wd = view.settings().get('9o.wd') or active_wd() m = SPLIT_FN_POS_PAT.match(path) path = gs.apath((m.group(1) if m else path), wd) row = max(0, int(m.group(2))-1 if (m and m.group(2)) else 0) col = max(0, int(m.group(3))-1 if (m and m.group(3)) else 0) if is_vfn or os.path.exists(path): gs.focus(path, row, col, win=view.window()) return True else: gs.notify(DOMAIN, "Invalid path `%s'" % path) return False
def f(res, err): if err: gs.notify(DOMAIN, err) return mats = {} args = {} decls = res.get('file_decls', []) decls.extend(res.get('pkg_decls', [])) for d in decls: name = d['name'] prefix, _ = match_prefix_name(name) if prefix and d['kind'] == 'func' and d['repr'] == '': mats[True] = prefix args[name] = name names = sorted(args.keys()) ents = ['Run all tests and examples'] for k in ['Test', 'Benchmark', 'Example']: if mats.get(k): s = 'Run %ss Only' % k ents.append(s) if k == 'Benchmark': args[s] = ['-test.run=none', '-test.bench="%s.*"' % k] else: args[s] = ['-test.run="%s.*"' % k] for k in names: ents.append(k) if k.startswith('Benchmark'): args[k] = ['-test.run=none', '-test.bench="^%s$"' % k] else: args[k] = ['-test.run=^%s$' % k] def cb(i, win): if i >= 0: a = args.get(ents[i], []) sargs = "" if len(a) > 0: sargs = a[0] # print sargs if debug: win.run_command('gdb_launch', { 'test': True, 'trun': sargs }) else: global g_builder g_builder = GoBuilder() g_builder.initEnv(True, sargs, self.window.active_view(), n_console_view) g_builder.run() gs.show_quick_panel(ents, cb)
def f(res, err): if err: gs.notify(DOMAIN, err) return mats = {} args = {} decls = res.get('file_decls', []) decls.extend(res.get('pkg_decls', [])) for d in decls: name = d['name'] prefix, _ = match_prefix_name(name) if prefix and d['kind'] == 'func' and d['repr'] == '': mats[True] = prefix args[name] = name names = sorted(args.keys()) ents = ['Run all tests and examples'] for k in ['Test', 'Benchmark', 'Example']: if mats.get(k): s = 'Run %ss Only' % k ents.append(s) if k == 'Benchmark': args[s] = ['-test.run=none', '-test.bench="%s.*"' % k] else: args[s] = ['-test.run="%s.*"' % k] for k in names: ents.append(k) if k.startswith('Benchmark'): args[k] = ['-test.run=none', '-test.bench="^%s$"' % k] else: args[k] = ['-test.run=^%s$' % k] def cb(i, win): if i >= 0: a = args.get(ents[i], []) sargs="" if len(a)>0: sargs=a[0] # print sargs if debug: win.run_command('gdb_launch', {'test':True,'trun':sargs}) else: global g_builder g_builder=GoBuilder() g_builder.initEnv(True,sargs,self.window.active_view(),n_console_view) g_builder.run() gs.show_quick_panel(ents, cb)
def f(res, err): if err: gs.notify('GsDeclarations', err) else: decls = res.get('file_decls', []) decls.sort(key=lambda v: v.get('row', 0)) added = 0 for i, v in enumerate(decls): loc = Loc(v['fn'], v['row'], v['col']) s = '%s %s' % (v['kind'], (v['repr'] or v['name'])) self.add_item(s, self.jump_to, (view, loc)) added += 1 if added < 1: self.add_item(['', 'No declarations found']) self.do_show_panel()
def f(res, err): if err: gs.notify("GsDeclarations", err) else: decls = res.get("file_decls", []) decls.sort(key=lambda v: v.get("row", 0)) added = 0 for i, v in enumerate(decls): loc = Loc(v["fn"], v["row"], v["col"]) s = "%s %s" % (v["kind"], (v["repr"] or v["name"])) self.add_item(s, self.jump_to, (view, loc)) added += 1 if added < 1: self.add_item(["", "No declarations found"]) self.do_show_panel()
def f(res, err): if err: gs.notify(DOMAIN, err) return mats = {} args = {} decls = res.get("file_decls", []) decls.extend(res.get("pkg_decls", [])) for d in decls: name = d["name"] prefix, _ = match_prefix_name(name) kind = d["kind"].lstrip("+- ") if prefix and kind == "func" and d["repr"] == "": mats[prefix] = True args[name] = name names = sorted(args.keys()) ents = ["Run all tests and examples"] for k in ["Test", "Benchmark", "Example"]: if mats.get(k): s = "Run %ss Only" % k ents.append(s) if k == "Benchmark": args[s] = ["-test.run=none", '-test.bench="%s.*"' % k] else: args[s] = ['-test.run="%s.*"' % k] for k in names: ents.append(k) if k.startswith("Benchmark"): args[k] = ["-test.run=none", '-test.bench="^%s$"' % k] else: args[k] = ['-test.run="^%s$"' % k] def cb(i, win): if i >= 0: a = args.get(ents[i], []) win.active_view().run_command( "gs9o_open", {"run": gs.lst("go", "test", a)} ) gs.show_quick_panel(ents, cb)
def f(res, err): if err: gs.notify(DOMAIN, err) return mats = {} args = {} decls = res.get('file_decls', []) decls.extend(res.get('pkg_decls', [])) for d in decls: name = d['name'] prefix, _ = match_prefix_name(name) kind = d['kind'].lstrip('+-~ ') if prefix and kind == 'func' and d['repr'] == '': mats[prefix] = True args[name] = name names = sorted(args.keys()) ents = ['Run all tests and examples'] for k in ['Test', 'Benchmark', 'Example']: if mats.get(k): s = 'Run %ss Only' % k ents.append(s) if k == 'Benchmark': args[s] = ['-test.run=none', '-test.bench="%s.*"' % k] else: args[s] = ['-test.run="%s.*"' % k] for k in names: ents.append(k) if k.startswith('Benchmark'): args[k] = ['-test.run=none', '-test.bench="^%s$"' % k] else: args[k] = ['-test.run="^%s$"' % k] def cb(i, win): if i >= 0: a = args.get(ents[i], []) win.active_view().run_command('gs9o_open', {'run': gs.lst('go', 'test', a)}) gs.show_quick_panel(ents, cb)
def f(res, err): if err: gs.notify(DOMAIN, err) return mats = {} args = {} decls = res.get('file_decls', []) decls.extend(res.get('pkg_decls', [])) for d in decls: name = d['name'] prefix, _ = match_prefix_name(name) if prefix and d['kind'] == 'func' and d['repr'] == '': mats[prefix] = True args[name] = name names = sorted(args.keys()) ents = ['Run all tests and examples'] for k in ['Test', 'Benchmark', 'Example']: if mats.get(k): s = 'Run %ss Only' % k ents.append(s) if k == 'Benchmark': args[s] = ['-test.run=none', '-test.bench="%s.*"' % k] else: args[s] = ['-test.run="%s.*"' % k] for k in names: ents.append(k) if k.startswith('Benchmark'): args[k] = ['-test.run=none', '-test.bench="^%s$"' % k] else: args[k] = ['-test.run="^%s$"' % k] def cb(i, win): if i >= 0: a = args.get(ents[i], []) win.active_view().run_command('gs9o_open', {'run': gs.lst('go', 'test', a)}) gs.show_quick_panel(ents, cb)
def act_on_path(view, path): row = 0 col = 0 m = gs.VFN_ID_PAT.match(path) if m: path = "gs.view://%s" % m.group(1) m2 = gs.ROWCOL_PAT.match(m.group(2)) if m2: row = int(m2.group(1)) - 1 if m2.group(1) else 0 col = int(m2.group(2)) - 1 if m2.group(2) else 0 else: if URL_PATH_PAT.match(path): if path.lower().startswith("gs.packages://"): path = os.path.join(gs.packages_dir(), path[14:]) else: try: if not URL_SCHEME_PAT.match(path): path = "http://%s" % path gs.notify(DOMAIN, "open url: %s" % path) webbrowser.open_new_tab(path) return True except Exception: gs.error_traceback(DOMAIN) return False wd = view.settings().get("9o.wd") or active_wd() m = SPLIT_FN_POS_PAT.match(path) path = gs.apath((m.group(1) if m else path), wd) row = max(0, int(m.group(2)) - 1 if (m and m.group(2)) else 0) col = max(0, int(m.group(3)) - 1 if (m and m.group(3)) else 0) if m or os.path.exists(path): gs.focus(path, row, col, win=view.window()) return True else: gs.notify(DOMAIN, "Invalid path `%s'" % path) return False
def run(self, edit): v = self.view sel = gs.sel(v) if (sel.end() - sel.begin()) == 0: pos = sel.begin() inscope = lambda p: v.score_selector(p, 'path.9o') > 0 if not inscope(pos): pos -= 1 if not inscope(pos): return r = v.extract_scope(pos) else: r = sel path = v.substr(r) if URL_PATH_PAT.match(path): if path.lower().startswith('gs.packages://'): path = os.path.join(sublime.packages_path(), path[14:]) else: try: if not URL_SCHEME_PAT.match(path): path = 'http://%s' % path gs.notify(DOMAIN, 'open url: %s' % path) webbrowser.open_new_tab(path) except Exception: gs.error_traceback(DOMAIN) return wd = v.settings().get('9o.wd') or active_wd() m = SPLIT_FN_POS_PAT.match(path) path = gs.apath((m.group(1) if m else path), wd) row = max(0, int(m.group(2)) - 1 if (m and m.group(2)) else 0) col = max(0, int(m.group(3)) - 1 if (m and m.group(3)) else 0) if os.path.exists(path): gs.focus(path, row, col, win=self.view.window()) else: gs.notify(DOMAIN, "Invalid path `%s'" % path)
def run(self, edit): v = self.view sel = gs.sel(v) if (sel.end() - sel.begin()) == 0: pos = sel.begin() inscope = lambda p: v.score_selector(p, 'path.9o') > 0 if not inscope(pos): pos -= 1 if not inscope(pos): return r = v.extract_scope(pos) else: r = sel path = v.substr(r) if URL_PATH_PAT.match(path): if path.lower().startswith('gs.packages://'): path = os.path.join(sublime.packages_path(), path[14:]) else: try: if not URL_SCHEME_PAT.match(path): path = 'http://%s' % path gs.notify(DOMAIN, 'open url: %s' % path) webbrowser.open_new_tab(path) except Exception: gs.error_traceback(DOMAIN) return wd = v.settings().get('9o.wd') or active_wd() m = SPLIT_FN_POS_PAT.match(path) path = gs.apath((m.group(1) if m else path), wd) row = max(0, int(m.group(2))-1 if (m and m.group(2)) else 0) col = max(0, int(m.group(3))-1 if (m and m.group(3)) else 0) if os.path.exists(path): gs.focus(path, row, col, win=self.view.window()) else: gs.notify(DOMAIN, "Invalid path `%s'" % path)
def install(aso_install_vesion, force_install): """Install GoSublime margo. """ global INSTALL_EXE if _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 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() # WARN (CEV): Hard coded GOPATH # gopath = gs.dist_path() + os.pathsep + "/Users/Charlie/go" gopath = gs.dist_path() + os.pathsep + sh.getenv("GOPATH") cmd = sh.Command( ["go", "build", "-v", "-x", "-o", INSTALL_EXE, "gosubli.me/margo"] ) cmd.wd = gs.home_dir_path("bin") cmd.env = {"CGO_ENABLED": "0", "GOBIN": "", "GOPATH": gopath} ev.debug("%s.build" % DOMAIN, {"cmd": cmd.cmd_lst, "cwd": cmd.wd}) cr = cmd.run() m_out = "cmd: `%s`\nstdout: `%s`\nstderr: `%s`\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()
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, 'disposa.blue/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
def install(aso_install_vesion, force_install): global INSTALL_EXE if gs.attr(_inst_name(), '') != "": gs.notify(DOMAIN, 'Installation aborted. Install command already called for GoSublime %s.' % INSTALL_VERSION) return _init_go_version() INSTALL_EXE = INSTALL_EXE.replace('_%s.exe' % about.DEFAULT_GO_VERSION, '_%s.exe' % 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 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() go_bin = _go_bin() if go_bin: cmd = [go_bin, 'build', '-o', _margo_bin(INSTALL_EXE)] cwd = _margo_src() ev.debug('%s.build' % DOMAIN, { 'cmd': cmd, 'cwd': cwd, }) m_out, err, _ = _run(cmd, cwd=cwd) else: m_out = '' err = 'Cannot find the `go` exe' m_out = gs.ustr(m_out) err = gs.ustr(err) m_out, m_ok = _so(m_out, err, start, time.time()) if m_ok: def f(): gs.aso().set('install_version', INSTALL_VERSION) gs.save_aso() sublime.set_timeout(f, 0) if not is_update: gs.notify('GoSublime', 'Syncing environment variables') out, err, _ = gsshell.run([INSTALL_EXE, '-env'], cwd=gs.home_dir_path(), shell=True) # notify this early so we don't mask any notices below gs.notify('GoSublime', 'Ready') if err: gs.notice(DOMAIN, 'Cannot run get env vars: %s' % (err)) else: env, err = gs.json_decode(out, {}) if err: gs.notice(DOMAIN, 'Cannot load env vars: %s\nenv output: %s' % (err, out)) else: gs.environ9.update(env) 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 = gs.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'), os.path.join(sublime.packages_path(), 'User', 'GoSublime', '9', '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()
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
def install(aso_install_vesion, force_install): global INSTALL_EXE if gs.attr(_inst_name(), "") != "": 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() err = "" if 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", "-v", "-x", "-o", _margo_bin(INSTALL_EXE)]) cmd.wd = _margo_src() cmd.env = {"GOBIN": "", "GOPATH": gs.dist_path("something_borrowed")} ev.debug("%s.build" % DOMAIN, {"cmd": cmd.cmd_lst, "cwd": cmd.wd}) cr = cmd.run() m_out = "cmd: `%s`\nstdout: `%s`\nstderr: `%s`" % (cr.cmd_lst, cr.out.strip(), cr.err.strip()) if not cr.ok: m_out = "%s\nexception: `%s`" % (m_out, cr.exc) err = "MarGo build failure\n%s" % m_out if not err and _bins_exist(): def f(): gs.aso().set("install_version", INSTALL_VERSION) gs.save_aso() sublime.set_timeout(f, 0) gs.set_attr(_inst_name(), "done") if err: gs.error(DOMAIN, err) else: # notify this early so we don't mask any notices below gs.notify("GoSublime", "Ready") 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"), os.path.join(sublime.packages_path(), "User", "GoSublime", "9", "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()
def install(aso_install_vesion, force_install): global INSTALL_EXE if gs.attr(_inst_name(), '') != "": gs.notify( DOMAIN, 'Installation aborted. Install command already called for GoSublime %s.' % INSTALL_VERSION) return _init_go_version() INSTALL_EXE = INSTALL_EXE.replace('_%s.exe' % about.DEFAULT_GO_VERSION, '_%s.exe' % 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 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() go_bin = _go_bin() if go_bin: cmd = [go_bin, 'build', '-o', _margo_bin(INSTALL_EXE)] cwd = _margo_src() ev.debug('%s.build' % DOMAIN, { 'cmd': cmd, 'cwd': cwd, }) m_out, err, _ = _run(cmd, cwd=cwd) else: m_out = '' err = 'Cannot find the `go` exe' m_out = gs.ustr(m_out) err = gs.ustr(err) m_out, m_ok = _so(m_out, err, start, time.time()) if m_ok: def f(): gs.aso().set('install_version', INSTALL_VERSION) gs.save_aso() sublime.set_timeout(f, 0) if not is_update: gs.notify('GoSublime', 'Syncing environment variables') out, err, _ = gsshell.run([INSTALL_EXE, '-env'], cwd=gs.home_dir_path(), shell=True) # notify this early so we don't mask any notices below gs.notify('GoSublime', 'Ready') if err: gs.notice(DOMAIN, 'Cannot run get env vars: %s' % (err)) else: env, err = gs.json_decode(out, {}) if err: gs.notice( DOMAIN, 'Cannot load env vars: %s\nenv output: %s' % (err, out)) else: gs.environ9.update(env) 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 = gs.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'), os.path.join(sublime.packages_path(), 'User', 'GoSublime', '9', '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()
def install(aso_install_vesion, force_install): if gs.attr(_inst_name(), '') != "": gs.notify(DOMAIN, 'Installation aborted. Install command already called for GoSublime %s.' % INSTALL_VERSION) return is_update = about.VERSION != INSTALL_VERSION gs.set_attr(_inst_name(), 'busy') init_start = time.time() try: os.makedirs(gs.home_path('bin')) except: pass if 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() vars = ['%PATH%', '$PATH'] out, err, _ = gsshell.run('echo %s' % os.pathsep.join(vars), shell=True, stderr=subprocess.PIPE, env=gs.env()) if not err: pl = [] for p in out.strip().split(os.pathsep): p = os.path.normcase(p) if p not in vars and p not in pl: pl.append(p) if pl: gs.environ9.update({'PATH': os.pathsep.join(pl)}) go_exe = gs.which('go') if go_exe: cmd = [go_exe, 'build', '-o', _margo_bin(INSTALL_EXE)] cwd = _margo_src() ev.debug('%s.build' % DOMAIN, { 'cmd': cmd, 'cwd': cwd, }) m_out, err, _ = _run(cmd, cwd=cwd) else: m_out = '' err = 'Cannot find the `go` exe' m_out = gs.ustr(m_out) err = gs.ustr(err) m_out, m_ok = _so(m_out, err, start, time.time()) if m_ok: def f(): gs.aso().set('install_version', INSTALL_VERSION) gs.save_aso() sublime.set_timeout(f, 0) if not is_update: gs.notify('GoSublime', 'Syncing environment variables') out, err, _ = gsshell.run([about.MARGO_EXE, '-env'], cwd=gs.home_path(), shell=True) # notify this early so we don't mask any notices below gs.notify('GoSublime', 'Ready') if err: gs.notice(DOMAIN, 'Cannot run get env vars: %s' % (err)) else: env, err = gs.json_decode(out, {}) if err: gs.notice(DOMAIN, 'Cannot load env vars: %s\nenv output: %s' % (err, out)) else: gs.environ9.update(env) 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 = gs.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: d = gs.home_path('bin') old_pat = re.compile(r'^gosublime.r\d{2}.\d{2}.\d{2}-\d+.margo.exe$') for fn in os.listdir(d): try: if fn != about.MARGO_EXE and (about.MARGO_EXE_PAT.match(fn) or old_pat.match(fn)): fn = os.path.join(d, fn) gs.println("GoSublime: removing old binary: %s" % fn) os.remove(fn) except Exception: report_x() except Exception: report_x()
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)
def install(aso_tokens, force_install): k = 'mg9.install.%s' % about.VERSION if gs.attr(k, False): gs.error(DOMAIN, 'Installation aborted. Install command already called for GoSublime %s.' % about.VERSION) return gs.set_attr(k, True) init_start = time.time() try: os.makedirs(gs.home_path('bin')) except: pass if not force_install and _bins_exist() and aso_tokens == _gen_tokens(): m_out = 'no' else: gs.notify('GoSublime', 'Installing MarGo') start = time.time() m_out, err, _ = _run(['go', 'build', '-o', _margo_bin()], cwd=_margo_src()) m_out, m_ok = _so(m_out, err, start, time.time()) if m_ok: def f(): gs.aso().set('mg9_install_tokens', _gen_tokens()) gs.save_aso() sublime.set_timeout(f, 0) gs.notify('GoSublime', 'Syncing environment variables') out, err, _ = gsshell.run([about.MARGO_EXE, '-env'], cwd=gs.home_path(), shell=True) # notify this early so we don't mask any notices below gs.notify('GoSublime', 'Ready') _check_changes() if err: gs.notice(DOMAIN, 'Cannot run get env vars: %s' % (err)) else: env, err = gs.json_decode(out, {}) if err: gs.notice(DOMAIN, 'Cannot load env vars: %s\nenv output: %s' % (err, out)) else: gs.environ9.update(env) e = gs.env() a = [ 'GoSublime init (%0.3fs)' % (time.time() - init_start), '| install margo: %s' % m_out, ] a.extend(['| %14s: %s' % ln for ln in sanity_check(e)]) gs.println(*a) missing = [k for k in ('GOROOT', 'GOPATH') if not e.get(k)] if missing: gs.notice(DOMAIN, "Missing environment variable(s): %s" % ', '.join(missing)) 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: d = gs.home_path('bin') for fn in os.listdir(d): try: if fn != about.MARGO_EXE and fn.startswith(('gosublime', 'gocode', 'margo')): fn = os.path.join(d, fn) gs.println("GoSublime: removing old binary: %s" % fn) os.remove(fn) except Exception: report_x() except Exception: report_x()
def on_mg_msg(res, err): msg = res.get("message", "") if msg: print("GoSublime: MarGo: %s" % msg) gs.notify("MarGo", msg) return True
def build_mg(force=False): if force: pass elif gs.setting('_rebuild'): print('GoSublime: `_rebuild` is set') elif _mg_exists(): return 'ok' gs.notify('GoSublime', 'Installing MarGo') gobin = sh.bin_dir() gopath = gs.dist_path() wd = gobin env = { 'CGO_ENABLED': '0', 'GOBIN': gobin, 'GOPATH': gopath, } # do a cleanup just-in-case there are old packages lying around... we don't really care if it fails clean = sh.Command(['go', 'clean', '-i', 'gosubli.me/...']) clean.wd = wd clean.env = env clean.run() f = gs.setting('_build_flags') or ['-v', '-x'] args = gs.lst('go', 'build', f, '-o', sh.exe('margo'), 'gosubli.me/margo') build = sh.Command(args) build.wd = wd build.env = env ev.debug('%s.build' % DOMAIN, { 'cmd': build.cmd_lst, 'cwd': build.wd, }) cr = build.run() if cr.ok and _mg_exists(): return 'ok' m_out = 'cmd: `%s`\nstdout: `%s`\nstderr: `%s`\nexception: `%s`' % ( cr.cmd_lst, cr.out.strip(), cr.err.strip(), cr.exc, ) 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))) return m_out
def install(aso_install_vesion, force_install): if gs.attr(_inst_name(), "") != "": gs.notify(DOMAIN, "Installation aborted. Install command already called for GoSublime %s." % INSTALL_VERSION) return is_update = about.VERSION != INSTALL_VERSION gs.set_attr(_inst_name(), "busy") init_start = time.time() try: os.makedirs(gs.home_path("bin")) except: pass if 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() vars = ["%PATH%", "$PATH"] out, err, _ = gsshell.run("echo %s" % os.pathsep.join(vars), shell=True, stderr=subprocess.PIPE, env=gs.env()) if not err: pl = [] for p in out.strip().split(os.pathsep): p = os.path.normcase(p) if p not in vars and p not in pl: pl.append(p) if pl: gs.environ9.update({"PATH": os.pathsep.join(pl)}) go_exe = gs.which("go") if go_exe: cmd = [go_exe, "build", "-o", _margo_bin(INSTALL_EXE)] cwd = _margo_src() gs.debug("%s.build" % DOMAIN, {"cmd": cmd, "cwd": cwd}) m_out, err, _ = _run(cmd, cwd=cwd) else: m_out = "" err = "Cannot find the `go` exe" m_out = gs.ustr(m_out) err = gs.ustr(err) m_out, m_ok = _so(m_out, err, start, time.time()) if m_ok: def f(): gs.aso().set("install_version", INSTALL_VERSION) gs.save_aso() sublime.set_timeout(f, 0) if not is_update: gs.notify("GoSublime", "Syncing environment variables") out, err, _ = gsshell.run([about.MARGO_EXE, "-env"], cwd=gs.home_path(), shell=True) # notify this early so we don't mask any notices below gs.notify("GoSublime", "Ready") if err: gs.notice(DOMAIN, "Cannot run get env vars: %s" % (err)) else: env, err = gs.json_decode(out, {}) if err: gs.notice(DOMAIN, "Cannot load env vars: %s\nenv output: %s" % (err, out)) else: gs.environ9.update(env) 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 = gs.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: d = gs.home_path("bin") old_pat = re.compile(r"^gosublime.r\d{2}.\d{2}.\d{2}-\d+.margo.exe$") for fn in os.listdir(d): try: if fn != about.MARGO_EXE and (about.MARGO_EXE_PAT.match(fn) or old_pat.match(fn)): fn = os.path.join(d, fn) gs.println("GoSublime: removing old binary: %s" % fn) os.remove(fn) except Exception: report_x() except Exception: report_x()
def install(aso_tokens, force_install): if gs.attr(INSTALL_ATTR_NAME, '') != "": gs.notify(DOMAIN, 'Installation aborted. Install command already called for GoSublime %s.' % about.VERSION) return gs.set_attr(INSTALL_ATTR_NAME, 'busy') init_start = time.time() try: os.makedirs(gs.home_path('bin')) except: pass if not force_install and _bins_exist() and aso_tokens == _gen_tokens(): m_out = 'no' else: gs.notify('GoSublime', 'Installing MarGo') start = time.time() m_out, err, _ = _run(['go', 'build', '-o', _margo_bin()], cwd=_margo_src()) m_out = gs.ustr(m_out) err = gs.ustr(err) m_out, m_ok = _so(m_out, err, start, time.time()) if m_ok: def f(): gs.aso().set('mg9_install_tokens', _gen_tokens()) gs.save_aso() sublime.set_timeout(f, 0) gs.notify('GoSublime', 'Syncing environment variables') out, err, _ = gsshell.run([about.MARGO_EXE, '-env'], cwd=gs.home_path(), shell=True) # notify this early so we don't mask any notices below gs.notify('GoSublime', 'Ready') if err: gs.notice(DOMAIN, 'Cannot run get env vars: %s' % (err)) else: env, err = gs.json_decode(out, {}) if err: gs.notice(DOMAIN, 'Cannot load env vars: %s\nenv output: %s' % (err, out)) else: gs.environ9.update(env) gs.set_attr(INSTALL_ATTR_NAME, 'done') e = gs.env() a = [ 'GoSublime init (%0.3fs)' % (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: gs.notice(DOMAIN, "Missing environment variable(s): %s" % ', '.join(missing)) 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: d = gs.home_path('bin') old_pat = re.compile(r'^gosublime.r\d{2}.\d{2}.\d{2}-\d+.margo.exe$') for fn in os.listdir(d): try: if fn != about.MARGO_EXE and (about.MARGO_EXE_PAT.match(fn) or old_pat.match(fn)): fn = os.path.join(d, fn) gs.println("GoSublime: removing old binary: %s" % fn) os.remove(fn) except Exception: report_x() except Exception: report_x()