code cosmetics
This commit is contained in:
parent
8c7a8a954a
commit
dc45b53b24
|
@ -103,7 +103,7 @@ def getEbooksFolderId(drive=None):
|
||||||
gDriveId.path='/'
|
gDriveId.path='/'
|
||||||
session.merge(gDriveId)
|
session.merge(gDriveId)
|
||||||
session.commit()
|
session.commit()
|
||||||
return
|
return
|
||||||
|
|
||||||
def getFolderInFolder(parentId, folderName, drive=None):
|
def getFolderInFolder(parentId, folderName, drive=None):
|
||||||
if not drive:
|
if not drive:
|
||||||
|
@ -112,7 +112,7 @@ def getFolderInFolder(parentId, folderName, drive=None):
|
||||||
drive.auth.Refresh()
|
drive.auth.Refresh()
|
||||||
folder= "title = '%s' and '%s' in parents and mimeType = 'application/vnd.google-apps.folder' and trashed = false" % (folderName.replace("'", "\\'"), parentId)
|
folder= "title = '%s' and '%s' in parents and mimeType = 'application/vnd.google-apps.folder' and trashed = false" % (folderName.replace("'", "\\'"), parentId)
|
||||||
fileList = drive.ListFile({'q': folder}).GetList()
|
fileList = drive.ListFile({'q': folder}).GetList()
|
||||||
return fileList[0]
|
return fileList[0]
|
||||||
|
|
||||||
def getFile(pathId, fileName, drive=None):
|
def getFile(pathId, fileName, drive=None):
|
||||||
if not drive:
|
if not drive:
|
||||||
|
@ -168,7 +168,7 @@ def getFileFromEbooksFolder(drive, path, fileName):
|
||||||
folderId=getFolderId(path, drive)
|
folderId=getFolderId(path, drive)
|
||||||
else:
|
else:
|
||||||
folderId=getEbooksFolderId(drive)
|
folderId=getEbooksFolderId(drive)
|
||||||
|
|
||||||
return getFile(folderId, fileName, drive)
|
return getFile(folderId, fileName, drive)
|
||||||
|
|
||||||
def copyDriveFileRemote(drive, origin_file_id, copy_title):
|
def copyDriveFileRemote(drive, origin_file_id, copy_title):
|
||||||
|
@ -221,7 +221,7 @@ def copyToDrive(drive, uploadFile, createRoot, replaceFiles,
|
||||||
if os.path.isdir(os.path.join(prevDir,uploadFile)):
|
if os.path.isdir(os.path.join(prevDir,uploadFile)):
|
||||||
existingFolder=drive.ListFile({'q' : "title = '%s' and '%s' in parents and trashed = false" % (os.path.basename(uploadFile), parent['id'])}).GetList()
|
existingFolder=drive.ListFile({'q' : "title = '%s' and '%s' in parents and trashed = false" % (os.path.basename(uploadFile), parent['id'])}).GetList()
|
||||||
if len(existingFolder) == 0 and (not isInitial or createRoot):
|
if len(existingFolder) == 0 and (not isInitial or createRoot):
|
||||||
parent = drive.CreateFile({'title': os.path.basename(uploadFile), 'parents' : [{"kind": "drive#fileLink", 'id' : parent['id']}],
|
parent = drive.CreateFile({'title': os.path.basename(uploadFile), 'parents' : [{"kind": "drive#fileLink", 'id' : parent['id']}],
|
||||||
"mimeType": "application/vnd.google-apps.folder" })
|
"mimeType": "application/vnd.google-apps.folder" })
|
||||||
parent.Upload()
|
parent.Upload()
|
||||||
else:
|
else:
|
||||||
|
@ -259,7 +259,7 @@ def uploadFileToEbooksFolder(drive, destFile, f):
|
||||||
else:
|
else:
|
||||||
existingFolder=drive.ListFile({'q' : "title = '%s' and '%s' in parents and trashed = false" % (x, parent['id'])}).GetList()
|
existingFolder=drive.ListFile({'q' : "title = '%s' and '%s' in parents and trashed = false" % (x, parent['id'])}).GetList()
|
||||||
if len(existingFolder) == 0:
|
if len(existingFolder) == 0:
|
||||||
parent = drive.CreateFile({'title': x, 'parents' : [{"kind": "drive#fileLink", 'id' : parent['id']}],
|
parent = drive.CreateFile({'title': x, 'parents' : [{"kind": "drive#fileLink", 'id' : parent['id']}],
|
||||||
"mimeType": "application/vnd.google-apps.folder" })
|
"mimeType": "application/vnd.google-apps.folder" })
|
||||||
parent.Upload()
|
parent.Upload()
|
||||||
else:
|
else:
|
||||||
|
@ -341,7 +341,7 @@ def stopChannel(drive, channel_id, resource_id):
|
||||||
if not drive:
|
if not drive:
|
||||||
drive=getDrive()
|
drive=getDrive()
|
||||||
if drive.auth.access_token_expired:
|
if drive.auth.access_token_expired:
|
||||||
drive.auth.Refresh()
|
drive.auth.Refresh()
|
||||||
# service=drive.auth.service
|
# service=drive.auth.service
|
||||||
body = {
|
body = {
|
||||||
'id': channel_id,
|
'id': channel_id,
|
||||||
|
@ -363,5 +363,5 @@ def getChangeById (drive, change_id):
|
||||||
change = drive.auth.service.changes().get(changeId=change_id).execute()
|
change = drive.auth.service.changes().get(changeId=change_id).execute()
|
||||||
return change
|
return change
|
||||||
except errors.HttpError, error:
|
except errors.HttpError, error:
|
||||||
web.app.logger.exception(error)
|
web.app.logger.exception(error)
|
||||||
return None
|
return None
|
||||||
|
|
|
@ -366,6 +366,7 @@ class Updater(threading.Thread):
|
||||||
def one_minus_two(self, one, two):
|
def one_minus_two(self, one, two):
|
||||||
return [x for x in one if x not in set(two)]
|
return [x for x in one if x not in set(two)]
|
||||||
|
|
||||||
|
@classmethod
|
||||||
def reduce_dirs(self, delete_files, new_list):
|
def reduce_dirs(self, delete_files, new_list):
|
||||||
new_delete = []
|
new_delete = []
|
||||||
for file in delete_files:
|
for file in delete_files:
|
||||||
|
|
|
@ -141,7 +141,7 @@ $(document).ready(function () {
|
||||||
function dbSearchBook (title) {
|
function dbSearchBook (title) {
|
||||||
var url = douban + dbSearch + "?q=" + title + "&fields=all&count=10";
|
var url = douban + dbSearch + "?q=" + title + "&fields=all&count=10";
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: url,
|
url,
|
||||||
type: "GET",
|
type: "GET",
|
||||||
dataType: "jsonp",
|
dataType: "jsonp",
|
||||||
jsonp: "callback",
|
jsonp: "callback",
|
||||||
|
@ -149,7 +149,7 @@ $(document).ready(function () {
|
||||||
dbResults = data.books;
|
dbResults = data.books;
|
||||||
},
|
},
|
||||||
error () {
|
error () {
|
||||||
$("#meta-info").html('<p class="text-danger">'+ msg.search_error+"!</p>");
|
$("#meta-info").html("<p class=\"text-danger\">"+ msg.search_error+"!</p>");
|
||||||
},
|
},
|
||||||
complete () {
|
complete () {
|
||||||
dbDone = true;
|
dbDone = true;
|
||||||
|
|
10
cps/web.py
10
cps/web.py
|
@ -484,7 +484,7 @@ def fill_indexpage(page, database, db_filter, order):
|
||||||
return entries, random, pagination
|
return entries, random, pagination
|
||||||
|
|
||||||
|
|
||||||
def modify_database_object(input_elements, db_book_object, db_object, db_session, type):
|
def modify_database_object(input_elements, db_book_object, db_object, db_session, db_type):
|
||||||
input_elements = [x for x in input_elements if x != '']
|
input_elements = [x for x in input_elements if x != '']
|
||||||
# we have all input element (authors, series, tags) names now
|
# we have all input element (authors, series, tags) names now
|
||||||
# 1. search for elements to remove
|
# 1. search for elements to remove
|
||||||
|
@ -516,7 +516,7 @@ def modify_database_object(input_elements, db_book_object, db_object, db_session
|
||||||
db_session.delete(del_element)
|
db_session.delete(del_element)
|
||||||
# if there are elements to add, we add them now!
|
# if there are elements to add, we add them now!
|
||||||
if len(add_elements) > 0:
|
if len(add_elements) > 0:
|
||||||
if type == 'languages':
|
if db_type == 'languages':
|
||||||
db_filter = db_object.lang_code
|
db_filter = db_object.lang_code
|
||||||
else:
|
else:
|
||||||
db_filter = db_object.name
|
db_filter = db_object.name
|
||||||
|
@ -525,12 +525,12 @@ def modify_database_object(input_elements, db_book_object, db_object, db_session
|
||||||
new_element = db_session.query(db_object).filter(db_filter == add_element).first()
|
new_element = db_session.query(db_object).filter(db_filter == add_element).first()
|
||||||
# if no element is found add it
|
# if no element is found add it
|
||||||
if new_element is None:
|
if new_element is None:
|
||||||
if type == 'author':
|
if db_type == 'author':
|
||||||
new_element = db_object(add_element, add_element, "")
|
new_element = db_object(add_element, add_element, "")
|
||||||
else:
|
else:
|
||||||
if type == 'series':
|
if db_type == 'series':
|
||||||
new_element = db_object(add_element, add_element)
|
new_element = db_object(add_element, add_element)
|
||||||
else: # type should be tag, or languages
|
else: # db_type should be tag, or languages
|
||||||
new_element = db_object(add_element)
|
new_element = db_object(add_element)
|
||||||
db_session.add(new_element)
|
db_session.add(new_element)
|
||||||
new_element = db.session.query(db_object).filter(db_filter == add_element).first()
|
new_element = db.session.query(db_object).filter(db_filter == add_element).first()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user