Minor changes
This commit is contained in:
parent
120c8105de
commit
8034dd06bb
@ -40,6 +40,20 @@ import images
|
||||
from sysutils import *
|
||||
|
||||
|
||||
# set up logging to file
|
||||
import logging
|
||||
LOG_FILENAME = "pylorax.log"
|
||||
logging.basicConfig(level=logging.DEBUG, filename=LOG_FILENAME, filemode="w")
|
||||
|
||||
# add the console handler
|
||||
console = logging.StreamHandler()
|
||||
console.setLevel(logging.INFO)
|
||||
logging.getLogger("").addHandler(console)
|
||||
|
||||
# get the logger
|
||||
logger = logging.getLogger("pylorax")
|
||||
|
||||
|
||||
# basearch efiarch 64bit
|
||||
ARCHMAP = {"i386": ["i386", "IA32", False],
|
||||
"i586": ["i386", "IA32", False],
|
||||
@ -65,13 +79,17 @@ class Lorax(BaseLoraxClass):
|
||||
|
||||
BaseLoraxClass.__init__(self)
|
||||
|
||||
# XXX check if we have root privileges
|
||||
assert os.geteuid() == self.const.ROOT_UID, "no root privileges"
|
||||
# XXX do we have root privileges?
|
||||
if not os.geteuid() == self.const.ROOT_UID:
|
||||
logger.critical("no root privileges")
|
||||
sys.exit(1)
|
||||
|
||||
# XXX check if we have a yumbase object
|
||||
assert isinstance(yb, yum.YumBase), "not an yum base object"
|
||||
# XXX do we have a proper yum base object?
|
||||
if not isinstance(yb, yum.YumBase):
|
||||
logger.critical("no yum base object")
|
||||
sys.exit(1)
|
||||
|
||||
# setup yum and the install tree
|
||||
# set up yum and the install tree
|
||||
self.yum = YumHelper(yb)
|
||||
self.installtree = insttree.InstallTree(yum=self.yum,
|
||||
rootdir=installtree,
|
||||
@ -80,21 +98,28 @@ class Lorax(BaseLoraxClass):
|
||||
# create the output directory
|
||||
self.outputdir = outputdir
|
||||
makedirs_(self.outputdir)
|
||||
logger.debug("using output directory {0}".format(self.outputdir))
|
||||
|
||||
# create the working directory
|
||||
self.workdir = workdir
|
||||
makedirs_(self.workdir)
|
||||
logger.debug("using working directory {0}".format(self.workdir))
|
||||
|
||||
# required parameters
|
||||
self.product = product
|
||||
self.version = version
|
||||
self.release = release
|
||||
|
||||
# create the working directory
|
||||
self.workdir = workdir
|
||||
makedirs_(self.workdir)
|
||||
logger.debug("set product = {0}".format(self.product))
|
||||
logger.debug("set version = {0}".format(self.version))
|
||||
logger.debug("set release = {0}".format(self.release))
|
||||
|
||||
# optional parameters
|
||||
self.variant = variant
|
||||
self.bugurl = bugurl
|
||||
logger.debug("set variant = {0}".format(self.variant))
|
||||
logger.debug("set bugurl = {0}".format(self.bugurl))
|
||||
|
||||
# setup the output
|
||||
# set up the output
|
||||
output_level = output.INFO
|
||||
if self.conf.debug:
|
||||
output_level = output.DEBUG
|
||||
@ -103,6 +128,7 @@ class Lorax(BaseLoraxClass):
|
||||
encoding=self.conf.encoding,
|
||||
output_level=output_level)
|
||||
|
||||
# read which output messages to ignore
|
||||
ignore_errors = set()
|
||||
if os.path.isfile(self.conf.ignore_errors):
|
||||
with open(self.conf.ignore_errors, "r") as f:
|
||||
|
@ -493,15 +493,29 @@ class EFI(BaseImageClass):
|
||||
os.unlink(efiboot)
|
||||
|
||||
# calculate the size of the efi tree directory
|
||||
self.pdebug("calculating the efiboot image size")
|
||||
fsoverhead = 100 * 1024
|
||||
self.pdebug("using {0} bytes for fs overhead".format(fsoverhead))
|
||||
|
||||
sizeinbytes = fsoverhead
|
||||
for root, dirs, files in os.walk(efitree):
|
||||
for file in files:
|
||||
filepath = os.path.join(root, file)
|
||||
sizeinbytes += os.path.getsize(filepath)
|
||||
filesize = os.path.getsize(filepath)
|
||||
|
||||
# round to multiplications of 1024
|
||||
filesize = math.ceil(filesize / 1024.0) * 1024
|
||||
|
||||
self.pdebug("adding {0} bytes for file {1}".format(filesize,
|
||||
filepath))
|
||||
|
||||
sizeinbytes += filesize
|
||||
|
||||
self.pdebug("required size in bytes: {0}".format(sizeinbytes))
|
||||
|
||||
# mkdosfs needs the size in blocks of 1024 bytes
|
||||
size = int(math.ceil(sizeinbytes / 1024.0))
|
||||
self.pdebug("required size in 1024 byte blocks: {0}".format(size))
|
||||
|
||||
cmd = "{0.MKDOSFS} -n ANACONDA -C {1} {2} > /dev/null"
|
||||
cmd = cmd.format(self.cmd, efiboot, size)
|
||||
|
@ -48,7 +48,7 @@ TAGS = [(re.compile(r"<b>"), C_BOLD),
|
||||
(re.compile(r"<red>"), C_RED),
|
||||
(re.compile(r"<green>"), C_GREEN),
|
||||
(re.compile(r"<blue>"), C_BLUE),
|
||||
(re.compile(r"</(b|u|red|green|blue)>"), C_RESET)]
|
||||
(re.compile(r"</(b|u|red|green|blue/)>"), C_RESET)]
|
||||
|
||||
|
||||
# output levels
|
||||
@ -67,10 +67,9 @@ class LoraxOutput(object):
|
||||
self._colors = True
|
||||
self._encoding = "utf-8"
|
||||
self._output_level = INFO
|
||||
self._ignore_msgs = set()
|
||||
self._indent_level = 0
|
||||
|
||||
self._ignore_errors = set()
|
||||
|
||||
def basic_config(self, colors=None, encoding=None, output_level=None):
|
||||
if colors is not None:
|
||||
self._colors = colors
|
||||
@ -81,13 +80,16 @@ class LoraxOutput(object):
|
||||
if output_level is not None:
|
||||
self._output_level = output_level
|
||||
|
||||
def ignore_message(self, messages):
|
||||
if type(messages) is str:
|
||||
self._ignore_msgs.add(messages)
|
||||
else:
|
||||
for msg in messages:
|
||||
self.ignore_message(msg)
|
||||
|
||||
@property
|
||||
def ignore(self):
|
||||
return self._ignore_errors
|
||||
|
||||
@ignore.setter
|
||||
def ignore(self, errors):
|
||||
self._ignore_errors = errors
|
||||
return self._ignore_msgs
|
||||
|
||||
def indent(self):
|
||||
self._indent_level += 1
|
||||
@ -135,12 +137,12 @@ class LoraxOutput(object):
|
||||
if self._output_level <= DEBUG:
|
||||
self.writeline(s, file=file)
|
||||
|
||||
def __raw(self, s):
|
||||
for tag, ccode in TAGS:
|
||||
s = tag.sub("", s)
|
||||
return s
|
||||
|
||||
def __format(self, s):
|
||||
for tag, ccode in TAGS:
|
||||
s = tag.sub(ccode, s)
|
||||
return s
|
||||
|
||||
def __raw(self, s):
|
||||
for tag, ccode in TAGS:
|
||||
s = tag.sub("", s)
|
||||
return s
|
||||
|
@ -33,6 +33,9 @@ import pwd
|
||||
import grp
|
||||
import commands
|
||||
|
||||
import logging
|
||||
logger = logging.getLogger("sysutils")
|
||||
|
||||
|
||||
class SysUtilsError(Exception):
|
||||
pass
|
||||
@ -326,6 +329,7 @@ class SmartCopy(object):
|
||||
|
||||
# copy all the files
|
||||
for src, dst in self.copyfiles:
|
||||
logger.debug("copying {0}".format(src))
|
||||
try:
|
||||
shutil.copy2(src, dst)
|
||||
except shutil.Error as why:
|
||||
|
Loading…
Reference in New Issue
Block a user