Shorten debug API calls.
This commit is contained in:
parent
804c8ce503
commit
a28bd09013
152
buku.py
152
buku.py
@ -67,6 +67,8 @@ CHUNKSIZE = 0x80000 # Read/write 512 KB chunks
|
|||||||
# Set up logging
|
# Set up logging
|
||||||
logging.basicConfig(format='[%(levelname)s] %(message)s')
|
logging.basicConfig(format='[%(levelname)s] %(message)s')
|
||||||
logger = logging.getLogger()
|
logger = logging.getLogger()
|
||||||
|
logdbg = logger.debug
|
||||||
|
logerr = logger.error
|
||||||
|
|
||||||
|
|
||||||
class BMHTMLParser(HTMLParser.HTMLParser):
|
class BMHTMLParser(HTMLParser.HTMLParser):
|
||||||
@ -154,11 +156,11 @@ class BukuCrypt:
|
|||||||
from cryptography.hazmat.primitives.ciphers import (Cipher, modes,
|
from cryptography.hazmat.primitives.ciphers import (Cipher, modes,
|
||||||
algorithms)
|
algorithms)
|
||||||
except ImportError:
|
except ImportError:
|
||||||
logger.error('cryptography lib(s) missing')
|
logerr('cryptography lib(s) missing')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
if iterations < 1:
|
if iterations < 1:
|
||||||
logger.error('Iterations must be >= 1')
|
logerr('Iterations must be >= 1')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
if not dbfile:
|
if not dbfile:
|
||||||
@ -171,28 +173,28 @@ class BukuCrypt:
|
|||||||
if db_exists and not enc_exists:
|
if db_exists and not enc_exists:
|
||||||
pass
|
pass
|
||||||
elif not db_exists:
|
elif not db_exists:
|
||||||
logger.error('%s missing. Already encrypted?', dbfile)
|
logerr('%s missing. Already encrypted?', dbfile)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
else:
|
else:
|
||||||
# db_exists and enc_exists
|
# db_exists and enc_exists
|
||||||
logger.error('Both encrypted and flat DB files exist!')
|
logerr('Both encrypted and flat DB files exist!')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
password = ''
|
password = ''
|
||||||
password = getpass()
|
password = getpass()
|
||||||
passconfirm = getpass()
|
passconfirm = getpass()
|
||||||
if password == '':
|
if password == '':
|
||||||
logger.error('Empty password')
|
logerr('Empty password')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
if password != passconfirm:
|
if password != passconfirm:
|
||||||
logger.error('Passwords do not match')
|
logerr('Passwords do not match')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Get SHA256 hash of DB file
|
# Get SHA256 hash of DB file
|
||||||
dbhash = BukuCrypt.get_filehash(dbfile)
|
dbhash = BukuCrypt.get_filehash(dbfile)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(e)
|
logerr(e)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
# Generate random 256-bit salt and key
|
# Generate random 256-bit salt and key
|
||||||
@ -232,7 +234,7 @@ class BukuCrypt:
|
|||||||
print('File encrypted')
|
print('File encrypted')
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(e)
|
logerr(e)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@ -252,11 +254,11 @@ class BukuCrypt:
|
|||||||
from cryptography.hazmat.primitives.ciphers import (Cipher, modes,
|
from cryptography.hazmat.primitives.ciphers import (Cipher, modes,
|
||||||
algorithms)
|
algorithms)
|
||||||
except ImportError:
|
except ImportError:
|
||||||
logger.error('cryptography lib(s) missing')
|
logerr('cryptography lib(s) missing')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
if iterations < 1:
|
if iterations < 1:
|
||||||
logger.error('Decryption failed')
|
logerr('Decryption failed')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
if not dbfile:
|
if not dbfile:
|
||||||
@ -273,17 +275,17 @@ class BukuCrypt:
|
|||||||
if enc_exists and not db_exists:
|
if enc_exists and not db_exists:
|
||||||
pass
|
pass
|
||||||
elif not enc_exists:
|
elif not enc_exists:
|
||||||
logger.error('%s missing', encfile)
|
logerr('%s missing', encfile)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
else:
|
else:
|
||||||
# db_exists and enc_exists
|
# db_exists and enc_exists
|
||||||
logger.error('Both encrypted and flat DB files exist!')
|
logerr('Both encrypted and flat DB files exist!')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
password = ''
|
password = ''
|
||||||
password = getpass()
|
password = getpass()
|
||||||
if password == '':
|
if password == '':
|
||||||
logger.error('Decryption failed')
|
logerr('Decryption failed')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -322,16 +324,16 @@ class BukuCrypt:
|
|||||||
dbhash = BukuCrypt.get_filehash(dbfile)
|
dbhash = BukuCrypt.get_filehash(dbfile)
|
||||||
if dbhash != enchash:
|
if dbhash != enchash:
|
||||||
os.remove(dbfile)
|
os.remove(dbfile)
|
||||||
logger.error('Decryption failed')
|
logerr('Decryption failed')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
else:
|
else:
|
||||||
os.remove(encfile)
|
os.remove(encfile)
|
||||||
print('File decrypted')
|
print('File decrypted')
|
||||||
except struct.error:
|
except struct.error:
|
||||||
logger.error('Tainted file')
|
logerr('Tainted file')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(e)
|
logerr(e)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
@ -398,7 +400,7 @@ class BukuDb:
|
|||||||
if not os.path.exists(dbpath):
|
if not os.path.exists(dbpath):
|
||||||
os.makedirs(dbpath)
|
os.makedirs(dbpath)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(e)
|
logerr(e)
|
||||||
os.exit(1)
|
os.exit(1)
|
||||||
|
|
||||||
db_exists = os.path.exists(dbfile)
|
db_exists = os.path.exists(dbfile)
|
||||||
@ -407,11 +409,10 @@ class BukuDb:
|
|||||||
if db_exists and not enc_exists:
|
if db_exists and not enc_exists:
|
||||||
pass
|
pass
|
||||||
elif enc_exists and not db_exists:
|
elif enc_exists and not db_exists:
|
||||||
logger.error('Unlock database first')
|
logerr('Unlock database first')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
elif db_exists and enc_exists:
|
elif db_exists and enc_exists:
|
||||||
logger.error('Both encrypted and flat DB files exist!')
|
logerr('Both encrypted and flat DB files exist!')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
else:
|
else:
|
||||||
# not db_exists and not enc_exists
|
# not db_exists and not enc_exists
|
||||||
@ -432,7 +433,7 @@ class BukuDb:
|
|||||||
conn.commit()
|
conn.commit()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
_, _, linenumber, func, _, _ = inspect.stack()[0]
|
_, _, linenumber, func, _, _ = inspect.stack()[0]
|
||||||
logger.error('%s(), ln %d: %s', func, linenumber, e)
|
logerr('%s(), ln %d: %s', func, linenumber, e)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
# Add description column in existing DB (from version 2.1)
|
# Add description column in existing DB (from version 2.1)
|
||||||
@ -498,13 +499,13 @@ class BukuDb:
|
|||||||
|
|
||||||
# Return error for empty URL
|
# Return error for empty URL
|
||||||
if not url or url == '':
|
if not url or url == '':
|
||||||
logger.error('Invalid URL')
|
logerr('Invalid URL')
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# Ensure that the URL does not exist in DB already
|
# Ensure that the URL does not exist in DB already
|
||||||
id = self.get_bm_id(url)
|
id = self.get_bm_id(url)
|
||||||
if id != -1:
|
if id != -1:
|
||||||
logger.error('URL [%s] already exists at index %d', url, id)
|
logerr('URL [%s] already exists at index %d', url, id)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# Process title
|
# Process title
|
||||||
@ -515,11 +516,11 @@ class BukuDb:
|
|||||||
if bad:
|
if bad:
|
||||||
print('\x1b[91mMalformed URL\x1b[0m\n')
|
print('\x1b[91mMalformed URL\x1b[0m\n')
|
||||||
elif mime:
|
elif mime:
|
||||||
logger.debug('Mime HEAD requested\n')
|
logdbg('Mime HEAD requested\n')
|
||||||
elif meta == '':
|
elif meta == '':
|
||||||
print('\x1b[91mTitle: []\x1b[0m\n')
|
print('\x1b[91mTitle: []\x1b[0m\n')
|
||||||
else:
|
else:
|
||||||
logger.debug('Title: [%s]', meta)
|
logdbg('Title: [%s]', meta)
|
||||||
|
|
||||||
# Process tags
|
# Process tags
|
||||||
if tags_in is None:
|
if tags_in is None:
|
||||||
@ -549,7 +550,7 @@ class BukuDb:
|
|||||||
return True
|
return True
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
_, _, linenumber, func, _, _ = inspect.stack()[0]
|
_, _, linenumber, func, _, _ = inspect.stack()[0]
|
||||||
logger.error('%s(), ln %d: %s', func, linenumber, e)
|
logerr('%s(), ln %d: %s', func, linenumber, e)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def append_tag_at_index(self, index, tags_in):
|
def append_tag_at_index(self, index, tags_in):
|
||||||
@ -658,7 +659,7 @@ class BukuDb:
|
|||||||
# Update URL if passed as argument
|
# Update URL if passed as argument
|
||||||
if url != '':
|
if url != '':
|
||||||
if index == 0:
|
if index == 0:
|
||||||
logger.error('All URLs cannot be same')
|
logerr('All URLs cannot be same')
|
||||||
return False
|
return False
|
||||||
query = '%s URL = ?,' % query
|
query = '%s URL = ?,' % query
|
||||||
arguments += (url,)
|
arguments += (url,)
|
||||||
@ -713,7 +714,7 @@ class BukuDb:
|
|||||||
elif title_to_insert == '':
|
elif title_to_insert == '':
|
||||||
print('\x1b[91mTitle: []\x1b[0m')
|
print('\x1b[91mTitle: []\x1b[0m')
|
||||||
else:
|
else:
|
||||||
logger.debug('Title: [%s]', title_to_insert)
|
logdbg('Title: [%s]', title_to_insert)
|
||||||
elif not to_update and not (append_tag or delete_tag):
|
elif not to_update and not (append_tag or delete_tag):
|
||||||
ret = self.refreshdb(index)
|
ret = self.refreshdb(index)
|
||||||
if ret and index and self.chatty:
|
if ret and index and self.chatty:
|
||||||
@ -738,7 +739,7 @@ class BukuDb:
|
|||||||
query = '%s WHERE id = ?' % query[:-1]
|
query = '%s WHERE id = ?' % query[:-1]
|
||||||
arguments += (index,)
|
arguments += (index,)
|
||||||
|
|
||||||
logger.debug('query: "%s", args: %s', query, arguments)
|
logdbg('query: "%s", args: %s', query, arguments)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.cur.execute(query, arguments)
|
self.cur.execute(query, arguments)
|
||||||
@ -747,10 +748,10 @@ class BukuDb:
|
|||||||
self.print_bm(index)
|
self.print_bm(index)
|
||||||
|
|
||||||
if self.cur.rowcount == 0:
|
if self.cur.rowcount == 0:
|
||||||
logger.error('No matching index %s', index)
|
logerr('No matching index %s', index)
|
||||||
return False
|
return False
|
||||||
except sqlite3.IntegrityError:
|
except sqlite3.IntegrityError:
|
||||||
logger.error('URL already exists')
|
logerr('URL already exists')
|
||||||
return False
|
return False
|
||||||
|
|
||||||
return True
|
return True
|
||||||
@ -774,7 +775,7 @@ class BukuDb:
|
|||||||
|
|
||||||
resultset = self.cur.fetchall()
|
resultset = self.cur.fetchall()
|
||||||
if not len(resultset):
|
if not len(resultset):
|
||||||
logger.error('No matching index or title immutable or empty DB')
|
logerr('No matching index or title immutable or empty DB')
|
||||||
return False
|
return False
|
||||||
|
|
||||||
query = 'UPDATE bookmarks SET metadata = ? WHERE id = ?'
|
query = 'UPDATE bookmarks SET metadata = ? WHERE id = ?'
|
||||||
@ -854,16 +855,16 @@ class BukuDb:
|
|||||||
qargs += (token, token, token, token,)
|
qargs += (token, token, token, token,)
|
||||||
qry = qry[:-3]
|
qry = qry[:-3]
|
||||||
else:
|
else:
|
||||||
logger.error('Invalid search option')
|
logerr('Invalid search option')
|
||||||
return None
|
return None
|
||||||
|
|
||||||
qry = '%s ORDER BY id ASC' % qry
|
qry = '%s ORDER BY id ASC' % qry
|
||||||
logger.debug('query: "%s", args: %s', qry, qargs)
|
logdbg('query: "%s", args: %s', qry, qargs)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.cur.execute(qry, qargs)
|
self.cur.execute(qry, qargs)
|
||||||
except sqlite3.OperationalError as e:
|
except sqlite3.OperationalError as e:
|
||||||
logger.error(e)
|
logerr(e)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
results = self.cur.fetchall()
|
results = self.cur.fetchall()
|
||||||
@ -882,7 +883,7 @@ class BukuDb:
|
|||||||
tag = '%s%s%s' % (DELIM, tag.strip(DELIM), DELIM)
|
tag = '%s%s%s' % (DELIM, tag.strip(DELIM), DELIM)
|
||||||
query = "SELECT id, url, metadata, tags, desc FROM bookmarks \
|
query = "SELECT id, url, metadata, tags, desc FROM bookmarks \
|
||||||
WHERE tags LIKE '%' || ? || '%' ORDER BY id ASC"
|
WHERE tags LIKE '%' || ? || '%' ORDER BY id ASC"
|
||||||
logger.debug('query: "%s", args: %s', query, tag)
|
logdbg('query: "%s", args: %s', query, tag)
|
||||||
|
|
||||||
self.cur.execute(query, (tag,))
|
self.cur.execute(query, (tag,))
|
||||||
results = self.cur.fetchall()
|
results = self.cur.fetchall()
|
||||||
@ -956,7 +957,7 @@ class BukuDb:
|
|||||||
if not delay_commit:
|
if not delay_commit:
|
||||||
self.conn.commit()
|
self.conn.commit()
|
||||||
except IndexError:
|
except IndexError:
|
||||||
logger.error('No matching index')
|
logerr('No matching index')
|
||||||
return False
|
return False
|
||||||
elif index == 0: # Remove the table
|
elif index == 0: # Remove the table
|
||||||
return self.cleardb()
|
return self.cleardb()
|
||||||
@ -970,10 +971,10 @@ class BukuDb:
|
|||||||
print('Removed index %d' % index)
|
print('Removed index %d' % index)
|
||||||
self.compactdb(index, delay_commit)
|
self.compactdb(index, delay_commit)
|
||||||
else:
|
else:
|
||||||
logger.error('No matching index')
|
logerr('No matching index')
|
||||||
return False
|
return False
|
||||||
except IndexError:
|
except IndexError:
|
||||||
logger.error('No matching index')
|
logerr('No matching index')
|
||||||
return False
|
return False
|
||||||
|
|
||||||
return True
|
return True
|
||||||
@ -1034,10 +1035,10 @@ class BukuDb:
|
|||||||
self.cur.execute(query, (index,))
|
self.cur.execute(query, (index,))
|
||||||
results = self.cur.fetchall()
|
results = self.cur.fetchall()
|
||||||
if len(results) == 0:
|
if len(results) == 0:
|
||||||
logger.error('No matching index')
|
logerr('No matching index')
|
||||||
return
|
return
|
||||||
except IndexError:
|
except IndexError:
|
||||||
logger.error('No matching index')
|
logerr('No matching index')
|
||||||
return
|
return
|
||||||
|
|
||||||
if not self.json:
|
if not self.json:
|
||||||
@ -1167,7 +1168,7 @@ class BukuDb:
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
index = result[0]
|
index = result[0]
|
||||||
logger.debug('Opening random index ' + str(index))
|
logdbg('Opening random index ' + str(index))
|
||||||
|
|
||||||
query = 'SELECT URL FROM bookmarks WHERE id = ?'
|
query = 'SELECT URL FROM bookmarks WHERE id = ?'
|
||||||
try:
|
try:
|
||||||
@ -1175,9 +1176,9 @@ class BukuDb:
|
|||||||
url = unquote(row[0])
|
url = unquote(row[0])
|
||||||
open_in_browser(url)
|
open_in_browser(url)
|
||||||
return True
|
return True
|
||||||
logger.error('No matching index')
|
logerr('No matching index')
|
||||||
except IndexError:
|
except IndexError:
|
||||||
logger.error('No matching index')
|
logerr('No matching index')
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@ -1202,7 +1203,7 @@ class BukuDb:
|
|||||||
tagstr = parse_tags(taglist)
|
tagstr = parse_tags(taglist)
|
||||||
|
|
||||||
if len(tagstr) == 0 or tagstr == DELIM:
|
if len(tagstr) == 0 or tagstr == DELIM:
|
||||||
logger.error('Invalid tag')
|
logerr('Invalid tag')
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if len(tagstr) > 0:
|
if len(tagstr) > 0:
|
||||||
@ -1220,7 +1221,7 @@ class BukuDb:
|
|||||||
else:
|
else:
|
||||||
query = query[:-6]
|
query = query[:-6]
|
||||||
|
|
||||||
logger.debug('(%s), %s' % (query, arguments))
|
logdbg('(%s), %s' % (query, arguments))
|
||||||
self.cur.execute(query, arguments)
|
self.cur.execute(query, arguments)
|
||||||
resultset = self.cur.fetchall()
|
resultset = self.cur.fetchall()
|
||||||
|
|
||||||
@ -1236,7 +1237,7 @@ class BukuDb:
|
|||||||
try:
|
try:
|
||||||
outfp = open(filepath, mode='w', encoding='utf-8')
|
outfp = open(filepath, mode='w', encoding='utf-8')
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(e)
|
logerr(e)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if not markdown:
|
if not markdown:
|
||||||
@ -1294,10 +1295,10 @@ Buku bookmarks</H3>
|
|||||||
with open(filepath, mode='r', encoding='utf-8') as infp:
|
with open(filepath, mode='r', encoding='utf-8') as infp:
|
||||||
soup = bs4.BeautifulSoup(infp, 'html.parser')
|
soup = bs4.BeautifulSoup(infp, 'html.parser')
|
||||||
except ImportError:
|
except ImportError:
|
||||||
logger.error('Beautiful Soup not found')
|
logerr('Beautiful Soup not found')
|
||||||
return False
|
return False
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(e)
|
logerr(e)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
html_tags = soup.findAll('a')
|
html_tags = soup.findAll('a')
|
||||||
@ -1358,7 +1359,7 @@ Buku bookmarks</H3>
|
|||||||
indb_cur = indb_conn.cursor()
|
indb_cur = indb_conn.cursor()
|
||||||
indb_cur.execute('SELECT * FROM bookmarks')
|
indb_cur.execute('SELECT * FROM bookmarks')
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(e)
|
logerr(e)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
resultset = indb_cur.fetchall()
|
resultset = indb_cur.fetchall()
|
||||||
@ -1385,7 +1386,7 @@ Buku bookmarks</H3>
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
if not index and not url:
|
if not index and not url:
|
||||||
logger.error('Either a valid DB index or URL required')
|
logerr('Either a valid DB index or URL required')
|
||||||
return None
|
return None
|
||||||
|
|
||||||
if index:
|
if index:
|
||||||
@ -1406,7 +1407,7 @@ Buku bookmarks</H3>
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
if r.status_code != 200:
|
if r.status_code != 200:
|
||||||
logger.error('[%s] %s', r.status_code, r.reason)
|
logerr('[%s] %s', r.status_code, r.reason)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return r.text
|
return r.text
|
||||||
@ -1473,7 +1474,7 @@ def is_bad_url(url):
|
|||||||
if not netloc:
|
if not netloc:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
logger.debug('netloc: %s' % netloc)
|
logdbg('netloc: %s' % netloc)
|
||||||
|
|
||||||
# netloc cannot start or end with a '.'
|
# netloc cannot start or end with a '.'
|
||||||
if netloc.startswith('.') or netloc.endswith('.'):
|
if netloc.startswith('.') or netloc.endswith('.'):
|
||||||
@ -1521,7 +1522,7 @@ def get_page_title(resp):
|
|||||||
if logger.isEnabledFor(logging.DEBUG) \
|
if logger.isEnabledFor(logging.DEBUG) \
|
||||||
and str(e) != 'we should not get here!':
|
and str(e) != 'we should not get here!':
|
||||||
_, _, linenumber, func, _, _ = inspect.stack()[0]
|
_, _, linenumber, func, _, _ = inspect.stack()[0]
|
||||||
logger.error('%s(), ln %d: %s', func, linenumber, e)
|
logerr('%s(), ln %d: %s', func, linenumber, e)
|
||||||
finally:
|
finally:
|
||||||
return htmlparser.parsed_title
|
return htmlparser.parsed_title
|
||||||
|
|
||||||
@ -1544,7 +1545,7 @@ def get_PoolManager():
|
|||||||
basic_auth=url.username + ':' + url.password
|
basic_auth=url.username + ':' + url.password
|
||||||
)
|
)
|
||||||
|
|
||||||
logger.debug('proxy: [%s]' % proxy)
|
logdbg('proxy: [%s]' % proxy)
|
||||||
return urllib3.ProxyManager(proxy, headers=headers)
|
return urllib3.ProxyManager(proxy, headers=headers)
|
||||||
|
|
||||||
return urllib3.PoolManager()
|
return urllib3.PoolManager()
|
||||||
@ -1554,7 +1555,7 @@ def network_handler(url):
|
|||||||
'''Handle server connection and redirections
|
'''Handle server connection and redirections
|
||||||
|
|
||||||
:param url: URL to fetch
|
:param url: URL to fetch
|
||||||
:return: {title, recognized mime, bad url} tuple
|
:return: (title, recognized mime, bad url) tuple
|
||||||
'''
|
'''
|
||||||
|
|
||||||
global http_handler
|
global http_handler
|
||||||
@ -1591,18 +1592,18 @@ def network_handler(url):
|
|||||||
# which fail when trying to fetch resource '/'
|
# which fail when trying to fetch resource '/'
|
||||||
# retry without trailing '/'
|
# retry without trailing '/'
|
||||||
|
|
||||||
logger.debug('Received status 403: retrying...')
|
logdbg('Received status 403: retrying...')
|
||||||
# Remove trailing /
|
# Remove trailing /
|
||||||
url = url[:-1]
|
url = url[:-1]
|
||||||
resp.release_conn()
|
resp.release_conn()
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
logger.error('[%s] %s', resp.status, resp.reason)
|
logerr('[%s] %s', resp.status, resp.reason)
|
||||||
|
|
||||||
break
|
break
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
_, _, linenumber, func, _, _ = inspect.stack()[0]
|
_, _, linenumber, func, _, _ = inspect.stack()[0]
|
||||||
logger.error('%s(), ln %d: %s', func, linenumber, e)
|
logerr('%s(), ln %d: %s', func, linenumber, e)
|
||||||
finally:
|
finally:
|
||||||
if resp:
|
if resp:
|
||||||
resp.release_conn()
|
resp.release_conn()
|
||||||
@ -1647,8 +1648,8 @@ def parse_tags(keywords=None):
|
|||||||
if tagstr != '':
|
if tagstr != '':
|
||||||
tags = '%s%s%s' % (tags, tagstr, DELIM)
|
tags = '%s%s%s' % (tags, tagstr, DELIM)
|
||||||
|
|
||||||
logger.debug('keywords: %s', keywords)
|
logdbg('keywords: %s', keywords)
|
||||||
logger.debug('parsed tags: [%s]', tags)
|
logdbg('parsed tags: [%s]', tags)
|
||||||
|
|
||||||
if tags == DELIM:
|
if tags == DELIM:
|
||||||
return tags
|
return tags
|
||||||
@ -1731,7 +1732,7 @@ def prompt(obj, results, noninteractive=False, deep=False, subprompt=False):
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
if not type(obj) is BukuDb:
|
if not type(obj) is BukuDb:
|
||||||
logger.error('Not a BukuDb instance')
|
logerr('Not a BukuDb instance')
|
||||||
return
|
return
|
||||||
|
|
||||||
new_results = True
|
new_results = True
|
||||||
@ -1829,7 +1830,7 @@ def prompt(obj, results, noninteractive=False, deep=False, subprompt=False):
|
|||||||
open_in_browser(unquote(results[index][1]))
|
open_in_browser(unquote(results[index][1]))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
_, _, linenumber, func, _, _ = inspect.stack()[0]
|
_, _, linenumber, func, _, _ = inspect.stack()[0]
|
||||||
logger.error('%s(), ln %d: %s', func, linenumber, e)
|
logerr('%s(), ln %d: %s', func, linenumber, e)
|
||||||
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@ -1844,7 +1845,7 @@ def prompt(obj, results, noninteractive=False, deep=False, subprompt=False):
|
|||||||
open_in_browser(unquote(results[index][1]))
|
open_in_browser(unquote(results[index][1]))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
_, _, linenumber, func, _, _ = inspect.stack()[0]
|
_, _, linenumber, func, _, _ = inspect.stack()[0]
|
||||||
logger.error('%s(), ln %d: %s', func, linenumber, e)
|
logerr('%s(), ln %d: %s', func, linenumber, e)
|
||||||
elif '-' in nav and is_int(nav.split('-')[0]) \
|
elif '-' in nav and is_int(nav.split('-')[0]) \
|
||||||
and is_int(nav.split('-')[1]):
|
and is_int(nav.split('-')[1]):
|
||||||
lower = int(nav.split('-')[0])
|
lower = int(nav.split('-')[0])
|
||||||
@ -1859,8 +1860,7 @@ def prompt(obj, results, noninteractive=False, deep=False, subprompt=False):
|
|||||||
print('No matching index')
|
print('No matching index')
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
_, _, linenumber, func, _, _ = inspect.stack()[0]
|
_, _, linenumber, func, _, _ = inspect.stack()[0]
|
||||||
logger.error('%s(), ln %d: %s',
|
logerr('%s(), ln %d: %s', func, linenumber, e)
|
||||||
func, linenumber, e)
|
|
||||||
else:
|
else:
|
||||||
print('Invalid input')
|
print('Invalid input')
|
||||||
break
|
break
|
||||||
@ -1968,7 +1968,7 @@ def open_in_browser(url):
|
|||||||
# Otherwise, opening in browser fails anyway
|
# Otherwise, opening in browser fails anyway
|
||||||
# We expect http to https redirection
|
# We expect http to https redirection
|
||||||
# will happen for https-only websites
|
# will happen for https-only websites
|
||||||
logger.error('scheme missing in URI, trying http')
|
logerr('scheme missing in URI, trying http')
|
||||||
url = '%s%s' % ('http://', url)
|
url = '%s%s' % ('http://', url)
|
||||||
|
|
||||||
_stderr = os.dup(2)
|
_stderr = os.dup(2)
|
||||||
@ -1982,7 +1982,7 @@ def open_in_browser(url):
|
|||||||
webbrowser.open(url)
|
webbrowser.open(url)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
_, _, linenumber, func, _, _ = inspect.stack()[0]
|
_, _, linenumber, func, _, _ = inspect.stack()[0]
|
||||||
logger.error('%s(), ln %d: %s', func, linenumber, e)
|
logerr('%s(), ln %d: %s', func, linenumber, e)
|
||||||
finally:
|
finally:
|
||||||
os.close(fd)
|
os.close(fd)
|
||||||
os.dup2(_stderr, 2)
|
os.dup2(_stderr, 2)
|
||||||
@ -1994,7 +1994,7 @@ def check_upstream_release():
|
|||||||
|
|
||||||
r = requests.get('https://api.github.com/repos/jarun/buku/tags?per_page=1')
|
r = requests.get('https://api.github.com/repos/jarun/buku/tags?per_page=1')
|
||||||
if r.status_code != 200:
|
if r.status_code != 200:
|
||||||
logger.error('[%s] %s', r.status_code, r.reason)
|
logerr('[%s] %s', r.status_code, r.reason)
|
||||||
else:
|
else:
|
||||||
latest = r.json()[0]['name']
|
latest = r.json()[0]['name']
|
||||||
if latest == 'v' + __version__:
|
if latest == 'v' + __version__:
|
||||||
@ -2322,7 +2322,7 @@ def main():
|
|||||||
desc_in = ' '.join(args.comment)
|
desc_in = ' '.join(args.comment)
|
||||||
if args.debug:
|
if args.debug:
|
||||||
logger.setLevel(logging.DEBUG)
|
logger.setLevel(logging.DEBUG)
|
||||||
logger.debug('Version %s', __version__)
|
logdbg('Version %s', __version__)
|
||||||
else:
|
else:
|
||||||
logging.disable(logging.WARNING)
|
logging.disable(logging.WARNING)
|
||||||
|
|
||||||
@ -2370,7 +2370,7 @@ def main():
|
|||||||
if tags_in is not None:
|
if tags_in is not None:
|
||||||
if (tags_in[0] == '+' or tags_in[0] == '-') \
|
if (tags_in[0] == '+' or tags_in[0] == '-') \
|
||||||
and len(tags_in) == 1:
|
and len(tags_in) == 1:
|
||||||
logger.error('Please specify a tag')
|
logerr('Please specify a tag')
|
||||||
bdb.close_quit(1)
|
bdb.close_quit(1)
|
||||||
elif tags_in[0] == '+':
|
elif tags_in[0] == '+':
|
||||||
tags_in = tags_in[1:]
|
tags_in = tags_in[1:]
|
||||||
@ -2470,7 +2470,7 @@ def main():
|
|||||||
else:
|
else:
|
||||||
bdb.delete_bm(0, int(vals[1]), int(vals[0]), True)
|
bdb.delete_bm(0, int(vals[1]), int(vals[0]), True)
|
||||||
else:
|
else:
|
||||||
logger.error('Incorrect index or range')
|
logerr('Incorrect index or range')
|
||||||
bdb.close_quit(1)
|
bdb.close_quit(1)
|
||||||
else:
|
else:
|
||||||
ids = []
|
ids = []
|
||||||
@ -2485,7 +2485,7 @@ def main():
|
|||||||
for idx in ids:
|
for idx in ids:
|
||||||
bdb.delete_bm(int(idx))
|
bdb.delete_bm(int(idx))
|
||||||
except ValueError:
|
except ValueError:
|
||||||
logger.error('Incorrect index or range')
|
logerr('Incorrect index or range')
|
||||||
|
|
||||||
# Print records
|
# Print records
|
||||||
if args.print is not None:
|
if args.print is not None:
|
||||||
@ -2504,7 +2504,7 @@ def main():
|
|||||||
for _id in range(lower, upper + 1):
|
for _id in range(lower, upper + 1):
|
||||||
bdb.print_bm(_id)
|
bdb.print_bm(_id)
|
||||||
else:
|
else:
|
||||||
logger.error('Invalid index or range')
|
logerr('Invalid index or range')
|
||||||
bdb.close_quit(1)
|
bdb.close_quit(1)
|
||||||
|
|
||||||
# Replace a tag in DB
|
# Replace a tag in DB
|
||||||
@ -2519,7 +2519,7 @@ def main():
|
|||||||
if args.tag is None:
|
if args.tag is None:
|
||||||
bdb.exportdb(args.export[0], args.markdown)
|
bdb.exportdb(args.export[0], args.markdown)
|
||||||
elif len(args.tag) == 0:
|
elif len(args.tag) == 0:
|
||||||
logger.error('Missing tag')
|
logerr('Missing tag')
|
||||||
else:
|
else:
|
||||||
bdb.exportdb(args.export[0], args.markdown, args.tag)
|
bdb.exportdb(args.export[0], args.markdown, args.tag)
|
||||||
|
|
||||||
@ -2534,7 +2534,7 @@ def main():
|
|||||||
# Open URL in browser
|
# Open URL in browser
|
||||||
if args.open is not None:
|
if args.open is not None:
|
||||||
if args.open < 0:
|
if args.open < 0:
|
||||||
logger.error('Index must be >= 0')
|
logerr('Index must be >= 0')
|
||||||
bdb.close_quit(1)
|
bdb.close_quit(1)
|
||||||
bdb.browse_by_index(args.open)
|
bdb.browse_by_index(args.open)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user