From 53da73b8dbf97179da9ed5de6d79c4aa132b2d1e Mon Sep 17 00:00:00 2001 From: Arun Prakash Jana Date: Mon, 23 May 2016 00:50:50 +0530 Subject: [PATCH] Remove insert bookmark operation. --- buku | 47 +++++++---------------------------------------- 1 file changed, 7 insertions(+), 40 deletions(-) diff --git a/buku b/buku index bf4f7ec..4290765 100755 --- a/buku +++ b/buku @@ -202,11 +202,10 @@ class BukuDb: return resultset[0][0] - def add_bookmark(self, keywords, insertindex=0): - """Add a new bookmark or insert a - new record at insertindex (if empty) + def add_bookmark(self, keywords): + """Add a new bookmark - Params: keywords, index to update, index to insert at + Params: keywords (url + optional tags) """ global tagManual @@ -244,21 +243,12 @@ class BukuDb: description = '' try: - if insertindex == 0: # insertindex is index number to insert record at - self.cur.execute('INSERT INTO bookmarks(URL, metadata, tags, desc) VALUES (?, ?, ?, ?)', (url, meta, tags, description)) - else: - self.cur.execute('INSERT INTO bookmarks(id, URL, metadata, tags, desc) VALUES (?, ?, ?, ?, ?)', (insertindex, url, meta, tags, description)) - + self.cur.execute('INSERT INTO bookmarks(URL, metadata, tags, desc) VALUES (?, ?, ?, ?)', (url, meta, tags, description)) self.conn.commit() print("Added at index %d\n" % self.cur.lastrowid) self.printdb(self.cur.lastrowid) - except sqlite3.IntegrityError: - for row in self.cur.execute("SELECT id from bookmarks where URL LIKE ?", (url,)): - print("URL already exists at index %s" % row[0]) - return - - # Print error for index existing case - print("Index %d exists" % insertindex) + except Exception as e: + print("\x1b[1mEXCEPTION\x1b[21m [add_bookmark]: (%s) %s" % (type(e).__name__, e)) def update_bookmark(self, index, url='', tag_manual=None, title_manual=None, desc=None): @@ -1336,13 +1326,6 @@ power_group.add_argument('-j', '--json', dest='jsonOutput', action='store_true', power_group.add_argument('-o', '--open', dest='openurl', type=int, metavar='N', help=argparse.SUPPRESS) power_group.add_argument('-z', '--debug', dest='debug', action='store_true', help=argparse.SUPPRESS) -""" -# NOTE: Insert is functional but commented because DB compaction serves the purpose. -addarg = argparser.add_argument -addarg('-i', '--insert', nargs='+', dest='insert', metavar=('N', 'URL tags'), - help=" insert new bookmark with URL and tags at free DB index N; frees index if URL and tags are omitted") -""" - # Show help and exit if no arguments if len(sys.argv) < 2: argparser.print_help(sys.stderr) @@ -1466,21 +1449,5 @@ if args.openurl is not None: bdb.close_quit(1) bdb.browse_by_index(args.openurl) -""" -# NOTE: Insert is functional but commented because DB compaction serves the purpose. -# Insert a record at an index -if args.insert is not None: - if not args.insert[0].isdigit(): - printmsg("Index must be a number >= 1", "ERROR") - close_quit(conn, 1) - insertindex = int(args.insert[0]) - if insertindex < 1: - printmsg("Index must be a number >= 1", "ERROR") - close_quit(conn, 1) - if len(args.insert) == 1: - pass # No operation - else: - add_bookmark(conn, cur, args.insert[1:], insertindex) -""" - +# Close DB connection and quit bdb.close_quit(0)