12345678910111213141516171819202122232425262728293031 |
- def upload_dir(dirpath,bucket_name=None):
- client = set_client()
- if not os.path.isdir(dirpath):
- raise Exception("Not a Valid Directory :%s" % (dirpath))
- bucket = BUCKET_NAME
- if bucket_name:
- bucket = bucket_name
- file_count = 0
- error_count = 0
- print(color("Initializing ...\n",fg="yellow"))
- for (root, dirs, filenames) in os.walk(top=dirpath, topdown=True):
- for filename in filenames:
- filepath = os.path.join(root, filename)
- try:
- print(color("%s \nuploading...\n"%filepath,fg='blue'))
- client.upload_file(filepath, bucket ,os.path.abspath(filepath) ,Callback=ProgressPercentage(filepath))
- print(color("Success\n",fg="lime"))
- file_count += 1
- except Exception as e:
- logging.error('FilePath: %s' % filepath, exc_info=True)
- error_count += 1
- print(color("Error encountered: %s"%e,fg="#ff1a1a"))
- log_error("%s\n"%filepath)
- continue
-
- print(color("Total number of files uploaded: %d.\n" % file_count,fg="lime"))
- print(color("Total number of errors encountered: %d." % error_count,fg="#ff1a1a"))
- if error_count > 1:
- print(color("Please Check the log file located at .logs in the current working directory",fg='#ff1a1a'))
|