def _create_google_spreadsheet(project_name, email): """ Once credentials are received, uploads a copy of tarbell_template.xlsx named for this project, makes it world-readable and returns the file ID. """ storage = Storage('fab.dat') http = _handle_oauth_flow(storage) service = discovery.build('drive', 'v2', http=http) media_body = _MediaFileUpload(os.path.join(fab.env.template_dir, '_project_template/tarbell_template.xlsx'), mimetype='application/vnd.ms-excel') body = { 'title': '%s [Tarbell project]' % project_name, 'description': '%s [Tarbell project]' % project_name, 'mimeType': 'application/vnd.ms-excel', } try: newfile = service.files()\ .insert(body=body, media_body=media_body, convert=True).execute() _add_user_to_file(newfile['id'], service, user_email=email) _add_user_to_file(newfile['id'], service, user_email='anyone', perm_type='anyone', role='reader') service.revisions()\ .update(fileId=newfile['id'], revisionId='head', body={'published': True, 'publishAuto': True}).execute() print ("Success! View the file at " "https://docs.google.com/spreadsheet/ccc?key=%s") % newfile['id'] return newfile['id'] except errors.HttpError, error: print 'An error occurred: %s' % error return '<< INSERT SPREADSHEET KEY >>'
def _create_google_spreadsheet(project_name): """ Once credentials are received, uploads a copy of microcopy_template.xlsx named for this project, puts it in the Trib Docs -> microcopy folder, adds the default tribapps gmail account as a reader, makes it world-readable and returns the file ID. """ storage = keyring_storage.Storage("fab", getpass.getuser()) http = _handle_oauth_flow(storage) service = discovery.build("drive", "v2", http=http) path = os.path.join(os.path.dirname(inspect.getfile(_TarbellSite)), "project_template/microcopy_template.xlsx") media_body = _MediaFileUpload(path, mimetype="application/vnd.ms-excel") body = { "title": "%s microcopy" % project_name, "description": "Microcopy file for %s project" % project_name, "mimeType": "application/vnd.ms-excel", } try: newfile = service.files().insert(body=body, media_body=media_body, convert=True).execute() _add_user_to_file(newfile["id"], service) _add_user_to_file(newfile["id"], service, user_email="anyone", perm_type="anyone", role="reader") service.revisions().update( fileId=newfile["id"], revisionId="head", body={"published": True, "publishAuto": True} ).execute() print ("Success! View the file at " "https://docs.google.com/spreadsheet/ccc?key=%s") % newfile["id"] return newfile["id"] except errors.HttpError, error: print "An error occurred: %s" % error return "<< INSERT SPREADSHEET KEY >>"
def _create_google_spreadsheet(project_name, email): """ Once credentials are received, uploads a copy of tarbell_template.xlsx named for this project, makes it world-readable and returns the file ID. """ storage = keyring_storage.Storage('fab', getpass.getuser()) http = _handle_oauth_flow(storage) service = discovery.build('drive', 'v2', http=http) media_body = _MediaFileUpload(os.path.join(fab.env.template_dir, '_project_template/tarbell_template.xlsx'), mimetype='application/vnd.ms-excel') body = { 'title': '%s [Tarbell project]' % project_name, 'description': '%s [Tarbell project]' % project_name, 'mimeType': 'application/vnd.ms-excel', } try: newfile = service.files()\ .insert(body=body, media_body=media_body, convert=True).execute() _add_user_to_file(newfile['id'], service, user_email=email) _add_user_to_file(newfile['id'], service, user_email='anyone', perm_type='anyone', role='reader') service.revisions()\ .update(fileId=newfile['id'], revisionId='head', body={'published': True, 'publishAuto': True}).execute() print ("Success! View the file at " "https://docs.google.com/spreadsheet/ccc?key=%s") % newfile['id'] return newfile['id'] except errors.HttpError, error: print 'An error occurred: %s' % error return '<< INSERT SPREADSHEET KEY >>'
def _create_spreadsheet(name, title, path, settings): """ Create Google spreadsheet. """ if not settings.client_secrets: return None create = raw_input("Would you like to create a Google spreadsheet? [Y/n] ") if create and not create.lower() == "y": return puts("Not creating spreadsheet.") email_message = ( "What Google account(s) should have access to this " "this spreadsheet? (Use a full email address, such as " "[email protected]. Separate multiple addresses with commas.)") if settings.config.get("google_account"): emails = raw_input("\n{0}(Default: {1}) ".format( email_message, settings.config.get("google_account"))) if not emails: emails = settings.config.get("google_account") else: emails = None while not emails: emails = raw_input(email_message) try: media_body = _MediaFileUpload(os.path.join( path, '_blueprint/_spreadsheet.xlsx'), mimetype='application/vnd.ms-excel') except IOError: show_error("_blueprint/_spreadsheet.xlsx doesn't exist!") return None service = get_drive_api() body = { 'title': '{0} (Tarbell)'.format(title), 'description': '{0} ({1})'.format(title, name), 'mimeType': 'application/vnd.ms-excel', } try: newfile = service.files()\ .insert(body=body, media_body=media_body, convert=True).execute() for email in emails.split(","): _add_user_to_file(newfile['id'], service, user_email=email.strip()) puts("\n{0}! View the spreadsheet at {1}".format( colored.green("Success"), colored.yellow( "https://docs.google.com/spreadsheet/ccc?key={0}".format( newfile['id'])))) return newfile['id'] except errors.HttpError, error: show_error('An error occurred creating spreadsheet: {0}'.format(error)) return None
def _create_spreadsheet(name, title, path, settings): """ Create Google spreadsheet. """ if not settings.client_secrets: return None create = raw_input("Would you like to create a Google spreadsheet? [Y/n] ") if create and not create.lower() == "y": return puts("Not creating spreadsheet.") email_message = ( "What Google account(s) should have access to this " "this spreadsheet? (Use a full email address, such as " "[email protected]. Separate multiple addresses with commas.)") if settings.config.get("google_account"): emails = raw_input("\n{0}(Default: {1}) ".format(email_message, settings.config.get("google_account") )) if not emails: emails = settings.config.get("google_account") else: emails = None while not emails: emails = raw_input(email_message) try: media_body = _MediaFileUpload(os.path.join(path, '_blueprint/_spreadsheet.xlsx'), mimetype='application/vnd.ms-excel') except IOError: show_error("_blueprint/_spreadsheet.xlsx doesn't exist!") return None service = get_drive_api() body = { 'title': '{0} (Tarbell)'.format(title), 'description': '{0} ({1})'.format(title, name), 'mimeType': 'application/vnd.ms-excel', } try: newfile = service.files()\ .insert(body=body, media_body=media_body, convert=True).execute() for email in emails.split(","): _add_user_to_file(newfile['id'], service, user_email=email.strip()) puts("\n{0}! View the spreadsheet at {1}".format( colored.green("Success"), colored.yellow("https://docs.google.com/spreadsheet/ccc?key={0}" .format(newfile['id'])) )) return newfile['id'] except errors.HttpError, error: show_error('An error occurred creating spreadsheet: {0}'.format(error)) return None