mirror of
https://github.com/janeczku/calibre-web
synced 2024-11-24 18:47:23 +00:00
Code cosmetics
This commit is contained in:
parent
395c6679b7
commit
78067b87bc
@ -293,7 +293,7 @@ def setup_db():
|
||||
engine = create_engine('sqlite:///'+ dbpath, echo=False, isolation_level="SERIALIZABLE")
|
||||
try:
|
||||
conn = engine.connect()
|
||||
except Exception as e:
|
||||
except Exception:
|
||||
content = ub.session.query(ub.Settings).first()
|
||||
content.config_calibre_dir = None
|
||||
content.db_configured = False
|
||||
|
@ -2,12 +2,11 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from lxml import etree
|
||||
import os
|
||||
import uploader
|
||||
try:
|
||||
from io import StringIO
|
||||
except ImportError as e:
|
||||
import StringIO
|
||||
#try:
|
||||
# from io import StringIO
|
||||
#except ImportError:
|
||||
# import StringIO
|
||||
|
||||
def get_fb2_info(tmp_file_path, original_file_extension):
|
||||
|
||||
|
@ -4,12 +4,11 @@ try:
|
||||
from apiclient import errors
|
||||
except ImportError:
|
||||
pass
|
||||
import os, time
|
||||
import os
|
||||
|
||||
from ub import config
|
||||
|
||||
from sqlalchemy import *
|
||||
from sqlalchemy import exc
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
from sqlalchemy.orm import *
|
||||
|
||||
@ -165,7 +164,7 @@ def getFileFromEbooksFolder(drive, path, fileName):
|
||||
if drive.auth.access_token_expired:
|
||||
drive.auth.Refresh()
|
||||
if path:
|
||||
sqlCheckPath=path if path[-1] =='/' else path + '/'
|
||||
# sqlCheckPath=path if path[-1] =='/' else path + '/'
|
||||
folderId=getFolderId(path, drive)
|
||||
else:
|
||||
folderId=getEbooksFolderId(drive)
|
||||
@ -273,20 +272,19 @@ def watchChange(drive, channel_id, channel_type, channel_address,
|
||||
drive=getDrive()
|
||||
if drive.auth.access_token_expired:
|
||||
drive.auth.Refresh()
|
||||
"""Watch for all changes to a user's Drive.
|
||||
Args:
|
||||
service: Drive API service instance.
|
||||
channel_id: Unique string that identifies this channel.
|
||||
channel_type: Type of delivery mechanism used for this channel.
|
||||
channel_address: Address where notifications are delivered.
|
||||
channel_token: An arbitrary string delivered to the target address with
|
||||
each notification delivered over this channel. Optional.
|
||||
channel_address: Address where notifications are delivered. Optional.
|
||||
Returns:
|
||||
The created channel if successful
|
||||
Raises:
|
||||
apiclient.errors.HttpError: if http request to create channel fails.
|
||||
"""
|
||||
# Watch for all changes to a user's Drive.
|
||||
# Args:
|
||||
# service: Drive API service instance.
|
||||
# channel_id: Unique string that identifies this channel.
|
||||
# channel_type: Type of delivery mechanism used for this channel.
|
||||
# channel_address: Address where notifications are delivered.
|
||||
# channel_token: An arbitrary string delivered to the target address with
|
||||
# each notification delivered over this channel. Optional.
|
||||
# channel_address: Address where notifications are delivered. Optional.
|
||||
# Returns:
|
||||
# The created channel if successful
|
||||
# Raises:
|
||||
# apiclient.errors.HttpError: if http request to create channel fails.
|
||||
body = {
|
||||
'id': channel_id,
|
||||
'type': channel_type,
|
||||
@ -344,7 +342,7 @@ def stopChannel(drive, channel_id, resource_id):
|
||||
drive=getDrive()
|
||||
if drive.auth.access_token_expired:
|
||||
drive.auth.Refresh()
|
||||
service=drive.auth.service
|
||||
# service=drive.auth.service
|
||||
body = {
|
||||
'id': channel_id,
|
||||
'resourceId': resource_id
|
||||
|
@ -464,7 +464,7 @@ class Updater(threading.Thread):
|
||||
logging.getLogger('cps.web').debug("Delete file " + item_path)
|
||||
log_from_thread("Delete file " + item_path)
|
||||
os.remove(item_path)
|
||||
except Exception as e:
|
||||
except Exception:
|
||||
logging.getLogger('cps.web').debug("Could not remove:" + item_path)
|
||||
shutil.rmtree(source, ignore_errors=True)
|
||||
|
||||
|
@ -6,8 +6,8 @@
|
||||
Takes a prefix, query typeahead callback, Bloodhound typeahead adapter
|
||||
and returns the completions it gets from the bloodhound engine prefixed.
|
||||
*/
|
||||
function prefixed_source(prefix, query, cb, bh_adapter) {
|
||||
bh_adapter(query, function(retArray){
|
||||
function prefixed_source(prefix, query, cb, bhAdapter) {
|
||||
bhAdapter(query, function(retArray){
|
||||
var matches = [];
|
||||
for (var i = 0; i < retArray.length; i++) {
|
||||
var obj = {name : prefix + retArray[i].name};
|
||||
@ -23,7 +23,7 @@ function get_path(){
|
||||
}
|
||||
|
||||
var authors = new Bloodhound({
|
||||
name: 'authors',
|
||||
name: "authors",
|
||||
datumTokenizer: function(datum) {
|
||||
return [datum.name];
|
||||
},
|
||||
@ -34,7 +34,7 @@ var authors = new Bloodhound({
|
||||
});
|
||||
|
||||
function authors_source(query, cb) {
|
||||
var bh_adapter = authors.ttAdapter();
|
||||
var bhAdapter = authors.ttAdapter();
|
||||
|
||||
var tokens = query.split("&");
|
||||
var current_author = tokens[tokens.length-1].trim();
|
||||
@ -46,7 +46,7 @@ function authors_source(query, cb) {
|
||||
prefix += author + " & ";
|
||||
}
|
||||
|
||||
prefixed_source(prefix, current_author, cb, bh_adapter);
|
||||
prefixed_source(prefix, current_author, cb, bhAdapter);
|
||||
}
|
||||
|
||||
|
||||
@ -65,7 +65,7 @@ var promise = authors.initialize();
|
||||
});
|
||||
|
||||
var series = new Bloodhound({
|
||||
name: 'series',
|
||||
name: "series",
|
||||
datumTokenizer: function(datum) {
|
||||
return [datum.name];
|
||||
},
|
||||
@ -94,7 +94,7 @@ var promise = series.initialize();
|
||||
});
|
||||
|
||||
var tags = new Bloodhound({
|
||||
name: 'tags',
|
||||
name: "tags",
|
||||
datumTokenizer: function(datum) {
|
||||
return [datum.name];
|
||||
},
|
||||
@ -104,12 +104,12 @@ var tags = new Bloodhound({
|
||||
return tokens
|
||||
},
|
||||
remote: {
|
||||
url: get_path()+'/get_tags_json?q=%QUERY'
|
||||
url: get_path()+"/get_tags_json?q=%QUERY"
|
||||
}
|
||||
});
|
||||
|
||||
function tag_source(query, cb) {
|
||||
var bh_adapter = tags.ttAdapter();
|
||||
var bhAdapter = tags.ttAdapter();
|
||||
|
||||
var tokens = query.split(",");
|
||||
var current_tag = tokens[tokens.length-1].trim();
|
||||
@ -121,7 +121,7 @@ function tag_source(query, cb) {
|
||||
prefix += tag + ", ";
|
||||
}
|
||||
|
||||
prefixed_source(prefix, current_tag, cb, bh_adapter);
|
||||
prefixed_source(prefix, current_tag, cb, bhAdapter);
|
||||
}
|
||||
|
||||
var promise = tags.initialize();
|
||||
@ -138,7 +138,7 @@ var promise = tags.initialize();
|
||||
});
|
||||
|
||||
var languages = new Bloodhound({
|
||||
name: 'languages',
|
||||
name: "languages",
|
||||
datumTokenizer: function(datum) {
|
||||
return [datum.name];
|
||||
},
|
||||
@ -155,10 +155,10 @@ var languages = new Bloodhound({
|
||||
});
|
||||
|
||||
function language_source(query, cb) {
|
||||
var bh_adapter = languages.ttAdapter();
|
||||
var bhAdapter = languages.ttAdapter();
|
||||
|
||||
var tokens = query.split(",");
|
||||
var current_language = tokens[tokens.length-1].trim();
|
||||
var currentLanguage = tokens[tokens.length-1].trim();
|
||||
|
||||
tokens.splice(tokens.length-1, 1); // remove last element
|
||||
var prefix = "";
|
||||
@ -167,7 +167,7 @@ function language_source(query, cb) {
|
||||
prefix += tag + ", ";
|
||||
}
|
||||
|
||||
prefixed_source(prefix, current_language, cb, bh_adapter);
|
||||
prefixed_source(prefix, currentLanguage, cb, bhAdapter);
|
||||
}
|
||||
|
||||
var promise = languages.initialize();
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
$(document).ready(function () {
|
||||
var msg = i18n_msg;
|
||||
var douban = 'https://api.douban.com';
|
||||
var douban = "https://api.douban.com";
|
||||
var db_search = '/v2/book/search';
|
||||
var db_get_info = '/v2/book/';
|
||||
var db_get_info_by_isbn = '/v2/book/isbn/ ';
|
||||
@ -23,7 +23,7 @@ $(document).ready(function () {
|
||||
var show_flag = 0;
|
||||
String.prototype.replaceAll = function (s1, s2) {
|
||||
return this.replace(new RegExp(s1, "gm"), s2);
|
||||
}
|
||||
};
|
||||
|
||||
gg_search_book = function (title) {
|
||||
title = title.replaceAll(/\s+/, '+');
|
||||
@ -45,38 +45,38 @@ $(document).ready(function () {
|
||||
|
||||
get_meta = function (source, id) {
|
||||
var meta;
|
||||
if (source == 'google') {;
|
||||
if (source == "google") {
|
||||
meta = gg_results[id];
|
||||
$('#description').val(meta.volumeInfo.description);
|
||||
$('#bookAuthor').val(meta.volumeInfo.authors.join(' & '));
|
||||
$('#book_title').val(meta.volumeInfo.title);
|
||||
$("#description").val(meta.volumeInfo.description);
|
||||
$("#bookAuthor").val(meta.volumeInfo.authors.join(' & '));
|
||||
$("#book_title").val(meta.volumeInfo.title);
|
||||
if (meta.volumeInfo.categories) {
|
||||
var tags = meta.volumeInfo.categories.join(',');
|
||||
$('#tags').val(tags);
|
||||
$("#tags").val(tags);
|
||||
}
|
||||
if (meta.volumeInfo.averageRating) {
|
||||
$('#rating').val(Math.round(meta.volumeInfo.averageRating));
|
||||
$("#rating").val(Math.round(meta.volumeInfo.averageRating));
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (source == 'douban') {
|
||||
if (source == "douban") {
|
||||
meta = db_results[id];
|
||||
$('#description').val(meta.summary);
|
||||
$('#bookAuthor').val(meta.author.join(' & '));
|
||||
$('#book_title').val(meta.title);
|
||||
$("#description").val(meta.summary);
|
||||
$("#bookAuthor").val(meta.author.join(' & '));
|
||||
$("#book_title").val(meta.title);
|
||||
var tags = '';
|
||||
for (var i = 0; i < meta.tags.length; i++) {
|
||||
tags = tags + meta.tags[i].title + ',';
|
||||
}
|
||||
$('#tags').val(tags);
|
||||
$('#rating').val(Math.round(meta.rating.average / 2));
|
||||
$("#tags").val(tags);
|
||||
$("#rating").val(Math.round(meta.rating.average / 2));
|
||||
return;
|
||||
}
|
||||
}
|
||||
do_search = function (keyword) {
|
||||
show_flag = 0;
|
||||
$('#meta-info').text(msg.loading);
|
||||
var keyword = $('#keyword').val();
|
||||
$("#meta-info").text(msg.loading);
|
||||
var keyword = $("#keyword").val();
|
||||
if (keyword) {
|
||||
db_search_book(keyword);
|
||||
gg_search_book(keyword);
|
||||
|
@ -5,11 +5,11 @@ var updateText;
|
||||
$(function() {
|
||||
$('.discover .row').isotope({
|
||||
// options
|
||||
itemSelector : '.book',
|
||||
layoutMode : 'fitRows'
|
||||
itemSelector : ".book",
|
||||
layoutMode : "fitRows"
|
||||
});
|
||||
|
||||
$('.load-more .row').infinitescroll({
|
||||
$(".load-more .row").infinitescroll({
|
||||
debug: false,
|
||||
navSelector : ".pagination",
|
||||
// selector for the paged navigation (it will be hidden)
|
||||
@ -20,13 +20,13 @@ $(function() {
|
||||
extraScrollPx: 300,
|
||||
// selector for all items you'll retrieve
|
||||
}, function(data){
|
||||
$('.load-more .row').isotope( 'appended', $(data), null );
|
||||
$(".load-more .row").isotope( 'appended', $(data), null );
|
||||
});
|
||||
|
||||
$('#sendbtn').click(function(){
|
||||
var $this = $(this);
|
||||
$this.text('Please wait...');
|
||||
$this.addClass('disabled');
|
||||
$this.text("Please wait...");
|
||||
$this.addClass("disabled");
|
||||
});
|
||||
$("#restart").click(function() {
|
||||
$.ajax({
|
||||
@ -57,10 +57,10 @@ $(function() {
|
||||
success: function(data) {
|
||||
$("#check_for_update").html(button_text);
|
||||
if (data.status == true) {
|
||||
$("#check_for_update").addClass('hidden');
|
||||
$("#perform_update").removeClass('hidden');
|
||||
$("#update_info").removeClass('hidden');
|
||||
$("#update_info").find('span').html(data.commit);
|
||||
$("#check_for_update").addClass("hidden");
|
||||
$("#perform_update").removeClass("hidden");
|
||||
$("#update_info").removeClass("hidden");
|
||||
$("#update_info").find("span").html(data.commit);
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -73,14 +73,14 @@ $(function() {
|
||||
});
|
||||
});
|
||||
$("#perform_update").click(function() {
|
||||
$('#spinner2').show();
|
||||
$("#spinner2").show();
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
dataType: 'json',
|
||||
data: { start: "True"},
|
||||
url: window.location.pathname+"/../../get_updater_status",
|
||||
success: function(data) {
|
||||
updateText=data.text
|
||||
updateText=data.text;
|
||||
$("#UpdateprogressDialog #Updatecontent").html(updateText[data.status]);
|
||||
console.log(data.status);
|
||||
updateTimerID=setInterval(updateTimer, 2000);}
|
||||
@ -90,8 +90,8 @@ $(function() {
|
||||
|
||||
|
||||
function restartTimer() {
|
||||
$('#spinner').hide();
|
||||
$('#RestartDialog').modal('hide');
|
||||
$("#spinner").hide();
|
||||
$("#RestartDialog").modal("hide");
|
||||
}
|
||||
|
||||
function updateTimer() {
|
||||
@ -110,13 +110,13 @@ function updateTimer() {
|
||||
}
|
||||
},
|
||||
error: function() {
|
||||
console.log('Done');
|
||||
// console.log('Done');
|
||||
clearInterval(updateTimerID);
|
||||
$('#spinner2').hide();
|
||||
$("#spinner2").hide();
|
||||
$("#UpdateprogressDialog #Updatecontent").html(updateText[7]);
|
||||
$('#UpdateprogressDialog #updateFinished').removeClass('hidden');
|
||||
$("#check_for_update").removeClass('hidden');
|
||||
$("#perform_update").addClass('hidden');
|
||||
$("#UpdateprogressDialog #updateFinished").removeClass("hidden");
|
||||
$("#check_for_update").removeClass("hidden");
|
||||
$("#perform_update").addClass("hidden");
|
||||
},
|
||||
timeout:2000
|
||||
});
|
||||
@ -124,5 +124,5 @@ function updateTimer() {
|
||||
|
||||
|
||||
$(window).resize(function(event) {
|
||||
$('.discover .row').isotope('reLayout');
|
||||
$(".discover .row").isotope("reLayout");
|
||||
});
|
||||
|
@ -506,7 +506,7 @@ def create_anonymous_user():
|
||||
session.add(user)
|
||||
try:
|
||||
session.commit()
|
||||
except Exception as e:
|
||||
except Exception:
|
||||
session.rollback()
|
||||
pass
|
||||
|
||||
|
15
cps/web.py
15
cps/web.py
@ -385,7 +385,7 @@ def shortentitle_filter(s):
|
||||
def mimetype_filter(val):
|
||||
try:
|
||||
s = mimetypes.types_map['.' + val]
|
||||
except Exception as e:
|
||||
except Exception:
|
||||
s = 'application/octet-stream'
|
||||
return s
|
||||
|
||||
@ -558,10 +558,6 @@ def before_request():
|
||||
@app.route("/opds")
|
||||
@requires_basic_auth_if_no_ano
|
||||
def feed_index():
|
||||
if current_user.filter_language() != "all":
|
||||
filter = db.Books.languages.any(db.Languages.lang_code == current_user.filter_language())
|
||||
else:
|
||||
filter = True
|
||||
xml = render_title_template('index.xml')
|
||||
response = make_response(xml)
|
||||
response.headers["Content-Type"] = "application/xml"
|
||||
@ -792,7 +788,6 @@ def partial(total_byte_len, part_size_limit):
|
||||
return s
|
||||
|
||||
def do_gdrive_download(df, headers):
|
||||
startTime=time.time()
|
||||
total_size = int(df.metadata.get('fileSize'))
|
||||
download_url = df.metadata.get('downloadUrl')
|
||||
s = partial(total_size, 1024 * 1024) # I'm downloading BIG files, so 100M chunk size is fine for me
|
||||
@ -832,7 +827,7 @@ def get_opds_download_link(book_id, format):
|
||||
return do_gdrive_download(df, headers)
|
||||
else:
|
||||
response = make_response(send_from_directory(os.path.join(config.config_calibre_dir, book.path), data.name + "." + format))
|
||||
response.headers=headers
|
||||
response.headers=headers
|
||||
return response
|
||||
|
||||
|
||||
@ -911,7 +906,7 @@ def get_updater_status():
|
||||
elif request.method == "GET":
|
||||
try:
|
||||
status['status']=helper.updater_thread.get_update_status()
|
||||
except Exception as e:
|
||||
except Exception:
|
||||
status['status'] = 7
|
||||
return json.dumps(status)
|
||||
|
||||
@ -1304,7 +1299,7 @@ def revoke_watch_gdrive():
|
||||
last_watch_response=config.config_google_drive_watch_changes_response
|
||||
if last_watch_response:
|
||||
try:
|
||||
response=gdriveutils.stopChannel(Gdrive.Instance().drive, last_watch_response['id'], last_watch_response['resourceId'])
|
||||
gdriveutils.stopChannel(Gdrive.Instance().drive, last_watch_response['id'], last_watch_response['resourceId'])
|
||||
except HttpError:
|
||||
pass
|
||||
settings = ub.session.query(ub.Settings).first()
|
||||
@ -1481,7 +1476,7 @@ def advanced_search():
|
||||
def get_cover_via_gdrive(cover_path):
|
||||
df=gdriveutils.getFileFromEbooksFolder(Gdrive.Instance().drive, cover_path, 'cover.jpg')
|
||||
if not gdriveutils.session.query(gdriveutils.PermissionAdded).filter(gdriveutils.PermissionAdded.gdrive_id == df['id']).first():
|
||||
permissions=df.GetPermissions()
|
||||
df.GetPermissions()
|
||||
df.InsertPermission({
|
||||
'type': 'anyone',
|
||||
'value': 'anyone',
|
||||
|
Loading…
Reference in New Issue
Block a user