def sanity_check(env={}, error_log=False): if not env: env = sh.env() ns = '(not set)' sl = [ ('install state', _inst_state()), ('sublime.version', sublime.version()), ('sublime.channel', sublime.channel()), ('about.ann', gs.attr('about.ann', '')), ('about.version', gs.attr('about.version', '')), ('version', about.VERSION), ('platform', about.PLATFORM), ('~bin', '%s' % gs.home_dir_path('bin')), ('margo.exe', '%s (%s)' % _tp(_margo_bin())), ('go.exe', '%s (%s)' % _tp(sh.which('go') or 'go')), ('go.version', sh.GO_VERSION), ('GOROOT', '%s' % env.get('GOROOT', ns)), ('GOPATH', '%s' % env.get('GOPATH', ns)), ('GOBIN', '%s (should usually be `%s`)' % (env.get('GOBIN', ns), ns)), ('set.shell', str(gs.lst(gs.setting('shell')))), ('env.shell', env.get('SHELL', '')), ('shell.cmd', str(sh.cmd('${CMD}'))), ] if error_log: try: with open(gs.home_path('log.txt'), 'r') as f: s = f.read().strip() sl.append(('error log', s)) except Exception: pass return sl
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 sanity_check(env={}, error_log=False): if not env: env = sh.env() ns = "(not set)" sl = [ ("install state", _inst_state()), ("sublime.version", sublime.version()), ("sublime.channel", sublime.channel()), ("about.ann", gs.attr("about.ann", "")), ("about.version", gs.attr("about.version", "")), ("version", about.VERSION), ("platform", about.PLATFORM), ("~bin", "%s" % gs.home_dir_path("bin")), ("margo.exe", "%s (%s)" % _tp(_margo_bin())), ("go.exe", "%s (%s)" % _tp(sh.which("go") or "go")), ("go.version", sh.GO_VERSION), ("GOROOT", "%s" % env.get("GOROOT", ns)), ("GOPATH", "%s" % env.get("GOPATH", ns)), ("GOBIN", "%s (should usually be `%s`)" % (env.get("GOBIN", ns), ns)), ("set.shell", str(gs.lst(gs.setting("shell")))), ("env.shell", env.get("SHELL", "")), ("shell.cmd", str(sh.cmd("${CMD}"))), ] if error_log: try: with open(gs.home_path("log.txt"), "r") as f: s = f.read().strip() sl.append(("error log", s)) except Exception: pass return sl
def fmt(fn, src): fn = fn or '' src = src or '' fmt_cmd = gs.settings_dict().get('fmt_cmd') if not fmt_cmd: return _mg_fmt(fn, src) env = sh.env() fmt_cmd = [string.Template(s).safe_substitute(env) for s in fmt_cmd] cmd_name = fmt_cmd[0] cmd_args = fmt_cmd[1:] res, err = bcall('sh', { 'Env': env, 'Cmd': { 'Name': cmd_name, 'Args': cmd_args, 'Input': src, }, }, err_title=cmd_name) err = err or res.get('err') or '' cmd_src = '' if err else (res.get('out') or '') if err: mg_src, mg_err = _mg_fmt(fn, src) if mg_src and not mg_err: err = 'Used MarGo fmt because %s failed:\n\n%s' % (cmd_name, err) cmd_src = mg_src return cmd_src, err
def cmd_9(view, edit, args, wd, rkey): if len(args) == 0 or args[0] not in ('run', 'replay', 'build'): push_output(view, rkey, ('9: invalid args %s' % args)) return subcmd = args[0] cid = '' if subcmd == 'replay': cid = '9replay-%s' % wd cid, cb = _9_begin_call(subcmd, view, edit, args, wd, rkey, cid) a = { 'cid': cid, 'env': sh.env(), 'dir': wd, 'args': args[1:], 'build_only': (subcmd == 'build'), } win = view.window() if win is not None: av = win.active_view() if av is not None: fn = av.file_name() if fn: _save_all(win, wd) else: if gs.is_go_source_view(av, False): a['fn'] = gs.view_fn(av) a['src'] = av.substr(sublime.Region(0, av.size())) sublime.set_timeout(lambda: mg9.acall('play', a, cb), 0)
def cmd_9(view, edit, args, wd, rkey): if len(args) == 0 or args[0] not in ("run", "replay", "build"): push_output(view, rkey, ("9: invalid args %s" % args)) return subcmd = args[0] cid = "" if subcmd == "replay": cid = "9replay-%s" % wd cid, cb = _9_begin_call(subcmd, view, edit, args, wd, rkey, cid) a = {"cid": cid, "env": sh.env(), "dir": wd, "args": args[1:], "build_only": (subcmd == "build")} win = view.window() if win is not None: av = win.active_view() if av is not None: fn = av.file_name() if fn: _save_all(win, wd) else: if gs.is_go_source_view(av, False): a["fn"] = gs.view_fn(av) a["src"] = av.substr(sublime.Region(0, av.size())) sublime.set_timeout(lambda: mg9.acall("play", a, cb), 0)
def fmt(fn, src): st = gs.settings_dict() x = st.get('fmt_cmd') if x: env = sh.env() x = [string.Template(s).safe_substitute(env) for s in x] res, err = bcall( 'sh', { 'Env': env, 'Cmd': { 'Name': x[0], 'Args': x[1:], 'Input': src or '', }, }) return res.get('out', ''), (err or res.get('err', '')) res, err = bcall( 'fmt', { 'Fn': fn or '', 'Src': src or '', 'TabIndent': st.get('fmt_tab_indent'), 'TabWidth': st.get('fmt_tab_width'), }) return res.get('src', ''), err
def pkg_dirs(f): tid = gs.begin(DOMAIN, "Fetching pkg dirs") def cb(res, err): gs.end(tid) f(res, err) acall("pkg_dirs", {"env": sh.env()}, cb)
def declarations(fn, src, pkg_dir, f): tid = gs.begin(DOMAIN, "Fetching declarations") def cb(res, err): gs.end(tid) f(res, err) return acall("declarations", {"fn": fn or "", "src": src, "env": sh.env(), "pkgDir": pkg_dir}, cb)
def import_paths(fn, src, f): tid = gs.begin(DOMAIN, "Fetching import paths") def cb(res, err): gs.end(tid) f(res, err) acall("import_paths", {"fn": fn or "", "src": src or "", "env": sh.env()}, cb)
def pkg_dirs(f): tid = gs.begin(DOMAIN, 'Fetching pkg dirs') def cb(res, err): gs.end(tid) f(res, err) acall('pkg_dirs', { 'env': sh.env(), }, cb)
def cmd_sh(view, edit, args, wd, rkey): cid, cb = _9_begin_call("sh", view, edit, args, wd, rkey, "") a = { "cid": cid, "env": sh.env(), "cwd": wd, "cmd": {"name": args[0], "args": args[1:]}, } sublime.set_timeout(lambda: mg9.acall("sh", a, cb), 0)
def imports(fn, src, toggle): return bcall('imports', { 'autoinst': gs.setting('autoinst'), 'env': sh.env(), 'fn': fn or '', 'src': src or '', 'toggle': toggle or [], 'tabIndent': gs.setting('fmt_tab_indent'), 'tabWidth': gs.setting('fmt_tab_width'), })
def import_paths(fn, src, f): tid = gs.begin(DOMAIN, 'Fetching import paths') def cb(res, err): gs.end(tid) f(res, err) acall('import_paths', { 'fn': fn or '', 'src': src or '', 'env': sh.env(), }, cb)
def _complete_opts(fn, src, pos): home = gs.home_path() builtins = gs.setting("autocomplete_builtins") is True or gs.setting("complete_builtins") is True return { "Dir": gs.basedir_or_cwd(fn), "Builtins": builtins, "Fn": fn or "", "Src": src or "", "Pos": pos or 0, "Home": home, "Env": sh.env({"XDG_CONFIG_HOME": home}), }
def declarations(fn, src, pkg_dir, f): tid = gs.begin(DOMAIN, 'Fetching declarations') def cb(res, err): gs.end(tid) f(res, err) return acall('declarations', { 'fn': fn or '', 'src': src, 'env': sh.env(), 'pkgDir': pkg_dir, }, cb)
def cmd_sh(view, edit, args, wd, rkey): cid, cb = _9_begin_call('sh', view, edit, args, wd, rkey, '') a = { 'cid': cid, 'env': sh.env(), 'cwd': wd, 'cmd': { 'name': args[0], 'args': args[1:], } } sublime.set_timeout(lambda: mg9.acall('sh', a, cb), 0)
def proc( cmd, shell=False, env={}, cwd=None, input=None, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE, bufsize=0, ): env = sh.env(env) shell, cmd = fix_shell_cmd(shell, cmd) if input is not None: input = gs.astr(input) if cwd: try: os.makedirs(cwd) except Exception: pass else: # an empty string isn't a valid value so just always set it None cwd = None try: setsid = os.setsid except Exception: setsid = None opts = {"cmd": cmd, "shell": shell, "env": env, "input": input} p = None err = "" try: p = subprocess.Popen( cmd, stdout=stdout, stderr=stderr, stdin=stdin, startupinfo=gs.STARTUP_INFO, shell=shell, env=env, cwd=cwd, preexec_fn=setsid, bufsize=bufsize, ) except Exception: err = "Error running command %s: %s" % (cmd, gs.traceback()) return (p, opts, err)
def imports(fn, src, toggle): return bcall( "imports", { "autoinst": gs.setting("autoinst"), "env": sh.env(), "fn": fn or "", "src": src or "", "toggle": toggle or [], "tabIndent": gs.setting("fmt_tab_indent"), "tabWidth": gs.setting("fmt_tab_width"), }, )
def return_package_if_inside_gopath(filename): env = sh.env() gopaths = env["GOPATH"].split(":") new_lines = [] for path in gopaths: print("GOPATH", path) print("FILENA", filename) path = os.path.join(path, "src") if filename.startswith(path): dirname = os.path.dirname(filename.replace(path, "")) print(dirname) return dirname return ""
def _complete_opts(fn, src, pos, builtins): nv = sh.env() return { "Dir": gs.basedir_or_cwd(fn), "Builtins": builtins, "Fn": fn or "", "Src": src or "", "Pos": pos or 0, "Home": sh.vdir(), "Autoinst": gs.setting("autoinst"), "InstallSuffix": gs.setting("installsuffix", ""), "Env": {"GOROOT": nv.get("GOROOT", ""), "GOPATH": nv.get("GOPATH", "")}, }
def import_paths(fn, src, f): tid = gs.begin(DOMAIN, 'Fetching import paths') def cb(res, err): gs.end(tid) f(res, err) acall('import_paths', { 'fn': fn or '', 'src': src or '', 'env': sh.env(), 'WantPkgNames': gs.setting('use_named_imports'), 'UseLegacyImports': gs.setting('use_legacy_imports'), }, cb)
def doc(fn, src, offset, f): tid = gs.begin(DOMAIN, 'Fetching doc info') def cb(res, err): gs.end(tid) f(res, err) acall('doc', { 'fn': fn or '', 'src': src or '', 'offset': offset or 0, 'env': sh.env(), 'tabIndent': gs.setting('fmt_tab_indent'), 'tabWidth': gs.setting('fmt_tab_width'), }, cb)
def _complete_opts(fn, src, pos): home = gs.home_path() builtins = (gs.setting('autocomplete_builtins') is True or gs.setting('complete_builtins') is True) return { 'Dir': gs.basedir_or_cwd(fn), 'Builtins': builtins, 'Fn': fn or '', 'Src': src or '', 'Pos': pos or 0, 'Home': home, 'Env': sh.env({ 'XDG_CONFIG_HOME': home, }), }
def cmd_go(view, edit, args, wd, rkey): _save_all(view.window(), wd) cid, cb = _9_begin_call('go', view, edit, args, wd, rkey, '9go-%s' % wd) a = { 'cid': cid, 'env': sh.env(), 'cwd': wd, 'cmd': { 'name': 'go', 'args': args, } } sublime.set_timeout(lambda: mg9.acall('sh', a, cb), 0)
def a_pkgpaths(exclude, f): tid = gs.begin(DOMAIN, '') def cb(res, err): gs.end(tid) f(res, err) m = sh.env() acall('pkgpaths', { 'env': { 'GOPATH': m.get('GOPATH'), 'GOROOT': m.get('GOROOT'), '_pathsep': m.get('_pathsep'), }, 'exclude': exclude, }, cb)
def _complete_opts(fn, src, pos, builtins): nv = sh.env() return { 'Dir': gs.basedir_or_cwd(fn), 'Builtins': builtins, 'Fn': fn or '', 'Src': src or '', 'Pos': pos or 0, 'Home': sh.vdir(), 'Autoinst': gs.setting('autoinst'), 'Env': { 'GOROOT': nv.get('GOROOT', ''), 'GOPATH': nv.get('GOPATH', ''), }, }
def a_pkgpaths(exclude, f): tid = gs.begin(DOMAIN, '') def cb(res, err): gs.end(tid) f(res, err) m = sh.env() acall('pkgpaths', { 'env': { 'GOPATH': m.get('GOPATH'), 'GOROOT': m.get('GOROOT'), }, 'exclude': exclude, 'WantPkgNames': gs.setting('use_named_imports'), }, cb)
def _complete_opts(fn, src, pos): home = gs.home_path() builtins = (gs.setting('autocomplete_builtins') is True or gs.setting('complete_builtins') is True) return { 'Dir': gs.basedir_or_cwd(fn), 'Builtins': builtins, 'Fn': fn or '', 'Src': src or '', 'Pos': pos or 0, 'Home': home, 'Autoinst': gs.setting('autoinst'), 'Env': sh.env({ 'XDG_CONFIG_HOME': home, }), }
def _complete_opts(fn, src, pos, builtins): nv = sh.env() return { 'Dir': gs.basedir_or_cwd(fn), 'Builtins': builtins, 'Fn': fn or '', 'Src': src or '', 'Pos': pos or 0, 'Home': sh.vdir(), 'Autoinst': gs.setting('autoinst'), 'InstallSuffix': gs.setting('installsuffix', ''), 'Env': { 'GOROOT': nv.get('GOROOT', ''), 'GOPATH': nv.get('GOPATH', ''), }, }
def import_paths(fn, src, f): tid = gs.begin(DOMAIN, "Fetching import paths") def cb(res, err): gs.end(tid) f(res, err) acall( "import_paths", { "fn": fn or "", "src": src or "", "env": sh.env(), "InstallSuffix": gs.setting("installsuffix", ""), }, cb, )
def doc(fn, src, offset, f, mode='doc'): tid = gs.begin(DOMAIN, 'Fetching doc info') def cb(res, err): gs.end(tid) f(res, err) #default to doc if mode not in ['usage', 'doc']: mode = 'doc' acall(mode, { 'fn': fn or '', 'src': src or '', 'offset': offset or 0, 'env': sh.env(), 'tabIndent': gs.setting('fmt_tab_indent'), 'tabWidth': gs.setting('fmt_tab_width'), }, cb)
def _complete_opts(fn, src, pos, builtins, *, forceInstall = False): nv = sh.env() return { 'Dir': gs.basedir_or_cwd(fn), 'Builtins': builtins, 'Fn': fn or '', 'Src': src or '', 'Pos': pos or 0, 'Home': sh.vdir(), 'Autoinst': gs.setting('autoinst'), 'InstallSuffix': gs.setting('installsuffix', ''), 'Env': { 'GOROOT': nv.get('GOROOT', ''), 'GOPATH': nv.get('GOPATH', ''), 'TEMP': nv.get('TEMP', ''), 'TMP': nv.get('TMP', ''), 'FORCE_INSTALL': str(int(forceInstall)), }, }
def cmd_cd(view, edit, args, wd, rkey): try: if args: wd = args[0] wd = string.Template(wd).safe_substitute(sh.env()) wd = os.path.expanduser(wd) wd = os.path.abspath(wd) else: fn = view.window().active_view().file_name() if fn: wd = os.path.dirname(fn) os.chdir(wd) except Exception as ex: push_output(view, rkey, 'Cannot chdir: %s' % ex) return push_output(view, rkey, '') view.run_command('gs9o_init', {'wd': wd})
def _complete_opts(fn, src, pos, builtins, *, forceInstall=False): nv = sh.env() return { 'Dir': gs.basedir_or_cwd(fn), 'Builtins': builtins, 'Fn': fn or '', 'Src': src or '', 'Pos': pos or 0, 'Home': sh.vdir(), 'Autoinst': gs.setting('autoinst'), 'InstallSuffix': gs.setting('installsuffix', ''), 'Env': { 'GOROOT': nv.get('GOROOT', ''), 'GOPATH': nv.get('GOPATH', ''), 'TEMP': nv.get('TEMP', ''), 'TMP': nv.get('TMP', ''), 'FORCE_INSTALL': str(int(forceInstall)), }, }
def on_query_completions(self, view, _, locations): pos = locations[0] if view.score_selector(pos, 'text.9o') == 0: return [] if view.substr(locations[0] - 2) == '$': return ([('$' + k, '\$' + k + ' ') for k in sh.env()], AC_OPTS) cl = set() slash = os.path.sep # the prefix passed tho us by definition doesn't contain slash because it's not a word char p = view.substr(sublime.Region(view.line(pos).begin(), pos)) p = p.split()[-1].lstrip(' #') file_only_comp = p.startswith('.') or slash in p if not p.startswith(('.', slash)): p = '.' + slash + p rm = '' m = word_sep_pat.match(p) if m: rm = m.group(1) try: for fn in glob.iglob(p + '*'): space = ' ' if os.path.isdir(fn): space = '' fn += '/' cl.add((fn, fn[len(rm):] + space)) except Exception: pass if not file_only_comp: hkey = _hkey(view.settings().get('9o.wd', '')) cl.update((k, k + ' ') for k in gs.dval(gs.aso().get(hkey), [])) cl.update((k, k + ' ') for k in builtins()) cl.update(DEFAULT_CL) return ([cl_esc(e) for e in sorted(cl)], AC_OPTS)
def fmt(fn, src): st = gs.settings_dict() x = st.get('fmt_cmd') if x: res, err = bcall( 'sh', { 'Env': sh.env(), 'Cmd': { 'Name': x[0], 'Args': x[1:], 'Input': src or '', }, }) return res.get('out', ''), (err or res.get('err', '')) res, err = bcall( 'fmt', { 'Fn': fn or '', 'Src': src or '', 'TabIndent': st.get('fmt_tab_indent'), 'TabWidth': st.get('fmt_tab_width'), }) return res.get('src', ''), err
def run(self, edit, save_hist=False): view = self.view pos = gs.sel(view).begin() line = view.line(pos) wd = view.settings().get('9o.wd') try: os.chdir(wd) except Exception: gs.error_traceback(DOMAIN) ln = view.substr(line).split('#', 1) if len(ln) == 2: cmd = ln[1].strip() if cmd: vs = view.settings() aso = gs.aso() hkey = _hkey(wd) hist = gs.dval(aso.get(hkey), []) m = HIST_EXPAND_PAT.match(cmd) if m: pfx = m.group(1) hl = len(hist) idx = hl - int(m.group(2)) cmd = '' if idx >= 0 and idx < hl: cmd = hist[idx] if pfx == '^' or not cmd: view.replace(edit, line, ('%s# %s' % (ln[0], cmd))) return elif save_hist: try: hist.remove(cmd) except ValueError: pass hist.append(cmd) aso.set(hkey, hist) gs.save_aso() if not cmd: view.run_command('gs9o_init') return view.replace(edit, line, (u'[ `%s` %s ]' % (cmd, HOURGLASS))) rkey = '9o.exec.%s' % uuid.uuid4() view.add_regions(rkey, [sublime.Region(line.begin(), view.size())], '') view.run_command('gs9o_init') nv = sh.env() anv = nv.copy() seen = {} am = aliases() while True: cli = cmd.split(' ', 1) nm = cli[0] if not nm: break ag = cli[1].strip() if len(cli) == 2 else '' alias = am.get(nm, '') if not alias: break if alias in seen: gs.error(DOMAIN, 'recursive alias detected: `%s`' % alias) break seen[alias] = True anv['_args'] = ag cmd = string.Template(alias).safe_substitute(anv) if nm != 'sh': f = builtins().get(nm) if f: args = [] if ag: args = [ _exparg(s, nv) for s in shlex.split(gs.astr(ag)) ] f(view, edit, args, wd, rkey) return if nm == 'sh': args = sh.cmd(ag) else: args = sh.cmd(cmd) cmd_sh(view, edit, args, wd, rkey) else: view.insert(edit, gs.sel(view).begin(), '\n')
def _exec(view, edit, save_hist=False): pos = gs.sel(view).begin() line = view.line(pos) wd = view.settings().get('9o.wd') try: os.chdir(wd) except Exception: ui.trace(DOMAIN) ln = view.substr(line).split('#', 1) if len(ln) == 2: cmd = ln[1].strip() if cmd: vs = view.settings() aso = gs.aso() hkey = _hkey(wd) hist = gs.dval(aso.get(hkey), []) m = HIST_EXPAND_PAT.match(cmd) if m: pfx = m.group(1) hl = len(hist) idx = hl - int(m.group(2)) cmd = '' if idx >= 0 and idx < hl: cmd = hist[idx] if pfx == '^' or not cmd: view.replace(edit, line, ('%s# %s' % (ln[0], cmd))) return elif save_hist: try: hist.remove(cmd) except ValueError: pass hist.append(cmd) aso.set(hkey, hist) gs.save_aso() if not cmd: view.run_command('gs9o_init') return line = view.full_line(pos) ctx = '9o.exec.%s' % gs.uid() view.replace(edit, line, ('[`%s`]\n' % cmd)) view.run_command('gs9o_init') ep = view.full_line(line.begin()).end() view.add_regions(ctx, [sublime.Region(ep, ep)], '') hellip = u'[ \u22EF ]' ep += 1 view.insert(edit, ep, hellip + '\n\n') view.add_regions(ctx + '.done', [sublime.Region(ep, ep + len(hellip))], '') cli = cmd.split(' ', 1) if cli[0] == 'sh': a = cli[1].strip() if len(cli) == 2 else '' mk_cmd(view, wd, ctx, sh.cmd(a)).start() return nv = sh.env() a = [_exparg(s, nv) for s in shlex.split(gs.astr(cmd))] f = builtins().get(a[0]) if f: f(view, edit, a[1:], wd, ctx) else: mk_cmd(view, wd, ctx, a).start() else: view.insert(edit, gs.sel(view).begin(), '\n')
def cmd_env(view, edit, args, wd, rkey): _env_settings(sh.env(), view, edit, args, wd, rkey)
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