def activate(self, leaf): leaf_text = kupferstring.tolocale(leaf.object) color = leaf_text[1:] result = "None" if len(color) == 3: r = color[0] + color[0] g = color[1] + color[1] b = color[2] + color[2] elif len(color) == 6: r = color[0:2] g = color[2:4] b = color[4:6] else: return TextLeaf("Unknown color format") color = colors.hex("#" + r + g + b) complement = colors.complementary(color)[4] r = int(complement.r * 255) g = int(complement.g * 255) b = int(complement.b * 255) r = '%02x' % r g = '%02x' % g b = '%02x' % b result = "#" + str(r) + str(g) + str(b) return TextLeaf(result)
def __init__(self, text): text = kupferstring.tounicode(text) summary = self.get_first_text_line(text) maxlen = 10 if len(summary) > maxlen: summary = summary[:maxlen] + u".." TextLeaf.__init__(self, text, _('Selected Text "%s"') % summary)
def __init__(self, text): text = kupferstring.tounicode(text) lines = filter(None, text.splitlines()) summary = lines[0] if lines else text maxlen = 10 if len(summary) > maxlen: summary = summary[:maxlen] + u".." TextLeaf.__init__(self, text, _('Selected Text "%s"') % summary)
def get_items(self, text): if not text: return basename = os_path.basename(self.sourcefile.object) root, ext = os_path.splitext(basename) t_root, t_ext = os_path.splitext(text) if text.endswith(" "): yield TextLeaf(text.rstrip()) else: yield TextLeaf(text) if t_ext else TextLeaf(t_root + ext)
def __init__(self, obj, code, currier): self.obj = obj self.code = code self.currier = currier txt = self.obj.get('meta', {}).get('message', '') checkpoint = self.obj.get('data', {}).get('checkpoint', {}) if checkpoint: if checkpoint.get('message'): fmt = '{message} {country_name} {checkpoint_time}' txt = fmt.format(**checkpoint) else: txt = 'Empty status info' TextLeaf.__init__(self, txt)
def activate(self, obj): result = '' try: result = urllib.parse.unquote(obj.object) except AttributeError: result = urllib.parse.unquote(obj.object) return TextLeaf(result)
def activate(self, obj): result = '' try: result = urllib.parse.quote(obj.object.encode('utf8')) except AttributeError: result = urllib.parse.quote(obj.object.encode('utf8')) return TextLeaf(result)
class Calculate(Action): # since it applies only to special queries, we can up the rank rank_adjust = 10 # global last_result last_result = {'last': None} def __init__(self): Action.__init__(self, _("Calculate")) def has_result(self): return True def activate(self, leaf): expr = leaf.object.lstrip("= ") # try to add missing parantheses brackets_missing = expr.count("(") - expr.count(")") if brackets_missing > 0: expr += ")" * brackets_missing # hack: change all decimal points (according to current locale) to '.' expr = expr.replace(locale.localeconv()['decimal_point'], '.') environment = make_environment(self.last_result['last']) pretty.print_debug(__name__, "Evaluating", repr(expr)) try: result = eval(expr, environment) resultstr = format_result(result) self.last_result['last'] = result except IgnoreResultException: return except Exception, exc: pretty.print_error(__name__, type(exc).__name__, exc) resultstr = unicode(exc) return TextLeaf(resultstr)
def activate(self, leaf): url = to_correios_url(leaf) with request.urlopen(url) as curreio: content = curreio.read() info = get_tracking_info(content.decode('iso-8859-1')) if info: txt = '-'.join(reversed(info[0])) return TextLeaf(leaf.object, txt)
def __init__(self, obj, code, currier): self.code = code self.currier = currier txt = obj.get('meta', {}).get('message', '') checkpoint = obj.get('data', {}) if checkpoint: origin_info = checkpoint.get('origin_info', {}) origin_info = origin_info if origin_info else {} trackinfos = origin_info.get('trackinfo', []) trackinfo = trackinfos[0] if trackinfos else {} if trackinfo: fmt = '{StatusDescription} {Details} {Date}' txt = fmt.format(**trackinfo) else: fmt = '{status} {original_country} {updated_at}' txt = fmt.format(**checkpoint) TextLeaf.__init__(self, txt)
def bash_items(self, text): bash_history_file = path.expanduser("~/.bash_history") mine = check_output(["file", "-i", bash_history_file]) encoding = mine.split(b'=')[1].decode(errors="ignore") with open(bash_history_file, encoding=encoding) as history: for command in history: if text in command.encode(): yield TextLeaf(command)
def get_items(self, start_at=0): i = get_issue(self.issue, self.jira) page_size = 50 users = self.jira.search_assignable_users_for_issues('', issueKey=i, startAt=start_at, maxResults=page_size) for u in users: yield TextLeaf(u.key, u.name) if len(users) == page_size: for leaf in self.get_items(start_at + page_size): yield leaf
def finish_command(ctx, acommand, stdout, stderr, post_result=True): """Show async error if @acommand returns error output & error status. Else post async result if @post_result. """ max_error_msg=512 pretty.print_debug(__name__, "Exited:", acommand) if acommand.exit_status != 0 and not stdout and stderr: errstr = kupferstring.fromlocale(stderr)[:max_error_msg] ctx.register_late_error(OperationError(errstr)) elif post_result: leaf = TextLeaf(kupferstring.fromlocale(stdout)) ctx.register_late_result(leaf)
def activate(self, leaf): # Try to find the __file__ attribute for the plugin # It will fail for files inside zip packages, but that is # uncommon for now. # Additionally, it will fail for fake plugins plugin_id = leaf.object["name"] filename = plugins.get_plugin_attribute(plugin_id, "__file__") if not filename: return leaf root, ext = os.path.splitext(filename) if ext.lower() == ".pyc" and os.path.exists(root + ".py"): return FileLeaf(root + ".py") if not os.path.exists(filename): # handle modules in zip or eggs import pkgutil pfull = "kupfer.plugin." + plugin_id loader = pkgutil.get_loader(pfull) if loader: return TextLeaf(loader.get_source(pfull)) return FileLeaf(filename)
def activate(self, leaf): expr = leaf.object.lstrip("= ") # try to add missing parantheses brackets_missing = expr.count("(") - expr.count(")") if brackets_missing > 0: expr += ")" * brackets_missing # hack: change all decimal points (according to current locale) to '.' #expr = expr.replace(locale.localeconv()['decimal_point'], '.') environment = make_environment(self.last_result['last']) pretty.print_debug(__name__, "Evaluating", repr(expr)) try: result = eval(expr, environment) resultstr = format_result(result) self.last_result['last'] = result except IgnoreResultException: return except Exception as exc: pretty.print_error(__name__, type(exc).__name__, exc) resultstr = str(exc) return TextLeaf(resultstr)
def __init__(self, obj): TextLeaf.__init__(self, obj)
def get_text_items(self, text): if not text: return yield TextLeaf(text)
def __init__(self, text, user, created_at, status_id): TextLeaf.__init__(self, text) self._description = _("%(user)s %(when)s") % dict( user=user, when=created_at) self.status_id = status_id
def __init__(self, id2key, token): TextLeaf.__init__(self, token) self.id2key = id2key self.id2cls = id2key[0]
def __init__(self, text): TextLeaf.__init__(self, text, _('Selected Text'))
def get_items(self): for e in self.ems: yield TextLeaf(e)
def __init__(self, obj): TextLeaf.__init__(self, obj['code'], obj['name'])
def __init__ (self, exepath, name): TextLeaf.__init__(self, exepath, name)
def fish_items(self, text): history_cmd = "history search {}".format(text.decode(errors="ignore")) history = check_output(["fish", "-c", history_cmd]).split(b'\n') for command in history: if command: yield TextLeaf(command)
def get_description(self): return self._descrtiption or TextLeaf.get_description(self)
def get_text_items(self, text): n = len(text) summary = text[:10] + (text[10:11] and "..") desc_template = ngettext("%s (%d character)", "%s (%d characters)", n) yield TextLeaf(text, desc_template % (summary, n))
def __init__(self, exepath, name): TextLeaf.__init__(self, name, name) self.exepath = exepath
def __init__(self, img, key, names): TextLeaf.__init__(self, key, ' '.join(names)) self._img = img
def get_text_items(self, text): n = len(text) summary = trunc_message(text) desc_template = ngettext("%s (%d character)", "%s (%d characters)", n) yield TextLeaf(text, desc_template % (summary, n))
def get_items(self, text): if not text: return t_root, t_ext = os.path.splitext(text) yield TextLeaf(text) if t_ext else TextLeaf(t_root + self.extension)
def __init__(self, translation, descr): TextLeaf.__init__(self, translation) self._descrtiption = descr
def get_items(self): for i, email in list(self.resource.items()): yield TextLeaf(email)
def __init__(self, img, key, names): TextLeaf.__init__(self, key, u' '.join(names) ) self._img = img
def get_items(self): i = get_issue(self.issue, self.jira) transitions = self.jira.transitions(i) for t in transitions: yield TextLeaf(t["id"], t["name"])
def activate(self, leaf): with open(leaf.object, "rb") as infile: l_text = infile.read() us_text = kupferstring.fromlocale(l_text) return TextLeaf(us_text)
def __init__(self, obj): TextLeaf.__init__(self, obj['slug'], obj['name'])