summaryrefslogtreecommitdiff
blob: c850505c642237ab9212c70401e4c6751e388e1c (plain)
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
#!/usr/bin/env python
# Copyright 1999-2009 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# python.uselect mephx.x@gmail.com

from umodule import *

module = Module(name = "python", description = "Python Version Switcher", version = "0.1", author ="mephx.x@gmail.com") # We define the module


bin = Action (name = 'bin', description = "Change Python's Version", type = "sym") # Define a Symlinking Action
python = Link(alias = "python", target = "/usr/bin/python", prefix = "/usr/bin/", regexp = "python([0-9]+\.[0-9]+$)") 
python_config = Link(alias = "python-config", target = "/usr/bin/python-config", prefix = "/usr/bin/", regexp = "python([0-9]+\.[0-9]+)-config$")
python.add_link(python_config) # For inheritance
bin.add_link(python) # Adding The Link to the action

module.add_action(bin) #Adding the action to the module

test = Action (name = 'test', description = 'Test Python Environment', type = 'runnable')

test.add_parameter('<times>')
test.add_parameter('[<what>]') # optional notation

test.add_usage("""#!/usr/bin/python
print "Python Test will echo <times> * <what>"
print "Usage can be multi-line Yay!"
print ""
for i in range(5):
	print "Usage can have dynamic options! " + str(i)
""")

test.add_code("""#!/usr/bin/python
import sys

def is_number(s):
    try:
        int(s)
        return True
    except ValueError:
        return False
		
argv = sys.argv[1:]
times = sys.argv[1:][0]
if is_number(times):
	times = int(times)	
	if len(argv) >= 2:
		what = sys.argv[1:][1]
	else: 
		what = 'Hello World...'
	print str(what) * times
else:
	print 'Invalid Option(s)'
	exit(1)
exit(0)
""")


module.add_action(test)

env = Action (name = 'env', description = 'Some env test', type = 'env')
path_var = env.get_var(name = 'PATH')

path_var.add_value(value = '~/.uselect/bin/')

module.add_action(env)