def upload_files(basedir, client): """Upload files to Dropbox. Looks for files ending with 'tar.xz' inside basedir. :param: basedir (string) path of the folder with the files to be uploaded. :param: client (object) DropboxClient object. :raise: ValueError if the .xz file doesn't have an .asc file. :raise: UploadError if something goes wrong while uploading the files to Dropbox. All files are uploaded to '/'. :return: (list) the names of the uploaded files. """ files = [] for name in os.listdir(basedir): path = os.path.abspath(os.path.join(basedir, name)) if os.path.isfile(path) and valid_format(name, 'linux'): files.append(name) for name in os.listdir(basedir): path = os.path.abspath(os.path.join(basedir, name)) if os.path.isfile(path) and valid_format(name, 'windows'): files.append(name) for name in os.listdir(basedir): path = os.path.abspath(os.path.join(basedir, name)) if os.path.isfile(path) and valid_format(name, 'osx'): files.append(name) for file in files: asc = "%s.asc" % file abs_file = os.path.abspath(os.path.join(basedir, file)) abs_asc = os.path.abspath(os.path.join(basedir, asc)) if not os.path.isfile(abs_asc): # there are some .mar files that don't have .asc, don't upload it continue # chunk upload for big files to_upload = open(abs_file, 'rb') size = os.path.getsize(abs_file) uploader = client.get_chunked_uploader(to_upload, size) while uploader.offset < size: try: upload = uploader.upload_chunked() except dropbox.rest.ErrorResponse, e: print("An error ocurred while uploading %s: %s" % abs_file, e) uploader.finish(file) print "Uploading %s" % file # this should be small, upload it simple to_upload_asc = open(abs_asc, 'rb') response = client.put_file(asc, to_upload_asc) print "Uploading %s" % asc
def upload_files(client, basedir): """Upload files to Google Drive. Looks for tor browser files inside basedir. :param: basedir (string) path of the folder with the files to be uploaded. :param: client (object) Google Drive object. :raise: UploadError if something goes wrong while uploading the files to Google Drive. All files are uploaded to '/'. :return: (dict) the names of the uploaded files as the keys, and file id as the value """ files = [] for name in os.listdir(basedir): path = os.path.abspath(os.path.join(basedir, name)) if os.path.isfile(path) and valid_format(name, 'linux'): files.append(name) for name in os.listdir(basedir): path = os.path.abspath(os.path.join(basedir, name)) if os.path.isfile(path) and valid_format(name, 'windows'): files.append(name) for name in os.listdir(basedir): path = os.path.abspath(os.path.join(basedir, name)) if os.path.isfile(path) and valid_format(name, 'osx'): files.append(name) # dictionary to store file names and IDs files_dict = dict() for file in files: asc = "%s.asc" % file abs_file = os.path.abspath(os.path.join(basedir, file)) abs_asc = os.path.abspath(os.path.join(basedir, asc)) if not os.path.isfile(abs_asc): # there are some .mar files that don't have .asc, don't upload it continue # upload tor browser installer file_body = MediaFileUpload(abs_file, mimetype="application/octet-stream", resumable=True) body = {'title': file} print "Uploading '%s'..." % file try: file_data = drive_service.files().insert( body=body, media_body=file_body).execute() except errors.HttpError, e: print str(e) # upload signature asc_body = MediaFileUpload(abs_asc, resumable=True) asc_head = {'title': "%s.asc" % file} print "Uploading '%s'..." % asc try: asc_data = drive_service.files().insert( body=asc_head, media_body=asc_body).execute() except errors.HttpError, e: print str(e)
def upload_files(client, basedir): """Upload files to Google Drive. Looks for tor browser files inside basedir. :param: basedir (string) path of the folder with the files to be uploaded. :param: client (object) Google Drive object. :raise: UploadError if something goes wrong while uploading the files to Google Drive. All files are uploaded to '/'. :return: (dict) the names of the uploaded files as the keys, and file id as the value """ files = [] for name in os.listdir(basedir): path = os.path.abspath(os.path.join(basedir, name)) if os.path.isfile(path) and valid_format(name, 'linux'): files.append(name) for name in os.listdir(basedir): path = os.path.abspath(os.path.join(basedir, name)) if os.path.isfile(path) and valid_format(name, 'windows'): files.append(name) for name in os.listdir(basedir): path = os.path.abspath(os.path.join(basedir, name)) if os.path.isfile(path) and valid_format(name, 'osx'): files.append(name) # dictionary to store file names and IDs files_dict = dict() for file in files: asc = "%s.asc" % file abs_file = os.path.abspath(os.path.join(basedir, file)) abs_asc = os.path.abspath(os.path.join(basedir, asc)) if not os.path.isfile(abs_asc): # there are some .mar files that don't have .asc, don't upload it continue # upload tor browser installer file_body = MediaFileUpload( abs_file, mimetype="application/octet-stream", resumable=True ) body = { 'title': file } print "Uploading '%s'..." % file try: file_data = drive_service.files().insert( body=body, media_body=file_body ).execute() except errors.HttpError, e: print str(e) # upload signature asc_body = MediaFileUpload(abs_asc, resumable=True) asc_head = { 'title': "%s.asc" % file } print "Uploading '%s'..." % asc try: asc_data = drive_service.files().insert( body=asc_head, media_body=asc_body ).execute() except errors.HttpError, e: print str(e)