Support selective unformatted output for batch update scripts.

Signed-off-by: Arun Prakash Jana <engineerarun@gmail.com>
This commit is contained in:
Arun Prakash Jana 2015-11-10 23:28:37 -08:00
parent 17067b1a6c
commit d7346c8bda
3 changed files with 26 additions and 2 deletions

View File

@ -81,6 +81,7 @@ Options
-s keyword(s) search all bookmarks for a (partial) tag or each keyword -s keyword(s) search all bookmarks for a (partial) tag or each keyword
-u N update entry at DB index N -u N update entry at DB index N
-w fetch title info from web, works with -a, -i, -u -w fetch title info from web, works with -a, -i, -u
-x N works with -P, N=1: show only URL, N=2: show URL and tag
-z show debug information -z show debug information
you can either add or update or delete in one instance you can either add or update or delete in one instance
any other option shows help and exits markit any other option shows help and exits markit

20
markit
View File

@ -36,6 +36,7 @@ delete = False
openurl = None openurl = None
show = False show = False
showindex = None showindex = None
showOpt = 0
search = False search = False
entry = None entry = None
update = False update = False
@ -59,6 +60,7 @@ def usage():
print(" -s keyword(s) search all bookmarks for a (partial) tag or each keyword") print(" -s keyword(s) search all bookmarks for a (partial) tag or each keyword")
print(" -u N update entry at DB index N") print(" -u N update entry at DB index N")
print(" -w fetch title info from web, works with -a, -i, -u") print(" -w fetch title info from web, works with -a, -i, -u")
print(" -x N works with -P, N=1: show only URL, N=2: show URL and tag")
print(" -z show debug information") print(" -z show debug information")
print(" you can either add or update or delete in one instance") print(" you can either add or update or delete in one instance")
print(" any other option shows help and exits markit\n") print(" any other option shows help and exits markit\n")
@ -291,9 +293,16 @@ def cleardb(conn, cur, index):
# Print all records in the table # Print all records in the table
def printdb(cur, index): def printdb(cur, index):
global showOpt
if index == None: # Show all entries if index == None: # Show all entries
for row in cur.execute('SELECT * FROM bookmarks'): for row in cur.execute('SELECT * FROM bookmarks'):
print("\x1B[1m\x1B[93m%s. \x1B[0m\x1B[92m%s\x1B[0m\n\t%s\n\t\x1B[91m[TAGS]\x1B[0m %s" % (row[0], row[1], row[2], row[3][1:-1])) if showOpt == 1:
print("%s %s" % (row[0], row[1]))
elif showOpt == 2:
print("%s %s %s" % (row[0], row[1], row[3][1:-1]))
else:
print("\x1B[1m\x1B[93m%s. \x1B[0m\x1B[92m%s\x1B[0m\n\t%s\n\t\x1B[91m[TAGS]\x1B[0m %s" % (row[0], row[1], row[2], row[3][1:-1]))
else: # Show record at index else: # Show record at index
try: try:
for row in cur.execute("SELECT * FROM bookmarks WHERE id = ?", (int(index),)): for row in cur.execute("SELECT * FROM bookmarks WHERE id = ?", (int(index),)):
@ -411,7 +420,7 @@ if len(sys.argv) < 2:
# Check cmdline options # Check cmdline options
try: try:
optlist, keywords = getopt(sys.argv[1:], "d:i:o:p:u:aDPswz") optlist, keywords = getopt(sys.argv[1:], "d:i:o:p:u:x:aDPswz")
if len(optlist) < 1: if len(optlist) < 1:
usage() usage()
@ -489,6 +498,13 @@ try:
update = True update = True
elif opt[0] == "-w": elif opt[0] == "-w":
online = True online = True
elif opt[0] == "-x":
if not opt[1].isdigit():
usage()
showOpt = int(opt[1])
if showOpt < 1 or showOpt > 2:
usage()
elif opt[0] == "-z": elif opt[0] == "-z":
debug = True debug = True
except GetoptError as e: except GetoptError as e:

View File

@ -68,6 +68,13 @@ in DB.
.BI \-w .BI \-w
Fetch title data from the web. Works with `-a`, `-i` or `-u` options. Fetch title data from the web. Works with `-a`, `-i` or `-u` options.
.TP .TP
.BI \-x " N"
Show selective monochrome output. Works with `-P`. If
.I N
= 1, only URL is shown. If
.I N
= 2, URL and tags are shown in a single line. Useful for creating batch update scripts.
.TP
.BI \-z .BI \-z
Enable debugging. Enable debugging.
.TP .TP