Gentoo Archives: gentoo-commits

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