Example #1
0
def do_get(args):
    db = create_db(args)
    try:
        entry = db.find_by_uuid(args.entry_id)
    except EntryNotFoundError:
        try:
            entry = db.find_by_title(args.entry_id)
        except EntryNotFoundError:
            # Last try, do a fuzzy match and see if we come up
            # with anything.
            matches = db.fuzzy_search_by_title(args.entry_id)
            if not matches:
                sys.stderr.write(
                    "Could not find an entry for: %s\n" % args.entry_id)
                return
            else:
                # There could be multiple fuzzy matches so we pick
                # the first one.  The fuzzy_search_by_title returns
                # the matches by closeness so the first element is
                # the closest match.
                entry = matches[0]
    default_fields = ['title', 'username', 'url', 'notes']
    if args.entry_fields:
        fields = args.entry_fields
    else:
        fields = default_fields
    sys.stderr.write('\n')
    for field in fields:
        print("%-10s %s" % (field + ':', getattr(entry, field)))
    if args.clipboard_copy:
        clipboard.copy(entry.password)
        sys.stderr.write("\nPassword has been copied to clipboard.\n")
Example #2
0
def do_get(args):
    with create_db(args) as db:
        try:
            entries = _search_for_entry(db, args.entry_id)
        except EntryNotFoundError as e:
            sys.stderr.write(str(e))
            sys.stderr.write("\n")
            return
    t = PrettyTable(['#', 'Title', 'Username', 'URL'])
    t.align['#'] = 'r'
    t.align['Title'] = 'l'
    t.align['Username'] = '******'
    t.align['URL'] = 'l'
    for i, entry in enumerate(entries, start=1):
        t.add_row([
            i,
            _find_string(entry, 'Title'),
            _find_string(entry, 'UserName'),
            _find_string(entry, 'URL')
        ])
    print(t)

    selected = 0
    if len(entries) > 1:
        choice = None
        while not choice:
            try:
                choice = int(raw_input('Which entry? '))
                if choice < 1 or choice > len(entries):
                    choice = None
            except KeyboardInterrupt:
                quit()
            except:
                choice = None
        selected = choice - 1

    entry = entries[selected]

    if args.clipboard_copy:
        clipboard.copy(_find_password(entry))

        if not args.quiet:
            default_fields = ['title', 'username', 'url']
            if args.entry_fields:
                fields = args.entry_fields
            else:
                fields = default_fields
            sys.stderr.write('\n')
            for field in fields:
                print("%-10s %s" % (field + ':', _find_string(entry, field)))

        sys.stderr.write("\nPassword has been copied to clipboard.\n")
Example #3
0
def do_get(args):
    db = create_db(args)
    try:
        entry = _search_for_entry(db, args.entry_id)[0]
    except EntryNotFoundError as e:
        sys.stderr.write(str(e))
        sys.stderr.write("\n")
        return
    default_fields = ['title', 'username', 'url', 'notes']
    if args.entry_fields:
        fields = args.entry_fields
    else:
        fields = default_fields
    sys.stderr.write('\n')
    for field in fields:
        print("%-10s %s" % (field + ':', getattr(entry, field)))
    if args.clipboard_copy:
        clipboard.copy(entry.password)
        sys.stderr.write("\nPassword has been copied to clipboard.\n")
Example #4
0
def do_get(args):
    db = create_db(args)
    try:
        entry = _search_for_entry(db, args.entry_id)[0]
    except EntryNotFoundError as e:
        sys.stderr.write(str(e))
        sys.stderr.write("\n")
        return
    default_fields = ['title', 'username', 'url', 'notes']
    if args.entry_fields:
        fields = args.entry_fields
    else:
        fields = default_fields
    sys.stderr.write('\n')
    for field in fields:
        print("%-10s %s" % (field + ':', getattr(entry, field)))
    if args.clipboard_copy:
        clipboard.copy(entry.password)
        sys.stderr.write("\nPassword has been copied to clipboard.\n")
Example #5
0
 def test_copy_function(self):
     with mock.patch('keepassx.clipboard.OSXClipBoard.copy') as mock_copy:
         self.platform.return_value = 'Darwin'
         clipboard.copy('foo')
         mock_copy.assert_called_with('foo')