1 |
commit: cbde5b6151f882ac7e2f53d57cb65cb1a7333fe8 |
2 |
Author: André Erdmann <dywi <AT> mailerd <DOT> de> |
3 |
AuthorDate: Wed Jun 26 17:23:26 2013 +0000 |
4 |
Commit: André Erdmann <dywi <AT> mailerd <DOT> de> |
5 |
CommitDate: Wed Jun 26 17:23:26 2013 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=cbde5b61 |
7 |
|
8 |
roverlay/: misc "distmap"/"run hook" changes |
9 |
|
10 |
* config |
11 |
-> added 'installed' and 'INSTALLINFO' to the config tree |
12 |
-> added OVERLAY_DISTMAP_COMPRESSION to the config entry map |
13 |
|
14 |
* roverlay.hook |
15 |
-> allow only one asterisk statement in EVENT_HOOK_RESTRICT |
16 |
-> catch hook script failure in run() and raise an exception |
17 |
|
18 |
* roverlay.tools.shenv |
19 |
-> $SHLIB env var is a list now (see previous commit) |
20 |
|
21 |
--- |
22 |
roverlay/config/const.py | 25 ++++++++++--------- |
23 |
roverlay/config/entrymap.py | 10 +++++++- |
24 |
roverlay/hook.py | 59 +++++++++++++++++++++++++++++++++++---------- |
25 |
roverlay/main.py | 7 +++--- |
26 |
roverlay/tools/shenv.py | 46 ++++++++++++++++++++++++++--------- |
27 |
5 files changed, 106 insertions(+), 41 deletions(-) |
28 |
|
29 |
diff --git a/roverlay/config/const.py b/roverlay/config/const.py |
30 |
index f9a2e14..c78e27c 100644 |
31 |
--- a/roverlay/config/const.py |
32 |
+++ b/roverlay/config/const.py |
33 |
@@ -12,11 +12,13 @@ import time |
34 |
__all__ = [ 'clone', 'lookup' ] |
35 |
|
36 |
_CONSTANTS = dict ( |
37 |
- # FIXME: capslock? ;) |
38 |
- DEBUG = False, |
39 |
- debug = False, |
40 |
+ debug = False, |
41 |
+ nosync = False, |
42 |
+ #installed = False, |
43 |
|
44 |
- nosync = False, |
45 |
+ INSTALLINFO = dict ( |
46 |
+ libexec = '/usr/libexec/roverlay', # ::LIBEXEC:: |
47 |
+ ), |
48 |
|
49 |
# logging defaults are in recipe/easylogger |
50 |
|
51 |
@@ -33,14 +35,13 @@ _CONSTANTS = dict ( |
52 |
), |
53 |
|
54 |
EBUILD = dict ( |
55 |
- default_header = '\n'.join ( ( |
56 |
- '# Copyright 1999-%i Gentoo Foundation' % ( time.gmtime() [0] ), |
57 |
- '# Distributed under the terms of the GNU General Public License v2', |
58 |
- '# $Header: $', |
59 |
- '', |
60 |
- # EAPI=N and inherit <eclasses> are no longer part |
61 |
- # of the default header |
62 |
- ) ), |
63 |
+ default_header = ( |
64 |
+ '# Copyright 1999-{year:d} Gentoo Foundation\n' |
65 |
+ '# Distributed under the terms of the GNU General Public License v2\n' |
66 |
+ '# $Header: $\n' |
67 |
+ '\n' |
68 |
+ ).format ( year=time.gmtime()[0] ), |
69 |
+ # EAPI=N and inherit <eclasses> are no longer part of the default header |
70 |
eapi = 4, |
71 |
|
72 |
# number of workers used by OverlayCreator |
73 |
|
74 |
diff --git a/roverlay/config/entrymap.py b/roverlay/config/entrymap.py |
75 |
index 6a282d9..87b4973 100644 |
76 |
--- a/roverlay/config/entrymap.py |
77 |
+++ b/roverlay/config/entrymap.py |
78 |
@@ -306,8 +306,15 @@ CONFIG_ENTRY_MAP = dict ( |
79 |
value_type = yesno, |
80 |
), |
81 |
|
82 |
+ overlay_distmap_compression = dict ( |
83 |
+ description = 'distmap compression format (none, bzip2 or gzip)', |
84 |
+ choices = frozenset ({ |
85 |
+ 'none', 'default', 'bz2', 'bzip2', 'gz', 'gzip' |
86 |
+ }), |
87 |
+ ), |
88 |
+ |
89 |
overlay_distmap_file = dict ( |
90 |
- path = [ 'OVERLAY', 'DISTMAP', 'dbfile', ] |
91 |
+ path = [ 'OVERLAY', 'DISTMAP', 'dbfile', ], |
92 |
value_type = 'fs_file', |
93 |
description = 'distmap file', |
94 |
), |
95 |
@@ -322,6 +329,7 @@ CONFIG_ENTRY_MAP = dict ( |
96 |
distdir_strategy = 'overlay_distdir_strategy', |
97 |
distdir_flat = 'overlay_distdir_flat', |
98 |
distdir_verify = 'overlay_distdir_verify', |
99 |
+ distmap_compression = 'overlay_distmap_compression', |
100 |
distmap_file = 'overlay_distmap_file', |
101 |
|
102 |
# --- overlay |
103 |
|
104 |
diff --git a/roverlay/hook.py b/roverlay/hook.py |
105 |
index 3b13315..3392e4e 100644 |
106 |
--- a/roverlay/hook.py |
107 |
+++ b/roverlay/hook.py |
108 |
@@ -28,6 +28,10 @@ _EVENT_RESTRICT = None |
109 |
# 4: deny all |
110 |
_EVENT_POLICY = 0 |
111 |
|
112 |
+ |
113 |
+class HookException ( Exception ): |
114 |
+ pass |
115 |
+ |
116 |
def setup(): |
117 |
global _EVENT_SCRIPT |
118 |
global _EVENT_POLICY |
119 |
@@ -35,14 +39,29 @@ def setup(): |
120 |
|
121 |
_EVENT_SCRIPT = roverlay.config.get ( 'EVENT_HOOK.exe', False ) |
122 |
if _EVENT_SCRIPT is False: |
123 |
- a_dir = roverlay.config.get ( 'OVERLAY.additions_dir', None ) |
124 |
- if a_dir: |
125 |
+ if roverlay.config.get_or_fail ( 'installed' ): |
126 |
s = os.path.join ( |
127 |
- a_dir, |
128 |
+ roverlay.config.get_or_fail ( 'INSTALLINFO.libexec' ), |
129 |
*roverlay.config.get_or_fail ( 'EVENT_HOOK.default_exe_relpath' ) |
130 |
) |
131 |
if os.path.isfile ( s ): |
132 |
_EVENT_SCRIPT = s |
133 |
+ else: |
134 |
+ LOGGER.error ( |
135 |
+ 'missing {!r} - ' |
136 |
+ 'has roverlay been installed properly?'.format ( s ) |
137 |
+ ) |
138 |
+ else: |
139 |
+ a_dir = roverlay.config.get ( 'OVERLAY.additions_dir', None ) |
140 |
+ if a_dir: |
141 |
+ s = os.path.join ( |
142 |
+ a_dir, *roverlay.config.get_or_fail ( |
143 |
+ 'EVENT_HOOK.default_exe_relpath' |
144 |
+ ) |
145 |
+ ) |
146 |
+ if os.path.isfile ( s ): |
147 |
+ _EVENT_SCRIPT = s |
148 |
+ # -- end if installed |
149 |
# -- end if _EVENT_SCRIPT |
150 |
|
151 |
conf_restrict = roverlay.config.get ( 'EVENT_HOOK.restrict', False ) |
152 |
@@ -53,12 +72,16 @@ def setup(): |
153 |
allow = set() |
154 |
deny = set() |
155 |
for p in conf_restrict: |
156 |
- if p == '*': |
157 |
- # "allow all" |
158 |
- is_whitelist = False |
159 |
- elif p == '-*': |
160 |
- # "deny all" |
161 |
- is_whitelist = True |
162 |
+ if p in { '*', '+*', '-*' }: |
163 |
+ # "allow all" / "deny all" |
164 |
+ # to avoid confusion, only one "[+-]*" statement is allowed |
165 |
+ if is_whitelist is None: |
166 |
+ is_whitelist = bool ( p[0] == '-' ) |
167 |
+ else: |
168 |
+ raise Exception ( |
169 |
+ 'EVENT_HOOK_RESTRICT must not contain more than one ' |
170 |
+ '"*"/"+*"/"-*" statement' |
171 |
+ ) |
172 |
elif p == '-' or p == '+': |
173 |
# empty |
174 |
pass |
175 |
@@ -148,19 +171,29 @@ def phase_allowed_nolog ( phase ): |
176 |
) |
177 |
# --- end of phase_allowed_nolog (...) --- |
178 |
|
179 |
-def run ( phase ): |
180 |
+def run ( phase, catch_failure=True ): |
181 |
if _EVENT_SCRIPT is None: |
182 |
LOGGER.warning ( |
183 |
"hook module not initialized - doing that now (FIXME!)" |
184 |
) |
185 |
setup() |
186 |
- |
187 |
+ # -- end if |
188 |
|
189 |
|
190 |
if _EVENT_SCRIPT and phase_allowed ( phase ): |
191 |
- return roverlay.tools.shenv.run_script ( |
192 |
+ if roverlay.tools.shenv.run_script ( |
193 |
_EVENT_SCRIPT, phase, return_success=True |
194 |
- ) |
195 |
+ ): |
196 |
+ return True |
197 |
+ elif catch_failure: |
198 |
+ raise HookException ( |
199 |
+ "hook {h!r} returned non-zero for phase {p!r}".format ( |
200 |
+ h=_EVENT_SCRIPT, p=phase |
201 |
+ ) |
202 |
+ ) |
203 |
+ #return False |
204 |
+ else: |
205 |
+ return False |
206 |
else: |
207 |
# nop |
208 |
return True |
209 |
|
210 |
diff --git a/roverlay/main.py b/roverlay/main.py |
211 |
index 4822e21..8bfecf6 100644 |
212 |
--- a/roverlay/main.py |
213 |
+++ b/roverlay/main.py |
214 |
@@ -289,8 +289,7 @@ def main ( |
215 |
# this hook should be called _after_ verifying the overlay |
216 |
# (verification is not implemented yet) |
217 |
# |
218 |
- if not roverlay.hook.run ( 'overlay_success' ): |
219 |
- die ( "overlay_success hook returned non-zero", DIE.OV_CREATE ) |
220 |
+ roverlay.hook.run ( 'overlay_success' ) |
221 |
|
222 |
set_action_done ( "create" ) |
223 |
|
224 |
@@ -348,11 +347,13 @@ def main ( |
225 |
DEFAULT_CONFIG_FILE = CONFIG_FILE_NAME |
226 |
|
227 |
|
228 |
- commands, config_file, additional_config, extra_opts = \ |
229 |
+ commands, config_file, additional_config, extra_opts = ( |
230 |
roverlay.argutil.parse_argv ( |
231 |
command_map=COMMAND_DESCRIPTION, |
232 |
default_config_file=DEFAULT_CONFIG_FILE, |
233 |
) |
234 |
+ ) |
235 |
+ additional_config ['installed'] = ROVERLAY_INSTALLED |
236 |
|
237 |
OPTION = extra_opts.get |
238 |
|
239 |
|
240 |
diff --git a/roverlay/tools/shenv.py b/roverlay/tools/shenv.py |
241 |
index f0c054b..794ed1e 100644 |
242 |
--- a/roverlay/tools/shenv.py |
243 |
+++ b/roverlay/tools/shenv.py |
244 |
@@ -90,6 +90,10 @@ NULL_PHASE = 'null' |
245 |
def setup_env(): |
246 |
"""Returns a 'well-defined' env dict for running scripts.""" |
247 |
|
248 |
+ ROVERLAY_INSTALLED = roverlay.config.get_or_fail ( 'installed' ) |
249 |
+ SHLIB_DIRNAME = 'shlib' |
250 |
+ SHFUNC_FILENAME = 'functions.sh' |
251 |
+ |
252 |
# @typedef shbool is SH_TRUE|SH_FALSE, where: |
253 |
SH_TRUE = 'y' |
254 |
SH_FALSE = 'n' |
255 |
@@ -175,30 +179,48 @@ def setup_env(): |
256 |
# shell file with "core" functions |
257 |
# |
258 |
additions_dir = roverlay.config.get ( 'OVERLAY.additions_dir', None ) |
259 |
+ shlib_path = [] |
260 |
+ |
261 |
+ if ROVERLAY_INSTALLED: |
262 |
+ installed_shlib = ( |
263 |
+ roverlay.config.get_or_fail ( 'INSTALLINFO.libexec' ) |
264 |
+ + os.sep + SHLIB_DIRNAME |
265 |
+ ) |
266 |
+ if os.path.isdir ( installed_shlib ): |
267 |
+ shlib_path.append ( installed_shlib ) |
268 |
+ shlib_file = installed_shlib + os.sep + SHFUNC_FILENAME |
269 |
+ if os.path.isfile ( shlib_file ): |
270 |
+ setup ( 'FUNCTIONS', shlib_file ) |
271 |
+ else: |
272 |
+ LOGGER.error ( |
273 |
+ "roverlay is installed, but $FUNCTIONS file is missing." |
274 |
+ ) |
275 |
+ else: |
276 |
+ LOGGER.error ( "roverlay is installed, but shlib dir is missing." ) |
277 |
+ # -- end if installed~shlib |
278 |
+ |
279 |
if additions_dir: |
280 |
setup ( 'ADDITIONS_DIR', additions_dir ) |
281 |
setup_self ( 'FILESDIR', 'ADDITIONS_DIR' ) |
282 |
|
283 |
- shlib_root = additions_dir + os.sep + 'shlib' |
284 |
- shlib_file = None |
285 |
- SHFUNC_FILENAME = 'functions.sh' |
286 |
+ shlib_root = additions_dir + os.sep + 'shlib' |
287 |
|
288 |
if os.path.isdir ( shlib_root ): |
289 |
- setup ( 'SHLIB', shlib_root ) |
290 |
- shlib_file = shlib_root + os.sep + SHFUNC_FILENAME |
291 |
+ shlib_path.append ( shlib_root ) |
292 |
|
293 |
+# if not ROVERLAY_INSTALLED: |
294 |
+ shlib_file = shlib_root + os.sep + SHFUNC_FILENAME |
295 |
if os.path.isfile ( shlib_file ): |
296 |
setup ( 'FUNCTIONS', shlib_file ) |
297 |
- else: |
298 |
- shlib_file = None |
299 |
# -- end if shlib_root; |
300 |
- |
301 |
- if not shlib_file: |
302 |
- shlib_file = additions_dir + os.sep + SHFUNC_FILENAME |
303 |
- if os.path.isfile ( shlib_file ): |
304 |
- setup ( 'FUNCTIONS', shlib_file ) |
305 |
# -- end if additions_dir; |
306 |
|
307 |
+ if shlib_path: |
308 |
+ # reversed shlib_path: |
309 |
+ # assuming that user-provided function files are more important |
310 |
+ # |
311 |
+ setup ( 'SHLIB', ':'.join ( reversed ( shlib_path ) ) ) |
312 |
+ |
313 |
# str::exe $EBUILD |
314 |
setup_conf ( 'EBUILD', 'TOOLS.EBUILD.exe' ) |