Example #1
0
def install(aso_tokens, force_install):
    init_start = time.time()

    try:
        os.makedirs(gs.home_path("bin"))
    except:
        pass

    if not force_install and aso_tokens == _gen_tokens():
        m_out = "no"
        g_out = "no"
    else:
        start = time.time()
        m_out, err, _ = _run(["go", "build", "-o", MARGO9_BIN], cwd=MARGO9_SRC)
        m_out, m_ok = _so(m_out, err, start, time.time())

        # on windows the file cannot be replaced if it's running so close gocode first.
        # in theory, mg9 has the same issue but since it's attached to a st2 instance,
        # the only way to close it is to close st2 (which we're presumably already doing)
        start = time.time()
        if os.path.exists(GOCODE_BIN):
            _run([GOCODE_BIN, "close"])

        g_out, err, _ = _run(["go", "build", "-o", GOCODE_BIN], cwd=GOCODE_SRC)
        g_out, g_ok = _so(g_out, err, start, time.time())

        if m_ok and g_ok:

            def f():
                gs.aso().set("mg9_install_tokens", _gen_tokens())
                gs.save_aso()

            sublime.set_timeout(f, 0)

    a = (
        "GoSublime init (%0.3fs)" % (time.time() - init_start),
        "| install margo9: %s" % m_out,
        "| install gocode: %s" % g_out,
        "|           ~bin: %s" % gs.home_path("bin"),
        "|         margo9: %s (%s)" % _tp(MARGO9_BIN),
        "|         gocode: %s (%s)" % _tp(GOCODE_BIN),
    )
    gs.println(*a)
Example #2
0
def _gocode(args, env={}, input=None):
    home = gs.home_path()
    # gocode should store its settings here
    nv = {"XDG_CONFIG_HOME": home}
    nv.update(env)

    # until mg9 is in active use we'll fallback to existing gocode
    bin = GOCODE_BIN if os.path.exists(GOCODE_BIN) else "gocode"
    cmd = gs.lst(bin, args)
    return gsshell.run(cmd, input=input, env=nv, cwd=home)
Example #3
0
def _send():
    while True:
        try:
            try:
                method, arg, cb = _send_q.get()

                proc = gs.attr(PROC_ATTR_NAME)
                if not proc or proc.poll() is not None:
                    if proc:
                        try:
                            proc.kill()
                            proc.stdout.close()
                        except:
                            pass

                    maybe_install()

                    if not gs.checked(DOMAIN, 'launch _recv'):
                        gsq.launch(DOMAIN, _recv)

                    proc, _, err = gsshell.proc([MARGO9_BIN, '-poll=30'],
                                                stderr=gs.LOGFILE,
                                                env={
                                                    'XDG_CONFIG_HOME':
                                                    gs.home_path(),
                                                })
                    gs.set_attr(PROC_ATTR_NAME, proc)

                    if not proc:
                        gs.notice(DOMAIN, 'Cannot MarGo: %s' % err)
                        continue

                    gsq.launch(DOMAIN, lambda: _read_stdout(proc))

                req = Request(f=cb, method=method)
                gs.set_attr(REQUEST_PREFIX + req.token, req)

                gs.debug(
                    DOMAIN, 'margo request: method: %s, token: %s' %
                    (req.method, req.token))

                header, _ = gs.json_encode({
                    'method': method,
                    'token': req.token
                })
                body, _ = gs.json_encode(arg)
                ln = '%s %s\n' % (header, body)
                proc.stdin.write(ln)
            except Exception:
                gs.println(gs.traceback())
        except Exception:
            gs.println(gs.traceback())
            break
Example #4
0
def _sanity_check(env={}):
	if not env:
		env = gs.env()

	return [
		('version', REV),
		('~bin', '%s' % gs.home_path('bin')),
		('MarGo', '%s (%s)' % _tp(MARGO_BIN)),
		('GOROOT', '%s' % env.get('GOROOT', '(not set)')),
		('GOPATH', '%s' % env.get('GOPATH', '(not set)')),
		('GOBIN', '%s (should usually be (not set))' % env.get('GOBIN', '(not set)')),
	]
Example #5
0
def _sanity_check(env={}):
    if not env:
        env = gs.env()

    return [
        ("version", REV),
        ("~bin", "%s" % gs.home_path("bin")),
        ("margo0", "%s (%s)" % _tp(MARGO0_BIN)),
        ("margo9", "%s (%s)" % _tp(MARGO9_BIN)),
        ("GOROOT", "%s" % env.get("GOROOT", "(not set)")),
        ("GOPATH", "%s" % env.get("GOPATH", "(not set)")),
        ("GOBIN", "%s (should usually be (not set))" % env.get("GOBIN", "(not set)")),
    ]
Example #6
0
def _sanity_check(env={}):
    if not env:
        env = gs.env()

    return [
        ('version', REV),
        ('~bin', '%s' % gs.home_path('bin')),
        ('MarGo', '%s (%s)' % _tp(MARGO_BIN)),
        ('GOROOT', '%s' % env.get('GOROOT', '(not set)')),
        ('GOPATH', '%s' % env.get('GOPATH', '(not set)')),
        ('GOBIN',
         '%s (should usually be (not set))' % env.get('GOBIN', '(not set)')),
    ]
Example #7
0
def complete(fn, src, pos):
	home = gs.home_path()
	builtins = (gs.setting('autocomplete_builtins') is True or gs.setting('complete_builtins') is True)
	res, err = bcall('gocode_complete', {
		'Dir': gs.basedir_or_cwd(fn),
		'Builtins': builtins,
		'Fn':  fn or '',
		'Src': src or '',
		'Pos': pos or 0,
		'Home': home,
		'Env': gs.env({
			'XDG_CONFIG_HOME': home,
		}),
	})

	res = gs.dval(res.get('completions'), [])
	return res, err
Example #8
0
def complete(fn, src, pos):
	home = gs.home_path()
	builtins = (gs.setting('autocomplete_builtins') is True or gs.setting('complete_builtins') is True)
	res, err = bcall('gocode_complete', {
		'Dir': gs.basedir_or_cwd(fn),
		'Builtins': builtins,
		'Fn':  fn or '',
		'Src': src or '',
		'Pos': pos or 0,
		'Home': home,
		'Env': gs.env({
			'XDG_CONFIG_HOME': home,
		}),
	})

	res = gs.dval(res.get('completions'), [])
	return res, err
Example #9
0
def _send():
	while True:
		try:
			try:
				method, arg, cb = _send_q.get()

				proc = gs.attr(PROC_ATTR_NAME)
				if not proc or proc.poll() is not None:
					if proc:
						try:
							proc.kill()
							proc.stdout.close()
						except:
							pass

					maybe_install()

					if not gs.checked(DOMAIN, 'launch _recv'):
						gsq.launch(DOMAIN, _recv)

					proc, _, err = gsshell.proc([MARGO9_BIN, '-poll=30'], stderr=gs.LOGFILE ,env={
						'XDG_CONFIG_HOME': gs.home_path(),
					})
					gs.set_attr(PROC_ATTR_NAME, proc)

					if not proc:
						gs.notice(DOMAIN, 'Cannot MarGo: %s' % err)
						continue

					gsq.launch(DOMAIN, lambda: _read_stdout(proc))

				req = Request(f=cb, method=method)
				gs.set_attr(REQUEST_PREFIX+req.token, req)

				gs.debug(DOMAIN, 'margo request: method: %s, token: %s' % (req.method, req.token))

				header, _ = gs.json_encode({'method': method, 'token': req.token})
				body, _ = gs.json_encode(arg)
				ln = '%s %s\n' % (header, body)
				proc.stdin.write(ln)
			except Exception:
				gs.println(gs.traceback())
		except Exception:
			gs.println(gs.traceback())
			break
Example #10
0
def complete(fn, src, pos):
    home = gs.home_path()
    builtins = gs.setting("autocomplete_builtins") is True or gs.setting("complete_builtins") is True
    res, err = bcall(
        "gocode_complete",
        {
            "Dir": gs.basedir_or_cwd(fn),
            "Builtins": builtins,
            "Fn": fn or "",
            "Src": src or "",
            "Pos": pos or 0,
            "Home": home,
            "Env": gs.env({"XDG_CONFIG_HOME": home}),
        },
    )

    res = gs.dval(res.get("completions"), [])
    return res, err
Example #11
0
import sublime
import threading
import os
import gsq
import time
import hashlib
import base64
import Queue

DOMAIN = 'MarGo9'

# customization of, or user-owned gocode and margo will no longer be supported
# so we'll hardcode the relevant paths and refer to them directly instead of relying on PATH
MARGO9_SRC = gs.dist_path('margo9')
GOCODE_SRC = gs.dist_path('something_borrowed/gocode')
MARGO9_BIN = gs.home_path('bin', 'gosublime.margo9.exe')
GOCODE_BIN = gs.home_path('bin', 'gosublime.gocode.exe')

def _sb(s):
	bdir = gs.home_path('bin')
	if s.startswith(bdir):
		s = '~bin%s' % (s[len(bdir):])
	return s

def _tp(s):
	return (_sb(s), ('ok' if os.path.exists(s) else 'missing'))

def _so(out, err, start, end):
	out = out.strip()
	err = err.strip()
	ok = not out and not err
Example #12
0
with open(CHANGELOG_FN) as f:
	s = f.read()

for m in CHANGES_SPLIT_PAT.split(s):
	m = CHANGES_MATCH_PAT.match(m)
	if m:
		CHANGES.append((m.group(1), m.group(2)))
CHANGES.sort(reverse=True)
REV = CHANGES[0][0]

# customization of, or user-owned margo will no longer be supported
# so we'll hardcode the relevant paths and refer to them directly instead of relying on PATH
MARGO_SRC = gs.dist_path('margo9')
MARGO_EXE = 'gosublime.%s.margo.exe' % REV
MARGO_BIN = gs.home_path('bin', MARGO_EXE)

if not gs.checked(DOMAIN, '_vars'):
	_send_q = Queue.Queue()
	_recv_q = Queue.Queue()

class Request(object):
	def __init__(self, f, method='', token=''):
		self.f = f
		self.tm = time.time()
		self.method = method
		if token:
			self.token = token
		else:
			self.token = 'mg9.autoken.%s' % uuid.uuid4()
Example #13
0
def install(aso_tokens, force_install):
	k = 'mg9.install.%s' % REV
	if gs.attr(k, False):
		gs.error(DOMAIN, 'Installation aborted. Install command already called for GoSublime %s.' % REV)
		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([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' % (MARGO_EXE, 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 != 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()

	gsq.launch(DOMAIN, margo.bye_ni)
Example #14
0
def _sb(s):
    bdir = gs.home_path('bin')
    if s.startswith(bdir):
        s = '~bin%s' % (s[len(bdir):])
    return s
Example #15
0
def install(aso_tokens, force_install):
    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():
        m0_out = 'no'
        m_out = 'no'
    else:
        gs.notify('GoSublime', 'Installing MarGo0')
        start = time.time()
        m0_out, err, _ = _run(['go', 'build', '-o', MARGO0_BIN],
                              cwd=MARGO0_SRC)
        m0_out, m0_ok = _so(m0_out, err, start, time.time())

        if os.path.exists(MARGO0_BIN):
            margo.bye_ni()

        gs.notify('GoSublime', 'Installing MarGo9')
        start = time.time()
        m_out, err, _ = _run(['go', 'build', '-o', MARGO9_BIN], cwd=MARGO9_SRC)
        m_out, m_ok = _so(m_out, err, start, time.time())

        if m_ok and m0_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([MARGO9_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' % (MARGO9_EXE, 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 margo0: %s' % m0_out,
        '| install margo9: %s' % m_out,
        '|           ~bin: %s' % gs.home_path('bin'),
        '|         margo0: %s (%s)' % _tp(MARGO0_BIN),
        '|         margo9: %s (%s)' % _tp(MARGO9_BIN),
        '|         GOROOT: %s' % e.get('GOROOT', '(not set)'),
        '|         GOPATH: %s' % e.get('GOPATH', '(not set)'),
        '|          GOBIN: %s (should usually be (not set))' %
        e.get('GOBIN', '(not set)'),
    )
    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()
Example #16
0
import uuid
import margo
import json
import atexit

DOMAIN = 'MarGo9'
REQUEST_PREFIX = '%s.rqst.' % DOMAIN
PROC_ATTR_NAME = 'mg9.proc'

# customization of, or user-owned margo will no longer be supported
# so we'll hardcode the relevant paths and refer to them directly instead of relying on PATH
MARGO0_SRC = gs.dist_path('something_borrowed/margo0')
MARGO9_SRC = gs.dist_path('margo9')
MARGO0_EXE = 'gosublime.margo0.exe'
MARGO9_EXE = 'gosublime.margo9.exe'
MARGO0_BIN = gs.home_path('bin', MARGO0_EXE)
MARGO9_BIN = gs.home_path('bin', MARGO9_EXE)

if not gs.checked(DOMAIN, '_vars'):
    _send_q = Queue.Queue()
    _recv_q = Queue.Queue()


class Request(object):
    def __init__(self, f, method='', token=''):
        self.f = f
        self.tm = time.time()
        self.method = method
        if token:
            self.token = token
        else:
Example #17
0
def _send():
    while True:
        try:
            try:
                method, arg, cb = _send_q.get()

                proc = gs.attr(PROC_ATTR_NAME)
                if not proc or proc.poll() is not None:
                    killSrv()
                    maybe_install()

                    if not gs.checked(DOMAIN, "launch _recv"):
                        gsq.launch(DOMAIN, _recv)

                    proc, _, err = gsshell.proc(
                        [MARGO9_BIN, "-poll=30"], stderr=gs.LOGFILE, env={"XDG_CONFIG_HOME": gs.home_path()}
                    )
                    gs.set_attr(PROC_ATTR_NAME, proc)

                    if not proc:
                        gs.notice(DOMAIN, "Cannot start MarGo: %s" % err)
                        try:
                            cb({}, "Abort. Cannot start MarGo")
                        except:
                            pass
                        continue

                    gsq.launch(DOMAIN, lambda: _read_stdout(proc))

                req = Request(f=cb, method=method)
                gs.set_attr(REQUEST_PREFIX + req.token, req)

                gs.debug(DOMAIN, "margo request: method: %s, token: %s" % (req.method, req.token))

                header, _ = gs.json_encode({"method": method, "token": req.token})
                body, _ = gs.json_encode(arg)
                ln = "%s %s\n" % (header, body)
                proc.stdin.write(ln)
            except Exception:
                killSrv()
                gs.println(gs.traceback())
        except Exception:
            gs.println(gs.traceback())
            break
Example #18
0
import threading
import os
import gsq
import time
import hashlib
import base64
import Queue
import uuid

DOMAIN = "MarGo9"

# customization of, or user-owned gocode and margo will no longer be supported
# so we'll hardcode the relevant paths and refer to them directly instead of relying on PATH
MARGO9_SRC = gs.dist_path("margo9")
GOCODE_SRC = gs.dist_path("something_borrowed/gocode")
MARGO9_BIN = gs.home_path("bin", "gosublime.margo9.exe")
GOCODE_BIN = gs.home_path("bin", "gosublime.gocode.exe")

if not gs.checked(DOMAIN, "_vars"):
    _send_q = Queue.Queue()
    _recv_q = Queue.Queue()
    _stash = {}


def _sb(s):
    bdir = gs.home_path("bin")
    if s.startswith(bdir):
        s = "~bin%s" % (s[len(bdir) :])
    return s

Example #19
0
File: mg9.py Project: d3z/GoSublime
def install(aso_tokens, force_install):
	k = 'mg9.install.%s' % REV
	if gs.attr(k, False):
		gs.error(DOMAIN, 'Installation aborted. Install command already called for GoSublime %s.' % REV)
		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():
		m0_out = 'no'
		m_out = 'no'
	else:
		gs.notify('GoSublime', 'Installing MarGo0')
		start = time.time()
		m0_out, err, _ = _run(['go', 'build', '-o', MARGO0_BIN], cwd=MARGO0_SRC)
		m0_out, m0_ok = _so(m0_out, err, start, time.time())

		if os.path.exists(MARGO0_BIN):
			margo.bye_ni()

		gs.notify('GoSublime', 'Installing MarGo9')
		start = time.time()
		m_out, err, _ = _run(['go', 'build', '-o', MARGO9_BIN], cwd=MARGO9_SRC)
		m_out, m_ok = _so(m_out, err, start, time.time())

		if m_ok and m0_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([MARGO9_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' % (MARGO9_EXE, 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 margo0: %s' % m0_out,
		'| install margo9: %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()
Example #20
0
def install(aso_tokens, force_install):
    k = "mg9.install.%s" % REV
    if gs.attr(k, False):
        gs.error(DOMAIN, "Installation aborted. Install command already called for GoSublime %s." % REV)
        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():
        m0_out = "no"
        m_out = "no"
    else:
        gs.notify("GoSublime", "Installing MarGo0")
        start = time.time()
        m0_out, err, _ = _run(["go", "build", "-o", MARGO0_BIN], cwd=MARGO0_SRC)
        m0_out, m0_ok = _so(m0_out, err, start, time.time())

        if os.path.exists(MARGO0_BIN):
            margo.bye_ni()

        gs.notify("GoSublime", "Installing MarGo9")
        start = time.time()
        m_out, err, _ = _run(["go", "build", "-o", MARGO9_BIN], cwd=MARGO9_SRC)
        m_out, m_ok = _so(m_out, err, start, time.time())

        if m_ok and m0_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([MARGO9_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" % (MARGO9_EXE, 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 margo0: %s" % m0_out,
        "| install margo9: %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 not in (MARGO9_EXE, MARGO0_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()
Example #21
0
import uuid
import margo
import json
import atexit

DOMAIN = 'MarGo9'
REQUEST_PREFIX = '%s.rqst.' % DOMAIN
PROC_ATTR_NAME = 'mg9.proc'

# customization of, or user-owned margo will no longer be supported
# so we'll hardcode the relevant paths and refer to them directly instead of relying on PATH
MARGO0_SRC = gs.dist_path('something_borrowed/margo0')
MARGO9_SRC = gs.dist_path('margo9')
MARGO0_EXE = 'gosublime.margo0.exe'
MARGO9_EXE = 'gosublime.margo9.exe'
MARGO0_BIN = gs.home_path('bin', MARGO0_EXE)
MARGO9_BIN = gs.home_path('bin', MARGO9_EXE)

if not gs.checked(DOMAIN, '_vars'):
	_send_q = Queue.Queue()
	_recv_q = Queue.Queue()

class Request(object):
	def __init__(self, f, method='', token=''):
		self.f = f
		self.tm = time.time()
		self.method = method
		if token:
			self.token = token
		else:
			self.token = 'mg9.autoken.%s' % uuid.uuid4()
Example #22
0
def _sb(s):
	bdir = gs.home_path('bin')
	if s.startswith(bdir):
		s = '~bin%s' % (s[len(bdir):])
	return s
Example #23
0
def install(aso_tokens, force_install):
    k = 'mg9.install.%s' % REV
    if gs.attr(k, False):
        gs.error(
            DOMAIN,
            'Installation aborted. Install command already called for GoSublime %s.'
            % REV)
        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([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' % (MARGO_EXE, 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 != 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()

    gsq.launch(DOMAIN, margo.bye_ni)
Example #24
0
with open(CHANGELOG_FN) as f:
    s = f.read()

for m in CHANGES_SPLIT_PAT.split(s):
    m = CHANGES_MATCH_PAT.match(m)
    if m:
        CHANGES.append((m.group(1), m.group(2)))
CHANGES.sort(reverse=True)
REV = CHANGES[0][0]

# customization of, or user-owned margo will no longer be supported
# so we'll hardcode the relevant paths and refer to them directly instead of relying on PATH
MARGO_SRC = gs.dist_path('margo9')
MARGO_EXE = 'gosublime.%s.margo.exe' % REV
MARGO_BIN = gs.home_path('bin', MARGO_EXE)

if not gs.checked(DOMAIN, '_vars'):
    _send_q = Queue.Queue()
    _recv_q = Queue.Queue()


class Request(object):
    def __init__(self, f, method='', token=''):
        self.f = f
        self.tm = time.time()
        self.method = method
        if token:
            self.token = token
        else:
            self.token = 'mg9.autoken.%s' % uuid.uuid4()
Example #25
0
def install(aso_tokens, force_install):
	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():
		m0_out = 'no'
		m_out = 'no'
		g_out = 'no'
	else:
		start = time.time()
		m0_out, err, _ = _run(['go', 'build', '-o', MARGO0_BIN], cwd=MARGO0_SRC)
		m0_out, m0_ok = _so(m0_out, err, start, time.time())

		if os.path.exists(GOCODE_BIN):
			margo.bye_ni()

		start = time.time()
		m_out, err, _ = _run(['go', 'build', '-o', MARGO9_BIN], cwd=MARGO9_SRC)
		m_out, m_ok = _so(m_out, err, start, time.time())

		# on windows the file cannot be replaced if it's running so close gocode first.
		# in theory, mg9 has the same issue but since it's attached to a st2 instance,
		# the only way to close it is to close st2 (which we're presumably already doing)
		start = time.time()
		if os.path.exists(GOCODE_BIN):
			_run([GOCODE_BIN, 'close'])

		g_out, err, _ = _run(['go', 'build', '-o', GOCODE_BIN], cwd=GOCODE_SRC)
		g_out, g_ok = _so(g_out, err, start, time.time())

		if m_ok and m0_ok and g_ok:
			def f():
				gs.aso().set('mg9_install_tokens', _gen_tokens())
				gs.save_aso()

			sublime.set_timeout(f, 0)

	out, err, _ = gsshell.run([MARGO9_EXE, '-env'], cwd=gs.home_path(), shell=True)
	if err:
		gs.notice(DOMAIN, 'Cannot run get env vars: %s' % (MARGO9_EXE, 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 margo0: %s' % m0_out,
		'| install margo9: %s' % m_out,
		'| install gocode: %s' % g_out,
		'|           ~bin: %s' % gs.home_path('bin'),
		'|         margo0: %s (%s)' % _tp(MARGO0_BIN),
		'|         margo9: %s (%s)' % _tp(MARGO9_BIN),
		'|         gocode: %s (%s)' % _tp(GOCODE_BIN),
		'|         GOROOT: %s' % e.get('GOROOT', '(not set)'),
		'|         GOPATH: %s' % e.get('GOPATH', '(not set)'),
		'|          GOBIN: %s (should usually be (not set))' % e.get('GOBIN', '(not set)'),
	)
	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))
Example #26
0
import Queue
import uuid
import margo
import json

DOMAIN = 'MarGo9'

# customization of, or user-owned gocode and margo will no longer be supported
# so we'll hardcode the relevant paths and refer to them directly instead of relying on PATH
MARGO0_SRC = gs.dist_path('something_borrowed/margo0')
MARGO9_SRC = gs.dist_path('margo9')
GOCODE_SRC = gs.dist_path('something_borrowed/gocode')
MARGO0_EXE = 'gosublime.margo0.exe'
MARGO9_EXE = 'gosublime.margo9.exe'
GOCODE_EXE = 'gosublime.gocode.exe'
MARGO0_BIN = gs.home_path('bin', MARGO0_EXE)
MARGO9_BIN = gs.home_path('bin', MARGO9_EXE)
GOCODE_BIN = gs.home_path('bin', GOCODE_EXE)

if not gs.checked(DOMAIN, '_vars'):
	_send_q = Queue.Queue()
	_recv_q = Queue.Queue()
	_stash = {}

def _sb(s):
	bdir = gs.home_path('bin')
	if s.startswith(bdir):
		s = '~bin%s' % (s[len(bdir):])
	return s

def _tp(s):
Example #27
0
def install(aso_tokens, force_install):
    k = 'mg9.install.%s' % REV
    if gs.attr(k, False):
        gs.error(
            DOMAIN,
            'Installation aborted. Install command already called for GoSublime %s.'
            % REV)
        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():
        m0_out = 'no'
        m_out = 'no'
    else:
        gs.notify('GoSublime', 'Installing MarGo0')
        start = time.time()
        m0_out, err, _ = _run(['go', 'build', '-o', MARGO0_BIN],
                              cwd=MARGO0_SRC)
        m0_out, m0_ok = _so(m0_out, err, start, time.time())

        if os.path.exists(MARGO0_BIN):
            margo.bye_ni()

        gs.notify('GoSublime', 'Installing MarGo9')
        start = time.time()
        m_out, err, _ = _run(['go', 'build', '-o', MARGO9_BIN], cwd=MARGO9_SRC)
        m_out, m_ok = _so(m_out, err, start, time.time())

        if m_ok and m0_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([MARGO9_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' % (MARGO9_EXE, 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 margo0: %s' % m0_out,
        '| install margo9: %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()
Example #28
0
def _sb(s):
    bdir = gs.home_path("bin")
    if s.startswith(bdir):
        s = "~bin%s" % (s[len(bdir) :])
    return s
Example #29
0
def install(aso_tokens, force_install):
	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():
		m0_out = 'no'
		m_out = 'no'
	else:
		gs.notify('GoSublime', 'Installing MarGo0')
		start = time.time()
		m0_out, err, _ = _run(['go', 'build', '-o', MARGO0_BIN], cwd=MARGO0_SRC)
		m0_out, m0_ok = _so(m0_out, err, start, time.time())

		if os.path.exists(MARGO0_BIN):
			margo.bye_ni()

		gs.notify('GoSublime', 'Installing MarGo9')
		start = time.time()
		m_out, err, _ = _run(['go', 'build', '-o', MARGO9_BIN], cwd=MARGO9_SRC)
		m_out, m_ok = _so(m_out, err, start, time.time())

		if m_ok and m0_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([MARGO9_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' % (MARGO9_EXE, 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 margo0: %s' % m0_out,
		'| install margo9: %s' % m_out,
		'|           ~bin: %s' % gs.home_path('bin'),
		'|         margo0: %s (%s)' % _tp(MARGO0_BIN),
		'|         margo9: %s (%s)' % _tp(MARGO9_BIN),
		'|         GOROOT: %s' % e.get('GOROOT', '(not set)'),
		'|         GOPATH: %s' % e.get('GOPATH', '(not set)'),
		'|          GOBIN: %s (should usually be (not set))' % e.get('GOBIN', '(not set)'),
	)
	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)))
Example #30
0
    s = f.read()

for m in CHANGES_SPLIT_PAT.split(s):
    m = CHANGES_MATCH_PAT.match(m)
    if m:
        CHANGES.append((m.group(1), m.group(2)))
CHANGES.sort(reverse=True)
REV = CHANGES[0][0]

# customization of, or user-owned margo will no longer be supported
# so we'll hardcode the relevant paths and refer to them directly instead of relying on PATH
MARGO0_SRC = gs.dist_path("something_borrowed/margo0")
MARGO9_SRC = gs.dist_path("margo9")
MARGO0_EXE = "gosublime.%s.margo0.exe" % REV
MARGO9_EXE = "gosublime.%s.margo9.exe" % REV
MARGO0_BIN = gs.home_path("bin", MARGO0_EXE)
MARGO9_BIN = gs.home_path("bin", MARGO9_EXE)

if not gs.checked(DOMAIN, "_vars"):
    _send_q = Queue.Queue()
    _recv_q = Queue.Queue()


class Request(object):
    def __init__(self, f, method="", token=""):
        self.f = f
        self.tm = time.time()
        self.method = method
        if token:
            self.token = token
        else: