From d4921362af2c00f295d456601b234484a5c4ba20 Mon Sep 17 00:00:00 2001 From: Arun Prakash Jana Date: Tue, 10 Nov 2015 14:41:05 +0530 Subject: [PATCH] Made -i option independent of -a. Signed-off-by: Arun Prakash Jana --- README.md | 8 ++++---- markit | 54 ++++++++++++++++++++++++++++++++++-------------------- markit.1 | 6 +++--- 3 files changed, 41 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index 779e545..e0ec9be 100644 --- a/README.md +++ b/README.md @@ -72,12 +72,12 @@ Options -a URL tag 1, tag 2, ... add URL as bookmark with comma separated tags -d N delete entry at index N -D delete ALL bookmarks - -i N add entry at index N, works with -a, use to fill deleted index + -i N insert entry at index N, useful to fill deleted index -p N show details of bookmark record at index N -P show all bookmarks along with real index from database -s keyword(s) search all bookmarks for a (partial) tag or each keyword - -u N update entry at index N (from output of -p) - -w fetch title info from web, works with -a or -u + -u N update entry at index N (from output of -P) + -w fetch title info from web, works with -a, -i, -u -z show debug information you can either add or update or delete in one instance any other option shows help and exits markit @@ -103,7 +103,7 @@ Updated 5. Delete all bookmarks:
$ markit -D
6. Insert a bookmark at deleted index 15012014 (fails if index or URL exists in database): -
$ markit -i 15012014 -a -w http://tuxdiary.com/about linux news, open source
+
$ markit -i 15012014 -w http://tuxdiary.com/about linux news, open source
 Title: [A journey with WordPress | TuxDiary]
 Added at index 15012014
This option is useful in filling deleted indices from database manually. diff --git a/markit b/markit index 2883cd9..317dba6 100755 --- a/markit +++ b/markit @@ -50,12 +50,12 @@ def usage(): print(" -a URL tag 1, tag 2, ... add URL as bookmark with comma separated tags") print(" -d N delete entry at index N") print(" -D delete ALL bookmarks") - print(" -i N add entry at index N, works with -a, use to fill deleted index") + print(" -i N insert entry at index N, useful to fill deleted index") print(" -p N show details of bookmark record at index N") print(" -P show all bookmarks along with real index from database") print(" -s keyword(s) search all bookmarks for a (partial) tag or each keyword") - print(" -u N update entry at index N (from output of -p)") - print(" -w fetch title info from web, works with -a or -u") + print(" -u N update entry at index N (from output of -P)") + print(" -w fetch title info from web, works with -a, -i, -u") print(" -z show debug information") print(" you can either add or update or delete in one instance") print(" any other option shows help and exits markit\n") @@ -275,21 +275,9 @@ def searchdb(cur, keywords): continue try: - _stderr = os.dup(2) - os.close(2) - _stdout = os.dup(1) - os.close(1) - fd = os.open(os.devnull, os.O_RDWR) - os.dup2(fd, 2) - os.dup2(fd, 1) - try: - openurl = unquote(results[int(nav) - 1]) - openurl = openurl.replace("%22", "\"") - webbrowser.open(openurl) - finally: - os.close(fd) - os.dup2(_stderr, 2) - os.dup2(_stdout, 1) + openurl = unquote(results[int(nav) - 1]) + openurl = openurl.replace("%22", "\"") + browser_open(openurl) except IndexError: print("Index out of bound") else: @@ -365,6 +353,26 @@ class BMHTMLParser(HTMLParser.HTMLParser): +# Open a URL in browser +def browser_open(url): + _stderr = os.dup(2) + os.close(2) + _stdout = os.dup(1) + os.close(1) + fd = os.open(os.devnull, os.O_RDWR) + os.dup2(fd, 2) + os.dup2(fd, 1) + try: + webbrowser.open(url) + except Exception as e: + print("Browser Exception: %s" % e) + finally: + os.close(fd) + os.dup2(_stderr, 2) + os.dup2(_stdout, 1) + + + # Main starts here # ---------------- optlist = None @@ -406,14 +414,18 @@ try: delete = True elif opt[0] == "-i": + if update == True or delete == True: + print("You can either add or update or delete in one instance\n") + usage() + if not opt[1].isdigit(): usage() addindex = opt[1] if int(addindex) <= 0: usage() - elif opt[0] == "-w": - online = True + + addurl = True elif opt[0] == "-p": if not opt[1].isdigit(): usage() @@ -440,6 +452,8 @@ try: usage() update = True + elif opt[0] == "-w": + online = True elif opt[0] == "-z": debug = True except GetoptError as e: diff --git a/markit.1 b/markit.1 index b1602d2..780f027 100644 --- a/markit.1 +++ b/markit.1 @@ -41,7 +41,7 @@ Delete ALL bookmarks. .BI \-i " N" Add a new record at index .I N -of the database. Works only if `-a` option is used. Use this option to fill blank indexes left by deleted bookmarks. +of the database. Use this option to fill blank indexes left by deleted bookmarks. .TP .BI \-p " N" Show details of bookmark record stored at @@ -57,10 +57,10 @@ Search bookmarks for a (partial) tag or keywords and show the results. Prompts t .BI \-u " N" Update bookmark at index .I N -(as shown in `-p` output). +(as shown in `-P` output). .TP .BI \-w -Fetch title data from the web. Works only with `-a` or `-u` options. +Fetch title data from the web. Works with `-a`, `-i` or `-u` options. .TP .BI \-z Enable debugging.