Support ranges and indices in update operation.
This commit is contained in:
parent
d967c81078
commit
441c4cd59d
@ -118,10 +118,11 @@ Please substitute `$version` with the appropriate package version.
|
||||
general options:
|
||||
-a, --add URL [tags ...]
|
||||
bookmark URL with comma-separated tags
|
||||
-u, --update [N] update fields of bookmark at DB index N
|
||||
-u, --update [...] update fields of bookmark at DB indices
|
||||
refresh all titles, if no arguments
|
||||
refresh title of bookmark at N, if only
|
||||
N is specified without any edit options
|
||||
refresh titles of bookmarks at indices,
|
||||
if no edit options are specified
|
||||
accepts indices and ranges
|
||||
-d, --delete [...] delete bookmarks. Valid inputs: either
|
||||
a hyphenated single range (100-200),
|
||||
OR space-separated indices (100 15 200)
|
||||
@ -199,7 +200,7 @@ Please substitute `$version` with the appropriate package version.
|
||||
- **Update** operation:
|
||||
- If --title, --tag or --comment is passed without argument, clear the corresponding field from DB.
|
||||
- If --url is passed (and --title is omitted), update the title from web using the URL.
|
||||
- If index number is passed without any other options (--url, --title, --tag and --comment), read the URL from DB and update title from web.
|
||||
- If indices are passed without any other options (--url, --title, --tag and --comment), read the URLs from DB and update titles from web.
|
||||
- **Delete** operation:
|
||||
- When a record is deleted, the last record is moved to the index.
|
||||
- Delete doesn't work with range and indices provided together as arguments. It's an intentional decision to avoid extra sorting, in-range checks and to keep the auto-DB compaction functionality intact. On the same lines, indices are deleted in descending order.
|
||||
|
38
buku
38
buku
@ -593,9 +593,9 @@ class BukuDb:
|
||||
if self.cur.rowcount == 1:
|
||||
self.print_bookmark(index)
|
||||
elif self.cur.rowcount == 0:
|
||||
logger.error('No matching index')
|
||||
logger.error('No matching index %s', index)
|
||||
except sqlite3.IntegrityError:
|
||||
print('URL already exists')
|
||||
logger.error('URL already exists')
|
||||
|
||||
def refreshdb(self, index):
|
||||
"""Refresh ALL records in the database. Fetch title for each
|
||||
@ -1552,10 +1552,11 @@ if __name__ == '__main__':
|
||||
title='general options',
|
||||
description='''-a, --add URL [tags ...]
|
||||
bookmark URL with comma-separated tags
|
||||
-u, --update [N] update fields of bookmark at DB index N
|
||||
-u, --update [...] update fields of bookmark at DB indices
|
||||
refresh all titles, if no arguments
|
||||
refresh title of bookmark at N, if only
|
||||
N is specified without any edit options
|
||||
refresh titles of bookmarks at indices,
|
||||
if no edit options are specified
|
||||
accepts indices and ranges
|
||||
-d, --delete [...] delete bookmarks. Valid inputs: either
|
||||
a hyphenated single range (100-200),
|
||||
OR space-separated indices (100 15 200)
|
||||
@ -1703,13 +1704,9 @@ if __name__ == '__main__':
|
||||
|
||||
# Update record
|
||||
if update:
|
||||
index_passed = None
|
||||
if len(args.update) == 0:
|
||||
update_index = 0
|
||||
elif not args.update[0].isdigit():
|
||||
logger.error('Index must be a number >= 0')
|
||||
bdb.close_quit(1)
|
||||
else:
|
||||
update_index = int(args.update[0])
|
||||
index_passed = 0
|
||||
|
||||
if args.url is not None:
|
||||
new_url = args.url[0]
|
||||
@ -1732,7 +1729,24 @@ if __name__ == '__main__':
|
||||
# Parse tags into a comma-separated string
|
||||
tags = parse_tags(tagManual)
|
||||
|
||||
bdb.update_bookmark(update_index, new_url, titleManual, tags, description, append, delete)
|
||||
if index_passed is None:
|
||||
for idx in args.update:
|
||||
if is_int(idx):
|
||||
bdb.update_bookmark(int(idx), new_url, titleManual, tags,
|
||||
description, append, delete)
|
||||
elif '-' in idx and is_int(idx.split('-')[0]) and is_int(idx.split('-')[1]):
|
||||
lower = int(idx.split('-')[0])
|
||||
upper = int(idx.split('-')[1])
|
||||
if lower > upper:
|
||||
tmp = upper
|
||||
upper = lower
|
||||
lower = tmp
|
||||
for _id in range(lower, upper + 1):
|
||||
bdb.update_bookmark(_id, new_url, titleManual, tags,
|
||||
description, append, delete)
|
||||
else:
|
||||
bdb.update_bookmark(index_passed, new_url, titleManual, tags,
|
||||
description, append, delete)
|
||||
|
||||
# Search URLs, titles, tags for any keyword and delete if wanted
|
||||
if args.sany is not None:
|
||||
|
10
buku.1
10
buku.1
@ -30,7 +30,7 @@ URLs are unique in DB. The same URL cannot be added twice. You can update tags a
|
||||
\fIUpdate\fR operation:
|
||||
- If --title, --tag or --comment is passed without argument, clear the corresponding field from DB.
|
||||
- If --url is passed (and --title is omitted), update the title from web using the URL.
|
||||
- If index number is passed without any other options (--url, --title, --tag and --comment), read the URL from DB and update title from web.
|
||||
- If indices are passed without any other options (--url, --title, --tag and --comment), read the URLs from DB and update titles from web.
|
||||
.PP
|
||||
\fISearch\fR works in mysterious ways:
|
||||
- Case-insensitive.
|
||||
@ -49,12 +49,8 @@ Bookmark
|
||||
.I URL
|
||||
along with comma-separated tags. A tag can have multiple words.
|
||||
.TP
|
||||
.BI \-u " " \--update " [N]"
|
||||
Update fields of the bookmark at index
|
||||
.I N
|
||||
in DB. If
|
||||
.I N
|
||||
and other options are omitted, all titles are refreshed from the web. Works with update modifiers for the fields url, title, tag and comment. If only N is passed without any edit options, title is fetched and updated (if not empty).
|
||||
.BI \-u " " \--update " [...]"
|
||||
Update fields of the bookmarks at specified indices in DB. If no arguments are specified, all titles are refreshed from the web. Works with update modifiers for the fields url, title, tag and comment. If only indices are passed without any edit options, titles are fetched and updated (if not empty).
|
||||
.TP
|
||||
.BI \-d " " \--delete " [...]"
|
||||
Delete bookmarks. You can either provide a single hyphenated range (e.g. 100-200) or a space-separated list of indices (e.g. 5 6 23 4 110 45). Note that range and list don't work together. Deletes search results when combined with search options.
|
||||
|
Loading…
x
Reference in New Issue
Block a user