Merge pull request #383 from humCopper/master

Add --preserve option
This commit is contained in:
Mischievous Meerkat 2019-05-04 21:07:37 +05:30 committed by GitHub
commit 04777b0475
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 44 additions and 10 deletions

View File

@ -195,6 +195,7 @@ EDIT OPTIONS:
clears description, if no arguments clears description, if no arguments
--immutable N disable web-fetch during auto-refresh --immutable N disable web-fetch during auto-refresh
N=0: mutable (default), N=1: immutable N=0: mutable (default), N=1: immutable
--preserve [...] values to preserve for -u
SEARCH OPTIONS: SEARCH OPTIONS:
-s, --sany [...] find records with ANY matching keyword -s, --sany [...] find records with ANY matching keyword
@ -453,10 +454,16 @@ PROMPT KEYS:
buku (? for help) g > 5 3-2 buku (? for help) g > 5 3-2
// remove tags at taglist indices 4 and 6-9 from tags in bookmarks at indices 5 and 2-3 // remove tags at taglist indices 4 and 6-9 from tags in bookmarks at indices 5 and 2-3
buku (? for help) g 4 9-6 << 5 3-2 buku (? for help) g 4 9-6 << 5 3-2
37. List bookmarks with **colored output**: 37. **Update** URL but **preserve** title
$ buku -u 479 --preserve title --url https://example.com
37. **Update** URL but **preserve** title and comment
$ buku -u 479 --preserve title comment --url https://example.com
38. List bookmarks with **colored output**:
$ buku --colors oKlxm -p $ buku --colors oKlxm -p
38. More **help**: 39. More **help**:
$ buku -h $ buku -h
$ man buku $ man buku

View File

@ -62,6 +62,7 @@ _buku () {
-i --import -i --import
--immutable --immutable
-n --count -n --count
--preserve
-r --sreg -r --sreg
--replace --replace
-s --sany -s --sany

View File

@ -30,6 +30,7 @@ args=(
'(--np)--np[noninteractive mode]' '(--np)--np[noninteractive mode]'
'(-o --open)'{-o,--open}'[open bookmarks in browser]' '(-o --open)'{-o,--open}'[open bookmarks in browser]'
'(--oa)--oa[browse all search results immediately]' '(--oa)--oa[browse all search results immediately]'
'(--preserve)--preserve[preserve options]'
'(-p --print)'{-p,--print}'[show bookmark details]' '(-p --print)'{-p,--print}'[show bookmark details]'
'(-r --sreg)'{-r,--sreg}'[match a regular exression]:regex' '(-r --sreg)'{-r,--sreg}'[match a regular exression]:regex'
'(--replace)--replace[replace a tag]:tag to replace' '(--replace)--replace[replace a tag]:tag to replace'

41
buku
View File

@ -755,7 +755,8 @@ class BukuDb:
tags_in=None, tags_in=None,
desc=None, desc=None,
immutable=-1, immutable=-1,
threads=4): threads=4,
preserve=None):
"""Update an existing record at index. """Update an existing record at index.
Update all records if index is 0 and url is not specified. Update all records if index is 0 and url is not specified.
@ -779,6 +780,8 @@ class BukuDb:
Disable title fetch from web if 1. Default is -1. Disable title fetch from web if 1. Default is -1.
threads : int, optional threads : int, optional
Number of threads to use to refresh full DB. Default is 4. Number of threads to use to refresh full DB. Default is 4.
preserve : array of str, optional
Values to preserve. Can be "url","title","tag","tags", and "comment"
Returns Returns
------- -------
@ -792,6 +795,23 @@ class BukuDb:
tag_modified = False tag_modified = False
ret = False ret = False
preserve_title = False
preserve_desc = False
if preserve is not None:
if len(preserve) == 0:
preserve = ['url', 'tag', 'comment', 'title']
for option in preserve:
if option == "url":
url = None
elif option in ('tag', 'tags'):
tags_in = None
elif option == "comment":
desc = None
preserve_desc = True
elif option == "title":
title_in = None
preserve_title = True
# Update URL if passed as argument # Update URL if passed as argument
if url is not None and url != '': if url is not None and url != '':
if index == 0: if index == 0:
@ -868,7 +888,7 @@ class BukuDb:
else: else:
LOGDBG('Title: [%s]', title_to_insert) LOGDBG('Title: [%s]', title_to_insert)
if not desc: if not desc and not preserve_desc:
if not pdesc: if not pdesc:
pdesc = '' pdesc = ''
query += ' desc = ?,' query += ' desc = ?,'
@ -880,7 +900,7 @@ class BukuDb:
self.print_rec(index) self.print_rec(index)
return ret return ret
if title_to_insert is not None: if title_to_insert is not None and not preserve_title:
query += ' metadata = ?,' query += ' metadata = ?,'
arguments += (title_to_insert,) arguments += (title_to_insert,)
to_update = True to_update = True
@ -4763,6 +4783,7 @@ POSITIONAL ARGUMENTS:
addarg('--title', nargs='*', help=hide) addarg('--title', nargs='*', help=hide)
addarg('-c', '--comment', nargs='*', help=hide) addarg('-c', '--comment', nargs='*', help=hide)
addarg('--immutable', type=int, default=-1, choices={0, 1}, help=hide) addarg('--immutable', type=int, default=-1, choices={0, 1}, help=hide)
addarg('--preserve', nargs='*', help=hide)
# -------------------- # --------------------
# SEARCH OPTIONS GROUP # SEARCH OPTIONS GROUP
@ -5223,7 +5244,7 @@ POSITIONAL ARGUMENTS:
if not args.update: if not args.update:
# Update all records only if search was not opted # Update all records only if search was not opted
if not search_opted: if not search_opted:
bdb.update_rec(0, url_in, title_in, tags, desc_in, args.immutable, args.threads) bdb.update_rec(0, url_in, title_in, tags, desc_in, args.immutable, args.threads, args.preserve)
elif update_search_results and search_results is not None: elif update_search_results and search_results is not None:
if not args.tacit: if not args.tacit:
print('Updated results:\n') print('Updated results:\n')
@ -5238,7 +5259,8 @@ POSITIONAL ARGUMENTS:
tags, tags,
desc_in, desc_in,
args.immutable, args.immutable,
args.threads args.threads,
args.preserve
) )
# Commit at every 200th removal # Commit at every 200th removal
@ -5256,7 +5278,8 @@ POSITIONAL ARGUMENTS:
tags, tags,
desc_in, desc_in,
args.immutable, args.immutable,
args.threads args.threads,
args.preserve
) )
elif '-' in idx: elif '-' in idx:
try: try:
@ -5273,7 +5296,8 @@ POSITIONAL ARGUMENTS:
tags, tags,
desc_in, desc_in,
args.immutable, args.immutable,
args.threads args.threads,
args.preserve
) )
else: else:
for _id in range(vals[0], vals[1] + 1): for _id in range(vals[0], vals[1] + 1):
@ -5284,7 +5308,8 @@ POSITIONAL ARGUMENTS:
tags, tags,
desc_in, desc_in,
args.immutable, args.immutable,
args.threads args.threads,
args.preserve
) )
if INTERRUPTED: if INTERRUPTED:
break break