From 1609b5a135a71bf6abeda8a027cc084e2bc8fba5 Mon Sep 17 00:00:00 2001
From: Arun Prakash Jana
Date: Sun, 20 Nov 2016 20:40:56 +0530
Subject: [PATCH] API to fix tags from earlier versions. Update image.
---
README.md | 2 +-
buku.py | 36 +++++++++++++++++++++++++++++++++++-
2 files changed, 36 insertions(+), 2 deletions(-)
diff --git a/README.md b/README.md
index 38351ac..25e4170 100644
--- a/README.md
+++ b/README.md
@@ -9,7 +9,7 @@
-
+
`buku` is a powerful bookmark management utility written in Python3 and SQLite3. When I started writing it, I couldn't find a flexible cmdline solution with a private, portable, merge-able database along with browser integration. Hence, `buku` (after my son's nickname).
diff --git a/buku.py b/buku.py
index 5b18c75..6946f50 100755
--- a/buku.py
+++ b/buku.py
@@ -1417,6 +1417,34 @@ Buku bookmarks
return r.text
+ def fixtags(self):
+ '''Undocumented API to fix tags set
+ in earlier versions. Functionalities:
+
+ 1. Remove duplicate tags
+ 2. Sort tags
+ 3. Use lower case to store tags
+ '''
+
+ to_commit = False
+ self.cur.execute('SELECT id, tags FROM bookmarks ORDER BY id ASC')
+ resultset = self.cur.fetchall()
+ query = 'UPDATE bookmarks SET tags = ? WHERE id = ?'
+ for row in resultset:
+ oldtags = row[1]
+ if oldtags == ',':
+ continue
+
+ tags = parse_tags([oldtags])
+ if tags == oldtags:
+ continue
+
+ self.cur.execute(query, (tags, row[0],))
+ to_commit = True
+
+ if to_commit:
+ self.conn.commit()
+
def close_quit(self, exitval=0):
'''Close a DB connection and exit
@@ -1634,7 +1662,7 @@ def parse_tags(keywords=None):
orig_tags += tags.strip(DELIM).split(DELIM)
for tag in orig_tags:
if tag.lower() not in unique_tags:
- # Add unique tags in lowercase
+ # Add unique tags in lower case
unique_tags += (tag.lower(), )
# Sort the tags
@@ -2269,6 +2297,8 @@ def main():
addarg('--tacit', action='store_true', help=HIDE)
addarg('--upstream', action='store_true', help=HIDE)
addarg('-z', '--debug', action='store_true', help=HIDE)
+ # Undocumented API
+ addarg('--fixtags', action='store_true', help=HIDE)
# Show help and exit if no arguments
if len(sys.argv) < 2:
@@ -2530,6 +2560,10 @@ def main():
if args.upstream:
check_upstream_release()
+ # Fix tags
+ if args.fixtags:
+ bdb.fixtags()
+
# Close DB connection and quit
bdb.close_quit(0)