|
1 | 1 | import os
|
| 2 | +import argparse |
2 | 3 | from Log import Log
|
3 | 4 | from figshare.Article import Article
|
4 | 5 | from time import asctime
|
5 | 6 | from Config import Config
|
6 | 7 | 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() |
8 | 24 |
|
9 | 25 |
|
10 | 26 | def check_logs_path_access(config_file):
|
@@ -33,37 +49,19 @@ def check_logs_path_access(config_file):
|
33 | 49 | exit()
|
34 | 50 |
|
35 | 51 |
|
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 |
| - |
59 | 52 | def main():
|
60 |
| - print(asctime() + ":Info: Log - ReBACH script has started.") |
61 | 53 | """
|
62 | 54 | This function will be called first.
|
63 | 55 | Setting up required variables and conditions.
|
64 | 56 | """
|
| 57 | + global args |
| 58 | + print(asctime() + ":Info: Log - ReBACH script has started.") |
| 59 | + |
65 | 60 | # 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) |
67 | 65 | print(asctime() + ":Info: Log - " + "Env file:" + env_file)
|
68 | 66 | print(asctime() + ":Info: Log - " + "Checking configuration file.")
|
69 | 67 | config_obj = Config(env_file)
|
@@ -134,6 +132,7 @@ def main():
|
134 | 132 |
|
135 | 133 |
|
136 | 134 | if __name__ == "__main__":
|
| 135 | + get_args() |
137 | 136 | config_file_path = main()
|
138 | 137 | log = Log(config_file_path)
|
139 | 138 |
|
|
0 commit comments