Merge branch 'develop' into personal

This commit is contained in:
Jack Darlington 2017-03-01 22:40:28 +00:00
commit 8e85d1b5bd
4 changed files with 60 additions and 4 deletions

View File

@ -21,7 +21,7 @@ Base = declarative_base()
# Open session for database connection
Session = sessionmaker()
Session.configure(bind=engine)
session = Session()
session = scoped_session(Session)
class GdriveId(Base):
__tablename__='gdrive_ids'
@ -29,16 +29,33 @@ class GdriveId(Base):
id = Column(Integer, primary_key=True)
gdrive_id = Column(Integer, unique=True)
path = Column(String)
__table_args__ = (UniqueConstraint('gdrive_id', 'path', name='_gdrive_path_uc'),)
def __repr__(self):
return str(self.path)
def migrate():
for sql in session.execute("select sql from sqlite_master where type='table'"):
if 'CREATE TABLE gdrive_ids' in sql[0]:
currUniqueConstraint='UNIQUE (gdrive_id)'
if currUniqueConstraint in sql[0]:
sql=sql[0].replace(currUniqueConstraint, 'UNIQUE (gdrive_id, path)')
sql=sql.replace(GdriveId.__tablename__, GdriveId.__tablename__+ '2')
session.execute(sql)
session.execute('INSERT INTO gdrive_ids2 (id, gdrive_id, path) SELECT id, gdrive_id, path FROM gdrive_ids;')
session.commit()
session.execute('DROP TABLE %s' % 'gdrive_ids')
session.execute('ALTER TABLE gdrive_ids2 RENAME to gdrive_ids')
break
if not os.path.exists(dbpath):
try:
Base.metadata.create_all(engine)
except Exception:
raise
migrate()
def getDrive(gauth=None):
if not gauth:
gauth=GoogleAuth(settings_file='settings.yaml')

View File

@ -28,6 +28,8 @@ import shutil
import requests
import zipfile
from tornado.ioloop import IOLoop
import gdriveutils as gd
import web
try:
import unidecode
@ -280,6 +282,30 @@ def update_dir_stucture(book_id, calibrepath):
book.path = new_authordir + '/' + book.path.split('/')[1]
db.session.commit()
def update_dir_structure_gdrive(book_id):
db.session.connection().connection.connection.create_function("title_sort", 1, db.title_sort)
book = db.session.query(db.Books).filter(db.Books.id == book_id).first()
authordir = book.path.split('/')[0]
new_authordir = get_valid_filename(book.authors[0].name)
titledir = book.path.split('/')[1]
new_titledir = get_valid_filename(book.title) + " (" + str(book_id) + ")"
if titledir != new_titledir:
print (titledir)
gFile=gd.getFileFromEbooksFolder(web.Gdrive.Instance().drive,os.path.dirname(book.path),titledir)
gFile['title']= new_titledir
gFile.Upload()
book.path = book.path.split('/')[0] + '/' + new_titledir
if authordir != new_authordir:
gFile=gd.getFileFromEbooksFolder(web.Gdrive.Instance().drive,None,authordir)
gFile['title']= new_authordir
gFile.Upload()
book.path = new_authordir + '/' + book.path.split('/')[1]
db.session.commit()
class Updater(threading.Thread):
def __init__(self):

View File

@ -2454,7 +2454,10 @@ def edit_book(book_id):
for author in book.authors:
author_names.append(author.name)
for b in edited_books_id:
helper.update_dir_stucture(b, config.config_calibre_dir)
if config.config_use_google_drive:
helper.update_dir_structure_gdrive(b)
else:
helper.update_dir_stucture(b, config.config_calibre_dir)
if config.config_use_google_drive:
updateGdriveCalibreFromLocal()
if "detail_view" in to_save:
@ -2549,8 +2552,7 @@ def upload():
for author in db_book.authors:
author_names.append(author.name)
if config.config_use_google_drive:
if not current_user.role_edit() and not current_user.role_admin():
updateGdriveCalibreFromLocal()
updateGdriveCalibreFromLocal()
cc = db.session.query(db.Custom_Columns).filter(db.Custom_Columns.datatype.notin_(db.cc_exceptions)).all()
if current_user.role_edit() or current_user.role_admin():
return render_title_template('book_edit.html', book=db_book, authors=author_names, cc=cc,

11
requirements.txt Normal file
View File

@ -0,0 +1,11 @@
google-api-python-client==1.6.1
httplib2==0.9.2
lxml==3.7.2
oauth2client==4.0.0
pyasn1==0.1.9
pyasn1-modules==0.0.8
PyDrive==1.3.1
PyYAML==3.12
rsa==3.4.2
six==1.10.0
uritemplate==3.0.0