|
a |
|
b/src/pythonargs.py |
|
|
1 |
#!/usr/bin/env python |
|
|
2 |
# -*- coding: utf-8 -*- |
|
|
3 |
""" |
|
|
4 |
DESCRIPTION: Simple Python template with an argument parser. Put all the "main" logic into the method called "main". |
|
|
5 |
Only use the true "__main__" section to add script arguments (and eventually a logger). |
|
|
6 |
|
|
|
7 |
@copyright: Copyright 2018 Deutsches Forschungszentrum fuer Kuenstliche |
|
|
8 |
Intelligenz GmbH or its licensors, as applicable. |
|
|
9 |
|
|
|
10 |
@author: YOU! |
|
|
11 |
""" |
|
|
12 |
|
|
|
13 |
# Base Dependencies |
|
|
14 |
# ----------------- |
|
|
15 |
import os |
|
|
16 |
import sys |
|
|
17 |
import time |
|
|
18 |
import logging |
|
|
19 |
import argparse |
|
|
20 |
import traceback |
|
|
21 |
|
|
|
22 |
|
|
|
23 |
def main(opts): |
|
|
24 |
"""Main loop""" |
|
|
25 |
print("Main run") |
|
|
26 |
|
|
|
27 |
if __name__ == "__main__": |
|
|
28 |
|
|
|
29 |
parser = argparse.ArgumentParser() |
|
|
30 |
parser.add_argument( |
|
|
31 |
"-i", |
|
|
32 |
"--input", |
|
|
33 |
metavar="FILE", |
|
|
34 |
dest="infile", |
|
|
35 |
required=False, |
|
|
36 |
default=None, |
|
|
37 |
help="Input file", |
|
|
38 |
) |
|
|
39 |
|
|
|
40 |
opts = parser.parse_args(sys.argv[1:]) |
|
|
41 |
|
|
|
42 |
try: |
|
|
43 |
main(opts) |
|
|
44 |
except Exception: |
|
|
45 |
print("Unhandled error!") |
|
|
46 |
traceback.print_exc() |
|
|
47 |
sys.exit(-1) |
|
|
48 |
|
|
|
49 |
print("All Done.") |