Skip to content

Commit

Permalink
Move get_storage_root into ocfl.py where it is used
Browse files Browse the repository at this point in the history
  • Loading branch information
zimeon committed Oct 9, 2024
1 parent c601f93 commit abd66b0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
16 changes: 15 additions & 1 deletion ocfl.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import sys

import ocfl # pylint: disable=import-self; this isn't actually self import
from ocfl.command_line_utils import add_version_arg, add_verbosity_args, check_version_arg, check_verbosity_args, get_storage_root
from ocfl.command_line_utils import add_version_arg, add_verbosity_args, check_version_arg, check_verbosity_args


def add_common_args(parser):
Expand Down Expand Up @@ -116,6 +116,20 @@ def validate(store, args):
print("Storage root %s is INVALID" % (store.root))


def get_storage_root(args):
"""Get OCFL storage root from --root argument or from $OCFL_ROOT.
Returns path string. Will throw error if the root is not set.
"""
if args.root:
return args.root
env_root = os.getenv('OCFL_ROOT')
if env_root is not None:
return env_root
logging.error("The storage root must be set either via --root or $OCFL_ROOT")
sys.exit(1)


def do_store_operation(args):
"""Do operation on store based on args."""
store = ocfl.StorageRoot(root=get_storage_root(args),
Expand Down
14 changes: 0 additions & 14 deletions ocfl/command_line_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,3 @@ def check_verbosity_args(args):
elif args.quiet:
level = logging.ERROR
logging.basicConfig(level=level)


def get_storage_root(args):
"""Get OCFL storage root from --root argument or from $OCFL_ROOT.
Returns path string. Will throw error if the root is not set.
"""
if args.root:
return args.root
env_root = os.getenv('OCFL_ROOT')
if env_root is not None:
return env_root
logging.error("The storage root must be set either via --root or $OCFL_ROOT")
sys.exit(1)

0 comments on commit abd66b0

Please sign in to comment.