-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtemplate_yaml_cli.py
More file actions
executable file
·62 lines (43 loc) · 1.44 KB
/
template_yaml_cli.py
File metadata and controls
executable file
·62 lines (43 loc) · 1.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
#! /usr/bin/env python3
import sys
import os
import argparse
import yaml
#sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir)))
NAME = os.path.basename(os.path.realpath(__file__))
DESCRIPTION = "\n" \
"\n" \
"usage: %s [options]\n" % NAME
EPILOG = "\n" \
"\n" \
"Examples:\n" \
"\tSomething\n" \
"\n"
DEFAULT_YAML_CONFIG = "config.yaml"
def main(argv):
#Parse out the commandline arguments
parser = argparse.ArgumentParser(
formatter_class=argparse.RawDescriptionHelpFormatter,
description=DESCRIPTION,
epilog=EPILOG
)
parser.add_argument("-c", "--config",
nargs=1,
default=[DEFAULT_YAML_CONFIG])
parser.add_argument("-d", "--debug",
action="store_true",
help="Enable Debug Messages")
args = parser.parse_args()
print ("Running Script: %s" % NAME)
if args.debug:
print ("YAML Config File: %s" % str(args.config[0]))
yconfig = None
with open(args.config[0]) as f:
yconfig = yaml.safe_load(f)
print ("String: %s" % yconfig["test_str"])
print ("Integer: %d" % yconfig["test_int"])
print ("Float: %f" % yconfig["test_float"])
print ("List: %s" % str(yconfig["test_list"]))
print ("Dict: %s" % str(yconfig["test_dict"]))
if __name__ == "__main__":
main(sys.argv)