예제 #1
0
    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)
예제 #2
0
파일: fileactions.py 프로젝트: guns/kupfer
 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)
예제 #3
0
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)
예제 #4
0
 def activate(self, obj):
     result = ''
     try:
         result = urllib.parse.unquote(obj.object)
     except AttributeError:
         result = urllib.parse.unquote(obj.object)
     return TextLeaf(result)
예제 #5
0
 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)
예제 #6
0
 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)
예제 #7
0
 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)
예제 #8
0
 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
예제 #9
0
파일: commands.py 프로젝트: somas95/kupfer
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)
예제 #10
0
    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)
예제 #11
0
    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)
예제 #12
0
 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)
예제 #13
0
 def activate(self, leaf):
     username = user_name(leaf.object)
     return TextLeaf(username)
예제 #14
0
 def get_items(self):
     for e in self.ems:
         yield TextLeaf(e)
예제 #15
0
 def text_with_key(self):
     yield TextLeaf(self.repr_key())
예제 #16
0
파일: text.py 프로젝트: emareg/kupfer
 def get_text_items(self, text):
     if not text:
         return
     yield TextLeaf(text)
예제 #17
0
 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"])
예제 #18
0
 def text_with_desc(self):
     yield TextLeaf(self.get_decription())
예제 #19
0
파일: __init__.py 프로젝트: jablan/kupfer
 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))
예제 #20
0
 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)
예제 #21
0
 def get_items(self):
     for i, email in list(self.resource.items()):
         yield TextLeaf(email)
예제 #22
0
파일: textfiles.py 프로젝트: guns/kupfer
 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)
예제 #23
0
	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))