Example #1
0
def cmd_tskill(view, edit, args, wd, rkey):
    if len(args) > 0:
        l = []
        for tid in args:
            tid = tid.lstrip('#')
            tid = tid_alias.get('%s-%s' % (tid, wd), tid)
            l.append('kill %s: %s' %
                     (tid, ('yes' if gs.cancel_task(tid) else 'no')))

        push_output(view, rkey, '\n'.join(l))
        return

    try:
        now = datetime.datetime.now().replace(microsecond=0)
        with gs.sm_lck:
            tasks = sorted(gs.sm_tasks.iteritems())

        l = []
        for tid, t in tasks:
            if t['cancel']:
                pfx = '#%s' % tid
            else:
                pfx = '(uninterruptible)'

            l.append('%s %s %s: %s' %
                     (pfx, (now - t['start'].replace(microsecond=0)),
                      t['domain'], t['message']))

        s = '\n'.join(l)
    except Exception as ex:
        gs.error_traceback(DOMAIN)
        s = 'Error: %s' % ex
    push_output(view, rkey, s)
Example #2
0
    def run(self, edit):
        v = self.view
        pos = gs.sel(v).begin()
        inscope = lambda p: v.score_selector(p, 'path.9o') > 0
        if not inscope(pos):
            pos -= 1
            if not inscope(pos):
                return

        path = v.substr(v.extract_scope(pos))
        if URL_PATH_PAT.match(path):
            if path.lower().startswith('gs.packages://'):
                path = os.path.join(sublime.packages_path(), path[14:])
            else:
                try:
                    if not URL_SCHEME_PAT.match(path):
                        path = 'http://%s' % path
                    gs.notify(DOMAIN, 'open url: %s' % path)
                    webbrowser.open_new_tab(path)
                except Exception:
                    gs.error_traceback(DOMAIN)

                return

        wd = v.settings().get('9o.wd') or active_wd()
        m = SPLIT_FN_POS_PAT.match(path)
        path = gs.apath((m.group(1) if m else path), wd)
        row = max(0, int(m.group(2)) - 1 if (m and m.group(2)) else 0)
        col = max(0, int(m.group(3)) - 1 if (m and m.group(3)) else 0)

        if os.path.exists(path):
            gs.focus(path, row, col, win=self.view.window())
        else:
            gs.notify(DOMAIN, "Invalid path `%s'" % path)
Example #3
0
    def run(self):
        default_file_name = 'untitled.go'
        pkg_name = 'main'
        view = gs.active_valid_go_view()
        try:
            basedir = gs.basedir_or_cwd(view and view.file_name())
            for fn in os.listdir(basedir):
                if fn.endswith('.go'):
                    name, _ = mg9.pkg_name(os.path.join(basedir, fn), '')
                    if name:
                        pkg_name = name
                        break
        except Exception:
            gs.error_traceback('GsNewGoFile')

        view = self.window.new_file()
        view.set_name(default_file_name)
        view.set_syntax_file('Packages/GoSublime/GoSublime.tmLanguage')
        edit = view.begin_edit()
        try:
            view.replace(edit, sublime.Region(0, view.size()),
                         'package %s\n' % pkg_name)
            view.sel().clear()
            view.sel().add(view.find(pkg_name, 0, sublime.LITERAL))
        finally:
            view.end_edit(edit)
Example #4
0
def cmd_tskill(view, edit, args, wd, rkey):
	if len(args) > 0:
		l = []
		for tid in args:
			tid = tid.lstrip('#')
			l.append('kill %s: %s' % (tid, ('yes' if gs.cancel_task(tid) else 'no')))

		push_output(view, rkey, '\n'.join(l))
		return

	try:
		now = datetime.datetime.now().replace(microsecond=0)
		with gs.sm_lck:
			tasks = sorted(gs.sm_tasks.iteritems())

		l = []
		for tid, t in tasks:
			if t['cancel']:
				pfx = '#%s' % tid
			else:
				pfx = '(uninterruptible)'

			l.append('%s %s %s: %s' % (pfx, (now - t['start'].replace(microsecond=0)), t['domain'], t['message']))

		s = '\n'.join(l)
	except Exception as ex:
		gs.error_traceback(DOMAIN)
		s = 'Error: %s' % ex
	push_output(view, rkey, s)
Example #5
0
	def run(self, edit):
		v = self.view
		pos = gs.sel(v).begin()
		inscope = lambda p: v.score_selector(p, 'path.9o') > 0
		if not inscope(pos):
			pos -= 1
			if not inscope(pos):
				return

		path = v.substr(v.extract_scope(pos))
		if URL_PATH_PAT.match(path):
			if path.lower().startswith('gs.packages://'):
				path = os.path.join(sublime.packages_path(), path[14:])
			else:
				try:
					if not URL_SCHEME_PAT.match(path):
						path = 'http://%s' % path
					gs.notify(DOMAIN, 'open url: %s' % path)
					webbrowser.open_new_tab(path)
				except Exception:
					gs.error_traceback(DOMAIN)

				return

		wd = v.settings().get('9o.wd') or active_wd()
		m = SPLIT_FN_POS_PAT.match(path)
		path = gs.apath((m.group(1) if m else path), wd)
		row = max(0, int(m.group(2))-1 if (m and m.group(2)) else 0)
		col = max(0, int(m.group(3))-1 if (m and m.group(3)) else 0)

		if os.path.exists(path):
			gs.focus(path, row, col, win=self.view.window())
		else:
			gs.notify(DOMAIN, "Invalid path `%s'" % path)
Example #6
0
    def run(self):
        default_file_name = "untitled.go"
        pkg_name = "main"
        view = gs.active_valid_go_view()
        try:
            basedir = gs.basedir_or_cwd(view and view.file_name())
            for fn in os.listdir(basedir):
                if fn.endswith(".go"):
                    name, _ = mg9.pkg_name(os.path.join(basedir, fn), "")
                    if name:
                        pkg_name = name
                        break
        except Exception:
            gs.error_traceback("GsNewGoFile")

        view = self.window.new_file()
        view.set_name(default_file_name)
        view.set_syntax_file("Packages/GoSublime/GoSublime.tmLanguage")
        edit = view.begin_edit()
        try:
            view.replace(edit, sublime.Region(0, view.size()), "package %s\n" % pkg_name)
            view.sel().clear()
            view.sel().add(view.find(pkg_name, 0, sublime.LITERAL))
        finally:
            view.end_edit(edit)
Example #7
0
def _save_all(win, wd):
	if gs.setting('autosave') is True and win is not None:
		for v in win.views():
			try:
				fn = v.file_name()
				if fn and v.is_dirty() and fn.endswith('.go') and os.path.dirname(fn) == wd:
					v.run_command('gs_fmt_save')
			except Exception:
				gs.error_traceback(DOMAIN)
Example #8
0
def _save_all(win, wd):
    if gs.setting('autosave') is True and win is not None:
        for v in win.views():
            try:
                fn = v.file_name()
                if fn and v.is_dirty() and fn.endswith(
                        '.go') and os.path.dirname(fn) == wd:
                    v.run_command('gs_fmt_save')
            except Exception:
                gs.error_traceback(DOMAIN)
Example #9
0
def expand_jdata(v):
	if gs.is_a(v, {}):
		for k in v:
			v[k] = expand_jdata(v[k])
	elif gs.is_a_string(v) and v.startswith('base64:'):
		try:
			v = base64.b64decode(v[7:])
		except Exception:
			v = ''
			gs.error_traceback(DOMAIN)
	return v
Example #10
0
def expand_jdata(v):
    if gs.is_a(v, {}):
        for k in v:
            v[k] = expand_jdata(v[k])
    elif gs.is_a_string(v) and v.startswith('base64:'):
        try:
            v = base64.b64decode(v[7:])
        except Exception:
            v = ''
            gs.error_traceback(DOMAIN)
    return v
Example #11
0
def _recv():
    while True:
        try:
            ln = _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
Example #12
0
def _recv():
	while True:
		try:
			ln = _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