-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcleanup-doi
More file actions
executable file
·90 lines (73 loc) · 2.44 KB
/
cleanup-doi
File metadata and controls
executable file
·90 lines (73 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/env python3
'''
cleanup-doi retrieves the previously saved processed doi
checks if they exist in EPrints or have status == 'imported' and
drops the rows from the doi table that match.
'''
import os
import sys
from acacia.settings import settings_example
from acacia.messages import EMailProcessor
from acacia.doi import DOIProcessor
from decouple import config
_db = config('DATABASE', 'acacia.db')
def usage(app_name, db_name, exit_code = None):
'''Describe how cleanup-doi cli works'''
print(f'''
USAGE: {app_name}
This program reads the doi table in {db_name}
and drops rows that have an eprint_id or status equal
of imported.
It requires that both the doi and message tables exist
in {db_name}. See configure-database if tables
do not already exist.
A "settings.ini" file needs to exist and be configured.
See example file and create it if necessary.
OPTIONS:
-h, --help this help page
--dry-run run process but don't update or
save records
EXAMPLE
Cleanup the doi table in {{db_name}}.
```
./cleanup-doi
```
You can now look at the web application for further
processing.
''')
if exit_code != None:
sys.exit(exit_code)
def apply(app_name, _db, args):
dry_run = False
for arg in args:
if arg.startswith('-'):
if arg.startswith('--dry-run'):
if "=" in arg:
p = arg.split("=", 2)
if (len(p) == 2) and (p[1].lower() == 'true'):
dry_run = True
elif (len(p) == 2) and (p[1].lower() == 'false'):
dry_run = False
else:
print(f'''Don't understand "{p[1]}" for --dry-run''')
exit(1)
else:
dry_run = True
elif arg.startswith('-h') or arg.startswith('--help'):
usage(app_name, _db, 0)
doi_processor = DOIProcessor()
# the request to the SMTP service
err = doi_processor.cleanup_doi_table(dry_run = dry_run)
if err:
print(f'ERROR cleanup_doi_table: {err}')
if dry_run:
sys.exit(1)
if dry_run:
print(f'Dry run: no records cleaned up.')
if __name__ == '__main__':
app_name = os.path.basename(sys.argv[0])
if not os.path.exists('settings.ini'):
print(f'ERROR: Missing settings.ini')
settings_example()
sys.exit(1)
apply(app_name, _db, sys.argv[1:])