コード例 #1
0
ファイル: mg9.py プロジェクト: vivicai/GoSublime
def _recv():
    while True:
        try:
            ln = gs.mg9_recv_q.get()
            try:
                ln = ln.strip()
                if ln:
                    r, _ = gs.json_decode(ln, {})
                    token = r.get("token", "")
                    tag = r.get("tag", "")
                    k = REQUEST_PREFIX + token
                    req = gs.attr(k, {})
                    gs.del_attr(k)
                    if req and req.f:
                        if tag != TAG:
                            gs.notice(
                                DOMAIN,
                                "\n".join(
                                    [
                                        "GoSublime/MarGo appears to be out-of-sync.",
                                        "Maybe restart Sublime Text.",
                                        "Received tag `%s', expected tag `%s'. " % (tag, TAG),
                                    ]
                                ),
                            )

                        err = r.get("error", "")

                        gs.debug(
                            DOMAIN,
                            "margo response: %s"
                            % {
                                "method": req.method,
                                "tag": tag,
                                "token": token,
                                "dur": "%0.3fs" % (time.time() - req.tm),
                                "err": err,
                                "size": "%0.1fK" % (len(ln) / 1024.0),
                            },
                        )

                        dat = expand_jdata(r.get("data", {}))
                        try:
                            keep = req.f(dat, err) is True
                            if keep:
                                req.tm = time.time()
                                gs.set_attr(k, req)
                        except Exception:
                            gs.error_traceback(DOMAIN)
                    else:
                        gs.debug(DOMAIN, "Ignoring margo: token: %s" % token)
            except Exception:
                gs.println(gs.traceback())
        except Exception:
            gs.println(gs.traceback())
            break
コード例 #2
0
def _recv():
    while True:
        try:
            ln = gs.mg9_recv_q.get()
            try:
                ln = ln.strip()
                if ln:
                    r, _ = gs.json_decode(ln, {})
                    token = r.get('token', '')
                    tag = r.get('tag', '')
                    k = REQUEST_PREFIX + token
                    req = gs.attr(k, {})
                    gs.del_attr(k)
                    if req and req.f:
                        if tag != TAG:
                            gs.notice(
                                DOMAIN, "\n".join([
                                    "GoSublime/MarGo appears to be out-of-sync.",
                                    "Maybe restart Sublime Text.",
                                    "Received tag `%s', expected tag `%s'. " %
                                    (tag, TAG),
                                ]))

                        err = r.get('error', '')

                        ev.debug(
                            DOMAIN, "margo response: %s" % {
                                'method': req.method,
                                'tag': tag,
                                'token': token,
                                'dur': '%0.3fs' % (time.time() - req.tm),
                                'err': err,
                                'size': '%0.1fK' % (len(ln) / 1024.0),
                            })

                        dat = expand_jdata(r.get('data', {}))
                        try:
                            keep = req.f(dat, err) is True
                            if keep:
                                req.tm = time.time()
                                gs.set_attr(k, req)
                        except Exception:
                            gs.error_traceback(DOMAIN)
                    else:
                        ev.debug(DOMAIN, 'Ignoring margo: token: %s' % token)
            except Exception:
                gs.println(gs.traceback())
        except Exception:
            gs.println(gs.traceback())
            break
コード例 #3
0
ファイル: mg9.py プロジェクト: campoy/GoSublime-next
def _recv():
	while True:
		try:
			ln = gs.mg9_recv_q.get()
			try:
				ln = ln.strip()
				if ln:
					r, _ = gs.json_decode(ln, {})
					token = r.get('token', '')
					tag = r.get('tag', '')
					k = REQUEST_PREFIX+token
					req = gs.attr(k, {})
					gs.del_attr(k)
					if req and req.f:
						if tag != TAG:
							gs.notice(DOMAIN, "\n".join([
								"GoSublime/MarGo appears to be out-of-sync.",
								"Maybe restart Sublime Text.",
								"Received tag `%s', expected tag `%s'. " % (tag, TAG),
							]))

						err = r.get('error', '')

						ev.debug(DOMAIN, {
							'_mode': 'response',
							'method': req.method,
							'tag': tag,
							'token': token,
							'dur': '%0.3fs' % (time.time() - req.tm),
							'err': err,
							'size': '%0.1fK' % (len(ln)/1024.0),
						})

						dat = expand_jdata(r.get('data', {}))
						try:
							keep = req.f(dat, err) is True
							if keep:
								req.tm = time.time()
								gs.set_attr(k, req)
						except Exception:
							gs.error_traceback(DOMAIN)
					else:
						ev.debug(DOMAIN, 'Ignoring margo: token: %s' % token)
			except Exception:
				gs.print_traceback()
		except Exception:
			gs.print_traceback()
			break
コード例 #4
0
ファイル: mg9.py プロジェクト: OlingCat/GoSublime
def _recv():
	while True:
		try:
			ln = gs.mg9_recv_q.get()
			try:
				ln = ln.strip()
				if ln:
					r, _ = gs.json_decode(ln, {})
					token = r.get('token', '')
					k = REQUEST_PREFIX+token
					req = gs.attr(k)
					gs.del_attr(k)
					if req and req.f:
						gs.debug(DOMAIN, "margo response: method: %s, token: %s, dur: %0.3fs, err: `%s'" % (
							req.method,
							req.token,
							(time.time() - req.tm),
							r.get('error', ''),
						))

						dat = expand_jdata(r.get('data', {}))
						err = r.get('error', '')
						try:
							keep = req.f(dat, err) is not True
							if keep:
								req.tm = time.time()
								gs.set_attr(k, req)
						except Exception:
							gs.error_traceback(DOMAIN)
					else:
						gs.debug(DOMAIN, 'Ignoring margo: token: %s' % token)
			except Exception:
				gs.println(gs.traceback())
		except Exception:
			gs.println(gs.traceback())
			break
コード例 #5
0
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()
コード例 #6
0
ファイル: mg9.py プロジェクト: GeertJohan/GoSublime
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()
コード例 #7
0
ファイル: mg9.py プロジェクト: OlingCat/GoSublime
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()
コード例 #8
0
ファイル: mg9.py プロジェクト: GeertJohan/GoSublime
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()
コード例 #9
0
ファイル: mg9.py プロジェクト: charlievieth/GoSubl
def _recv():
    """Polls the mg9_recv_q queue parsing responses.
    """
    # TODO: REFACTOR.
    while True:
        try:
            ln = gs.mg9_recv_q.get()
            try:
                ln = ln.strip()
                if ln:
                    r, _ = gs.json_decode(ln, {})
                    token = r.get("token", "")
                    tag = r.get("tag", "")
                    k = REQUEST_PREFIX + token

                    # TODO: try req = gs.del_attr(k)
                    req = gs.attr(k, {})
                    gs.del_attr(k)

                    if req and req.f:
                        if tag != TAG:
                            gs.notice(
                                DOMAIN,
                                "\n".join(
                                    [
                                        "GoSublime/MarGo appears to be out-of-sync.",
                                        "Maybe restart Sublime Text.",
                                        "Received tag `%s', expected tag `%s'. "
                                        % (tag, TAG),
                                    ]
                                ),
                            )

                        err = r.get("error", "")

                        # TODO: Check if debug is enabled (len()).
                        ev.debug(
                            DOMAIN,
                            "margo response: %s"
                            % {
                                "method": req.method,
                                "tag": tag,
                                "token": token,
                                "dur": "%0.3fs" % (time.time() - req.tm),
                                "err": err,
                                "size": "%0.1fK" % (len(ln) / 1024.0),
                            },
                        )

                        # CEV: req.f is the callback 'cb' set in _send().
                        #
                        dat = expand_jdata(r.get("data", {}))
                        try:
                            # Add request back to the attr dict.
                            #
                            # TODO: Document, which calls keep the request.
                            keep = req.f(dat, err) is True
                            if keep:
                                req.tm = time.time()
                                gs.set_attr(k, req)
                        except Exception:
                            gs.error_traceback(DOMAIN)
                    else:
                        ev.debug(DOMAIN, "Ignoring margo: token: %s" % token)
            except Exception:
                gs.println(gs.traceback())
        except Exception:
            gs.println(gs.traceback())
            break
コード例 #10
0
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()
コード例 #11
0
ファイル: mg9.py プロジェクト: vivicai/GoSublime
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()