From 6ec4e0a65110a316402490b9b5f96b6c729b6d73 Mon Sep 17 00:00:00 2001
From: OzzieIsaacs
Date: Tue, 21 Feb 2017 19:40:22 +0100
Subject: [PATCH 1/2] Bugfix Updater Improved logging
---
cps.py | 4 ++--
cps/helper.py | 24 +++++++++++++-----------
cps/web.py | 13 ++++++++-----
3 files changed, 23 insertions(+), 18 deletions(-)
diff --git a/cps.py b/cps.py
index 00d0f356..fdc5bce7 100755
--- a/cps.py
+++ b/cps.py
@@ -22,8 +22,8 @@ if __name__ == '__main__':
IOLoop.instance().start()
if web.helper.global_task == 0:
- print("Performing restart of Calibre-web")
+ web.app.logger.info("Performing restart of Calibre-web")
os.execl(sys.executable, sys.executable, *sys.argv)
else:
- print("Performing shutdown of Calibre-web")
+ web.app.logger.info("Performing shutdown of Calibre-web")
sys.exit(0)
diff --git a/cps/helper.py b/cps/helper.py
index 20d9402a..5e9c9210 100755
--- a/cps/helper.py
+++ b/cps/helper.py
@@ -338,7 +338,7 @@ class Updater(threading.Thread):
def reduce_files(self, remove_items, exclude_items):
rf = []
for item in remove_items:
- if not item in exclude_items:
+ if not item.startswith(exclude_items):
rf.append(item)
return rf
@@ -347,15 +347,14 @@ class Updater(threading.Thread):
if sys.platform == "win32" or sys.platform == "darwin":
change_permissions = False
else:
- app.logger.debug('Update on OS-System : ' + sys.platform)
- # print('OS-System: '+sys.platform )
+ logging.getLogger('cps.web').debug('Update on OS-System : ' + sys.platform)
new_permissions = os.stat(root_dst_dir)
# print new_permissions
for src_dir, dirs, files in os.walk(root_src_dir):
dst_dir = src_dir.replace(root_src_dir, root_dst_dir, 1)
if not os.path.exists(dst_dir):
os.makedirs(dst_dir)
- # print('Create-Dir: '+dst_dir)
+ logging.getLogger('cps.web').debug('Create-Dir: '+dst_dir)
if change_permissions:
# print('Permissions: User '+str(new_permissions.st_uid)+' Group '+str(new_permissions.st_uid))
os.chown(dst_dir, new_permissions.st_uid, new_permissions.st_gid)
@@ -365,27 +364,28 @@ class Updater(threading.Thread):
if os.path.exists(dst_file):
if change_permissions:
permission = os.stat(dst_file)
- # print('Remove file before copy: '+dst_file)
+ logging.getLogger('cps.web').debug('Remove file before copy: '+dst_file)
os.remove(dst_file)
else:
if change_permissions:
permission = new_permissions
shutil.move(src_file, dst_dir)
- # print('Move File '+src_file+' to '+dst_dir)
+ logging.getLogger('cps.web').debug('Move File '+src_file+' to '+dst_dir)
if change_permissions:
try:
os.chown(dst_file, permission.st_uid, permission.st_uid)
# print('Permissions: User '+str(new_permissions.st_uid)+' Group '+str(new_permissions.st_uid))
except:
e = sys.exc_info()
- # print('Fail '+str(dst_file)+' error: '+str(e))
+ logging.getLogger('cps.web').debug('Fail '+str(dst_file)+' error: '+str(e))
return
def update_source(self, source, destination):
# destination files
old_list = list()
exclude = (
- ['vendor' + os.sep + 'kindlegen.exe', 'vendor' + os.sep + 'kindlegen', '/app.db', 'vendor', '/update.py'])
+ 'vendor' + os.sep + 'kindlegen.exe', 'vendor' + os.sep + 'kindlegen', os.sep + 'app.db',
+ os.sep + 'vendor',os.sep + 'calibre-web.log')
for root, dirs, files in os.walk(destination, topdown=True):
for name in files:
old_list.append(os.path.join(root, name).replace(destination, ''))
@@ -410,12 +410,14 @@ class Updater(threading.Thread):
for item in remove_items:
item_path = os.path.join(destination, item[1:])
if os.path.isdir(item_path):
- app.logger.debug("Delete dir " + item_path)
+ logging.getLogger('cps.web').debug("Delete dir " + item_path)
shutil.rmtree(item_path)
else:
try:
- app.logger.debug("Delete file " + item_path)
+ logging.getLogger('cps.web').debug("Delete file " + item_path)
+ log_from_thread("Delete file " + item_path)
os.remove(item_path)
except:
- app.logger.debug("Could not remove:" + item_path)
+ logging.getLogger('cps.web').debug("Could not remove:" + item_path)
shutil.rmtree(source, ignore_errors=True)
+
diff --git a/cps/web.py b/cps/web.py
index 5c1cb975..bfe42444 100755
--- a/cps/web.py
+++ b/cps/web.py
@@ -744,7 +744,10 @@ def get_updater_status():
helper.updater_thread.start()
status['status']=helper.updater_thread.get_update_status()
elif request.method == "GET":
- status['status']=helper.updater_thread.get_update_status()
+ try:
+ status['status']=helper.updater_thread.get_update_status()
+ except:
+ status['status'] = 7
return json.dumps(status)
@@ -1044,9 +1047,9 @@ def stats():
@login_required
@admin_required
def shutdown():
- global global_task
+ # global global_task
task = int(request.args.get("parameter").strip())
- global_task = task
+ helper.global_task = task
if task == 1 or task == 0: # valid commandos received
# close all database connections
db.session.close()
@@ -1611,7 +1614,7 @@ def basic_configuration():
def configuration_helper(origin):
- global global_task
+ # global global_task
reboot_required = False
db_change = False
success = False
@@ -1686,7 +1689,7 @@ def configuration_helper(origin):
# stop tornado server
server = IOLoop.instance()
server.add_callback(server.stop)
- global_task = 0
+ helper.global_task = 0
app.logger.info('Reboot required, restarting')
if origin:
success = True
From 7e19e1dd9d1da5761e1da85be9e8eef55a8c85cf Mon Sep 17 00:00:00 2001
From: OzzieIsaacs
Date: Wed, 22 Feb 2017 20:59:48 +0100
Subject: [PATCH 2/2] Added Publisher and search/advanced search/opds search
for publisher
---
cps/db.py | 20 ++++++++++++++++++++
cps/templates/detail.html | 9 ++++++++-
cps/templates/search_form.html | 28 ++++++++++++++++------------
cps/web.py | 22 ++++++++++++++--------
4 files changed, 58 insertions(+), 21 deletions(-)
diff --git a/cps/db.py b/cps/db.py
index f6ee790e..e4082a16 100755
--- a/cps/db.py
+++ b/cps/db.py
@@ -56,6 +56,10 @@ books_languages_link = Table('books_languages_link', Base.metadata,
Column('lang_code', Integer, ForeignKey('languages.id'), primary_key=True)
)
+books_publishers_link = Table('books_publishers_link', Base.metadata,
+ Column('book', Integer, ForeignKey('books.id'), primary_key=True),
+ Column('publisher', Integer, ForeignKey('publishers.id'), primary_key=True)
+ )
class Identifiers(Base):
__tablename__ = 'identifiers'
@@ -182,6 +186,21 @@ class Languages(Base):
def __repr__(self):
return u"".format(self.lang_code)
+class Publishers(Base):
+ __tablename__ = 'publishers'
+
+ id = Column(Integer, primary_key=True)
+ name = Column(String)
+ sort = Column(String)
+
+ def __init__(self, name,sort):
+ self.name = name
+ self.sort = sort
+
+ def __repr__(self):
+ return u"".format(self.name, self.sort)
+
+
class Data(Base):
__tablename__ = 'data'
@@ -224,6 +243,7 @@ class Books(Base):
series = relationship('Series', secondary=books_series_link, backref='books')
ratings = relationship('Ratings', secondary=books_ratings_link, backref='books')
languages = relationship('Languages', secondary=books_languages_link, backref='books')
+ publishers = relationship('Publishers', secondary=books_publishers_link, backref='books')
identifiers = relationship('Identifiers', backref='books')
def __init__(self, title, sort, author_sort, timestamp, pubdate, series_index, last_modified, path, has_cover,
diff --git a/cps/templates/detail.html b/cps/templates/detail.html
index 8775f079..0a5167b6 100644
--- a/cps/templates/detail.html
+++ b/cps/templates/detail.html
@@ -50,6 +50,7 @@
{% if entry.identifiers|length > 0 %}
{% endif %}
+ {% if entry.publishers|length > 0 %}
+
+
+ {{_('Publisher')}}:{% for publisher in entry.publishers %} {{publisher.name}}{% if not loop.last %},{% endif %}{% endfor %}
+
+
+ {% endif %}
{% if entry.pubdate[:10] != '0101-01-01' %}
{{_('Publishing date')}}: {{entry.pubdate|formatdate}}
{% endif %}
diff --git a/cps/templates/search_form.html b/cps/templates/search_form.html
index 2e9f4d3d..e61195ec 100644
--- a/cps/templates/search_form.html
+++ b/cps/templates/search_form.html
@@ -10,63 +10,67 @@
-
+
+
+
+
+
-
+
-
+
-
+
{% if languages %}
-
+
-
+