diff --git a/src/pylorax/__init__.py b/src/pylorax/__init__.py index e6465f43..ebfbf2e6 100644 --- a/src/pylorax/__init__.py +++ b/src/pylorax/__init__.py @@ -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: diff --git a/src/pylorax/images.py b/src/pylorax/images.py index 89d8275d..fd2696e7 100644 --- a/src/pylorax/images.py +++ b/src/pylorax/images.py @@ -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) diff --git a/src/pylorax/output.py b/src/pylorax/output.py index c2e6c391..b0630675 100644 --- a/src/pylorax/output.py +++ b/src/pylorax/output.py @@ -48,7 +48,7 @@ TAGS = [(re.compile(r""), C_BOLD), (re.compile(r""), C_RED), (re.compile(r""), C_GREEN), (re.compile(r""), C_BLUE), - (re.compile(r""), C_RESET)] + (re.compile(r""), 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 diff --git a/src/pylorax/sysutils.py b/src/pylorax/sysutils.py index 1a6548a1..fd4123e5 100644 --- a/src/pylorax/sysutils.py +++ b/src/pylorax/sysutils.py @@ -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: