Gentoo Archives: gentoo-dev

From: "Sérgio Almeida" <mephx.x@×××××.com>
To: Gentoo SoC <gentoo-soc@l.g.o>
Cc: Gentoo Dev <gentoo-dev@l.g.o>
Subject: [gentoo-dev] Re: Progress on Universal Select Tool
Date: Wed, 22 Jul 2009 18:42:04
Message-Id: 1248288117.7494.34.camel@thedude
In Reply to: [gentoo-dev] Progress on Universal Select Tool by "Sérgio Almeida"
1 Hello,
2
3 This has been a very productive week regarding uselect.
4
5 I'm still not doing any commits as uselect can still break your python
6 environment while testing and i don't have the time to learn how to
7 handle branches in git.
8
9 Status:
10
11 * Fully Converted all action types to new module syntax
12 * Infinite symlinking dependency fully working
13 * Runnable Actions now support dynamic usage showing
14
15 An example fully commented module follows
16
17 ### Start of Module
18
19 #!/usr/bin/env python
20 # Copyright 1999-2009 Gentoo Foundation
21 # Distributed under the terms of the GNU General Public License v2
22 # python.py mephx.x@×××××.com
23 # (will explain .py instead of .uselect below)
24 # still lacking vim/emacs python line
25
26 from umodule import *
27
28 # We Create The Module
29 module = Module(name = "python", description = "Python Version
30 Switcher", version = "0.1", author ="mephx.x@×××××.com")
31
32 # We Create a Linking Action
33 action_bin = Action (name = 'bin', description = "Change Python's
34 Version", type = "sym")
35
36 # We Create a Link
37 link_python = Link(alias = "python", target = "/usr/bin/python", prefix
38 = "/usr/bin/", regexp = "python([0-9]+\.[0-9]+$)")
39
40 # We Create Another Link
41 link_python_config = Link(alias = "python-config", target =
42 "/usr/bin/python-config", prefix = "/usr/bin/", regexp =
43 "python([0-9]+\.[0-9]+)-config$")
44
45 # Make the link "python_config" depend of "link_python"
46 link_python.add_link(link_python_config)
47
48 # Add the link to the action
49 action_bin.add_link(python)
50
51 # Add the action to the module
52 module.add_action(action_bin)
53
54
55 # We create a simple runnable action that "tests" python environment
56 test = Action (name = 'test', description = 'Test Python Environment',
57 type = 'runnable')
58
59 # We add the parameters/arguments
60
61 test.add_parameter('<times>')
62 test.add_parameter('[<what>]')
63
64 # We add the usage code
65
66 test.add_usage("""#!/usr/bin/python
67 print "Python Test will echo <times> * <what>"
68 print "Usage can be multi-line Yay!"
69 print ""
70 for i in range(5):
71 print "Usage can have dynamic options! " + str(i)
72 """)
73
74 # We add the action code
75 test.add_code("""#!/usr/bin/python
76 import sys
77
78 def is_number(s):
79 try:
80 int(s)
81 return True
82 except ValueError:
83 return False
84
85 argv = sys.argv[1:]
86 times = sys.argv[1:][0]
87 if is_number(times):
88 times = int(times)
89 if len(argv) >= 2:
90 what = sys.argv[1:][1]
91 else:
92 what = 'Hello World...'
93 print str(what) * times
94 else:
95 print 'Invalid Option(s)'
96 exit(1)
97 exit(0)
98 """)
99
100 # We add the action to the module
101 module.add_action(test)
102
103 ### End of Module
104
105
106 So... what's the output of this?
107
108 ### Start Examples
109
110 * uselect
111
112 Usage: uselect <options> <module> <action>
113
114 Options:
115 -v (*) Verbose Mode
116 -nc (*) No Colors
117 -version (*) Version Information
118
119 Modules:
120 python (*) Python Version Switcher
121 gcc (*) Python GCC Version Switcher
122
123 * uselect python
124
125 Usage: uselect <options> python <action>
126
127 Module python:
128 Author: mephx.x@×××××.com Version: 0.1
129
130 Actions:
131 bin Change Python's Version
132 test Test Python Environment
133
134
135 * uselect python bin
136
137 Usage: uselect <options> python bin <target> ... <target>
138
139 Change Python's Version
140
141 0 - /usr/bin/python2.6 - (>)
142 1 - /usr/bin/python2.6-config - (>)
143 2 - /usr/bin/python2.5-config - (!)
144 3 - /usr/bin/python2.5 - (!)
145 4 - /usr/bin/python2.6-config - (>)
146 5 - /usr/bin/python2.5-config - (!)
147
148 * uselect python bin 2
149
150 Setting /usr/bin/python2.5-config success!
151 Setting /usr/bin/python2.6 success
152
153 * uselect python bin (again)
154
155 Usage: uselect <options> python bin <target> ... <target>
156
157 Change Python's Version
158
159 0 - /usr/bin/python2.6 - (>)
160 1 - /usr/bin/python2.6-config - (!)
161 2 - /usr/bin/python2.5-config - (>)
162 3 - /usr/bin/python2.5 - (!)
163 4 - /usr/bin/python2.6-config - (>)
164 5 - /usr/bin/python2.5-config - (!)
165
166 * uselect python test
167
168 Usage: uselect <options> python test <times> [<what>]
169
170 Test Python Environment
171
172 Python Test will echo <times> * <what>
173 Usage can be multi-line Yay!
174
175 Usage can have dynamic options! 0
176 Usage can have dynamic options! 1
177 Usage can have dynamic options! 2
178 Usage can have dynamic options! 3
179 Usage can have dynamic options! 4
180
181 * uselect python test 10 "yeah! "
182
183 yeahyeahyeahyeahyeahyeahyeahyeahyeahyeah
184
185 I guess this is all for the past week. Symlinking dependency really
186 cranked my brain and almost got me stuck.
187
188 Next steps:
189
190 * add the --system option for system-wide changes
191 * Implement env actions
192 * Structure folders ".uselect/" (probabily will have a bin folder and a
193 env.d folder)
194 * Start structuring uprofile application and api
195 * Profiles will be xml/json (and will use this part of code to uselect
196 too)
197
198
199 * Call for ideas
200
201 * Python gurus: Atm i'm retrieving the module from .uselect
202 files this way:
203
204 def get_modules(self):
205 self.modules = []
206 for module in filesystem.list_dir(modules_dir):
207 if re.match('__init__.py$', module):
208 continue
209 match = re.match('(.*).py$', module)
210 if match:
211 import modules
212 modname = match.group(1)
213 modpath = 'modules.'+ modname
214 __import__(modpath)
215 module = eval(modpath + '.module')
216 self.modules.append(module)
217
218 This is a bit ugly. Should there be a better way? I can't seem
219 to achieve one. This is the reason why new modules are still
220 called module.py and not module.uselect as should be.
221
222
223 * If you are a developer of any eselect modules or
224 something-config please reply with suggestions. All ideas are
225 welcome.
226
227 * Everyone else:
228 User profiles will stand in ~/.uselect
229 Folder Profiles will stand in $FOLDER/.uselect
230 What about group profiles?
231
232 Modules like bash-completion work in a "env.d" style. Should an
233 action type be created for actions like these (I believe they
234 are very common).
235
236 Well, all ideas are welcome again.
237
238 P.S: I have successfully passed the first midterm evaluation. Thanks to
239 everyone that has contributed to this new project, especially my mentor
240 Sébastien Fabbro (bicatali).
241
242 Cheers,
243 Sérgio
244
245 --
246 Sérgio Almeida - mephx.x@×××××.com
247 mephx @ freenode

Attachments

File name MIME type
signature.asc application/pgp-signature

Replies

Subject Author
[gentoo-dev] Re: [gentoo-soc] Re: Progress on Universal Select Tool Nirbheek Chauhan <nirbheek@g.o>