From 09f05eb6b8067f43cd7642b5aac856fd0d4d0e7e Mon Sep 17 00:00:00 2001 From: humCopper Date: Thu, 2 May 2019 21:57:26 -0500 Subject: [PATCH 1/6] Add --preserve option when using --update --- buku | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/buku b/buku index 096ef48..f6ea257 100755 --- a/buku +++ b/buku @@ -755,7 +755,8 @@ class BukuDb: tags_in=None, desc=None, immutable=-1, - threads=4): + threads=4, + preserve=None): """Update an existing record at index. 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. threads : int, optional 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 ------- @@ -792,6 +795,17 @@ class BukuDb: tag_modified = False ret = False + if preserve is not None: + for option in preserve: + if option == "url": + url = None + elif option in ('tag', 'tags'): + tags_in = None + elif option == "comment": + desc = None + elif option == "title": + title_in = None + # Update URL if passed as argument if url is not None and url != '': if index == 0: @@ -4763,6 +4777,7 @@ POSITIONAL ARGUMENTS: addarg('--title', nargs='*', help=hide) addarg('-c', '--comment', nargs='*', help=hide) addarg('--immutable', type=int, default=-1, choices={0, 1}, help=hide) + addarg('--preserve', nargs='*', help=hide) # -------------------- # SEARCH OPTIONS GROUP @@ -5223,7 +5238,7 @@ POSITIONAL ARGUMENTS: if not args.update: # Update all records only if search was not 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: if not args.tacit: print('Updated results:\n') @@ -5238,7 +5253,8 @@ POSITIONAL ARGUMENTS: tags, desc_in, args.immutable, - args.threads + args.threads, + args.preserve ) # Commit at every 200th removal @@ -5256,7 +5272,8 @@ POSITIONAL ARGUMENTS: tags, desc_in, args.immutable, - args.threads + args.threads, + args.preserve ) elif '-' in idx: try: @@ -5273,7 +5290,8 @@ POSITIONAL ARGUMENTS: tags, desc_in, args.immutable, - args.threads + args.threads, + args.preserve ) else: for _id in range(vals[0], vals[1] + 1): @@ -5284,7 +5302,8 @@ POSITIONAL ARGUMENTS: tags, desc_in, args.immutable, - args.threads + args.threads, + args.preserve ) if INTERRUPTED: break From cf4d0112d20b296fcb14f7ac1717d725780a041f Mon Sep 17 00:00:00 2001 From: humCopper <35010945+humCopper@users.noreply.github.com> Date: Fri, 3 May 2019 17:40:59 -0500 Subject: [PATCH 2/6] Add example and fix preserving title --- README.md | 8 ++++++-- buku | 4 +++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 93cae5a..962b012 100644 --- a/README.md +++ b/README.md @@ -195,6 +195,7 @@ EDIT OPTIONS: clears description, if no arguments --immutable N disable web-fetch during auto-refresh N=0: mutable (default), N=1: immutable + --preserve [...] values to preserve for -u SEARCH OPTIONS: -s, --sany [...] find records with ANY matching keyword @@ -453,10 +454,13 @@ PROMPT KEYS: 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 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 +38. List bookmarks with **colored output**: $ buku --colors oKlxm -p -38. More **help**: +39. More **help**: $ buku -h $ man buku diff --git a/buku b/buku index f6ea257..2f16b3f 100755 --- a/buku +++ b/buku @@ -795,6 +795,7 @@ class BukuDb: tag_modified = False ret = False + preserve_title = False if preserve is not None: for option in preserve: if option == "url": @@ -805,6 +806,7 @@ class BukuDb: desc = None elif option == "title": title_in = None + preserve_title = True # Update URL if passed as argument if url is not None and url != '': @@ -871,7 +873,7 @@ class BukuDb: ptags = None if title_in is not None: title_to_insert = title_in - elif url is not None and url != '': + elif url is not None and url != '' and not preserve_title: title_to_insert, pdesc, ptags, mime, bad = network_handler(url) if bad: print('Malformed URL') From 60de643ec547e33e2d94f11960b763e5c4431baf Mon Sep 17 00:00:00 2001 From: humCopper <35010945+humCopper@users.noreply.github.com> Date: Fri, 3 May 2019 17:50:28 -0500 Subject: [PATCH 3/6] Add autocomplete for --preserve in bash and zsh --- auto-completion/bash/buku-completion.bash | 1 + auto-completion/zsh/_buku | 1 + 2 files changed, 2 insertions(+) diff --git a/auto-completion/bash/buku-completion.bash b/auto-completion/bash/buku-completion.bash index 77f967a..b8971a0 100644 --- a/auto-completion/bash/buku-completion.bash +++ b/auto-completion/bash/buku-completion.bash @@ -62,6 +62,7 @@ _buku () { -i --import --immutable -n --count + --preserve -r --sreg --replace -s --sany diff --git a/auto-completion/zsh/_buku b/auto-completion/zsh/_buku index 4182aa3..8dac5b4 100644 --- a/auto-completion/zsh/_buku +++ b/auto-completion/zsh/_buku @@ -30,6 +30,7 @@ args=( '(--np)--np[noninteractive mode]' '(-o --open)'{-o,--open}'[open bookmarks in browser]' '(--oa)--oa[browse all search results immediately]' + '(--preserve)--preserve[preserve options]' '(-p --print)'{-p,--print}'[show bookmark details]' '(-r --sreg)'{-r,--sreg}'[match a regular exression]:regex' '(--replace)--replace[replace a tag]:tag to replace' From cd17b27e83bc3c1a4b4d8dbedfec730ddc344181 Mon Sep 17 00:00:00 2001 From: humCopper <35010945+humCopper@users.noreply.github.com> Date: Sat, 4 May 2019 08:39:27 -0500 Subject: [PATCH 4/6] Add example of --preserve --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 962b012..6f0b2fe 100644 --- a/README.md +++ b/README.md @@ -454,9 +454,12 @@ PROMPT KEYS: 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 buku (? for help) g 4 9-6 << 5 3-2 -37. **Update** URL but **Preserve** title +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 From 23ee887e8e54a14c828df4010d72b323cbaafb42 Mon Sep 17 00:00:00 2001 From: humCopper <35010945+humCopper@users.noreply.github.com> Date: Sat, 4 May 2019 09:04:47 -0500 Subject: [PATCH 5/6] Change --preserve so that it can preserve everything --- buku | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/buku b/buku index 2f16b3f..f9cea62 100755 --- a/buku +++ b/buku @@ -796,7 +796,10 @@ class BukuDb: 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 @@ -804,6 +807,7 @@ class BukuDb: tags_in = None elif option == "comment": desc = None + preserve_desc = True elif option == "title": title_in = None preserve_title = True @@ -873,7 +877,7 @@ class BukuDb: ptags = None if title_in is not None: title_to_insert = title_in - elif url is not None and url != '' and not preserve_title: + elif url is not None and url != '': title_to_insert, pdesc, ptags, mime, bad = network_handler(url) if bad: print('Malformed URL') @@ -884,7 +888,7 @@ class BukuDb: else: LOGDBG('Title: [%s]', title_to_insert) - if not desc: + if not desc and not preserve_desc: if not pdesc: pdesc = '' query += ' desc = ?,' @@ -896,7 +900,7 @@ class BukuDb: self.print_rec(index) return ret - if title_to_insert is not None: + if title_to_insert is not None and not preserve_title: query += ' metadata = ?,' arguments += (title_to_insert,) to_update = True From c5e874229a456e38cb00137ca21cb73b789b7ac5 Mon Sep 17 00:00:00 2001 From: humCopper <35010945+humCopper@users.noreply.github.com> Date: Sat, 4 May 2019 09:04:47 -0500 Subject: [PATCH 6/6] Change --preserve so that it can preserve everything --- buku | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/buku b/buku index 2f16b3f..0365b8a 100755 --- a/buku +++ b/buku @@ -796,7 +796,10 @@ class BukuDb: 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 @@ -804,6 +807,7 @@ class BukuDb: tags_in = None elif option == "comment": desc = None + preserve_desc = True elif option == "title": title_in = None preserve_title = True @@ -873,7 +877,7 @@ class BukuDb: ptags = None if title_in is not None: title_to_insert = title_in - elif url is not None and url != '' and not preserve_title: + elif url is not None and url != '': title_to_insert, pdesc, ptags, mime, bad = network_handler(url) if bad: print('Malformed URL') @@ -884,7 +888,7 @@ class BukuDb: else: LOGDBG('Title: [%s]', title_to_insert) - if not desc: + if not desc and not preserve_desc: if not pdesc: pdesc = '' query += ' desc = ?,' @@ -896,7 +900,7 @@ class BukuDb: self.print_rec(index) return ret - if title_to_insert is not None: + if title_to_insert is not None and not preserve_title: query += ' metadata = ?,' arguments += (title_to_insert,) to_update = True