|
|
@ -31,13 +31,9 @@ from ub import config
|
|
|
|
import cli
|
|
|
|
import cli
|
|
|
|
import shutil
|
|
|
|
import shutil
|
|
|
|
from flask import Response, stream_with_context
|
|
|
|
from flask import Response, stream_with_context
|
|
|
|
import time
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from sqlalchemy import *
|
|
|
|
from sqlalchemy import *
|
|
|
|
from sqlalchemy.ext.declarative import declarative_base
|
|
|
|
from sqlalchemy.ext.declarative import declarative_base
|
|
|
|
from sqlalchemy.orm import *
|
|
|
|
from sqlalchemy.orm import *
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import web
|
|
|
|
import web
|
|
|
|
|
|
|
|
|
|
|
|
class Singleton:
|
|
|
|
class Singleton:
|
|
|
@ -286,9 +282,10 @@ def downloadFile(path, filename, output):
|
|
|
|
def moveGdriveFolderRemote(origin_file, target_folder):
|
|
|
|
def moveGdriveFolderRemote(origin_file, target_folder):
|
|
|
|
drive = getDrive(Gdrive.Instance().drive)
|
|
|
|
drive = getDrive(Gdrive.Instance().drive)
|
|
|
|
previous_parents = ",".join([parent["id"] for parent in origin_file.get('parents')])
|
|
|
|
previous_parents = ",".join([parent["id"] for parent in origin_file.get('parents')])
|
|
|
|
|
|
|
|
children = drive.auth.service.children().list(folderId=previous_parents).execute()
|
|
|
|
gFileTargetDir = getFileFromEbooksFolder(None, target_folder)
|
|
|
|
gFileTargetDir = getFileFromEbooksFolder(None, target_folder)
|
|
|
|
if not gFileTargetDir:
|
|
|
|
if not gFileTargetDir:
|
|
|
|
# Folder is not exisiting, create, and move folder
|
|
|
|
# Folder is not existing, create, and move folder
|
|
|
|
gFileTargetDir = drive.CreateFile(
|
|
|
|
gFileTargetDir = drive.CreateFile(
|
|
|
|
{'title': target_folder, 'parents': [{"kind": "drive#fileLink", 'id': getEbooksFolderId()}],
|
|
|
|
{'title': target_folder, 'parents': [{"kind": "drive#fileLink", 'id': getEbooksFolderId()}],
|
|
|
|
"mimeType": "application/vnd.google-apps.folder"})
|
|
|
|
"mimeType": "application/vnd.google-apps.folder"})
|
|
|
@ -298,15 +295,10 @@ def moveGdriveFolderRemote(origin_file, target_folder):
|
|
|
|
addParents=gFileTargetDir['id'],
|
|
|
|
addParents=gFileTargetDir['id'],
|
|
|
|
removeParents=previous_parents,
|
|
|
|
removeParents=previous_parents,
|
|
|
|
fields='id, parents').execute()
|
|
|
|
fields='id, parents').execute()
|
|
|
|
# if previous_parents has no childs anymore, delete originfileparent
|
|
|
|
# if previous_parents has no childs anymore, delete original fileparent
|
|
|
|
# is not working correctly, because of slow update on gdrive -> could cause trouble in gdrive.db
|
|
|
|
if len(children['items']) == 1:
|
|
|
|
# (nonexisting folder has id)
|
|
|
|
deleteDatabaseEntry(previous_parents)
|
|
|
|
time.sleep(20)
|
|
|
|
|
|
|
|
children = drive.auth.service.children().list(folderId=previous_parents).execute()
|
|
|
|
|
|
|
|
if not len(children['items']):
|
|
|
|
|
|
|
|
drive.auth.service.files().delete(fileId=previous_parents).execute()
|
|
|
|
drive.auth.service.files().delete(fileId=previous_parents).execute()
|
|
|
|
time.sleep(20)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def copyToDrive(drive, uploadFile, createRoot, replaceFiles,
|
|
|
|
def copyToDrive(drive, uploadFile, createRoot, replaceFiles,
|
|
|
|