removed globals from updateEntry and slight formatting

This commit is contained in:
toyg 2016-05-21 11:40:37 +01:00
parent 326e8c6093
commit ab65c94dfe

45
buku
View File

@ -261,40 +261,41 @@ class BukuDb:
print("Index %d exists" % insertindex) print("Index %d exists" % insertindex)
def UpdateEntry(self, index, url=''): def UpdateEntry(self, index, url='', tag_manual=None, title_manual=None, desc=None):
"""Update an existing record at index """ Update an existing record at index
Params: self.conn.ction, self.cur.or, index to update, url :param index: int position to update
:param url: address
:param tag_manual: list of tags to add manually
:param title_manual: string title to add manually
:param desc: string description
:return:
""" """
global tagManual
global titleManual
global description
arguments = [] arguments = []
query = "UPDATE bookmarks SET" query = "UPDATE bookmarks SET"
toUpdate = False to_update = False
# Update URL if passed as argument # Update URL if passed as argument
if url != '': if url != '':
query += " URL = ?," query += " URL = ?,"
arguments.append(url) arguments.append(url)
toUpdate = True to_update = True
# Update tags if passed as argument # Update tags if passed as argument
if tagManual is not None: if tag_manual is not None:
tags = ',' tags = ','
if False == (tagManual[0] == ',' and len(tagManual) == 1): if not (tag_manual[0] == ',' and len(tag_manual) == 1):
tags = getTags(tagManual) tags = getTags(tag_manual)
query += " tags = ?," query += " tags = ?,"
arguments.append(tags) arguments.append(tags)
toUpdate = True to_update = True
# Update description if passed as an argument # Update description if passed as an argument
if description is not None: if desc is not None:
query += " desc = ?," query += " desc = ?,"
arguments.append(description) arguments.append(desc)
toUpdate = True to_update = True
# Update title # Update title
# #
@ -304,24 +305,24 @@ class BukuDb:
# if URL is passed, update the title from web using the URL # if URL is passed, update the title from web using the URL
# 4. if no other argument (url, tag, comment) passed update title from web using DB URL # 4. if no other argument (url, tag, comment) passed update title from web using DB URL
meta = None meta = None
if titleManual is not None: if title_manual is not None:
meta = titleManual meta = title_manual
elif url != '': elif url != '':
meta = fetchTitle(url) meta = fetchTitle(url)
if meta == '': if meta == '':
print("\x1B[91mTitle: []\x1B[0m") print("\x1B[91mTitle: []\x1B[0m")
else: else:
print("Title: [%s]" % meta) print("Title: [%s]" % meta)
elif toUpdate == False: elif not to_update:
self.dbRefresh(index) self.dbRefresh(index)
self.printdb(index) self.printdb(index)
if meta is not None: if meta is not None:
query += " metadata = ?," query += " metadata = ?,"
arguments.append(meta) arguments.append(meta)
toUpdate = True to_update = True
if toUpdate == False: # Nothing to update if not to_update: # Nothing to update
return return
query = query[:-1] + " WHERE id = ?" query = query[:-1] + " WHERE id = ?"
@ -1440,7 +1441,7 @@ if update == True:
new_url = args.url[0] new_url = args.url[0]
else: else:
new_url = '' new_url = ''
bdb.UpdateEntry(int(args.update[0]), new_url) bdb.UpdateEntry(int(args.update[0]), new_url, tagManual, titleManual, description)
# Print all records # Print all records
if args.printindex is not None: if args.printindex is not None: