This repository was archived by the owner on Apr 14, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathdemo.py
executable file
·50 lines (39 loc) · 1.44 KB
/
demo.py
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
#!/usr/bin/env python2
#
# Released under the BSD license. See LICENSE.txt file for details.
#
import os
import ramona
class MyDemoConsoleApp(ramona.console_app):
@ramona.tool
def tool_demo(self):
"""Printing message about demo of custom ramona.tool"""
print "This is implementation of custom tool (see ./demo.sh --help)"
# Example how to access configuration from tool:
print "Value of env:RAMONADEMO = {0}".format(self.config.get("env", "RAMONADEMO"))
env = ramona.config.get_env()
print "All environment variables", env
print
env_alternative1 = ramona.config.get_env("alternative1")
print "All alternative1 environment variables", env_alternative1
@ramona.tool
class tool_class_demo(object):
"""Demo of custom ramona.tool (class)"""
def init_parser(self, cnsapp, parser):
parser.description = 'You can use methods from argparse module of Python to customize tool (sub)parser.'
parser.add_argument('integers', metavar='N', type=int, nargs='+',
help='an integer for the accumulator'
)
parser.add_argument('--sum', dest='accumulate', action='store_const',
const=sum, default=max,
help='sum the integers (default: find the max)'
)
def main(self, cnsapp, args):
print args.accumulate(args.integers)
@ramona.proxy_tool
def proxy_tool_demo(self, argv):
"""Proxying execution of /bin/ls"""
os.execv('/bin/ls', argv)
if __name__ == '__main__':
app = MyDemoConsoleApp(configuration='./demo.conf')
app.run()