-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.py
More file actions
57 lines (47 loc) · 1.57 KB
/
run.py
File metadata and controls
57 lines (47 loc) · 1.57 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
import sys
import importlib
import hapimeta
def _email(to, subject, body):
import smtplib
from email.mime.text import MIMEText
msg = MIMEText(body)
msg['Subject'] = subject
msg['From'] = to
msg['To'] = to
with smtplib.SMTP('localhost') as server:
server.send_message(msg, from_addr=to, to_addrs=[to])
def main():
args = hapimeta.cli()
if args.command is None:
command_names = importlib.import_module('hapimeta.cli').commands()
else:
command_names = [args.command]
for command_name in command_names:
sys.argv = [sys.argv[0]]
if args.servers is not None:
sys.argv.extend(['--servers', ','.join(args.servers)])
if args.n_servers is not None:
sys.argv.extend(['--n-servers', str(args.n_servers)])
if args.n_datasets is not None:
sys.argv.extend(['--n-datasets', str(args.n_datasets)])
if args.use_remote_catalog:
sys.argv.append('--use-remote-catalog')
try:
module_name = f'hapimeta.generators.{command_name}'
module = importlib.import_module(module_name)
module.run()
except Exception as e:
# Include full stack trace with line numbers in the error message
import traceback
stack_trace = traceback.format_exc()
body = f"Error running {module_name}: \n{stack_trace}"
print(body)
if args.email_on_exception:
try:
_email('rweigel@gmu.edu', "Uncaught hapimeta/run.py exception", body)
except Exception as e2:
print(f"Error sending email: {e2}")
continue
hapimeta.error.combine()
if __name__ == '__main__':
main()