Remove global showOpt
.
This commit is contained in:
parent
0db71207f5
commit
a6b406ebc4
34
buku
34
buku
@ -37,7 +37,6 @@ titleManual = None # Manually add a title offline
|
|||||||
description = None # Description of the bookmark
|
description = None # Description of the bookmark
|
||||||
tagsearch = False # Search bookmarks by tag
|
tagsearch = False # Search bookmarks by tag
|
||||||
titleData = None # Title fetched from a page
|
titleData = None # Title fetched from a page
|
||||||
showOpt = 0 # Modify show. 1: show only URL, 2: show URL and tag
|
|
||||||
debug = False # Enable debug logs
|
debug = False # Enable debug logs
|
||||||
pipeargs = [] # Holds arguments piped to the program
|
pipeargs = [] # Holds arguments piped to the program
|
||||||
interrupted = False # Received SIGINT
|
interrupted = False # Received SIGINT
|
||||||
@ -266,12 +265,13 @@ class BukuCrypt:
|
|||||||
|
|
||||||
class BukuDb:
|
class BukuDb:
|
||||||
|
|
||||||
def __init__(self, noninteractive=False, json=False):
|
def __init__(self, noninteractive=False, json=False, showOpt=0):
|
||||||
conn, cur = BukuDb.initdb()
|
conn, cur = BukuDb.initdb()
|
||||||
self.conn = conn
|
self.conn = conn
|
||||||
self.cur = cur
|
self.cur = cur
|
||||||
self.noninteractive = noninteractive
|
self.noninteractive = noninteractive
|
||||||
self.json = json
|
self.json = json
|
||||||
|
self.showOpt = showOpt
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_dbdir_path():
|
def get_dbdir_path():
|
||||||
@ -620,7 +620,7 @@ class BukuDb:
|
|||||||
if not self.json:
|
if not self.json:
|
||||||
prompt(results, self.noninteractive)
|
prompt(results, self.noninteractive)
|
||||||
else:
|
else:
|
||||||
print(format_json(results))
|
print(format_json(results, showOpt=self.showOpt))
|
||||||
|
|
||||||
def search_by_tag(self, tag):
|
def search_by_tag(self, tag):
|
||||||
"""Search and list bookmarks with a tag
|
"""Search and list bookmarks with a tag
|
||||||
@ -636,7 +636,7 @@ class BukuDb:
|
|||||||
if not self.json:
|
if not self.json:
|
||||||
prompt(results, self.noninteractive)
|
prompt(results, self.noninteractive)
|
||||||
else:
|
else:
|
||||||
print(format_json(results))
|
print(format_json(results, showOpt=self.showOpt))
|
||||||
|
|
||||||
def compactdb(self, index):
|
def compactdb(self, index):
|
||||||
"""When an entry at index is deleted, move the last
|
"""When an entry at index is deleted, move the last
|
||||||
@ -717,17 +717,17 @@ class BukuDb:
|
|||||||
print('\x1b[1m%s records found\x1b[21m\n' % len(resultset))
|
print('\x1b[1m%s records found\x1b[21m\n' % len(resultset))
|
||||||
|
|
||||||
if not self.json:
|
if not self.json:
|
||||||
if showOpt == 0:
|
if self.showOpt == 0:
|
||||||
for row in resultset:
|
for row in resultset:
|
||||||
print_record(row)
|
print_record(row)
|
||||||
elif showOpt == 1:
|
elif self.showOpt == 1:
|
||||||
for row in resultset:
|
for row in resultset:
|
||||||
print('%s\t%s' % (row[0], row[1]))
|
print('%s\t%s' % (row[0], row[1]))
|
||||||
elif showOpt == 2:
|
elif self.showOpt == 2:
|
||||||
for row in resultset:
|
for row in resultset:
|
||||||
print('%s\t%s\t%s' % (row[0], row[1], row[3][1:-1]))
|
print('%s\t%s\t%s' % (row[0], row[1], row[3][1:-1]))
|
||||||
else:
|
else:
|
||||||
print(format_json(resultset))
|
print(format_json(resultset, showOpt=self.showOpt))
|
||||||
else: # Show record at index
|
else: # Show record at index
|
||||||
try:
|
try:
|
||||||
self.cur.execute('SELECT * FROM bookmarks WHERE id = ?', (index,))
|
self.cur.execute('SELECT * FROM bookmarks WHERE id = ?', (index,))
|
||||||
@ -741,14 +741,14 @@ class BukuDb:
|
|||||||
|
|
||||||
if not self.json:
|
if not self.json:
|
||||||
for row in results:
|
for row in results:
|
||||||
if showOpt == 0:
|
if self.showOpt == 0:
|
||||||
print_record(row)
|
print_record(row)
|
||||||
elif showOpt == 1:
|
elif self.showOpt == 1:
|
||||||
print('%s\t%s' % (row[0], row[1]))
|
print('%s\t%s' % (row[0], row[1]))
|
||||||
elif showOpt == 2:
|
elif self.showOpt == 2:
|
||||||
print('%s\t%s\t%s' % (row[0], row[1], row[3][1:-1]))
|
print('%s\t%s\t%s' % (row[0], row[1], row[3][1:-1]))
|
||||||
else:
|
else:
|
||||||
print(format_json(results, True))
|
print(format_json(results, True, self.showOpt))
|
||||||
|
|
||||||
def list_tags(self):
|
def list_tags(self):
|
||||||
"""Print all unique tags ordered alphabetically"""
|
"""Print all unique tags ordered alphabetically"""
|
||||||
@ -1247,11 +1247,9 @@ def print_record(row, count=0):
|
|||||||
print(printstr)
|
print(printstr)
|
||||||
|
|
||||||
|
|
||||||
def format_json(resultset, single=False):
|
def format_json(resultset, single=False, showOpt=0):
|
||||||
"""Return results in Json format"""
|
"""Return results in Json format"""
|
||||||
|
|
||||||
global showOpt
|
|
||||||
|
|
||||||
if not single:
|
if not single:
|
||||||
marks = []
|
marks = []
|
||||||
for row in resultset:
|
for row in resultset:
|
||||||
@ -1537,7 +1535,7 @@ if __name__ == '__main__':
|
|||||||
-o, --open N open bookmark at DB index N in web browser
|
-o, --open N open bookmark at DB index N in web browser
|
||||||
-z, --debug show debug information and additional logs''')
|
-z, --debug show debug information and additional logs''')
|
||||||
power_group.add_argument('-p', '--print', nargs='?', dest='printindex', type=int, const=0, metavar='N', help=argparse.SUPPRESS)
|
power_group.add_argument('-p', '--print', nargs='?', dest='printindex', type=int, const=0, metavar='N', help=argparse.SUPPRESS)
|
||||||
power_group.add_argument('-f', '--format', dest='showOpt', type=int, choices=[1, 2], metavar='N', help=argparse.SUPPRESS)
|
power_group.add_argument('-f', '--format', dest='showOpt', type=int, default=0, choices=[1, 2], metavar='N', help=argparse.SUPPRESS)
|
||||||
power_group.add_argument('-r', '--replace', nargs='+', dest='replace', metavar=('oldtag', 'newtag'), help=argparse.SUPPRESS)
|
power_group.add_argument('-r', '--replace', nargs='+', dest='replace', metavar=('oldtag', 'newtag'), help=argparse.SUPPRESS)
|
||||||
power_group.add_argument('-j', '--json', dest='jsonOutput', action='store_true', help=argparse.SUPPRESS)
|
power_group.add_argument('-j', '--json', dest='jsonOutput', action='store_true', help=argparse.SUPPRESS)
|
||||||
general_group.add_argument('-e', '--export', nargs=1, dest='export', metavar='file', help=argparse.SUPPRESS)
|
general_group.add_argument('-e', '--export', nargs=1, dest='export', metavar='file', help=argparse.SUPPRESS)
|
||||||
@ -1561,8 +1559,6 @@ if __name__ == '__main__':
|
|||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
# Assign the values to globals
|
# Assign the values to globals
|
||||||
if args.showOpt is not None:
|
|
||||||
showOpt = args.showOpt
|
|
||||||
if tagManual is not None and len(args.tag) > 0:
|
if tagManual is not None and len(args.tag) > 0:
|
||||||
tagManual = args.tag
|
tagManual = args.tag
|
||||||
if titleManual is not None and len(args.title) > 0:
|
if titleManual is not None and len(args.title) > 0:
|
||||||
@ -1588,7 +1584,7 @@ if __name__ == '__main__':
|
|||||||
BukuCrypt.decrypt_file(args.decrypt)
|
BukuCrypt.decrypt_file(args.decrypt)
|
||||||
|
|
||||||
# Initialize the database and get handles
|
# Initialize the database and get handles
|
||||||
bdb = BukuDb(args.noninteractive, args.jsonOutput)
|
bdb = BukuDb(args.noninteractive, args.jsonOutput, args.showOpt)
|
||||||
|
|
||||||
# Add a record
|
# Add a record
|
||||||
if args.addurl is not None:
|
if args.addurl is not None:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user