Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add: Display Filename in File Exports #122

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions drive_cli/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,35 +79,38 @@ def drive_data(*argv):
return data


def get_request(service, fid, mimeType):
def get_request(service, fid, mimeType, filename):
if(re.match('^application/vnd\.google-apps\..+', mimeType)):
if(mimeType == 'application/vnd.google-apps.document'):
mimeTypes = {extension: mime.guess_type("placeholder_filename." + extension)[0] for extension
mimeTypes = {extension: mime.guess_type(filename + "." + extension)[0] for extension
in ("pdf",
"txt",
"doc",
"zip",
"html",
"rtf",
"odt")}
docType = "Google Docs"
elif(mimeType == 'application/vnd.google-apps.spreadsheet'):
mimeTypes = {extension: mime.guess_type("placeholder_filename." + extension)[0] for extension
mimeTypes = {extension: mime.guess_type(filename + "." + extension)[0] for extension
in ("pdf",
"xlsx",
"zip",
"html",
"ods",
"csv",
"tsv")}
docType = "Google Sheets"
elif(mimeType == 'application/vnd.google-apps.presentation'):
mimeTypes = {extension: mime.guess_type("paceholder_filename." + extension)[0] for extension
mimeTypes = {extension: mime.guess_type(filename + "." + extension)[0] for extension
in ("pdf",
"zip",
"html",
"pptx",
"txt")}
docType = "Google Slides"
else:
mimeTypes = {extension: mime.guess_type("paceholder_filename." + extension)[0] for extension
mimeTypes = {extension: mime.guess_type(filename + "." + extension)[0] for extension
in ("ods",
"csv",
"pdf",
Expand All @@ -126,9 +129,10 @@ def get_request(service, fid, mimeType):
"cab",
"html",
"htm")}
docType = "Unknown"
mimeTypes.update(
{'tmpl': 'text/plain', 'php': 'application/x-httpd-php', 'arj': 'application/arj'})
promptMessage = 'Choose type to export to \n(ENTER to select, s to stop):'
promptMessage = 'Choose the export type for the ' + docType + ' document: ' + filename + ' \n(ENTER to select, s to stop):'
title = promptMessage
options = [x for x in mimeTypes.keys()]
picker = Picker(options, title, indicator='=>', default_index=0)
Expand Down Expand Up @@ -314,7 +318,7 @@ def file_download(item, cwd, clone=False):
fname = item['name']
fh = io.BytesIO()
click.echo("Preparing: " + click.style(fname, fg='red') + " for download")
request, ext = get_request(service, fid, item['mimeType'])
request, ext = get_request(service, fid, item['mimeType'], item["name"])
file_path = (os.path.join(cwd, fname) + ext)
if(not clone and (os.path.exists(file_path)) and (not write_needed(file_path, item))):
return
Expand Down Expand Up @@ -342,7 +346,7 @@ def concat(fid):
service = build('drive', 'v3', http=creds.authorize(Http()))
fh = io.BytesIO()
item = get_file(fid)
request, ext = get_request(service, fid, item['mimeType'])
request, ext = get_request(service, fid, item['mimeType'], item["name"])
downloader = MediaIoBaseDownload(fh, request)
done = False
while done is False:
Expand Down