Run black on all files

This commit is contained in:
Jon Banafato
2019-11-17 16:59:14 -05:00
parent e5a634d805
commit 72403bd981
18 changed files with 170 additions and 150 deletions

View File

@@ -8,12 +8,13 @@ from .config import Config
# db_pointer = Config().catalogue_db
class Storage():
class Storage:
"""Contains all methods for system storage"""
def __init__(self, db_pointer=None):
# Optionaly pass db_file to specify another db or for testing
if db_pointer is None: db_pointer = Config().catalogue_db
if db_pointer is None:
db_pointer = Config().catalogue_db
self.db_file = db_pointer
self.database()
# self.create_tables()
@@ -32,9 +33,9 @@ class Storage():
def create_tables(self):
"""Create table structure"""
q_check = "SELECT * FROM books"
q_create = '''CREATE TABLE books(title text, author text,
q_create = """CREATE TABLE books(title text, author text,
categories text null, cover blob null, pages int null, progress int null,
file_name text)'''
file_name text)"""
try:
self.cursor.execute(q_check)
except sqlite3.OperationalError as e:
@@ -45,15 +46,18 @@ class Storage():
Insert book in database
:returns: True if succeeds False if not
"""
q_x = '''SELECT title FROM books WHERE EXISTS(SELECT * from books WHERE `title` = ?)'''
q = '''INSERT INTO books (title, author, cover, progress, file_name, pages) values (?, ?, ?, 0, ?, 0)'''
q_x = """SELECT title FROM books WHERE EXISTS(SELECT * from books WHERE `title` = ?)"""
q = """INSERT INTO books (title, author, cover, progress, file_name, pages) values (?, ?, ?, 0, ?, 0)"""
try:
try: cover_image = book[2].data
except: cover_image = book[2]
try:
cover_image = book[2].data
except:
cover_image = book[2]
x = self.cursor.execute(q_x, (book[0],))
try: len(x.fetchone()) > 0
try:
len(x.fetchone()) > 0
except Exception:
if not book[2]: # If cover image is missing unset entry
if not book[2]: # If cover image is missing unset entry
cover_image = None
self.cursor.execute(q, (book[0], book[1], cover_image, book[3]))
return True
@@ -62,15 +66,20 @@ class Storage():
return False
def book_paths_list(self):
q = '''SELECT file_name FROM books'''
q = """SELECT file_name FROM books"""
x = self.cursor.execute(q)
try: x = x.fetchall()
except Exception: x = []
try:
x = x.fetchall()
except Exception:
x = []
return x
def commit(self):
try: self.db.commit(); return True
except Exception as e: return e
try:
self.db.commit()
return True
except Exception as e:
return e
def close(self):
self.db.close()