Пример #1
0
    def print_node(self, node):
        width = tools._defaultwidth
        print("Node {}.".format(node._id))
        print("{} {}".format(tools.typeset("Username:"******"{} {}".format(tools.typeset("Password:"******"{} {}".format(tools.typeset("Url:", Fore.RED).ljust(width), node.url))
        print("{} {}".format(tools.typeset("Notes:", Fore.RED).ljust(width), node.notes))
        print("{}".format(tools.typeset("Tags: ", Fore.RED)), end=" ")
        for t in node.tags:
            print(t)

        def heardEnterWin():
            c = msvcrt.kbhit()
            if c == 1:
                ret = msvcrt.getch()
                if ret is not None:
                    return True
            return False

        def waituntil_enter(somepredicate, timeout, period=0.25):
            mustend = time.time() + timeout
            while time.time() < mustend:
                cond = somepredicate()
                if cond:
                    break
                time.sleep(period)
            self.do_cls('')

        flushtimeout = int(config.get_value("Global", "cls_timeout"))
        if flushtimeout > 0:
            print("Press any key to flush screen (autoflash "
                  "in %d sec.)" % flushtimeout)
            waituntil_enter(heardEnterWin, flushtimeout)
Пример #2
0
 def _print_node_line(self, node, rows, cols):
     tagstring = ','.join([t.decode() for t in node.tags])
     fmt = self._format_line(
         cols, node._id, node.username, node.url[:20] + '...' if
         (len(node.url) > 22) else node.url, tagstring)
     formatted_entry = tools.typeset(fmt, Fore.YELLOW, False)
     print(formatted_entry)
Пример #3
0
 def _print_node_line(self, node, rows, cols):
     tagstring = ','.join([t for t in node.tags])
     fmt = self._format_line(cols, node._id, node.username,
                             node.url[:20]+'...' if (len(node.url) > 22)
                             else node.url,
                             tagstring)
     formatted_entry = tools.typeset(fmt, Fore.YELLOW, False)
     print(formatted_entry)
Пример #4
0
    def do_list(self, args):

        if len(args.split()) > 0:
            self.do_clear("")
            self.do_filter(args)
        try:
            if sys.platform != "win32":
                rows, cols = tools.gettermsize()
            else:
                rows, cols = 18, 80
            nodeids = self._db.listnodes()
            nodes = self._db.getnodes(nodeids)
            cols -= 8
            i = 0
            for n in nodes:
                tags = n.get_tags()
                tagstring = ""
                first = True
                for t in tags:
                    if not first:
                        tagstring += ", "
                    else:
                        first = False
                    tagstring += t.get_name()
                name = "%s@%s" % (n.get_username(), n.get_url())

                name_len = cols * 2 / 3
                tagstring_len = cols / 3
                if len(name) > name_len:
                    name = name[: name_len - 3] + "..."
                if len(tagstring) > tagstring_len:
                    tagstring = tagstring[: tagstring_len - 3] + "..."

                fmt = "%%5d. %%-%ds %%-%ds" % (name_len, tagstring_len)
                print tools.typeset(fmt % (n.get_id(), name, tagstring), Fore.YELLOW, False)
                i += 1
                if i > rows - 2:
                    i = 0
                    c = tools.getonechar("Press <Space> for more, " "or 'Q' to cancel")
                    if c == "q":
                        break

        except Exception, e:
            self.error(e)
Пример #5
0
    def print_node(self, node):
        width = str(tools._defaultwidth)
        print ("Node %d." % (node._id))
        print (("%" + width + "s %s") % (tools.typeset("Username:"******"%" + width + "s %s") % (tools.typeset("Password:"******"%" + width + "s %s") % (tools.typeset("Url:", Fore.RED),
                                         node.url))
        print (("%" + width + "s %s") % (tools.typeset("Notes:", Fore.RED),
                                         node.notes))
        print (tools.typeset("Tags: ", Fore.RED)),
        for t in node.tags:
            print (" %s " % t)
        print()

        def heardEnter():
            i, o, e = uselect.select([sys.stdin], [], [], 0.0001)
            for s in i:
                if s == sys.stdin:
                    sys.stdin.readline()
                    return True
                return False

        def waituntil_enter(somepredicate, timeout, period=0.25):
            mustend = time.time() + timeout
            while time.time() < mustend:
                cond = somepredicate()
                if cond:
                    break
                time.sleep(period)
            self.do_cls('')

        try:
            flushtimeout = int(config.get_value("Global", "cls_timeout"))
        except ValueError:
            flushtimeout = 10

        if flushtimeout > 0:
            print ("Type Enter to flush screen (autoflash in "
                   "%d sec.)" % flushtimeout)
            waituntil_enter(heardEnter, flushtimeout)
Пример #6
0
 def do_list(self, args):
     """
     list all existing nodes in database
     """
     rows, cols = self._prep_term()
     nodeids = self._get_node_ids(args)
     raw_nodes = self._db.getnodes(nodeids)
     _nodes_inst = self._db_entries_to_nodes(raw_nodes)
     head = self._format_line(cols - 32)
     print(tools.typeset(head, Fore.YELLOW, False))
     for idx, node in enumerate(_nodes_inst):
         self._print_node_line(node, rows, cols)
Пример #7
0
    def do_list(self, args):

        # crypto  = CryptoEngine.get()
        # crypto.auth('YOURPASSWORD')

        if len(args.split()) > 0:
            self.do_clear('')
            self.do_filter(args)
        try:
            if sys.platform != 'win32':
                rows, cols = tools.gettermsize()
            else:
                rows, cols = 18, 80  # fix this !
            nodeids = self._db.listnodes()
            nodes = self._db.getnodes(nodeids)

            cols -= 8
            i = 0
            for n in nodes:
                tags = n.tags
                tags = filter(None, tags)
                tagstring = ''
                first = True
                for t in tags:
                    if not first:
                        tagstring += ", "
                    else:
                        first = False
                    tagstring += t

                name = "%s@%s" % (n.username, n.url)

                name_len = cols * 2 / 3
                tagstring_len = cols / 3
                if len(name) > name_len:
                    name = name[:name_len - 3] + "..."
                if len(tagstring) > tagstring_len:
                    tagstring = tagstring[:tagstring_len - 3] + "..."
                fmt = "%%5d. %%-%ds %%-%ds" % (name_len, tagstring_len)
                formatted_entry = tools.typeset(fmt % (n._id,
                                                name, tagstring),
                                                Fore.YELLOW, False)
                print (formatted_entry)
                i += 1
                if i > rows - 2:
                    i = 0
                    c = tools.getonechar("Press <Space> for more,"
                                         " or 'Q' to cancel")
                    if c.lower() == 'q':
                        break

        except Exception as e:
            self.error(e)
Пример #8
0
 def do_list(self, args):
     """
     list all existing nodes in database
     """
     rows, cols = self._prep_term()
     nodeids = self._get_node_ids(args)
     raw_nodes = self._db.getnodes(nodeids)
     _nodes_inst = self._db_entries_to_nodes(raw_nodes)
     head = self._format_line(cols-32)
     print(tools.typeset(head, Fore.YELLOW, False))
     for idx, node in enumerate(_nodes_inst):
         self._print_node_line(node, rows, cols)
Пример #9
0
    def print_node(self, node):
        width = str(tools._defaultwidth)
        print "Node %d." % (node.get_id())
        print ("%" + width + "s %s") % (tools.typeset("Username:"******"%" + width + "s %s") % (tools.typeset("Password:"******"%" + width + "s %s") % (tools.typeset("Url:", Fore.RED), node.get_url())
        print ("%" + width + "s %s") % (tools.typeset("Notes:", Fore.RED), node.get_notes())
        print tools.typeset("Tags: ", Fore.RED),
        for t in node.get_tags():
            print " %s \n" % t.get_name(),

        def heardEnter():
            inpt, out, err = uselect.select([sys.stdin], [], [], 0.0001)
            for stream in inpt:
                if stream == sys.stdin:
                    sys.stdin.readline()
                    return True
                return False

        def waituntil_enter(somepredicate, timeout, period=0.25):
            mustend = time.time() + timeout
            while time.time() < mustend:
                cond = somepredicate()
                if cond:
                    break
                time.sleep(period)
            self.do_cls("")

        flushtimeout = int(config.get_value("Global", "cls_timeout"))
        if flushtimeout > 0:
            print "Type Enter to flush screen (autoflash in " + "%d sec.)" % flushtimeout
            waituntil_enter(heardEnter, flushtimeout)
Пример #10
0
    def _print_node_line(self, node, rows, cols, url_filter):
        if url_filter != "" and node.url.find(url_filter) == -1:
            return

        tagstring = ','.join([t.decode() for t in node.tags])

        if len(node.url) > int(self.config.get_value("UI", "URL_length")):
            node_url = node.url[:int(self.config.get_value("UI", "URL_length"))] + "..." # noqa
        else:
            node_url = node.url

        fmt = self._format_line(cols, node._id, node.username,
                                node_url,
                                tagstring)
        formatted_entry = tools.typeset(fmt, Fore.YELLOW, False)
        print(formatted_entry)
Пример #11
0
    def do_list(self, args):
        """
        list all existing nodes in database
        """
        rows, cols = self._prep_term()
        url_filter = ""
        m = re.search('^u:([^ ]+) ?(.*)$', args)

        if m:
            url_filter, args = m.groups()

        nodeids = self._get_node_ids(args)
        raw_nodes = self._db.getnodes(nodeids)
        _nodes_inst = self._db_entries_to_nodes(raw_nodes)
        head = self._format_line(cols - 32)
        print(tools.typeset(head, Fore.YELLOW, False))

        for idx, node in enumerate(_nodes_inst):
            self._print_node_line(node, rows, cols, url_filter)
Пример #12
0
    def print_node(self, node):
        width = str(tools._defaultwidth)
        print "Node %d." % (node.get_id())
        print ("%" + width+"s %s") % (tools.typeset("Username:"******"%"+width+"s %s") % (tools.typeset("Password:"******"%"+width+"s %s") % (tools.typeset("Url:", Fore.RED),
                                    node.get_url())
        print ("%"+width+"s %s") % (tools.typeset("Notes:", Fore.RED),
                                    node.get_notes())
        print tools.typeset("Tags: ", Fore.RED),
        for t in node.get_tags():
            print " %s \n" % t.get_name(),

        def heardEnterWin():
            c = msvcrt.kbhit()
            if c == 1:
                ret = msvcrt.getch()
                if ret is not None:
                    return True
            return False

        def waituntil_enter(somepredicate, timeout, period=0.25):
            mustend = time.time() + timeout
            while time.time() < mustend:
                cond = somepredicate()
                if cond:
                    break
                time.sleep(period)
            self.do_cls('')

        flushtimeout = int(config.get_value("Global", "cls_timeout"))
        if flushtimeout > 0:
            print "Press any key to flush screen (autoflash "\
                + "in %d sec.)" % flushtimeout
            waituntil_enter(heardEnterWin, flushtimeout)