def drive_upload(source):
if MEDIA_DIR in source:
target = os.path.dirname(source.replace(MEDIA_DIR, 'media'))
else:
target = os.path.dirname(source.replace(CONVERTED_DIR, 'media'))
target_copy = target
to_add = []
while (not FILES.get(target_copy)):
to_add.insert(0, os.path.basename(target_copy))
target_copy = os.path.dirname(target_copy)
if (to_add):
for folder in to_add:
create_folder(folder, FILES[target_copy], target_copy)
target_copy = os.path.join(target_copy,folder)
Logger.info("Uploading file: {name} to {target}, with Title: {title}".format(name=source, target=target, title=os.path.basename(source)))
f = DRIVE.CreateFile({"parents": [{"id": FILES[target]}], "title" : os.path.basename(source)})
f.SetContentFile(source)
f.Upload()
if not f['id']:
logging.error("Failed to upload file {source}".format(source=source))
raise Exception("Failed to upload file {source}".format(source=source))
评论列表
文章目录