From 935b6e314346c255c1b9455b9955b6b4920f152d Mon Sep 17 00:00:00 2001 From: OzzieIsaacs Date: Sun, 29 Jan 2017 21:06:08 +0100 Subject: [PATCH] Code cosmetics Bugfix download opds added changable title to opds feed removed unused search.xml file --- cps.py | 3 +++ cps/book_formats.py | 3 +++ cps/epub.py | 3 +++ cps/fb2.py | 2 ++ cps/templates/feed.xml | 4 ++-- cps/templates/index.xml | 4 ++-- cps/templates/osd.xml | 10 +++++----- cps/templates/search.xml | 20 -------------------- cps/uploader.py | 3 +++ cps/web.py | 32 ++++++++++++++++---------------- 10 files changed, 39 insertions(+), 45 deletions(-) delete mode 100644 cps/templates/search.xml diff --git a/cps.py b/cps.py index b8f51e02..4c8bfbe2 100755 --- a/cps.py +++ b/cps.py @@ -1,3 +1,6 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + import os import sys import time diff --git a/cps/book_formats.py b/cps/book_formats.py index bd7d17c5..3aa26f4e 100644 --- a/cps/book_formats.py +++ b/cps/book_formats.py @@ -1,3 +1,6 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + import logging import uploader import os diff --git a/cps/epub.py b/cps/epub.py index 3c79b82b..49900724 100644 --- a/cps/epub.py +++ b/cps/epub.py @@ -1,3 +1,6 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + import zipfile from lxml import etree import os diff --git a/cps/fb2.py b/cps/fb2.py index ccc85207..f073c71e 100644 --- a/cps/fb2.py +++ b/cps/fb2.py @@ -1,3 +1,5 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- from lxml import etree import os diff --git a/cps/templates/feed.xml b/cps/templates/feed.xml index 8f8679de..9e9c9c02 100644 --- a/cps/templates/feed.xml +++ b/cps/templates/feed.xml @@ -29,9 +29,9 @@ - Calibre Web + {{instance}} - Calibre Web + {{instance}} https://github.com/janeczku/calibre-web diff --git a/cps/templates/index.xml b/cps/templates/index.xml index c522ec8d..fc1d5b12 100644 --- a/cps/templates/index.xml +++ b/cps/templates/index.xml @@ -6,9 +6,9 @@ type="application/atom+xml;profile=opds-catalog;kind=navigation"/> - Calibre Web + {{instance}} - Calibre Web + {{instance}} https://github.com/janeczku/calibre-web diff --git a/cps/templates/osd.xml b/cps/templates/osd.xml index 1d943981..35c1147c 100644 --- a/cps/templates/osd.xml +++ b/cps/templates/osd.xml @@ -1,16 +1,16 @@ - Calibre Web - Calibre Web - Calibre Web ebook catalog - janeczku + {{instance}} + {{instance}} + {{_('instanceCalibre Web ebook catalog')}} + Janeczku https://github.com/janeczku/calibre-web open - de-DE + {{lang}} UTF-8 UTF-8 diff --git a/cps/templates/search.xml b/cps/templates/search.xml deleted file mode 100644 index ddbb3e91..00000000 --- a/cps/templates/search.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - Calibre Web - Calibre Web - Calibre Web ebook catalog - janeczku - https://github.com/janeczku/calibre-web - - - - - - open - de-DE - UTF-8 - UTF-8 - diff --git a/cps/uploader.py b/cps/uploader.py index 0da801fa..41283361 100644 --- a/cps/uploader.py +++ b/cps/uploader.py @@ -1,3 +1,6 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + import os from tempfile import gettempdir import hashlib diff --git a/cps/web.py b/cps/web.py index a37497ef..735318e9 100755 --- a/cps/web.py +++ b/cps/web.py @@ -106,7 +106,7 @@ mimetypes.add_type('image/vnd.djvu', '.djvu') app = (Flask(__name__)) app.wsgi_app = ReverseProxied(app.wsgi_app) -'''formatter = logging.Formatter( +formatter = logging.Formatter( "[%(asctime)s] {%(pathname)s:%(lineno)d} %(levelname)s - %(message)s") file_handler = RotatingFileHandler(os.path.join(config.get_main_dir, "calibre-web.log"), maxBytes=50000, backupCount=1) file_handler.setFormatter(formatter) @@ -115,7 +115,7 @@ app.logger.setLevel(config.config_log_level) app.logger.info('Starting Calibre Web...') logging.getLogger("book_formats").addHandler(file_handler) -logging.getLogger("book_formats").setLevel(config.config_log_level)''' +logging.getLogger("book_formats").setLevel(config.config_log_level) Principal(app) @@ -434,7 +434,7 @@ def feed_index(): filter = db.Books.languages.any(db.Languages.lang_code == current_user.filter_language()) else: filter = True - xml = render_template('index.xml') + xml = render_title_template('index.xml') response = make_response(xml) response.headers["Content-Type"] = "application/xml" return response @@ -443,7 +443,7 @@ def feed_index(): @app.route("/opds/osd") @requires_basic_auth_if_no_ano def feed_osd(): - xml = render_template('osd.xml') + xml = render_title_template('osd.xml',lang='de-DE') response = make_response(xml) response.headers["Content-Type"] = "application/xml" return response @@ -472,9 +472,9 @@ def feed_search(term): db.Books.title.like("%" + term + "%"))).filter(filter).all() entriescount = len(entries) if len(entries) > 0 else 1 pagination = Pagination(1, entriescount, entriescount) - xml = render_template('feed.xml', searchterm=term, entries=entries, pagination=pagination) + xml = render_title_template('feed.xml', searchterm=term, entries=entries, pagination=pagination) else: - xml = render_template('feed.xml', searchterm="") + xml = render_title_template('feed.xml', searchterm="") response = make_response(xml) response.headers["Content-Type"] = "application/xml" return response @@ -494,7 +494,7 @@ def feed_new(): config.config_books_per_page) pagination = Pagination((int(off) / (int(config.config_books_per_page)) + 1), config.config_books_per_page, len(db.session.query(db.Books).filter(filter).all())) - xml = render_template('feed.xml', entries=entries, pagination=pagination) + xml = render_title_template('feed.xml', entries=entries, pagination=pagination) response = make_response(xml) response.headers["Content-Type"] = "application/xml" return response @@ -512,7 +512,7 @@ def feed_discover(): # off = 0 entries = db.session.query(db.Books).filter(filter).order_by(func.random()).limit(config.config_books_per_page) pagination = Pagination(1, config.config_books_per_page, int(config.config_books_per_page)) - xml = render_template('feed.xml', entries=entries, pagination=pagination) + xml = render_title_template('feed.xml', entries=entries, pagination=pagination) response = make_response(xml) response.headers["Content-Type"] = "application/xml" return response @@ -533,7 +533,7 @@ def feed_hot(): pagination = Pagination((int(off) / (int(config.config_books_per_page)) + 1), config.config_books_per_page, len(db.session.query(db.Books).filter(filter).filter( db.Books.ratings.any(db.Ratings.rating > 9)).all())) - xml = render_template('feed.xml', entries=entries, pagination=pagination) + xml = render_title_template('feed.xml', entries=entries, pagination=pagination) response = make_response(xml) response.headers["Content-Type"] = "application/xml" return response @@ -553,7 +553,7 @@ def feed_authorindex(): authors = db.session.query(db.Authors).order_by(db.Authors.sort).offset(off).limit(config.config_books_per_page) pagination = Pagination((int(off) / (int(config.config_books_per_page)) + 1), config.config_books_per_page, len(db.session.query(db.Authors).all())) - xml = render_template('feed.xml', authors=authors, pagination=pagination) + xml = render_title_template('feed.xml', authors=authors, pagination=pagination) response = make_response(xml) response.headers["Content-Type"] = "application/xml" return response @@ -574,7 +574,7 @@ def feed_author(id): pagination = Pagination((int(off) / (int(config.config_books_per_page)) + 1), config.config_books_per_page, len(db.session.query(db.Books).filter(db.Books.authors.any(db.Authors.id == id)).filter( filter).all())) - xml = render_template('feed.xml', entries=entries, pagination=pagination) + xml = render_title_template('feed.xml', entries=entries, pagination=pagination) response = make_response(xml) response.headers["Content-Type"] = "application/xml" return response @@ -589,7 +589,7 @@ def feed_categoryindex(): entries = db.session.query(db.Tags).order_by(db.Tags.name).offset(off).limit(config.config_books_per_page) pagination = Pagination((int(off) / (int(config.config_books_per_page)) + 1), config.config_books_per_page, len(db.session.query(db.Tags).all())) - xml = render_template('feed.xml', categorys=entries, pagination=pagination) + xml = render_title_template('feed.xml', categorys=entries, pagination=pagination) response = make_response(xml) response.headers["Content-Type"] = "application/xml" return response @@ -610,7 +610,7 @@ def feed_category(id): pagination = Pagination((int(off) / (int(config.config_books_per_page)) + 1), config.config_books_per_page, len(db.session.query(db.Books).filter(db.Books.tags.any(db.Tags.id == id)).filter( filter).all())) - xml = render_template('feed.xml', entries=entries, pagination=pagination) + xml = render_title_template('feed.xml', entries=entries, pagination=pagination) response = make_response(xml) response.headers["Content-Type"] = "application/xml" return response @@ -629,7 +629,7 @@ def feed_seriesindex(): entries = db.session.query(db.Series).order_by(db.Series.name).offset(off).limit(config.config_books_per_page) pagination = Pagination((int(off) / (int(config.config_books_per_page)) + 1), config.config_books_per_page, len(db.session.query(db.Series).all())) - xml = render_template('feed.xml', series=entries, pagination=pagination) + xml = render_title_template('feed.xml', series=entries, pagination=pagination) response = make_response(xml) response.headers["Content-Type"] = "application/xml" return response @@ -650,7 +650,7 @@ def feed_series(id): pagination = Pagination((int(off) / (int(config.config_books_per_page)) + 1), config.config_books_per_page, len(db.session.query(db.Books).filter(db.Books.series.any(db.Series.id == id)).filter( filter).all())) - xml = render_template('feed.xml', entries=entries, pagination=pagination) + xml = render_title_template('feed.xml', entries=entries, pagination=pagination) response = make_response(xml) response.headers["Content-Type"] = "application/xml" return response @@ -670,7 +670,7 @@ def get_opds_download_link(book_id, format): if len(author) > 0: file_name = author + '-' + file_name file_name = helper.get_valid_filename(file_name) - response = make_response(send_from_directory(os.path.join(config.DB_ROOT, book.path), data.name + "." + format)) + response = make_response(send_from_directory(os.path.join(config.config_calibre_dir, book.path), data.name + "." + format)) response.headers["Content-Disposition"] = "attachment; filename=\"%s.%s\"" % (data.name, format) return response