From b710e36c767a4dae6e2eae414b80507fe1837df7 Mon Sep 17 00:00:00 2001 From: Andrew Gaffney Date: Sun, 11 Jan 2009 15:58:43 -0600 Subject: [PATCH] Move normpath() from catalyst.support to catalyst.util --- ChangeLog | 10 ++++++ modules/catalyst/support.py | 12 ------- modules/catalyst/target/embedded.py | 7 ++-- modules/catalyst/target/generic_stage.py | 42 ++++++++++++------------ modules/catalyst/target/grp.py | 18 +++++----- modules/catalyst/target/livecd_stage1.py | 5 +-- modules/catalyst/target/livecd_stage2.py | 6 ++-- modules/catalyst/target/netboot.py | 2 +- modules/catalyst/target/netboot2.py | 4 +-- modules/catalyst/target/snapshot.py | 7 ++-- modules/catalyst/target/stage1.py | 4 +-- modules/catalyst/target/stage2.py | 8 ++--- modules/catalyst/util.py | 10 +++++- 13 files changed, 71 insertions(+), 64 deletions(-) diff --git a/ChangeLog b/ChangeLog index 91cd8e08..a695ae6a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,16 @@ # 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/embedded.py, + modules/catalyst/target/generic_stage.py, modules/catalyst/target/grp.py, + modules/catalyst/target/livecd_stage1.py, + modules/catalyst/target/livecd_stage2.py, + modules/catalyst/target/netboot.py, modules/catalyst/target/netboot2.py, + modules/catalyst/target/snapshot.py, modules/catalyst/target/stage1.py, + modules/catalyst/target/stage2.py, modules/catalyst/util.py: + Move normpath() from catalyst.support to catalyst.util + 11 Jan 2009; Andrew Gaffney modules/catalyst/support.py, modules/catalyst/target/stage1.py, modules/catalyst/target/stage2.py, modules/catalyst/util.py: diff --git a/modules/catalyst/support.py b/modules/catalyst/support.py index 47e25744..091c0a9c 100644 --- a/modules/catalyst/support.py +++ b/modules/catalyst/support.py @@ -632,15 +632,3 @@ def countdown(secs=5, doing="Starting"): time.sleep(1) print -def normpath(mypath): - TrailingSlash=False - if mypath[-1] == "/": - TrailingSlash=True - newpath = os.path.normpath(mypath) - if len(newpath) > 1: - if newpath[:2] == "//": - newpath = newpath[1:] - if TrailingSlash: - newpath=newpath+'/' - return newpath - diff --git a/modules/catalyst/target/embedded.py b/modules/catalyst/target/embedded.py index ed15b5ad..5a3bc4bf 100644 --- a/modules/catalyst/target/embedded.py +++ b/modules/catalyst/target/embedded.py @@ -9,10 +9,9 @@ It sounds real complicated but basically it runs ROOT=/tmp/submerge emerge --blahblah foo bar """ -import os,string,imp,types,shutil from catalyst.support import * from generic_stage import * -from stat import * +import catalyst.util class embedded_target(generic_stage_target): @@ -36,11 +35,11 @@ class embedded_target(generic_stage_target): "unbind","remove","empty","clean","capture","clear_autoresume"] def set_stage_path(self): - self.settings["stage_path"]=normpath(self.settings["chroot_path"]+"/tmp/mergeroot") + self.settings["stage_path"]=catalyst.util.normpath(self.settings["chroot_path"]+"/tmp/mergeroot") print "embedded stage path is "+self.settings["stage_path"] def set_root_path(self): - self.settings["root_path"]=normpath("/tmp/mergeroot") + self.settings["root_path"]=catalyst.util.normpath("/tmp/mergeroot") print "embedded root path is "+self.settings["root_path"] __target_map = {"embedded":embedded_target} diff --git a/modules/catalyst/target/generic_stage.py b/modules/catalyst/target/generic_stage.py index 2f5c97fd..80469487 100644 --- a/modules/catalyst/target/generic_stage.py +++ b/modules/catalyst/target/generic_stage.py @@ -256,23 +256,23 @@ class generic_stage_target(generic_target): if "pkgcache_path" in self.settings: if type(self.settings["pkgcache_path"])!=types.StringType: self.settings["pkgcache_path"]=\ - normpath(string.join(self.settings["pkgcache_path"])) + catalyst.util.normpath(string.join(self.settings["pkgcache_path"])) else: self.settings["pkgcache_path"]=\ - normpath(self.settings["storedir"]+"/packages/"+\ + catalyst.util.normpath(self.settings["storedir"]+"/packages/"+\ self.settings["target_subpath"]+"/") def set_kerncache_path(self): if "kerncache_path" in self.settings: if type(self.settings["kerncache_path"])!=types.StringType: self.settings["kerncache_path"]=\ - normpath(string.join(self.settings["kerncache_path"])) + catalyst.util.normpath(string.join(self.settings["kerncache_path"])) else: - self.settings["kerncache_path"]=normpath(self.settings["storedir"]+\ + self.settings["kerncache_path"]=catalyst.util.normpath(self.settings["storedir"]+\ "/kerncache/"+self.settings["target_subpath"]+"/") def set_target_path(self): - self.settings["target_path"]=normpath(self.settings["storedir"]+\ + self.settings["target_path"]=catalyst.util.normpath(self.settings["storedir"]+\ "/builds/"+self.settings["target_subpath"]+".tar.bz2") if "AUTORESUME" in self.settings\ and os.path.exists(self.settings["autoresume_path"]+\ @@ -314,18 +314,18 @@ class generic_stage_target(generic_target): def set_cdtar(self): if self.settings["spec_prefix"]+"/cdtar" in self.settings: self.settings["cdtar"]=\ - normpath(self.settings[self.settings["spec_prefix"]+"/cdtar"]) + catalyst.util.normpath(self.settings[self.settings["spec_prefix"]+"/cdtar"]) del self.settings[self.settings["spec_prefix"]+"/cdtar"] def set_iso(self): if self.settings["spec_prefix"]+"/iso" in self.settings: if self.settings[self.settings["spec_prefix"]+"/iso"].startswith('/'): self.settings["iso"]=\ - normpath(self.settings[self.settings["spec_prefix"]+"/iso"]) + catalyst.util.normpath(self.settings[self.settings["spec_prefix"]+"/iso"]) else: # This automatically prepends the build dir to the ISO output path # if it doesn't start with a / - self.settings["iso"] = normpath(self.settings["storedir"] + \ + self.settings["iso"] = catalyst.util.normpath(self.settings["storedir"] + \ "/builds/" + self.settings["rel_type"] + "/" + \ self.settings[self.settings["spec_prefix"]+"/iso"]) del self.settings[self.settings["spec_prefix"]+"/iso"] @@ -353,12 +353,12 @@ class generic_stage_target(generic_target): def set_source_path(self): if "SEEDCACHE" in self.settings\ - and os.path.isdir(normpath(self.settings["storedir"]+"/tmp/"+\ + and os.path.isdir(catalyst.util.normpath(self.settings["storedir"]+"/tmp/"+\ self.settings["source_subpath"]+"/")): - self.settings["source_path"]=normpath(self.settings["storedir"]+\ + self.settings["source_path"]=catalyst.util.normpath(self.settings["storedir"]+\ "/tmp/"+self.settings["source_subpath"]+"/") else: - self.settings["source_path"]=normpath(self.settings["storedir"]+\ + self.settings["source_path"]=catalyst.util.normpath(self.settings["storedir"]+\ "/builds/"+self.settings["source_subpath"]+".tar.bz2") if os.path.isfile(self.settings["source_path"]): # XXX: Is this even necessary if the previous check passes? @@ -372,22 +372,22 @@ class generic_stage_target(generic_target): print "\tIf this is not desired, remove this directory or turn off" print "\tseedcache in the options of catalyst.conf the source path" print "\twill then be "+\ - normpath(self.settings["storedir"]+"/builds/"+\ + catalyst.util.normpath(self.settings["storedir"]+"/builds/"+\ self.settings["source_subpath"]+".tar.bz2\n") def set_dest_path(self): if "root_path" in self.settings: - self.settings["destpath"]=normpath(self.settings["chroot_path"]+\ + self.settings["destpath"]=catalyst.util.normpath(self.settings["chroot_path"]+\ self.settings["root_path"]) else: - self.settings["destpath"]=normpath(self.settings["chroot_path"]) + self.settings["destpath"]=catalyst.util.normpath(self.settings["chroot_path"]) def set_cleanables(self): self.settings["cleanables"]=["/etc/resolv.conf","/var/tmp/*","/tmp/*",\ "/root/*","/usr/portage"] def set_snapshot_path(self): - self.settings["snapshot_path"]=normpath(self.settings["storedir"]+\ + self.settings["snapshot_path"]=catalyst.util.normpath(self.settings["storedir"]+\ "/snapshots/portage-"+self.settings["snapshot"]+".tar.bz2") if os.path.exists(self.settings["snapshot_path"]): @@ -398,7 +398,7 @@ class generic_stage_target(generic_target): def set_snapcache_path(self): if "SNAPCACHE" in self.settings: self.settings["snapshot_cache_path"]=\ - normpath(self.settings["snapshot_cache"]+"/"+\ + catalyst.util.normpath(self.settings["snapshot_cache"]+"/"+\ self.settings["snapshot"]+"/") self.snapcache_lock=\ catalyst.lock.LockDir(self.settings["snapshot_cache_path"]) @@ -409,12 +409,12 @@ class generic_stage_target(generic_target): NOTE: the trailing slash is very important! Things *will* break without it! """ - self.settings["chroot_path"]=normpath(self.settings["storedir"]+\ + self.settings["chroot_path"]=catalyst.util.normpath(self.settings["storedir"]+\ "/tmp/"+self.settings["target_subpath"]+"/") self.chroot_lock=catalyst.lock.LockDir(self.settings["chroot_path"]) def set_autoresume_path(self): - self.settings["autoresume_path"]=normpath(self.settings["storedir"]+\ + self.settings["autoresume_path"]=catalyst.util.normpath(self.settings["storedir"]+\ "/tmp/"+self.settings["rel_type"]+"/"+".autoresume-"+\ self.settings["target"]+"-"+self.settings["subarch"]+"-"+\ self.settings["version_stamp"]+"/") @@ -424,7 +424,7 @@ class generic_stage_target(generic_target): os.makedirs(self.settings["autoresume_path"],0755) def set_controller_file(self): - self.settings["controller_file"]=normpath(self.settings["sharedir"]+\ + self.settings["controller_file"]=catalyst.util.normpath(self.settings["sharedir"]+\ "/targets/"+self.settings["target"]+"/"+self.settings["target"]+\ "-controller.sh") @@ -461,7 +461,7 @@ class generic_stage_target(generic_target): self.settings["use"].append("bindist") def set_stage_path(self): - self.settings["stage_path"]=normpath(self.settings["chroot_path"]) + self.settings["stage_path"]=catalyst.util.normpath(self.settings["chroot_path"]) def set_mounts(self): pass @@ -740,7 +740,7 @@ class generic_stage_target(generic_target): print "Valid snapshot cache, skipping unpack of portage tree..." unpack=False else: - destdir=normpath(self.settings["chroot_path"]+"/usr/portage") + destdir=catalyst.util.normpath(self.settings["chroot_path"]+"/usr/portage") cleanup_errmsg="Error removing existing snapshot directory." cleanup_msg=\ "Cleaning up existing portage tree (This can take a long time)..." diff --git a/modules/catalyst/target/grp.py b/modules/catalyst/target/grp.py index 4b9428b7..46891298 100644 --- a/modules/catalyst/target/grp.py +++ b/modules/catalyst/target/grp.py @@ -33,7 +33,7 @@ class grp_target(generic_stage_target): generic_stage_target.__init__(self,spec,addlargs) def set_target_path(self): - self.settings["target_path"]=normpath(self.settings["storedir"]+"/builds/"+self.settings["target_subpath"]+"/") + self.settings["target_path"]=catalyst.util.normpath(self.settings["storedir"]+"/builds/"+self.settings["target_subpath"]+"/") if "AUTORESUME" in self.settings \ and os.path.exists(self.settings["autoresume_path"]+"setup_target_path"): print "Resume point detected, skipping target path setup operation..." @@ -73,7 +73,7 @@ class grp_target(generic_stage_target): def generate_digests(self): for pkgset in self.settings["grp"]: if self.settings["grp/"+pkgset+"/type"] == "pkgset": - destdir=normpath(self.settings["target_path"]+"/"+pkgset+"/All") + destdir=catalyst.util.normpath(self.settings["target_path"]+"/"+pkgset+"/All") print "Digesting files in the pkgset....." digests=glob.glob(destdir+'/*.DIGESTS') for i in digests: @@ -84,11 +84,11 @@ class grp_target(generic_stage_target): #ignore files starting with '.' using list comprehension files=[filename for filename in files if filename[0] != '.'] for i in files: - if os.path.isfile(normpath(destdir+"/"+i)): - self.gen_contents_file(normpath(destdir+"/"+i)) - self.gen_digest_file(normpath(destdir+"/"+i)) + if os.path.isfile(catalyst.util.normpath(destdir+"/"+i)): + self.gen_contents_file(catalyst.util.normpath(destdir+"/"+i)) + self.gen_digest_file(catalyst.util.normpath(destdir+"/"+i)) else: - destdir=normpath(self.settings["target_path"]+"/"+pkgset) + destdir=catalyst.util.normpath(self.settings["target_path"]+"/"+pkgset) print "Digesting files in the srcset....." digests=glob.glob(destdir+'/*.DIGESTS') @@ -100,9 +100,9 @@ class grp_target(generic_stage_target): #ignore files starting with '.' using list comprehension files=[filename for filename in files if filename[0] != '.'] for i in files: - if os.path.isfile(normpath(destdir+"/"+i)): - #self.gen_contents_file(normpath(destdir+"/"+i)) - self.gen_digest_file(normpath(destdir+"/"+i)) + if os.path.isfile(catalyst.util.normpath(destdir+"/"+i)): + #self.gen_contents_file(catalyst.util.normpath(destdir+"/"+i)) + self.gen_digest_file(catalyst.util.normpath(destdir+"/"+i)) def set_action_sequence(self): self.settings["action_sequence"]=["unpack","unpack_snapshot",\ diff --git a/modules/catalyst/target/livecd_stage1.py b/modules/catalyst/target/livecd_stage1.py index b41dbee5..e54657de 100644 --- a/modules/catalyst/target/livecd_stage1.py +++ b/modules/catalyst/target/livecd_stage1.py @@ -5,6 +5,7 @@ Builder class for LiveCD stage1. from catalyst.support import * from generic_stage import * +import catalyst.util class livecd_stage1_target(generic_stage_target): def __init__(self,spec,addlargs): @@ -20,7 +21,7 @@ class livecd_stage1_target(generic_stage_target): "bind","chroot_setup","setup_environment","build_packages",\ "unbind", "clean","clear_autoresume"] def set_target_path(self): - self.settings["target_path"]=normpath(self.settings["storedir"]+"/builds/"+self.settings["target_subpath"]) + self.settings["target_path"]=catalyst.util.normpath(self.settings["storedir"]+"/builds/"+self.settings["target_subpath"]) if "AUTORESUME" in self.settings \ and os.path.exists(self.settings["autoresume_path"]+"setup_target_path"): print "Resume point detected, skipping target path setup operation..." @@ -60,7 +61,7 @@ class livecd_stage1_target(generic_stage_target): def set_pkgcache_path(self): if "pkgcache_path" in self.settings: if type(self.settings["pkgcache_path"]) != types.StringType: - self.settings["pkgcache_path"]=normpath(string.join(self.settings["pkgcache_path"])) + self.settings["pkgcache_path"]=catalyst.util.normpath(string.join(self.settings["pkgcache_path"])) else: generic_stage_target.set_pkgcache_path(self) diff --git a/modules/catalyst/target/livecd_stage2.py b/modules/catalyst/target/livecd_stage2.py index d09cb623..270b858e 100644 --- a/modules/catalyst/target/livecd_stage2.py +++ b/modules/catalyst/target/livecd_stage2.py @@ -31,11 +31,11 @@ class livecd_stage2_target(generic_stage_target): file_locate(self.settings, ["cdtar","controller_file"]) def set_source_path(self): - self.settings["source_path"]=normpath(self.settings["storedir"]+"/builds/"+self.settings["source_subpath"]+".tar.bz2") + self.settings["source_path"]=catalyst.util.normpath(self.settings["storedir"]+"/builds/"+self.settings["source_subpath"]+".tar.bz2") if os.path.isfile(self.settings["source_path"]): self.settings["source_path_hash"]=generate_hash(self.settings["source_path"]) else: - self.settings["source_path"]=normpath(self.settings["storedir"]+"/tmp/"+self.settings["source_subpath"]+"/") + self.settings["source_path"]=catalyst.util.normpath(self.settings["storedir"]+"/tmp/"+self.settings["source_subpath"]+"/") if not os.path.exists(self.settings["source_path"]): raise CatalystError,"Source Path: "+self.settings["source_path"]+" does not exist." @@ -43,7 +43,7 @@ class livecd_stage2_target(generic_stage_target): self.settings["spec_prefix"]="livecd" def set_target_path(self): - self.settings["target_path"]=normpath(self.settings["storedir"]+"/builds/"+self.settings["target_subpath"]+"/") + self.settings["target_path"]=catalyst.util.normpath(self.settings["storedir"]+"/builds/"+self.settings["target_subpath"]+"/") if "AUTORESUME" in self.settings \ and os.path.exists(self.settings["autoresume_path"]+"setup_target_path"): print "Resume point detected, skipping target path setup operation..." diff --git a/modules/catalyst/target/netboot.py b/modules/catalyst/target/netboot.py index bb026372..864ffe99 100644 --- a/modules/catalyst/target/netboot.py +++ b/modules/catalyst/target/netboot.py @@ -53,7 +53,7 @@ class netboot_target(generic_stage_target): def set_root_path(self): # ROOT= variable for emerges - self.settings["root_path"]=normpath("/tmp/image") + self.settings["root_path"]=catalyst.util.normpath("/tmp/image") print "netboot root path is "+self.settings["root_path"] # def build_packages(self): diff --git a/modules/catalyst/target/netboot2.py b/modules/catalyst/target/netboot2.py index f0827761..db5edfe1 100644 --- a/modules/catalyst/target/netboot2.py +++ b/modules/catalyst/target/netboot2.py @@ -38,10 +38,10 @@ class netboot2_target(generic_stage_target): generic_stage_target.__init__(self,spec,addlargs) self.set_build_kernel_vars() - self.settings["merge_path"]=normpath("/tmp/image/") + self.settings["merge_path"]=catalyst.util.normpath("/tmp/image/") def set_target_path(self): - self.settings["target_path"]=normpath(self.settings["storedir"]+"/builds/"+\ + self.settings["target_path"]=catalyst.util.normpath(self.settings["storedir"]+"/builds/"+\ self.settings["target_subpath"]+"/") if "AUTORESUME" in self.settings \ and os.path.exists(self.settings["autoresume_path"]+"setup_target_path"): diff --git a/modules/catalyst/target/snapshot.py b/modules/catalyst/target/snapshot.py index 5cc47165..d46963c2 100644 --- a/modules/catalyst/target/snapshot.py +++ b/modules/catalyst/target/snapshot.py @@ -6,6 +6,7 @@ Builder class for snapshots. import os from catalyst.support import * from generic_stage import * +import catalyst.util class snapshot_target(generic_stage_target): def __init__(self,myspec,addlargs): @@ -16,12 +17,12 @@ class snapshot_target(generic_stage_target): self.settings=myspec self.settings["target_subpath"]="portage" st=self.settings["storedir"] - self.settings["snapshot_path"]=normpath(st+"/snapshots/portage-"+self.settings["version_stamp"]\ + self.settings["snapshot_path"]=catalyst.util.normpath(st+"/snapshots/portage-"+self.settings["version_stamp"]\ +".tar.bz2") - self.settings["tmp_path"]=normpath(st+"/tmp/"+self.settings["target_subpath"]) + self.settings["tmp_path"]=catalyst.util.normpath(st+"/tmp/"+self.settings["target_subpath"]) def setup(self): - x=normpath(self.settings["storedir"]+"/snapshots") + x=catalyst.util.normpath(self.settings["storedir"]+"/snapshots") if not os.path.exists(x): os.makedirs(x) diff --git a/modules/catalyst/target/stage1.py b/modules/catalyst/target/stage1.py index 369d02f0..ac2b192c 100644 --- a/modules/catalyst/target/stage1.py +++ b/modules/catalyst/target/stage1.py @@ -14,12 +14,12 @@ class stage1_target(generic_stage_target): generic_stage_target.__init__(self,spec,addlargs) def set_stage_path(self): - self.settings["stage_path"]=normpath(self.settings["chroot_path"]+self.settings["root_path"]) + self.settings["stage_path"]=catalyst.util.normpath(self.settings["chroot_path"]+self.settings["root_path"]) print "stage1 stage path is "+self.settings["stage_path"] def set_root_path(self): # sets the root path, relative to 'chroot_path', of the stage1 root - self.settings["root_path"]=normpath("/tmp/stage1root") + self.settings["root_path"]=catalyst.util.normpath("/tmp/stage1root") print "stage1 root path is "+self.settings["root_path"] def set_cleanables(self): diff --git a/modules/catalyst/target/stage2.py b/modules/catalyst/target/stage2.py index 0c38337b..90877847 100644 --- a/modules/catalyst/target/stage2.py +++ b/modules/catalyst/target/stage2.py @@ -14,10 +14,10 @@ class stage2_target(generic_stage_target): generic_stage_target.__init__(self,spec,addlargs) def set_source_path(self): - if "SEEDCACHE" in self.settings and os.path.isdir(normpath(self.settings["storedir"]+"/tmp/"+self.settings["source_subpath"]+"/tmp/stage1root/")): - self.settings["source_path"]=normpath(self.settings["storedir"]+"/tmp/"+self.settings["source_subpath"]+"/tmp/stage1root/") + if "SEEDCACHE" in self.settings and os.path.isdir(catalyst.util.normpath(self.settings["storedir"]+"/tmp/"+self.settings["source_subpath"]+"/tmp/stage1root/")): + self.settings["source_path"]=catalyst.util.normpath(self.settings["storedir"]+"/tmp/"+self.settings["source_subpath"]+"/tmp/stage1root/") else: - self.settings["source_path"]=normpath(self.settings["storedir"]+"/builds/"+self.settings["source_subpath"]+".tar.bz2") + self.settings["source_path"]=catalyst.util.normpath(self.settings["storedir"]+"/builds/"+self.settings["source_subpath"]+".tar.bz2") if os.path.isfile(self.settings["source_path"]): if os.path.exists(self.settings["source_path"]): # XXX: Is this even necessary if the previous check passes? @@ -26,7 +26,7 @@ class stage2_target(generic_stage_target): print "Source path set to "+self.settings["source_path"] if os.path.isdir(self.settings["source_path"]): print "\tIf this is not desired, remove this directory or turn of seedcache in the options of catalyst.conf" - print "\tthe source path will then be "+normpath(self.settings["storedir"]+"/builds/"+self.settings["source_subpath"]+".tar.bz2\n") + print "\tthe source path will then be "+catalyst.util.normpath(self.settings["storedir"]+"/builds/"+self.settings["source_subpath"]+".tar.bz2\n") # XXX: How do these override_foo() functions differ from the ones in # generic_stage_target and why aren't they in stage3_target? diff --git a/modules/catalyst/util.py b/modules/catalyst/util.py index 815c23e8..dd3eab37 100644 --- a/modules/catalyst/util.py +++ b/modules/catalyst/util.py @@ -2,7 +2,7 @@ Collection of utility functions for catalyst """ -import sys, traceback, os +import sys, traceback, os, os.path def capture_traceback(): etype, value, tb = sys.exc_info() @@ -65,3 +65,11 @@ def list_to_string(mylist): mypack = " ".join(mypack) return mypack +def normpath(mypath): + newpath = os.path.normpath(mypath) + if mypath.endswith('/'): + newpath += '/' + if len(newpath) > 1 and newpath[:2] == '//': + newpath = newpath[1:] + return newpath + -- 2.26.2