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