From 0c8d98c2c86571aee2a2fa8ca7b66e90ff8cd0a3 Mon Sep 17 00:00:00 2001 From: Andrew Gaffney Date: Sun, 11 Jan 2009 17:17:20 -0600 Subject: [PATCH] Move file_locate() from catalyst.support to catalyst.util --- ChangeLog | 6 ++++++ modules/catalyst/support.py | 17 ----------------- modules/catalyst/target/generic_stage.py | 4 ++-- modules/catalyst/target/livecd_stage2.py | 2 +- modules/catalyst/target/netboot.py | 2 +- modules/catalyst/util.py | 15 +++++++++++++++ 6 files changed, 25 insertions(+), 21 deletions(-) diff --git a/ChangeLog b/ChangeLog index 702dac86..478527d6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,12 @@ # Copyright 2002-2009 Gentoo Foundation; 2008-2009 Various authors (see AUTHORS) # Distributed under the GPL v2 + 11 Jan 2009; Andrew Gaffney + modules/catalyst/support.py, modules/catalyst/target/generic_stage.py, + modules/catalyst/target/livecd_stage2.py, + modules/catalyst/target/netboot.py, modules/catalyst/util.py: + Move file_locate() from catalyst.support to catalyst.util + 11 Jan 2009; Andrew Gaffney modules/catalyst/spawn.py, modules/catalyst/support.py, modules/catalyst/target/generic_stage.py, modules/catalyst/target/grp.py, diff --git a/modules/catalyst/support.py b/modules/catalyst/support.py index 84bb5043..8d2c0a9c 100644 --- a/modules/catalyst/support.py +++ b/modules/catalyst/support.py @@ -29,23 +29,6 @@ valid_config_file_values.append("SEEDCACHE") verbosity=1 -def file_locate(settings,filelist,expand=1): - #if expand=1, non-absolute paths will be accepted and - # expanded to os.getcwd()+"/"+localpath if file exists - for myfile in filelist: - if not myfile in settings: - #filenames such as cdtar are optional, so we don't assume the variable is defined. - pass - else: - if len(settings[myfile])==0: - raise CatalystError, "File variable \""+myfile+"\" has a length of zero (not specified.)" - if settings[myfile][0]=="/": - if not os.path.exists(settings[myfile]): - raise CatalystError, "Cannot locate specified "+myfile+": "+settings[myfile] - elif expand and os.path.exists(os.getcwd()+"/"+settings[myfile]): - settings[myfile]=os.getcwd()+"/"+settings[myfile] - else: - raise CatalystError, "Cannot locate specified "+myfile+": "+settings[myfile]+" (2nd try)" """ Spec file format: diff --git a/modules/catalyst/target/generic_stage.py b/modules/catalyst/target/generic_stage.py index 1b1f2dd5..1d73e858 100644 --- a/modules/catalyst/target/generic_stage.py +++ b/modules/catalyst/target/generic_stage.py @@ -153,11 +153,11 @@ class generic_stage_target(generic_target): on disk. """ #pdb.set_trace() - file_locate(self.settings,["source_path","snapshot_path","distdir"],\ + catalyst.util.file_locate(self.settings,["source_path","snapshot_path","distdir"],\ expand=0) """ If we are using portage_confdir, check that as well. """ if "portage_confdir" in self.settings: - file_locate(self.settings,["portage_confdir"],expand=0) + catalyst.util.file_locate(self.settings,["portage_confdir"],expand=0) """ Setup our mount points """ if "SNAPCACHE" in self.settings: diff --git a/modules/catalyst/target/livecd_stage2.py b/modules/catalyst/target/livecd_stage2.py index de47f31a..8ad662e7 100644 --- a/modules/catalyst/target/livecd_stage2.py +++ b/modules/catalyst/target/livecd_stage2.py @@ -31,7 +31,7 @@ class livecd_stage2_target(generic_stage_target): if not "livecd/type" in self.settings: self.settings["livecd/type"] = "generic-livecd" - file_locate(self.settings, ["cdtar","controller_file"]) + catalyst.util.file_locate(self.settings, ["cdtar","controller_file"]) def set_source_path(self): self.settings["source_path"]=catalyst.util.normpath(self.settings["storedir"]+"/builds/"+self.settings["source_subpath"]+".tar.bz2") diff --git a/modules/catalyst/target/netboot.py b/modules/catalyst/target/netboot.py index 6bbca71e..e1a87ae9 100644 --- a/modules/catalyst/target/netboot.py +++ b/modules/catalyst/target/netboot.py @@ -42,7 +42,7 @@ class netboot_target(generic_stage_target): generic_stage_target.__init__(self,spec,addlargs) self.set_build_kernel_vars(addlargs) if "netboot/busybox_config" in addlargs: - file_locate(self.settings, ["netboot/busybox_config"]) + catalyst.util.file_locate(self.settings, ["netboot/busybox_config"]) # Custom Kernel Tarball --- use that instead ... diff --git a/modules/catalyst/util.py b/modules/catalyst/util.py index b97d1f1b..3bb35fbf 100644 --- a/modules/catalyst/util.py +++ b/modules/catalyst/util.py @@ -117,3 +117,18 @@ def countdown(secs=5, doing="Starting"): time.sleep(1) print +def file_locate(settings, filelist, expand=True): + #if expand is True, non-absolute paths will be accepted and + # expanded to os.getcwd()+"/"+localpath if file exists + for myfile in filelist: + if myfile in settings: + # filenames such as cdtar are optional, so we don't assume the variable is defined. + if not len(settings[myfile]): + raise CatalystError, "File variable \"" + myfile + "\" has a length of zero (not specified)" + if settings[myfile].startswith('/'): + if not os.path.exists(settings[myfile]): + raise CatalystError, "Cannot locate specified " + myfile + ": " + settings[myfile] + elif expand and os.path.exists(os.getcwd() + "/" + settings[myfile]): + settings[myfile] = os.getcwd() + "/" + settings[myfile] + else: + raise CatalystError, "Cannot locate specified " + myfile + ": " + settings[myfile] + " (2nd try)" -- 2.26.2