forked from ateska/ramona
-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.py
executable file
·46 lines (34 loc) · 1.24 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
#!/usr/bin/env python
#
# 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"))
@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()