forked from wishful-project/examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwishful_simple_agent
executable file
·88 lines (68 loc) · 2.04 KB
/
wishful_simple_agent
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
wishful_agent_simple.py: First implementation of WiSHFUL agent
sudo su REQUIRED !! see readme.txt
Usage:
wishful_agent_simple.py [options] [-q | -v]
Options:
--logfile name Name of the logfile
--config configFile Config file path
Example:
./wishful_agent_simple -v --config ./config.yaml
Other options:
-h, --help show this help message and exit
-q, --quiet print less text
-v, --verbose print more text
--version show version and exit
"""
import logging
import signal
import yaml
import sys, os
import wishful_agent
__author__ = "Piotr Gawlowicz, Mikolaj Chwalisz"
__copyright__ = "Copyright (c) 2015, Technische Universität Berlin"
__version__ = "0.1.0"
__email__ = "{gawlowicz, chwalisz}@tkn.tu-berlin.de"
simpleModuleLogger = logging.getLogger('SimpleModule2')
simpleModuleLogger.setLevel(logging.CRITICAL)
log = logging.getLogger('wishful_agent.main')
agent = wishful_agent.Agent()
def main(args):
log.debug(args)
config_file_path = args['--config']
config = None
with open(config_file_path, 'r') as f:
config = yaml.load(f)
agent.load_config(config)
agent.run()
if __name__ == "__main__":
try:
from docopt import docopt
except:
print("""
Please install docopt using:
pip install docopt==0.6.1
For more refer to:
https://github.com/docopt/docopt
""")
raise
args = docopt(__doc__, version=__version__)
log_level = logging.INFO # default
if args['--verbose']:
log_level = logging.DEBUG
elif args['--quiet']:
log_level = logging.ERROR
logfile = None
if args['--logfile']:
logfile = args['--logfile']
logging.basicConfig(filename=logfile, level=log_level,
format='%(asctime)s - %(name)s.%(funcName)s() - %(levelname)s - %(message)s')
try:
main(args)
except KeyboardInterrupt:
log.debug("Agent exits")
finally:
log.debug("Exit")
agent.stop()