# Copyright 2002-2009 Gentoo Foundation; 2008-2009 Various authors (see AUTHORS)
# Distributed under the GPL v2
+ 11 Jan 2009; Andrew Gaffney <agaffney@gentoo.org>
+ 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 <agaffney@gentoo.org>
modules/catalyst/support.py, modules/catalyst/target/stage1.py,
modules/catalyst/target/stage2.py, modules/catalyst/util.py:
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
-
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):
"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}
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"]+\
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"]
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?
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"]):
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"])
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"]+"/")
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")
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
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)..."
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..."
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:
#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')
#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",\
from catalyst.support import *
from generic_stage import *
+import catalyst.util
class livecd_stage1_target(generic_stage_target):
def __init__(self,spec,addlargs):
"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..."
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)
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."
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..."
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):
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"):
import os
from catalyst.support import *
from generic_stage import *
+import catalyst.util
class snapshot_target(generic_stage_target):
def __init__(self,myspec,addlargs):
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)
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):
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?
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?
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()
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
+