Skip to content

WIP: Beginning of an S3 experiment #117

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 41 additions & 23 deletions bagit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)


Expand Down Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
)