Last active
May 22, 2019 12:04
-
-
Save sbalnojan/27ce558bddcf75a0dd707775155a150e to your computer and use it in GitHub Desktop.
Mini Cli to copy tree to S3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import s3fs | |
import fire | |
import os | |
class S3CopyMachine(object): | |
"""Copy to S3 via s3fs.""" | |
def to_s3(self, local_bucket, s3_bucket): | |
fs = s3fs.S3FileSystem(anon=False) # connecting to S3 | |
main_root = os.path.join(os.getcwd(),local_bucket) | |
for root, subdirs, files in os.walk(main_root): | |
print('--\nroot = ' + root) | |
for subdir in subdirs: | |
print('\t- subdirectory ' + subdir) | |
for filename in files: | |
file_path = os.path.join(root, filename) | |
rel_path = os.path.relpath(file_path, main_root) | |
print('\t- file %s (full path: %s, rel. path: %s)' % (filename, file_path, rel_path)) | |
fs.put(file_path,s3_bucket + "/" + rel_path) | |
return 0 | |
if __name__ == '__main__': | |
fire.Fire(S3CopyMachine) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment