def expand_jdata(v): if gs.is_a(v, {}): for k in v: v[k] = expand_jdata(v[k]) else: if gs.PY3K and isinstance(v, bytes): v = gs.ustr(v) if gs.is_a_string(v) and v.startswith('base64:'): try: v = gs.ustr(base64.b64decode(v[7:])) except Exception: v = '' gs.error_traceback(DOMAIN) return v
def run(cmd=[], shell=False, env={}, cwd=None, input=None, stderr=subprocess.STDOUT): out = u"" err = u"" exc = None try: p, opts, err = proc(cmd, input=input, shell=shell, stderr=stderr, env=env, cwd=cwd) if p: out, _ = p.communicate(input=opts.get('input')) out = gs.ustr(out) if out else u'' except Exception as ex: err = u'Error communicating with command %s: %s' % (opts.get('cmd'), gs.traceback()) exc = ex return (out, err, exc)
def expand_jdata(v): """Expands a byte or base64 encoded string. """ if gs.is_a(v, {}): for k in v: v[k] = expand_jdata(v[k]) elif gs.is_a(v, []): v = [expand_jdata(e) for e in v] else: if gs.PY3K and isinstance(v, bytes): v = gs.ustr(v) if gs.is_a_string(v) and v.startswith("base64:"): try: v = gs.ustr(base64.b64decode(v[7:])) except Exception: v = "" gs.error_traceback(DOMAIN) return v
def run(self, edit, rkey, output, hourglass_repl=''): view = self.view output = '\t%s' % gs.ustr(output).strip().replace('\r', '').replace('\n', '\n\t') regions = view.get_regions(rkey) if regions: line = view.line(regions[0].begin()) lsrc = view.substr(line).replace(HOURGLASS, (hourglass_repl or '| done')) view.replace(edit, line, lsrc) if output.strip(): line = view.line(regions[0].begin()) view.insert(edit, line.end(), '\n%s' % output) else: view.insert(edit, view.size(), '\n%s' % output)
def sanity_check_sl(sl): n = 0 for p in sl: n = max(n, len(p[0])) t = '%d' % n t = '| %'+t+'s: %s' indent = '| %s> ' % (' ' * n) a = '~%s' % os.sep b = os.path.expanduser(a) return [t % (k, gs.ustr(v).replace(b, a).replace('\n', '\n%s' % indent)) for k,v in sl]
def sanity_check_sl(sl): n = 0 for p in sl: n = max(n, len(p[0])) t = "%d" % n t = "| %" + t + "s: %s" indent = "| %s> " % (" " * n) a = "~%s" % os.sep b = os.path.expanduser(a) return [t % (k, gs.ustr(v).replace(b, a).replace("\n", "\n%s" % indent)) for k, v in sl]
def _read_stdout(proc): try: while True: ln = proc.stdout.readline() if not ln: break gs.mg9_recv_q.put(gs.ustr(ln)) except Exception: gs.println(gs.traceback()) proc.stdout.close() proc.wait() proc = None
def run(self, edit, rkey, output, hourglass_repl=''): view = self.view output = '\t%s' % gs.ustr(output).strip().replace('\r', '').replace( '\n', '\n\t') regions = view.get_regions(rkey) if regions: line = view.line(regions[0].begin()) lsrc = view.substr(line).replace(HOURGLASS, (hourglass_repl or '| done')) view.replace(edit, line, lsrc) if output.strip(): line = view.line(regions[0].begin()) view.insert(edit, line.end(), '\n%s' % output) else: view.insert(edit, view.size(), '\n%s' % output)
def _read_stdout(proc): """Reads lines from proc stdout into the mg9_recv_q queue.Queue, which is polled by _recv(). """ try: while True: ln = proc.stdout.readline() if not ln: break gs.mg9_recv_q.put(gs.ustr(ln)) except Exception: gs.println(gs.traceback()) proc.stdout.close() proc.wait() proc = None
def run(self): try: while True: line = self.stdout.readline() if not line: self.c.close_stdout() break if not self.c.output_started: self.c.output_started = time.time() try: self.c.on_output(self.c, gs.ustr(line.rstrip('\r\n'))) except Exception: gs.println(gs.traceback(DOMAIN)) except Exception: gs.println(gs.traceback(DOMAIN))
def run(self): try: while True: line = self.stdout.readline() if not line: self.c.close_stdout() break if not self.c.output_started: self.c.output_started = time.time() try: self.c.on_output(self.c, gs.ustr(line.rstrip("\r\n"))) except Exception: gs.println(gs.traceback(DOMAIN)) except Exception: gs.println(gs.traceback(DOMAIN))
def run(self, edit, rkey, output, hourglass_repl=""): view = self.view output = "\t%s" % gs.ustr(output).strip().replace("\r", "").replace("\n", "\n\t") regions = view.get_regions(rkey) if regions: line = view.line(regions[0].begin()) lsrc = view.substr(line).replace(HOURGLASS, (hourglass_repl or "| done")) view.replace(edit, line, lsrc) r = line if output.strip(): line = view.line(regions[0].begin()) view.insert(edit, line.end(), "\n%s" % output) r = view.get_regions(rkey)[0] else: n = view.size() view.insert(edit, n, "\n%s" % output) r = sublime.Region(n, view.size()) if gs.setting("9o_show_end") is True: view.show(r.end()) else: view.show(r.begin())
def run(self, edit, rkey, output, hourglass_repl=''): view = self.view output = '\t%s' % gs.ustr(output).strip().replace('\r', '').replace('\n', '\n\t') regions = view.get_regions(rkey) if regions: line = view.line(regions[0].begin()) lsrc = view.substr(line).replace(HOURGLASS, (hourglass_repl or '| done')) view.replace(edit, line, lsrc) r = line if output.strip(): line = view.line(regions[0].begin()) view.insert(edit, line.end(), '\n%s' % output) r = view.get_regions(rkey)[0] else: n = view.size() view.insert(edit, n, '\n%s' % output) r = sublime.Region(n, view.size()) if gs.setting('9o_show_end') is True: view.show(r.end()) else: view.show(r.begin())
def on_done(new_name): if new_name == current_selection: return gs.println(DOMAIN, 'Requested New Name: {0}'.format(new_name)) offset = '{0}:#{1}'.format(filename, region.begin()) command = ['gorename', '-offset', offset, '-to', new_name] gs.println(DOMAIN, 'CMD: {0}'.format(' '.join(command))) out = "" try: p = gs.popen(command, stderr=subprocess.STDOUT) out = p.communicate()[0] if p.returncode != 0: raise OSError("GoRename failed") except Exception as e: msg = gs.tbck.format_exc() if out: msg = '{0}\n{1}'.format(msg, gs.ustr(out)) gs.show_output('GsGorename', msg, replace=False, merge_domain=False)
def run(self, edit, rkey, output, hourglass_repl=''): view = self.view output = '\t%s' % gs.ustr(output).strip().replace('\r', '').replace( '\n', '\n\t') regions = view.get_regions(rkey) if regions: line = view.line(regions[0].begin()) lsrc = view.substr(line).replace(HOURGLASS, (hourglass_repl or '| done')) view.replace(edit, line, lsrc) r = line if output.strip(): line = view.line(regions[0].begin()) view.insert(edit, line.end(), '\n%s' % output) r = view.get_regions(rkey)[0] else: n = view.size() view.insert(edit, n, '\n%s' % output) r = sublime.Region(n, view.size()) if cfg.nineo_show_end: view.show(r.end()) else: view.show(r.begin())
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()
def on_done(c): out = gs.ustr('\n'.join(c.consume_outq())) sublime.set_timeout(lambda: push_output(view, rkey, out), 0)
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 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_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()