def _init_go_bin(): global GO_BIN if GO_BIN: return tid = gs.begin(DOMAIN, 'Looking for go') GO_BIN = gs.which('go') if not GO_BIN: _init_shell_path() GO_BIN = gs.which('go') gs.end(tid)
def sanity_check(env={}, error_log=False): if not env: env = gs.env() ns = '(not set)' sl = [ ('install state', gs.attr(_inst_name(), '')), ('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_path('bin')), ('margo.exe', '%s (%s)' % _tp(_margo_bin())), ('go.exe', '%s (%s)' % _tp(gs.which('go') or 'go')), ('GOROOT', '%s' % env.get('GOROOT', ns)), ('GOPATH', '%s' % env.get('GOPATH', ns)), ('GOBIN', '%s (should usually be `%s`)' % (env.get('GOBIN', ns), ns)), ] 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 sanity_check(env={}, error_log=False): if not env: env = gs.env() ns = "(not set)" sl = [ ("install state", gs.attr(_inst_name(), "")), ("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_path("bin")), ("margo.exe", "%s (%s)" % _tp(_margo_bin())), ("go.exe", "%s (%s)" % _tp(gs.which("go") or "go")), ("GOROOT", "%s" % env.get("GOROOT", ns)), ("GOPATH", "%s" % env.get("GOPATH", ns)), ("GOBIN", "%s (should usually be `%s`)" % (env.get("GOBIN", ns), ns)), ] 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(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 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()