Add debug options.
Vaiable name changes. Signed-off-by: Arun Prakash Jana <engineerarun@gmail.com>
This commit is contained in:
parent
6df582db2a
commit
78c0c639e6
56
markit
56
markit
@ -32,11 +32,12 @@ from urllib.parse import urljoin, unquote
|
||||
addurl = False
|
||||
addindex = None
|
||||
online = False
|
||||
deletedb = False
|
||||
showdb = False
|
||||
delete = False
|
||||
show = False
|
||||
search = False
|
||||
entry = None
|
||||
updatedb = False
|
||||
update = False
|
||||
debug = False
|
||||
|
||||
def usage():
|
||||
print("Usage: markit [OPTIONS] KEYWORDS...")
|
||||
@ -50,6 +51,7 @@ def usage():
|
||||
print(" -p print all bookmarks, shows real index from database")
|
||||
print(" -s keyword(s) search all bookmarks for a (partial) tag or keywords")
|
||||
print(" -u N update entry at index N (from output of -p)")
|
||||
print(" -z show debug information")
|
||||
print(" you can either add or update or delete in one instance")
|
||||
print(" any other input shows help and exits markit\n")
|
||||
print("Version 0.1")
|
||||
@ -101,12 +103,15 @@ def AddUpdateEntry(conn, cur, keywords, entry):
|
||||
server = server[:marker]
|
||||
|
||||
try:
|
||||
print("server: [%s]" % server)
|
||||
if debug:
|
||||
print("server: [%s]" % server)
|
||||
if secure == True:
|
||||
urlconn = HTTPSConnection(server, timeout=30)
|
||||
else:
|
||||
urlconn = HTTPConnection(server, timeout=30)
|
||||
print("URL: [%s]" % url)
|
||||
|
||||
if debug:
|
||||
print("URL: [%s]" % url)
|
||||
urlconn.request("GET", url)
|
||||
resp = urlconn.getresponse()
|
||||
if resp.status != 200:
|
||||
@ -134,8 +139,9 @@ def AddUpdateEntry(conn, cur, keywords, entry):
|
||||
server = server[:marker]
|
||||
urlconn = HTTPConnection(server, timeout=30)
|
||||
|
||||
print("Redir server [%s]" % server)
|
||||
print("Redir URL [%s]" % redirurl)
|
||||
if debug:
|
||||
print("Redir server: [%s]" % server)
|
||||
print("Redir URL: [%s]" % redirurl)
|
||||
|
||||
urlconn.request("GET", redirurl)
|
||||
resp = urlconn.getresponse()
|
||||
@ -147,7 +153,6 @@ def AddUpdateEntry(conn, cur, keywords, entry):
|
||||
parser.feed(resp.read().decode('utf-8'))
|
||||
if parser.data != None and parser.data.find("Error") < 0:
|
||||
meta = parser.data
|
||||
print("Title: [%s]" % meta)
|
||||
else:
|
||||
print("ERROR:", str(resp.status), ": ", resp.reason)
|
||||
meta = ''
|
||||
@ -162,7 +167,7 @@ def AddUpdateEntry(conn, cur, keywords, entry):
|
||||
finally:
|
||||
urlconn.close()
|
||||
|
||||
print("meta: [%s]" % meta)
|
||||
print("Title: [%s]" % meta)
|
||||
|
||||
if entry == None: # Add a new entry
|
||||
try:
|
||||
@ -198,7 +203,8 @@ def searchdb(cur, keywords):
|
||||
query += " OR URL LIKE (%s) OR metadata LIKE (%s)" % (placeholder, placeholder)
|
||||
arguments.append(token)
|
||||
arguments.append(token)
|
||||
print("%s, (%s)" % (query, arguments))
|
||||
if debug:
|
||||
print("%s, (%s)" % (query, arguments))
|
||||
|
||||
count = 0
|
||||
results = []
|
||||
@ -256,7 +262,7 @@ def cleardb(conn, cur, entry):
|
||||
except IndexError:
|
||||
print("Index out of bound.")
|
||||
|
||||
def printtable(cur):
|
||||
def printdb(cur):
|
||||
for row in cur.execute('SELECT * FROM bookmarks'):
|
||||
print("\x1B[1m\x1B[93m%s. \x1B[0m\x1B[92m%s\x1B[0m\n\t[TAGS] %s\n\t[META] %s" % (row[0], row[1], row[2][1:-1], row[3]))
|
||||
|
||||
@ -298,19 +304,19 @@ if len(sys.argv) < 2:
|
||||
usage()
|
||||
|
||||
try:
|
||||
optlist, keywords = getopt(sys.argv[1:], "d:i:u:aDops")
|
||||
optlist, keywords = getopt(sys.argv[1:], "d:i:u:aDopsz")
|
||||
if len(optlist) < 1:
|
||||
usage()
|
||||
|
||||
for opt in optlist:
|
||||
if opt[0] == "-a":
|
||||
if updatedb == True or deletedb == True:
|
||||
if update == True or delete == True:
|
||||
print("You can either add or update or delete in one instance\n")
|
||||
usage()
|
||||
|
||||
addurl = True
|
||||
elif opt[0] == "-d":
|
||||
if addurl == True or updatedb == True:
|
||||
if addurl == True or update == True:
|
||||
print("You can either add or update or delete in one instance\n")
|
||||
usage()
|
||||
|
||||
@ -321,13 +327,13 @@ try:
|
||||
if int(entry) <= 0:
|
||||
usage()
|
||||
|
||||
deletedb = True
|
||||
delete = True
|
||||
elif opt[0] == "-D":
|
||||
if addurl == True or updatedb == True:
|
||||
if addurl == True or update == True:
|
||||
print("You can either add or update or delete in one instance\n")
|
||||
usage()
|
||||
|
||||
deletedb = True
|
||||
delete = True
|
||||
elif opt[0] == "-i":
|
||||
if not opt[1].isdigit():
|
||||
usage()
|
||||
@ -338,11 +344,11 @@ try:
|
||||
elif opt[0] == "-o":
|
||||
online = True
|
||||
elif opt[0] == "-p":
|
||||
showdb = True
|
||||
show = True
|
||||
elif opt[0] == "-s":
|
||||
search = True
|
||||
elif opt[0] == "-u":
|
||||
if addurl == True or deletedb == True:
|
||||
if addurl == True or delete == True:
|
||||
print("You can either add or update or delete in one instance\n")
|
||||
usage()
|
||||
|
||||
@ -353,7 +359,9 @@ try:
|
||||
if int(entry) <= 0:
|
||||
usage()
|
||||
|
||||
updatedb = True
|
||||
update = True
|
||||
elif opt[0] == "-z":
|
||||
debug = True
|
||||
except GetoptError as e:
|
||||
print("markit:", e)
|
||||
sys.exit(1)
|
||||
@ -364,7 +372,7 @@ if addindex != None and addurl == False:
|
||||
conn.close()
|
||||
usage()
|
||||
|
||||
if addurl == True or updatedb == True:
|
||||
if addurl == True or update == True:
|
||||
if len(keywords) < 1:
|
||||
conn.close()
|
||||
usage()
|
||||
@ -378,10 +386,10 @@ if search == True:
|
||||
|
||||
searchdb(cur, keywords)
|
||||
|
||||
if showdb == True:
|
||||
printtable(cur)
|
||||
if show == True:
|
||||
printdb(cur)
|
||||
|
||||
if deletedb == True:
|
||||
if delete == True:
|
||||
cleardb(conn, cur, entry)
|
||||
|
||||
conn.close()
|
||||
|
Loading…
Reference in New Issue
Block a user