Gentoo Archives: gentoo-commits

From: Brian Dolbec <brian.dolbec@×××××.com>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/catalyst:pending commit in: catalyst/, catalyst/targets/
Date: Tue, 02 Sep 2014 05:55:03
Message-Id: 1409637114.bff2fcf34e933732c472712d04e69f671bb417a3.dol-sen@gentoo
1 commit: bff2fcf34e933732c472712d04e69f671bb417a3
2 Author: Brian Dolbec <dolsen <AT> gentoo <DOT> org>
3 AuthorDate: Sun Jan 20 21:50:23 2013 +0000
4 Commit: Brian Dolbec <brian.dolbec <AT> gmail <DOT> com>
5 CommitDate: Tue Sep 2 05:51:54 2014 +0000
6 URL: http://sources.gentoo.org/gitweb/?p=proj/catalyst.git;a=commit;h=bff2fcf3
7
8 Update module loading for the new python structure, rename snapshot_target to snapshot
9
10 Conflicts:
11 catalyst/defaults.py
12 catalyst/main.py
13 catalyst/targets/stage1_target.py
14
15 ---
16 catalyst/main.py | 75 ++++++++--------------
17 catalyst/targets/embedded_target.py | 4 --
18 catalyst/targets/grp_target.py | 4 --
19 catalyst/targets/livecd_stage1_target.py | 4 --
20 catalyst/targets/livecd_stage2_target.py | 4 --
21 catalyst/targets/netboot2_target.py | 4 --
22 catalyst/targets/netboot_target.py | 4 --
23 .../targets/{snapshot_target.py => snapshot.py} | 6 +-
24 catalyst/targets/stage1_target.py | 4 --
25 catalyst/targets/stage2_target.py | 4 --
26 catalyst/targets/stage3_target.py | 4 --
27 catalyst/targets/stage4_target.py | 5 --
28 catalyst/targets/tinderbox_target.py | 4 --
29 13 files changed, 27 insertions(+), 99 deletions(-)
30
31 diff --git a/catalyst/main.py b/catalyst/main.py
32 index 15664de..1446cf9 100644
33 --- a/catalyst/main.py
34 +++ b/catalyst/main.py
35 @@ -16,21 +16,20 @@ import os.path
36
37 __selfpath__ = os.path.abspath(os.path.dirname(__file__))
38
39 -sys.path.append(__selfpath__ + "/modules")
40
41 from . import __version__
42 import catalyst.config
43 import catalyst.util
44 +from catalyst.contents import ContentsMap, CONTENTS_DEFINITIONS
45 +from catalyst.defaults import confdefaults, option_messages
46 +from catalyst.hash_utils import HashMap, HASH_DEFINITIONS
47 from catalyst.lock import LockInUse
48 from catalyst.support import CatalystError, find_binary
49 -from catalyst.defaults import (confdefaults, option_messages,
50 - required_build_targets, valid_build_targets)
51 -from hash_utils import HashMap, HASH_DEFINITIONS
52 -from contents import ContentsMap, CONTENTS_DEFINITIONS
53
54
55 conf_values={}
56
57 +
58 def usage():
59 print """Usage catalyst [options] [-C variable=value...] [ -s identifier]
60 -a --clear-autoresume clear autoresume flags
61 @@ -135,59 +134,40 @@ def parse_config(myconfig):
62 print "Envscript support enabled."
63
64
65 -def import_modules():
66 - # import catalyst's own modules
67 - # (i.e. stage and the arch modules)
68 - targetmap={}
69 -
70 +def import_module(target):
71 + """
72 + import catalyst's own modules
73 + (i.e. targets and the arch modules)
74 + """
75 try:
76 - module_dir = __selfpath__ + "/targets/"
77 - for x in required_build_targets:
78 - try:
79 - fh=open(module_dir + x + ".py")
80 - module=imp.load_module(x, fh,"targets/" + x + ".py",
81 - (".py", "r", imp.PY_SOURCE))
82 - fh.close()
83 -
84 - except IOError:
85 - raise CatalystError, "Can't find " + x + ".py plugin in " + \
86 - module_dir
87 - for x in valid_build_targets:
88 - try:
89 - fh=open(module_dir + x + ".py")
90 - module=imp.load_module(x, fh, "targets/" + x + ".py",
91 - (".py", "r", imp.PY_SOURCE))
92 - module.register(targetmap)
93 - fh.close()
94 -
95 - except IOError:
96 - raise CatalystError,"Can't find " + x + ".py plugin in " + \
97 - module_dir
98 -
99 + mod_name = "catalyst.targets." + target
100 + module = __import__(mod_name, [],[], ["not empty"])
101 except ImportError as e:
102 - print "!!! catalyst: Python modules not found in "+\
103 - module_dir + "; exiting."
104 - print e
105 + print "!!! catalyst: Python module import error: %s " % target + \
106 + "in catalyst/targets/ ... exiting."
107 + print "ERROR was: ", e
108 sys.exit(1)
109 + return module
110
111 - return targetmap
112
113 -def build_target(addlargs, targetmap):
114 +def build_target(addlargs):
115 try:
116 - if addlargs["target"] not in targetmap:
117 - raise CatalystError,"Target \""+addlargs["target"]+"\" not available."
118 -
119 - mytarget=targetmap[addlargs["target"]](conf_values, addlargs)
120 -
121 - mytarget.run()
122 + module = import_module(addlargs["target"])
123 + target = getattr(module, addlargs["target"])(conf_values, addlargs)
124 + except AttributeError:
125 + raise CatalystError(
126 + "Target \"%s\" not available." % addlargs["target"],
127 + print_traceback=True)
128
129 + try:
130 + target.run()
131 except:
132 + print "Target run() exception: Python traceback output follows:"
133 catalyst.util.print_traceback()
134 print "!!! catalyst: Error encountered during run of target " + addlargs["target"]
135 sys.exit(1)
136
137 def main():
138 - targetmap={}
139
140 version()
141 if os.getuid() != 0:
142 @@ -341,9 +321,6 @@ def main():
143 print "Catalyst aborting...."
144 sys.exit(2)
145
146 - # import the rest of the catalyst modules
147 - targetmap=import_modules()
148 -
149 addlargs={}
150
151 if myspecfile:
152 @@ -364,7 +341,7 @@ def main():
153
154 # everything is setup, so the build is a go
155 try:
156 - build_target(addlargs, targetmap)
157 + build_target(addlargs)
158
159 except CatalystError:
160 print
161
162 diff --git a/catalyst/targets/embedded_target.py b/catalyst/targets/embedded_target.py
163 index 528d545..aee0f00 100644
164 --- a/catalyst/targets/embedded_target.py
165 +++ b/catalyst/targets/embedded_target.py
166 @@ -45,7 +45,3 @@ class embedded_target(StageBase):
167 def set_root_path(self):
168 self.settings["root_path"]=normpath("/tmp/mergeroot")
169 print "embedded root path is "+self.settings["root_path"]
170 -
171 -def register(foo):
172 - foo.update({"embedded":embedded_target})
173 - return foo
174
175 diff --git a/catalyst/targets/grp_target.py b/catalyst/targets/grp_target.py
176 index deba80a..e3f08a2 100644
177 --- a/catalyst/targets/grp_target.py
178 +++ b/catalyst/targets/grp_target.py
179 @@ -118,7 +118,3 @@ class grp_target(StageBase):
180 "config_profile_link","setup_confdir","portage_overlay","bind","chroot_setup",\
181 "setup_environment","run_local","unbind",\
182 "generate_digests","clear_autoresume"]
183 -
184 -def register(foo):
185 - foo.update({"grp":grp_target})
186 - return foo
187
188 diff --git a/catalyst/targets/livecd_stage1_target.py b/catalyst/targets/livecd_stage1_target.py
189 index a19f4ac..9c74253 100644
190 --- a/catalyst/targets/livecd_stage1_target.py
191 +++ b/catalyst/targets/livecd_stage1_target.py
192 @@ -76,7 +76,3 @@ class livecd_stage1_target(StageBase):
193 self.settings["pkgcache_path"]=normpath(string.join(self.settings["pkgcache_path"]))
194 else:
195 StageBase.set_pkgcache_path(self)
196 -
197 -def register(foo):
198 - foo.update({"livecd-stage1":livecd_stage1_target})
199 - return foo
200
201 diff --git a/catalyst/targets/livecd_stage2_target.py b/catalyst/targets/livecd_stage2_target.py
202 index e7ae212..a4630e6 100644
203 --- a/catalyst/targets/livecd_stage2_target.py
204 +++ b/catalyst/targets/livecd_stage2_target.py
205 @@ -145,7 +145,3 @@ class livecd_stage2_target(StageBase):
206 "unbind","remove","empty","target_setup",\
207 "setup_overlay","create_iso"]
208 self.settings["action_sequence"].append("clear_autoresume")
209 -
210 -def register(foo):
211 - foo.update({"livecd-stage2":livecd_stage2_target})
212 - return foo
213
214 diff --git a/catalyst/targets/netboot2_target.py b/catalyst/targets/netboot2_target.py
215 index 987afd8..130e2b6 100644
216 --- a/catalyst/targets/netboot2_target.py
217 +++ b/catalyst/targets/netboot2_target.py
218 @@ -167,7 +167,3 @@ class netboot2_target(StageBase):
219 "setup_environment","build_packages","root_overlay",\
220 "copy_files_to_image","setup_overlay","build_kernel","move_kernels",\
221 "remove","empty","unbind","clean","clear_autoresume"]
222 -
223 -def register(foo):
224 - foo.update({"netboot2":netboot2_target})
225 - return foo
226
227 diff --git a/catalyst/targets/netboot_target.py b/catalyst/targets/netboot_target.py
228 index c880289..9d92ef2 100644
229 --- a/catalyst/targets/netboot_target.py
230 +++ b/catalyst/targets/netboot_target.py
231 @@ -127,7 +127,3 @@ class netboot_target(StageBase):
232 "setup_environment","build_packages","build_busybox",\
233 "build_kernel","copy_files_to_image",\
234 "clean","create_netboot_files","unbind","clear_autoresume"]
235 -
236 -def register(foo):
237 - foo.update({"netboot":netboot_target})
238 - return foo
239
240 diff --git a/catalyst/targets/snapshot_target.py b/catalyst/targets/snapshot.py
241 similarity index 95%
242 rename from catalyst/targets/snapshot_target.py
243 rename to catalyst/targets/snapshot.py
244 index 337ff1d..6c2396e 100644
245 --- a/catalyst/targets/snapshot_target.py
246 +++ b/catalyst/targets/snapshot.py
247 @@ -11,7 +11,7 @@ from catalyst.support import normpath, cmd
248 from catalyst.base.targetbase import TargetBase
249 from catalyst.base.genbase import GenBase
250
251 -class snapshot_target(TargetBase, GenBase):
252 +class snapshot(TargetBase, GenBase):
253 """
254 Builder class for snapshots.
255 """
256 @@ -91,7 +91,3 @@ class snapshot_target(TargetBase, GenBase):
257 os.makedirs(myemp,0755)
258 os.chown(myemp,mystat[ST_UID],mystat[ST_GID])
259 os.chmod(myemp,mystat[ST_MODE])
260 -
261 -def register(foo):
262 - foo.update({"snapshot":snapshot_target})
263 - return foo
264
265 diff --git a/catalyst/targets/stage1_target.py b/catalyst/targets/stage1_target.py
266 index 0a36432..2329b58 100644
267 --- a/catalyst/targets/stage1_target.py
268 +++ b/catalyst/targets/stage1_target.py
269 @@ -94,7 +94,3 @@ class stage1_target(StageBase):
270 self.mounts.append("stage1root/proc")
271 self.target_mounts["stage1root/proc"] = "/tmp/stage1root/proc"
272 self.mountmap["stage1root/proc"] = "/proc"
273 -
274 -def register(foo):
275 - foo.update({"stage1":stage1_target})
276 - return foo
277
278 diff --git a/catalyst/targets/stage2_target.py b/catalyst/targets/stage2_target.py
279 index 783d42e..ec6d78d 100644
280 --- a/catalyst/targets/stage2_target.py
281 +++ b/catalyst/targets/stage2_target.py
282 @@ -62,7 +62,3 @@ class stage2_target(StageBase):
283 print "\tUsing an portage overlay for earlier stages could cause build issues."
284 print "\tIf you break it, you buy it. Don't complain to us about it."
285 print "\tDont say we did not warn you\n"
286 -
287 -def register(foo):
288 - foo.update({"stage2":stage2_target})
289 - return foo
290
291 diff --git a/catalyst/targets/stage3_target.py b/catalyst/targets/stage3_target.py
292 index 28021b1..103242d 100644
293 --- a/catalyst/targets/stage3_target.py
294 +++ b/catalyst/targets/stage3_target.py
295 @@ -25,7 +25,3 @@ class stage3_target(StageBase):
296
297 def set_cleanables(self):
298 StageBase.set_cleanables(self)
299 -
300 -def register(foo):
301 - foo.update({"stage3":stage3_target})
302 - return foo
303
304 diff --git a/catalyst/targets/stage4_target.py b/catalyst/targets/stage4_target.py
305 index 0d725c7..4dbdb45 100644
306 --- a/catalyst/targets/stage4_target.py
307 +++ b/catalyst/targets/stage4_target.py
308 @@ -36,8 +36,3 @@ class stage4_target(StageBase):
309 if "fetch" not in self.settings['options']:
310 self.settings["action_sequence"].append("capture")
311 self.settings["action_sequence"].append("clear_autoresume")
312 -
313 -def register(foo):
314 - foo.update({"stage4":stage4_target})
315 - return foo
316 -
317
318 diff --git a/catalyst/targets/tinderbox_target.py b/catalyst/targets/tinderbox_target.py
319 index 1e245f2..0c389e6 100644
320 --- a/catalyst/targets/tinderbox_target.py
321 +++ b/catalyst/targets/tinderbox_target.py
322 @@ -45,7 +45,3 @@ class tinderbox_target(StageBase):
323 "config_profile_link","setup_confdir","bind","chroot_setup",\
324 "setup_environment","run_local","preclean","unbind","clean",\
325 "clear_autoresume"]
326 -
327 -def register(foo):
328 - foo.update({"tinderbox":tinderbox_target})
329 - return foo