Example #1
0
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
Example #2
0
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' % env.get('GOBIN', 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
Example #3
0
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_dir_path('bin')),
        ('margo.exe', '%s (%s)' % _tp(_margo_bin())),
        ('go.exe', '%s (%s)' % _tp(gs.which('go') or 'go')),
        ('go.version', 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)),
    ]

    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
Example #4
0
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
Example #5
0
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
Example #6
0
def _sb(s):
	bdir = gs.home_dir_path('bin')
	if s.startswith(bdir):
		s = '~bin%s' % (s[len(bdir):])
	return s
Example #7
0
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
Example #8
0
def _sb(s):
    bdir = gs.home_dir_path('bin')
    if s.startswith(bdir):
        s = '~bin%s' % (s[len(bdir):])
    return s
Example #9
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()
Example #10
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()
Example #11
0
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()
Example #12
0
def _sb(s):
    bdir = gs.home_dir_path("bin")
    if s.startswith(bdir):
        s = "~bin%s" % (s[len(bdir) :])
    return s