Пример #1
0
def plugin_loaded():
	from gosubl import about
	from gosubl import sh
	from gosubl import ev
	from gosubl import gs
	from gosubl import mg9

	if VERSION != about.VERSION:
		gs.show_output('GoSublime-main', '\n'.join([
			'GoSublime has been updated.',
			'New version: `%s`, current version: `%s`' % (VERSION, about.VERSION),
			'Please restart Sublime Text to complete the update.',
			execErr,
		]))
		return

	if gs.attr('about.version'):
		gs.show_output('GoSublime-main', '\n'.join([
			'GoSublime appears to have been updated.',
			'New ANNOUNCE: `%s`, current ANNOUNCE: `%s`' % (ANN, about.ANN),
			'You may need to restart Sublime Text.',
		]))
		return

	mods = [
		('gs', gs),
		('sh', sh),
		('mg9', mg9),
	]

	gs.set_attr('about.version', VERSION)
	gs.set_attr('about.ann', ANN)

	for mod_name, mod in mods:
		print('GoSublime %s: init mod(%s)' % (VERSION, mod_name))

		try:
			mod.gs_init({
				'version': VERSION,
				'ann': ANN,
				'margo_exe': MARGO_EXE,
			})
		except TypeError:
			# old versions didn't take an arg
			mod.gs_init()

	ev.init.post_add = lambda e, f: f()
	ev.init()

	def cb():
		aso = gs.aso()
		old_version = aso.get('version', '')
		old_ann = aso.get('ann', '')
		if about.VERSION > old_version or about.ANN > old_ann:
			aso.set('version', about.VERSION)
			aso.set('ann', about.ANN)
			gs.save_aso()
			gs.focus(gs.dist_path('CHANGELOG.md'))

	sublime.set_timeout(cb, 0)
Пример #2
0
def plugin_loaded():
    from gosubl import about
    from gosubl import gs
    from gosubl import mg9

    gs.gs_init()
    mg9.gs_init()

    # we need the values in the file on-disk but we don't want any interference with the live env
    try:
        gs.set_attr('about.version', VERSION)
        gs.set_attr('about.ann', ANN)

        if about.VERSION != VERSION:
            gs.show_output(
                'GoSublime-source', '\n'.join([
                    'GoSublime source has been updated.',
                    'New version: `%s`, current version: `%s`' %
                    (VERSION, about.VERSION),
                    'Please restart Sublime Text to complete the update.',
                ]))
    except Exception:
        pass

    def cb():
        aso = gs.aso()
        old_version = aso.get('version', '')
        old_ann = aso.get('ann', '')
        if about.VERSION > old_version or about.ANN > old_ann:
            aso.set('version', about.VERSION)
            aso.set('ann', about.ANN)
            gs.save_aso()
            gs.focus(gs.dist_path('CHANGELOG.md'))

    sublime.set_timeout(cb, 0)
Пример #3
0
            def f2(cl, err):
                c = {}
                if len(cl) == 1:
                    c = cl[0]

                if set_status:
                    if c:
                        pfx = 'func('
                        typ = c['type']
                        if typ.startswith(pfx):
                            s = 'func %s(%s' % (c['name'], typ[len(pfx):])
                        else:
                            s = '%s: %s' % (c['name'], typ)

                        view.set_status(HINT_KEY, s)
                    else:
                        view.erase_status(HINT_KEY)
                else:
                    if c:
                        s = '%s %s\n%s' % (c['name'], c['class'], c['type'])
                    else:
                        s = '// %s' % (err or 'No calltips found')

                    gs.show_output(HINT_KEY,
                                   s,
                                   print_output=False,
                                   syntax_file='GsDoc')
Пример #4
0
			def f2(cl, err):
				c = {}
				if len(cl) == 1:
					c = cl[0]

				if set_status:
					if c:
						pfx = 'func('
						typ = c['type']
						if typ.startswith(pfx):
							s = 'func %s(%s' % (c['name'], typ[len(pfx):])
						else:
							s = '%s: %s' % (c['name'], typ)


						view.set_status(HINT_KEY, s)
					else:
						view.erase_status(HINT_KEY)
				else:
					if c:
						s = '%s %s\n%s' % (c['name'], c['class'], c['type'])
					else:
						s = '// %s' % (err or 'No calltips found')

					gs.show_output(HINT_KEY, s, print_output=False, syntax_file='GsDoc')
Пример #5
0
def plugin_loaded():
	from gosubl import about
	from gosubl import sh
	from gosubl import ev
	from gosubl import gs
	from gosubl import mg9

	if VERSION != about.VERSION:
		gs.show_output('GoSublime-main', '\n'.join([
			'GoSublime has been updated.',
			'New version: `%s`, current version: `%s`' % (VERSION, about.VERSION),
			'Please restart Sublime Text to complete the update.',
			execErr,
		]))
		return

	if gs.attr('about.version'):
		gs.show_output('GoSublime-main', '\n'.join([
			'GoSublime appears to have been updated.',
			'New ANNOUNCE: `%s`, current ANNOUNCE: `%s`' % (ANN, about.ANN),
			'You may need to restart Sublime Text.',
		]))
		return

	mods = [
		('gs', gs),
		('sh', sh),
		('mg9', mg9),
	]

	gs.set_attr('about.version', VERSION)
	gs.set_attr('about.ann', ANN)

	for mod_name, mod in mods:
		print('GoSublime %s: init mod(%s)' % (VERSION, mod_name))

		try:
			mod.gs_init({
				'version': VERSION,
				'ann': ANN,
				'margo_exe': MARGO_EXE,
			})
		except TypeError:
			# old versions didn't take an arg
			mod.gs_init()

	ev.init.post_add = lambda e, f: f()
	ev.init()

	def cb():
		aso = gs.aso()
		old_version = aso.get('version', '')
		old_ann = aso.get('ann', '')
		if about.VERSION > old_version or about.ANN > old_ann:
			aso.set('version', about.VERSION)
			aso.set('ann', about.ANN)
			gs.save_aso()
			gs.focus(gs.dist_path('CHANGELOG.md'))

	sublime.set_timeout(cb, 0)
Пример #6
0
def plugin_loaded():
	from gosubl import about
	from gosubl import gs
	from gosubl import mg9

	gs.gs_init()
	mg9.gs_init()

	# we need the values in the file on-disk but we don't want any interference with the live env
	try:
		gs.set_attr('about.version', VERSION)
		gs.set_attr('about.ann', ANN)

		if about.VERSION != VERSION:
			gs.show_output('GoSublime-source', '\n'.join([
				'GoSublime source has been updated.',
				'New version: `%s`, current version: `%s`' % (VERSION, about.VERSION),
				'Please restart Sublime Text to complete the update.',
			]))
	except Exception:
		pass

	def cb():
		aso = gs.aso()
		old_version = aso.get('version', '')
		old_ann = aso.get('ann', '')
		if about.VERSION > old_version or about.ANN > old_ann:
			aso.set('version', about.VERSION)
			aso.set('ann', about.ANN)
			gs.save_aso()
			gs.focus(gs.dist_path('CHANGELOG.md'))

	sublime.set_timeout(cb, 0)
Пример #7
0
	def run(self, edit, set_status=False):
		view = self.view
		c, err = self.tip(edit)
		if set_status:
			if c:
				s = '%s: %s' % (c['name'], c['type'])
				view.set_status(HINT_KEY, s)
			else:
				view.erase_status(HINT_KEY)
		else:
			if c:
				s = '%s %s\n%s' % (c['name'], c['class'], c['type'])
			else:
				s = '// %s' % err
			gs.show_output(HINT_KEY, s, print_output=False, syntax_file='GsDoc')
 def run(self, edit, set_status=False):
     view = self.view
     c, err = self.tip(edit)
     if set_status:
         if c:
             s = '%s: %s' % (c['name'], c['type'])
             view.set_status(HINT_KEY, s)
         else:
             view.erase_status(HINT_KEY)
     else:
         if c:
             s = '%s %s\n%s' % (c['name'], c['class'], c['type'])
         else:
             s = '// %s' % err
         gs.show_output(HINT_KEY,
                        s,
                        print_output=False,
                        syntax_file='GsDoc')
Пример #9
0
def _check_env(e):
	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)
Пример #10
0
            def f2(cl, err):
                c = {}
                if len(cl) == 1:
                    c = cl[0]

                if set_status:
                    intel, _ = mg9.bcall('intel', {
                        'Fn': fn,
                        'Src': src,
                        'Pos': pos,
                    })

                    s = ''
                    if c:
                        pfx = 'func('
                        typ = c['type']
                        if typ.startswith(pfx):
                            s = 'func %s(%s' % (c['name'], typ[len(pfx):])
                        else:
                            s = '%s: %s' % (c['name'], typ)

                    func = intel.get('Func')
                    if func:
                        s = u'%s \u00B7 %s > %s' % (s, intel.get('Pkg'), func)

                    if s:
                        view.set_status(HINT_KEY, s)
                    else:
                        view.erase_status(HINT_KEY)
                else:
                    if c:
                        s = '%s %s\n%s' % (c['name'], c['class'], c['type'])
                    else:
                        s = '// %s' % (err or 'No calltips found')

                    gs.show_output(HINT_KEY,
                                   s,
                                   print_output=False,
                                   syntax_file='GsDoc')
Пример #11
0
		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)
Пример #12
0
            def f2(cl, err):
                c = {}
                if len(cl) == 1:
                    c = cl[0]

                if set_status:
                    if c:
                        pfx = "func("
                        typ = c["type"]
                        if typ.startswith(pfx):
                            s = "func %s(%s" % (c["name"], typ[len(pfx) :])
                        else:
                            s = "%s: %s" % (c["name"], typ)

                        view.set_status(HINT_KEY, s)
                    else:
                        view.erase_status(HINT_KEY)
                else:
                    if c:
                        s = "%s %s\n%s" % (c["name"], c["class"], c["type"])
                    else:
                        s = "// %s" % (err or "No calltips found")

                    gs.show_output(HINT_KEY, s, print_output=False, syntax_file="GsDoc")
Пример #13
0
			def f2(cl, err):
				c = {}
				if len(cl) == 1:
					c = cl[0]

				if set_status:
					intel, _ = mg9.bcall('intel', {
						'Fn': fn,
						'Src': src,
						'Pos': pos,
					})

					s = ''
					if c:
						pfx = 'func('
						typ = c['type']
						if typ.startswith(pfx):
							s = 'func %s(%s' % (c['name'], typ[len(pfx):])
						else:
							s = '%s: %s' % (c['name'], typ)

					func = intel.get('Func')
					if func:
						s = u'%s \u00B7 %s > %s' % (s, intel.get('Pkg'), func)

					if s:
						view.set_status(HINT_KEY, s)
					else:
						view.erase_status(HINT_KEY)
				else:
					if c:
						s = '%s %s\n%s' % (c['name'], c['class'], c['type'])
					else:
						s = '// %s' % (err or 'No calltips found')

					gs.show_output(HINT_KEY, s, print_output=False, syntax_file='GsDoc')
Пример #14
0
	def run(self):
		s = 'GoSublime Sanity Check\n\n%s' % '\n'.join(mg9.sanity_check_sl(mg9.sanity_check({}, True)))
		gs.show_output('GoSublime', s)
Пример #15
0
 def run(self):
     s = 'GoSublime Sanity Check\n\n%s' % '\n'.join(
         ['%7s: %s' % ln for ln in mg9.sanity_check()])
     gs.show_output('GoSublime', s)
Пример #16
0
	def show_hint(self, s):
		dmn = '%s.completion-hint' % DOMAIN
		gs.show_output(dmn, s, print_output=False, syntax_file='GsDoc')
Пример #17
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()
            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()
Пример #18
0
 def show_hint(self, s):
     dmn = '%s.completion-hint' % DOMAIN
     gs.show_output(dmn, s, print_output=False, syntax_file='GsDoc')
Пример #19
0
def plugin_loaded():
    from gosubl import about
    from gosubl import cfg
    from gosubl import ui
    from gosubl import vu
    from gosubl import sh
    from gosubl import ev
    from gosubl import gs
    from gosubl import mg9
    from gosubl import hl
    from gosubl import nineo
    from gosubl import nineo_builtins

    if VERSION != about.VERSION:
        gs.show_output(
            'GoSublime-main', '\n'.join([
                'GoSublime has been updated.',
                'New version: `%s`, current version: `%s`' %
                (VERSION, about.VERSION),
                'Please restart Sublime Text to complete the update.',
                execErr,
            ]))
        return

    if gs.attr('about.version'):
        gs.show_output(
            'GoSublime-main', '\n'.join([
                'GoSublime appears to have been updated.',
                'New ANNOUNCE: `%s`, current ANNOUNCE: `%s`' %
                (ANN, about.ANN),
                'You may need to restart Sublime Text.',
            ]))
        return

    mods = [
        ('cfg', cfg),
        ('ui', ui),
        ('vu', vu),
        ('gs', gs),
        ('sh', sh),
        ('mg9', mg9),
        ('9o', nineo),
        ('hl', hl),
        ('9o-builtins', nineo_builtins),
    ]

    gs.set_attr('about.version', VERSION)
    gs.set_attr('about.ann', ANN)

    m = {
        'version': VERSION,
        'ann': ANN,
    }

    for mod_name, mod in mods:
        print('GoSublime %s: init mod(%s)' % (about.VERSION, mod_name))

        try:
            mod.gs_init(m)
        except TypeError:
            # old versions didn't take an arg
            mod.gs_init()

    ev.init.post_add = lambda e, f: f()
    ev.init()

    def cb():
        aso = gs.aso()
        if about.ANN != aso.get('ann', ''):
            aso.set('ann', about.ANN)
            gs.save_aso()
            vu.open(gs.dist_path('CHANGELOG.md'))

    sublime.set_timeout(cb, 0)

    pd = os.path.join(gs.packages_dir(), 'User')
    sys.path.insert(0, pd)
    try:
        import MyGoSublime
        MyGoSublime.gs_init(m)
    except AttributeError:
        pass
    except ImportError:
        pass
    finally:
        sys.path.remove(pd)
Пример #20
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()
Пример #21
0
	def show_output(self, s):
		gs.show_output(DOMAIN+'-output', s, False, 'GsDoc')
Пример #22
0
	def run(self):
		s = 'GoSublime Sanity Check\n\n%s' % '\n'.join(['%7s: %s' % ln for ln in mg9.sanity_check()])
		gs.show_output('GoSublime', s)
Пример #23
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()
Пример #24
0
 def show_output(self, s):
     gs.show_output(DOMAIN + '-output', s, False, 'GsDoc')
Пример #25
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
Пример #26
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

    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()
    err = ""

    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()

        cmd = sh.Command(["go", "build", "-v", "-x", "-o", _margo_bin(INSTALL_EXE)])
        cmd.wd = _margo_src()
        cmd.env = {"GOBIN": "", "GOPATH": gs.dist_path("something_borrowed")}

        ev.debug("%s.build" % DOMAIN, {"cmd": cmd.cmd_lst, "cwd": cmd.wd})

        cr = cmd.run()
        m_out = "cmd: `%s`\nstdout: `%s`\nstderr: `%s`" % (cr.cmd_lst, cr.out.strip(), cr.err.strip())

        if not cr.ok:
            m_out = "%s\nexception: `%s`" % (m_out, cr.exc)
            err = "MarGo build failure\n%s" % m_out

        if not err and _bins_exist():

            def f():
                gs.aso().set("install_version", INSTALL_VERSION)
                gs.save_aso()

            sublime.set_timeout(f, 0)

    gs.set_attr(_inst_name(), "done")

    if err:
        gs.error(DOMAIN, err)
    else:
        # notify this early so we don't mask any notices below
        gs.notify("GoSublime", "Ready")

    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"), 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()
Пример #27
0
def plugin_loaded():
    from gosubl import about
    from gosubl import sh
    from gosubl import ev
    from gosubl import gs
    from gosubl import mg9

    if VERSION != about.VERSION:
        gs.show_output(
            "GoSublime-main",
            "\n".join(
                [
                    "GoSublime has been updated.",
                    "New version: `%s`, current version: `%s`" % (VERSION, about.VERSION),
                    "Please restart Sublime Text to complete the update.",
                    execErr,
                ]
            ),
        )
        return

    if gs.attr("about.version"):
        gs.show_output(
            "GoSublime-main",
            "\n".join(
                [
                    "GoSublime appears to have been updated.",
                    "New ANNOUNCE: `%s`, current ANNOUNCE: `%s`" % (ANN, about.ANN),
                    "You may need to restart Sublime Text.",
                ]
            ),
        )
        return

    mods = [("gs", gs), ("sh", sh), ("mg9", mg9)]

    gs.set_attr("about.version", VERSION)
    gs.set_attr("about.ann", ANN)

    for mod_name, mod in mods:
        print("GoSublime %s: init mod(%s)" % (VERSION, mod_name))

        try:
            mod.gs_init({"version": VERSION, "ann": ANN, "margo_exe": MARGO_EXE})
        except TypeError:
            # old versions didn't take an arg
            mod.gs_init()

    ev.init.post_add = lambda e, f: f()
    ev.init()

    def cb():
        aso = gs.aso()
        old_version = aso.get("version", "")
        old_ann = aso.get("ann", "")
        if about.VERSION > old_version or about.ANN > old_ann:
            aso.set("version", about.VERSION)
            aso.set("ann", about.ANN)
            gs.save_aso()
            gs.focus(gs.dist_path("CHANGELOG.md"))

    sublime.set_timeout(cb, 0)
Пример #28
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()
Пример #29
0
 def run(self):
     s = "GoSublime Sanity Check\n\n%s" % "\n".join(mg9.sanity_check_sl(mg9.sanity_check({}, True)))
     gs.show_output("GoSublime", s)
Пример #30
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()
Пример #31
0
def plugin_loaded():
	from gosubl import about
	from gosubl import cfg
	from gosubl import ui
	from gosubl import vu
	from gosubl import sh
	from gosubl import ev
	from gosubl import gs
	from gosubl import mg9
	from gosubl import hl
	from gosubl import nineo
	from gosubl import nineo_builtins

	if VERSION != about.VERSION:
		gs.show_output('GoSublime-main', '\n'.join([
			'GoSublime has been updated.',
			'New version: `%s`, current version: `%s`' % (VERSION, about.VERSION),
			'Please restart Sublime Text to complete the update.',
			execErr,
		]))
		return

	if gs.attr('about.version'):
		gs.show_output('GoSublime-main', '\n'.join([
			'GoSublime appears to have been updated.',
			'New ANNOUNCE: `%s`, current ANNOUNCE: `%s`' % (ANN, about.ANN),
			'You may need to restart Sublime Text.',
		]))
		return

	mods = [
		('cfg', cfg),
		('ui', ui),
		('vu', vu),
		('gs', gs),
		('sh', sh),
		('mg9', mg9),
		('9o', nineo),
		('hl', hl),
		('9o-builtins', nineo_builtins),
	]

	gs.set_attr('about.version', VERSION)
	gs.set_attr('about.ann', ANN)

	m = {
		'version': VERSION,
		'ann': ANN,
	}

	for mod_name, mod in mods:
		print('GoSublime %s: init mod(%s)' % (about.VERSION, mod_name))

		try:
			mod.gs_init(m)
		except TypeError:
			# old versions didn't take an arg
			mod.gs_init()

	ev.init.post_add = lambda e, f: f()
	ev.init()

	def cb():
		aso = gs.aso()
		if about.ANN != aso.get('ann', ''):
			aso.set('ann', about.ANN)
			gs.save_aso()
			vu.open(gs.dist_path('CHANGELOG.md'))

	sublime.set_timeout(cb, 0)

	pd = os.path.join(gs.packages_dir(), 'User')
	sys.path.insert(0, pd)
	try:
		import MyGoSublime
		MyGoSublime.gs_init(m)
	except AttributeError:
		pass
	except ImportError:
		pass
	finally:
		sys.path.remove(pd)
Пример #32
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
Пример #33
0
def build_mg(force=False):
	if force:
		pass
	elif gs.setting('_rebuild'):
		print('GoSublime: `_rebuild` is set')
	elif _mg_exists():
		return 'ok'

	gs.notify('GoSublime', 'Installing MarGo')

	gobin = sh.bin_dir()
	gopath = gs.dist_path()
	wd = gobin
	env = {
		'CGO_ENABLED': '0',
		'GOBIN': gobin,
		'GOPATH': gopath,
	}

	# do a cleanup just-in-case there are old packages lying around... we don't really care if it fails
	clean = sh.Command(['go', 'clean', '-i', 'gosubli.me/...'])
	clean.wd = wd
	clean.env = env
	clean.run()

	f = gs.setting('_build_flags') or ['-v', '-x']
	args = gs.lst('go', 'build', f, '-o', sh.exe('margo'), 'gosubli.me/margo')

	build = sh.Command(args)
	build.wd = wd
	build.env = env

	ev.debug('%s.build' % DOMAIN, {
		'cmd': build.cmd_lst,
		'cwd': build.wd,
	})

	cr = build.run()

	if cr.ok and _mg_exists():
		return 'ok'

	m_out = 'cmd: `%s`\nstdout: `%s`\nstderr: `%s`\nexception: `%s`' % (
		cr.cmd_lst,
		cr.out.strip(),
		cr.err.strip(),
		cr.exc,
	)

	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)))

	return m_out