From c8b229a214e860f5324a3a54044bb931ce9a544a Mon Sep 17 00:00:00 2001 From: Rosie Storey Date: Fri, 2 Nov 2018 15:38:58 -0400 Subject: [PATCH] Beginning of an experiment --- bagit.py | 64 ++++++++++++++++++++++++++++++++++++-------------------- setup.py | 1 + 2 files changed, 42 insertions(+), 23 deletions(-) diff --git a/bagit.py b/bagit.py index a821973..8e6e9f1 100755 --- a/bagit.py +++ b/bagit.py @@ -136,36 +136,16 @@ def find_locale_dir(): UNICODE_BYTE_ORDER_MARK = "\uFEFF" -def make_bag( - bag_dir, bag_info=None, processes=1, checksums=None, checksum=None, encoding="utf-8" -): - """ - Convert a given directory into a bag. You can pass in arbitrary - key/value pairs to put into the bag-info.txt metadata file as - the bag_info dictionary. - """ - - if checksum is not None: - warnings.warn( - _( - "The `checksum` argument for `make_bag` should be replaced with `checksums`" - ), - DeprecationWarning, - ) - checksums = checksum - - if checksums is None: - checksums = DEFAULT_CHECKSUMS - +def create_filesystem_bag(bag_dir): bag_dir = os.path.abspath(bag_dir) cwd = os.path.abspath(os.path.curdir) if cwd.startswith(bag_dir) and cwd != bag_dir: raise RuntimeError( _("Bagging a parent of the current directory is not supported") + ) - LOGGER.info(_("Creating bag for directory %s"), bag_dir) if not os.path.isdir(bag_dir): LOGGER.error(_("Bag directory %s does not exist"), bag_dir) @@ -266,6 +246,39 @@ def make_bag( finally: os.chdir(old_dir) + +def create_s3_bag(bag_dir): + pass + +def make_bag( + bag_dir, bag_info=None, processes=1, checksums=None, checksum=None, encoding="utf-8" +): + """ + Convert a given directory into a bag. You can pass in arbitrary + key/value pairs to put into the bag-info.txt metadata file as + the bag_info dictionary. + """ + + if checksum is not None: + warnings.warn( + _( + "The `checksum` argument for `make_bag` should be replaced with `checksums`" + ), + DeprecationWarning, + ) + checksums = checksum + + if checksums is None: + checksums = DEFAULT_CHECKSUMS + + if bag_dir.startswith("s3://"): + # Instantiate boto client + LOGGER.info(_("Creating bag directory on S3 location: %s"), bag_dir) + create_s3_bag(bag_dir) + else: + LOGGER.info(_("Creating bag for directory %s"), bag_dir) + create_filesystem_bag(bag_dir) + return Bag(bag_dir) @@ -297,7 +310,12 @@ def __init__(self, path=None): self.algorithms = [] self.tag_file_name = None - self.path = abspath(path) + if(path.startswith("s3://")): + self.path = path + S3_MODE = True + else: + self.path = abspath(path) + S3_MODE = False if path: # if path ends in a path separator, strip it off if path[-1] == os.sep: diff --git a/setup.py b/setup.py index 0374e01..5d99a96 100644 --- a/setup.py +++ b/setup.py @@ -76,5 +76,6 @@ def get_message_catalogs(): "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", + "Programming Language :: Python :: 3.7", ], )