Skip to content

Commit 6132f51

Browse files
authored
Merge pull request #44 from UAL-RE/Issue_43
Address Issue 43 - Enhance ReBACH to accept specific article and collection IDs for selective processing
2 parents f329833 + 82efcc4 commit 6132f51

File tree

2 files changed

+26
-27
lines changed

2 files changed

+26
-27
lines changed

app.py

+25-26
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,26 @@
11
import os
2+
import argparse
23
from Log import Log
34
from figshare.Article import Article
45
from time import asctime
56
from Config import Config
67
from figshare.Collection import Collection
7-
import sys
8+
from pathlib import Path
9+
10+
args = None
11+
12+
13+
def get_args():
14+
"""
15+
Parse command line arguments
16+
"""
17+
global args
18+
parser = argparse.ArgumentParser(description='ReDATA preservation software (ReBACH)', prog='ReBACH', allow_abbrev=False)
19+
parser.add_argument('--version', action='version', version='%(prog)s 1.0.0')
20+
parser.add_argument('--xfg', required=True, type=Path, help='Path to the ReBACH configuration file. E.g., .env.ini')
21+
parser.add_argument('--ids', type=lambda s: [int(item) for item in s.split(',')],
22+
help='list of article and/or collection IDs to process. E.g., "2323,4353,5454"')
23+
args = parser.parse_args()
824

925

1026
def check_logs_path_access(config_file):
@@ -33,37 +49,19 @@ def check_logs_path_access(config_file):
3349
exit()
3450

3551

36-
def get_config_file_path():
37-
args = sys.argv
38-
39-
if (len(args) == 1 or args[1] == ''):
40-
print(asctime() + ":ERROR: Log - " + "First parameter must be configuration (.ini) file.")
41-
exit()
42-
43-
path_val = args[1]
44-
path_val = path_val.strip()
45-
check_path = path_val.split('.')[-1]
46-
if (check_path != 'ini'):
47-
print(asctime() + ":ERROR: Log - " + "Configuration file extension must be .ini .")
48-
exit()
49-
50-
file_exists = os.path.exists(path_val)
51-
52-
if (file_exists is False):
53-
print(asctime() + ":ERROR: Log - " + "Configuration file is missing on the given path.")
54-
exit()
55-
56-
return path_val
57-
58-
5952
def main():
60-
print(asctime() + ":Info: Log - ReBACH script has started.")
6153
"""
6254
This function will be called first.
6355
Setting up required variables and conditions.
6456
"""
57+
global args
58+
print(asctime() + ":Info: Log - ReBACH script has started.")
59+
6560
# Check .env file exists.
66-
env_file = get_config_file_path()
61+
if not args.xfg.is_file():
62+
print(asctime() + ":ERROR: Log - " + "Configuration file is missing or cannot be read.")
63+
exit()
64+
env_file = str(args.xfg)
6765
print(asctime() + ":Info: Log - " + "Env file:" + env_file)
6866
print(asctime() + ":Info: Log - " + "Checking configuration file.")
6967
config_obj = Config(env_file)
@@ -134,6 +132,7 @@ def main():
134132

135133

136134
if __name__ == "__main__":
135+
get_args()
137136
config_file_path = main()
138137
log = Log(config_file_path)
139138

bagger/config/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,6 @@ def get_args(path: Optional[PathLike] = None,
7474
help='Log execution steps without actually executing. (default: False)',
7575
action='store_true')
7676
parser.add_argument('path', help='Path to the package or batch directory.')
77-
args = parser.parse_args(remaining_argv)
77+
args, remaining_argv = parser.parse_known_args(remaining_argv)
7878

7979
return args, config

0 commit comments

Comments
 (0)