Gentoo Archives: gentoo-commits

From: "André Erdmann" <dywi@×××××××.de>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/R_overlay:master commit in: /
Date: Mon, 09 Jul 2012 17:19:20
Message-Id: 1341851208.2a93dae11e32165040f1e9af3dd2e49d647c0e05.dywi@gentoo
1 commit: 2a93dae11e32165040f1e9af3dd2e49d647c0e05
2 Author: André Erdmann <dywi <AT> mailerd <DOT> de>
3 AuthorDate: Mon Jul 9 16:26:48 2012 +0000
4 Commit: André Erdmann <dywi <AT> mailerd <DOT> de>
5 CommitDate: Mon Jul 9 16:26:48 2012 +0000
6 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=2a93dae1
7
8 move main.py -> roverlay.py
9
10 modified: README
11 typechange: main.py
12 renamed: main.py -> roverlay.py
13
14 ---
15 README | 2 +-
16 main.py | 242 +-----------------------------------------------
17 main.py => roverlay.py | 0
18 3 files changed, 2 insertions(+), 242 deletions(-)
19
20 diff --git a/README b/README
21 index 542fa30..e9a9f6f 100644
22 --- a/README
23 +++ b/README
24 @@ -9,7 +9,7 @@ There is currently no "R overlay" script, only modules that implement functional
25
26 Real tests are scheduled for July 10 - July 30.
27
28 -A main script is available. See ./main.py --help for usage.
29 +A main script is available. See ./roverlay.py --help for usage.
30
31
32 == Configuration ==
33
34 diff --git a/main.py b/main.py
35 deleted file mode 100755
36 index ce1189f..0000000
37 --- a/main.py
38 +++ /dev/null
39 @@ -1,241 +0,0 @@
40 -#!/usr/bin/env python
41 -
42 -import os
43 -import sys
44 -
45 -# roverlay modules will be imported later
46 -
47 -HIDE_EXCEPTIONS = False
48 -
49 -class DIE ( object ):
50 - NOP = os.EX_OK
51 - ERR = 1
52 - BAD_USAGE = os.EX_USAGE
53 - ARG = 9
54 - CONFIG = os.EX_CONFIG
55 - OV_CREATE = 20
56 - SYNC = 30
57 - CMD_LEFTOVER = 90
58 - IMPORT = 91
59 - UNKNOWN = 95
60 - INTERRUPT = 130
61 -
62 - @staticmethod
63 - def die ( msg=None, code=None ):
64 - code = DIE.ERR if code is None else code
65 - if msg is not None:
66 - sys.stderr.write ( msg + "\n" )
67 -# else:
68 -# sys.stderr.write ( "died.\n" )
69 - sys.exit ( code )
70 - # --- end of die (...) ---
71 -
72 -# --- DIE: exit codes ---
73 -die = DIE.die
74 -
75 -
76 -if __name__ != '__main__':
77 - die ( "Please don't import this script...", DIE.BAD_USAGE )
78 -
79 -
80 -# get args
81 -# imports roverlay.argutil (deleted when done)
82 -
83 -
84 -try:
85 - import roverlay.argutil
86 -except ImportError:
87 - if HIDE_EXCEPTIONS:
88 - die ( "Cannot import roverlay modules!", DIE.IMPORT )
89 - else:
90 - raise
91 -
92 -COMMAND_DESCRIPTION = {
93 - 'sync' : 'sync repos',
94 - 'create' : 'create the overlay '
95 - '(implies sync, override with --nosync)',
96 -# 'depres_console' : 'run an interactive depres console; TODO/REMOVE',
97 - 'nop' : 'does nothing',
98 -}
99 -
100 -commands, config_file, additional_config, extra_opts = \
101 - roverlay.argutil.parse_argv (
102 - CMD_DESC=COMMAND_DESCRIPTION,
103 - DEFAULT_CONFIG="R-overlay.conf"
104 - )
105 -
106 -OPTION = extra_opts.get
107 -
108 -del roverlay.argutil
109 -
110 -# -- load config
111 -
112 -# imports: roverlay, roverlay.config.entryutil (if --help-config)
113 -
114 -try:
115 - import roverlay
116 -except ImportError:
117 - if HIDE_EXCEPTIONS:
118 - die ( "Cannot import roverlay modules!", DIE.IMPORT )
119 - else:
120 - raise
121 -
122 -try:
123 - conf = roverlay.load_config_file (
124 - config_file,
125 - extraconf=additional_config
126 - )
127 - del config_file, additional_config
128 -except:
129 - if HIDE_EXCEPTIONS:
130 - die ( "Cannot load config file {!r}.".format ( config_file ), DIE.CONFIG )
131 - else:
132 - raise
133 -
134 -if OPTION ( 'list_config' ):
135 - try:
136 - from roverlay.config.entryutil import list_entries
137 - print ( "== main config file ==\n" )
138 - print ( list_entries() )
139 - except:
140 - raise
141 - die ( "Cannot list config entries!" )
142 -
143 - EXIT_AFTER_CONFIG = True
144 -
145 -if OPTION ( 'print_config' ):
146 - try:
147 - conf.visualize ( into=sys.stdout )
148 - except:
149 - die ( "Cannot print config!" )
150 - EXIT_AFTER_CONFIG = True
151 -
152 -
153 -if 'EXIT_AFTER_CONFIG' in locals() and EXIT_AFTER_CONFIG:
154 - sys.exit ( os.EX_OK )
155 -
156 -
157 -# -- determine commands to run
158 -# (TODO) could replace this section when adding more actions
159 -# imports roverlay.remote, roverlay.overlay.creator
160 -
161 -actions = set ( filter ( lambda x : x != 'nop', commands ) )
162 -
163 -if 'sync' in actions and OPTION ( 'nosync' ):
164 - die ( "sync command blocked by --nosync opt.", DIE.ARG )
165 -
166 -del commands
167 -
168 -
169 -if not actions:
170 - # this happens if a command is nop
171 - die ( "Nothing to do!", DIE.NOP )
172 -
173 -
174 -# -- import roverlay modules
175 -
176 -try:
177 - from roverlay.remote import RepoList
178 - from roverlay.overlay.creator import OverlayCreator
179 -except ImportError:
180 - if HIDE_EXCEPTIONS:
181 - die ( "Cannot import roverlay modules!", DIE.IMPORT )
182 - else:
183 - raise
184 -
185 -
186 -
187 -# -- run methods (and some vars)
188 -# imports: nothing
189 -
190 -actions_done = set()
191 -set_action_done = actions_done.add
192 -
193 -def optionally ( call, option, *args, **kw ):
194 - if OPTION ( option ):
195 - return call ( *args, **kw )
196 -# --- end of optionally (...) ---
197 -
198 -#repo_list = None
199 -#overlay = None
200 -def run_sync():
201 - if "sync" in actions_done: return
202 - try:
203 - # set up the repo list
204 - global repo_list
205 - repo_list = RepoList (
206 - sync_enabled = not OPTION ( 'nosync' ),
207 - force_distroot = OPTION ( 'force_distroot' )
208 - )
209 -
210 - ## extra_opts->distdir ... TODO
211 - if 'distdirs' in extra_opts:
212 - repo_list.add_distdirs ( OPTION ( 'distdirs' ) )
213 - else:
214 - # default repo list
215 - repo_list.load()
216 -
217 - ## this runs _nosync() or _sync(), depending on extra_opts->nosync
218 - repo_list.sync()
219 -
220 - set_action_done ( "sync" )
221 -
222 - except KeyboardInterrupt:
223 - die ( "Interrupted", DIE.INTERRUPT )
224 - except:
225 - if HIDE_EXCEPTIONS:
226 - die (
227 - "nosync() failed!" if OPTION ( "nosync" ) \
228 - else "sync() failed!",
229 - DIE.SYNC
230 - )
231 - else:
232 - raise
233 -# --- end of run_sync() ---
234 -
235 -def run_overlay_create():
236 - if "create" in actions_done: return
237 - #run_sync()
238 - try:
239 - global overlay
240 - overlay = OverlayCreator()
241 - # explicitly allow overlay writing (FIXME: remove that in OverlayCreator)
242 - overlay.can_write_overlay = OPTION ( 'write_overlay' )
243 -
244 - repo_list.add_packages ( overlay.add_package )
245 -
246 - overlay.run ( close_when_done=True )
247 -
248 - optionally ( overlay.write_overlay, 'write_overlay' )
249 - optionally ( overlay.show_overlay, 'show_overlay' )
250 - if OPTION ( 'print_stats' ): print ( "\n" + overlay.stats_str() )
251 -
252 - set_action_done ( "create" )
253 -
254 - except KeyboardInterrupt:
255 - die ( "Interrupted", DIE.INTERRUPT )
256 - except:
257 - if HIDE_EXCEPTIONS:
258 - die ( "Overlay creation failed.", DIE.OV_CREATE )
259 - else:
260 - raise
261 - finally:
262 - if 'overlay' in locals() and not overlay.closed:
263 - # This is important 'cause it unblocks remaining ebuild creation
264 - # jobs/threads, specifically waiting EbuildJobChannels in depres.
265 - # It also writes the deps_unresolved file
266 - overlay.close()
267 -# --- end of run_overlay_create() ---
268 -
269 -# -- run
270 -
271 -# always run sync 'cause commands = {create,sync} and create implies (no)sync
272 -run_sync()
273 -
274 -if 'create' in actions: run_overlay_create()
275 -
276 -if len ( actions ) > len ( actions_done ):
277 - die (
278 - "Some actions (out of %r) could not be performed!" % actions,
279 - DIE.CMD_LEFTOVER
280 - )
281
282 diff --git a/main.py b/main.py
283 new file mode 120000
284 index 0000000..34b2545
285 --- /dev/null
286 +++ b/main.py
287 @@ -0,0 +1 @@
288 +roverlay.py
289 \ No newline at end of file
290
291 diff --git a/main.py b/roverlay.py
292 similarity index 100%
293 copy from main.py
294 copy to roverlay.py