# 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/generic_stage.py,
+ modules/catalyst/util.py:
+ Move read_makeconf() and parse_makeconf() from catalyst.support to
+ catalyst.util
+
11 Jan 2009; Andrew Gaffney <agaffney@gentoo.org>
modules/catalyst/support.py, modules/catalyst/target/generic_stage.py,
modules/catalyst/target/livecd_stage2.py,
-import sys, os, re, signal
-from catalyst.output import warn
-import catalyst.util
+import os, re
from catalyst.error import *
required_config_file_values=["storedir","sharedir","distdir","portdir"]
"item2" "item3" ordering is not, as the item strings are stored in a dictionary (hash).
"""
-def parse_makeconf(mylines):
- mymakeconf={}
- pos=0
- pat=re.compile("([0-9a-zA-Z_]*)=(.*)")
- while pos<len(mylines):
- if len(mylines[pos])<=1:
- #skip blanks
- pos += 1
- continue
- if mylines[pos][0] in ["#"," ","\t"]:
- #skip indented lines, comments
- pos += 1
- continue
- else:
- myline=mylines[pos]
- mobj=pat.match(myline)
- pos += 1
- if mobj.group(2):
- clean_string = re.sub(r"\"",r"",mobj.group(2))
- mymakeconf[mobj.group(1)]=clean_string
- return mymakeconf
-
-def read_makeconf(mymakeconffile):
- if os.path.exists(mymakeconffile):
- try:
- try:
- import snakeoil.fileutils
- return snakeoil.fileutils.read_bash_dict(mymakeconffile, sourcing_command="source")
- except ImportError:
- try:
- import portage_util
- return portage_util.getconfig(mymakeconffile, tolerant=1, allow_sourcing=True)
- except ImportError:
- myf=open(mymakeconffile,"r")
- mylines=myf.readlines()
- myf.close()
- return parse_makeconf(mylines)
- except:
- raise CatalystError, "Could not parse make.conf file "+mymakeconffile
- else:
- makeconf={}
- return makeconf
-
def addl_arg_parse(myspec,addlargs,requiredspec,validspec):
"helper function to help targets parse additional arguments"
global valid_config_file_values
"Couldn't umount one or more bind-mounts; aborting for safety."
def chroot_setup(self):
- self.makeconf=read_makeconf(self.settings["chroot_path"]+\
+ self.makeconf=catalyst.util.read_makeconf(self.settings["chroot_path"]+\
"/etc/make.conf")
self.override_cbuild()
self.override_chost()
else:
print "Setting up chroot..."
- #self.makeconf=read_makeconf(self.settings["chroot_path"]+"/etc/make.conf")
+ #self.makeconf=catalyst.util.read_makeconf(self.settings["chroot_path"]+"/etc/make.conf")
cmd("cp /etc/resolv.conf "+self.settings["chroot_path"]+"/etc",\
"Could not copy resolv.conf into place.",env=self.env)
settings[myfile] = os.getcwd() + "/" + settings[myfile]
else:
raise CatalystError, "Cannot locate specified " + myfile + ": " + settings[myfile] + " (2nd try)"
+
+def parse_makeconf(mylines):
+ mymakeconf={}
+ pos=0
+ pat=re.compile("([0-9a-zA-Z_]*)=(.*)")
+ while pos<len(mylines):
+ if len(mylines[pos])<=1:
+ #skip blanks
+ pos += 1
+ continue
+ if mylines[pos][0] in ["#"," ","\t"]:
+ #skip indented lines, comments
+ pos += 1
+ continue
+ else:
+ myline=mylines[pos]
+ mobj=pat.match(myline)
+ pos += 1
+ if mobj.group(2):
+ clean_string = re.sub(r"\"",r"",mobj.group(2))
+ mymakeconf[mobj.group(1)]=clean_string
+ return mymakeconf
+
+def read_makeconf(mymakeconffile):
+ if os.path.exists(mymakeconffile):
+ try:
+ try:
+ import snakeoil.fileutils
+ return snakeoil.fileutils.read_bash_dict(mymakeconffile, sourcing_command="source")
+ except ImportError:
+ try:
+ import portage_util
+ return portage_util.getconfig(mymakeconffile, tolerant=1, allow_sourcing=True)
+ except ImportError:
+ myf=open(mymakeconffile,"r")
+ mylines=myf.readlines()
+ myf.close()
+ return parse_makeconf(mylines)
+ except:
+ raise CatalystError, "Could not parse make.conf file "+mymakeconffile
+ else:
+ makeconf={}
+ return makeconf
+