Skip to content

Commit

Permalink
Merge pull request #44 from UAL-RE/Issue_43
Browse files Browse the repository at this point in the history
Address Issue 43 - Enhance ReBACH to accept specific article and collection IDs for selective processing
  • Loading branch information
zoidy authored Jun 3, 2023
2 parents f329833 + 82efcc4 commit 6132f51
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 27 deletions.
51 changes: 25 additions & 26 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
import os
import argparse
from Log import Log
from figshare.Article import Article
from time import asctime
from Config import Config
from figshare.Collection import Collection
import sys
from pathlib import Path

args = None


def get_args():
"""
Parse command line arguments
"""
global args
parser = argparse.ArgumentParser(description='ReDATA preservation software (ReBACH)', prog='ReBACH', allow_abbrev=False)
parser.add_argument('--version', action='version', version='%(prog)s 1.0.0')
parser.add_argument('--xfg', required=True, type=Path, help='Path to the ReBACH configuration file. E.g., .env.ini')
parser.add_argument('--ids', type=lambda s: [int(item) for item in s.split(',')],
help='list of article and/or collection IDs to process. E.g., "2323,4353,5454"')
args = parser.parse_args()


def check_logs_path_access(config_file):
Expand Down Expand Up @@ -33,37 +49,19 @@ def check_logs_path_access(config_file):
exit()


def get_config_file_path():
args = sys.argv

if (len(args) == 1 or args[1] == ''):
print(asctime() + ":ERROR: Log - " + "First parameter must be configuration (.ini) file.")
exit()

path_val = args[1]
path_val = path_val.strip()
check_path = path_val.split('.')[-1]
if (check_path != 'ini'):
print(asctime() + ":ERROR: Log - " + "Configuration file extension must be .ini .")
exit()

file_exists = os.path.exists(path_val)

if (file_exists is False):
print(asctime() + ":ERROR: Log - " + "Configuration file is missing on the given path.")
exit()

return path_val


def main():
print(asctime() + ":Info: Log - ReBACH script has started.")
"""
This function will be called first.
Setting up required variables and conditions.
"""
global args
print(asctime() + ":Info: Log - ReBACH script has started.")

# Check .env file exists.
env_file = get_config_file_path()
if not args.xfg.is_file():
print(asctime() + ":ERROR: Log - " + "Configuration file is missing or cannot be read.")
exit()
env_file = str(args.xfg)
print(asctime() + ":Info: Log - " + "Env file:" + env_file)
print(asctime() + ":Info: Log - " + "Checking configuration file.")
config_obj = Config(env_file)
Expand Down Expand Up @@ -134,6 +132,7 @@ def main():


if __name__ == "__main__":
get_args()
config_file_path = main()
log = Log(config_file_path)

Expand Down
2 changes: 1 addition & 1 deletion bagger/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,6 @@ def get_args(path: Optional[PathLike] = None,
help='Log execution steps without actually executing. (default: False)',
action='store_true')
parser.add_argument('path', help='Path to the package or batch directory.')
args = parser.parse_args(remaining_argv)
args, remaining_argv = parser.parse_known_args(remaining_argv)

return args, config

0 comments on commit 6132f51

Please sign in to comment.