[molecule] improve Python 3.x support
This commit is contained in:
+1
-1
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/python -O
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
# Molecule Disc Image builder for Sabayon Linux
|
||||
# Copyright (C) 2009 Fabio Erculiani
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#!/usr/bin/python -O
|
||||
# -*- coding: iso-8859-1 -*-
|
||||
# -*- coding: utf-8 -*-
|
||||
# Molecule Disc Image builder for Sabayon Linux
|
||||
# Copyright (C) 2009 Fabio Erculiani
|
||||
#
|
||||
|
||||
+7
-8
@@ -1,4 +1,3 @@
|
||||
#!/usr/bin/python -O
|
||||
# -*- coding: utf-8 -*-
|
||||
# Molecule Disc Image builder for Sabayon Linux
|
||||
# Copyright (C) 2009 Fabio Erculiani
|
||||
@@ -42,7 +41,7 @@ def parse():
|
||||
|
||||
data_order = []
|
||||
for el in myargs:
|
||||
if os.path.isfile(el) and os.access(el,os.R_OK):
|
||||
if os.path.isfile(el) and os.access(el, os.R_OK):
|
||||
obj = SpecParser(el)
|
||||
el_data = obj.parse()
|
||||
del obj
|
||||
@@ -55,17 +54,17 @@ def print_help():
|
||||
config = Configuration()
|
||||
help_data = [
|
||||
None,
|
||||
(0," ~ Molecule %s ~ " % (config.get('version'),) ,1,
|
||||
(0, " ~ Molecule %s ~ " % (config.get('version'),), 1,
|
||||
'Disc Image builder for Sabayon Linux - (C) %s' % (
|
||||
molecule.utils.get_year(),) ),
|
||||
None,
|
||||
(0,_('Basic Options'),0,None),
|
||||
(0, _('Basic Options'), 0, None),
|
||||
None,
|
||||
(1,'--help',2,_('this output')),
|
||||
(1,'--nocolor',1,_('disable colorized output')),
|
||||
(1, '--help', 2, _('this output')),
|
||||
(1, '--nocolor', 1, _('disable colorized output')),
|
||||
None,
|
||||
(0,_('Application Options'),0,None),
|
||||
(1,'<spec file path 1> <spec file path 2> ...',1,
|
||||
(0, _('Application Options'), 0, None),
|
||||
(1, '<spec file path 1> <spec file path 2> ...', 1,
|
||||
_('execute against specified specification files')),
|
||||
None,
|
||||
]
|
||||
|
||||
@@ -0,0 +1,172 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Molecule Python 2.6/3.x compatibility module
|
||||
# Copyright (C) 2010 Fabio Erculiani
|
||||
#
|
||||
# Copyright 1998-2004 Gentoo Foundation
|
||||
# # $Id: output.py 4906 2006-11-01 23:55:29Z zmedico $
|
||||
# Copyright (C) 2007-2008 Fabio Erculiani
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
import sys
|
||||
|
||||
def get_stringtype():
|
||||
"""
|
||||
Return generic string type for usage in isinstance().
|
||||
On Python 2.x, it returns basestring while on Python 3.x it returns
|
||||
(str, bytes,)
|
||||
"""
|
||||
if sys.hexversion >= 0x3000000:
|
||||
return (str, bytes,)
|
||||
else:
|
||||
return (basestring,)
|
||||
|
||||
def isstring(obj):
|
||||
"""
|
||||
Return whether obj is a string (unicode or raw).
|
||||
|
||||
@param obj: Python object
|
||||
@type obj: Python object
|
||||
@return: True, if object is string
|
||||
@rtype: bool
|
||||
"""
|
||||
if sys.hexversion >= 0x3000000:
|
||||
return isinstance(obj, (str, bytes))
|
||||
else:
|
||||
return isinstance(obj, basestring)
|
||||
|
||||
def isunicode(obj):
|
||||
"""
|
||||
Return whether obj is a unicode.
|
||||
|
||||
@param obj: Python object
|
||||
@type obj: Python object
|
||||
@return: True, if object is unicode
|
||||
@rtype: bool
|
||||
"""
|
||||
if sys.hexversion >= 0x3000000:
|
||||
return isinstance(obj, str)
|
||||
else:
|
||||
return isinstance(obj, unicode)
|
||||
|
||||
def israwstring(obj):
|
||||
if sys.hexversion >= 0x3000000:
|
||||
return isinstance(obj, bytes)
|
||||
else:
|
||||
return isinstance(obj, str)
|
||||
|
||||
def get_gettext_kwargs():
|
||||
if sys.hexversion >= 0x3000000:
|
||||
return {'str': True}
|
||||
else:
|
||||
return {'unicode': True}
|
||||
|
||||
def convert_to_unicode(obj, enctype = 'raw_unicode_escape'):
|
||||
"""
|
||||
Convert generic string to unicode format, this function supports both
|
||||
Python 2.x and Python 3.x unicode bullshit.
|
||||
|
||||
@param obj: generic string object
|
||||
@type obj: string
|
||||
@return: unicode string object
|
||||
@rtype: unicode object
|
||||
"""
|
||||
|
||||
# None support
|
||||
if obj is None:
|
||||
if sys.hexversion >= 0x3000000:
|
||||
return "None"
|
||||
else:
|
||||
return u"None"
|
||||
|
||||
# int support
|
||||
if isinstance(obj, int):
|
||||
if sys.hexversion >= 0x3000000:
|
||||
return str(obj)
|
||||
else:
|
||||
return unicode(obj)
|
||||
|
||||
# buffer support
|
||||
if isinstance(obj, get_buffer()):
|
||||
if sys.hexversion >= 0x3000000:
|
||||
return str(obj.tobytes(), enctype)
|
||||
else:
|
||||
return unicode(obj, enctype)
|
||||
|
||||
# string/unicode support
|
||||
if isunicode(obj):
|
||||
return obj
|
||||
if hasattr(obj, 'decode'):
|
||||
return obj.decode(enctype)
|
||||
else:
|
||||
if sys.hexversion >= 0x3000000:
|
||||
return str(obj, enctype)
|
||||
else:
|
||||
return unicode(obj, enctype)
|
||||
|
||||
def convert_to_rawstring(obj, from_enctype = 'raw_unicode_escape'):
|
||||
"""
|
||||
Convert generic string to raw string (str for Python 2.x or bytes for
|
||||
Python 3.x).
|
||||
|
||||
@param obj: input string
|
||||
@type obj: string object
|
||||
@keyword from_enctype: encoding which string is using
|
||||
@type from_enctype: string
|
||||
@return: raw string
|
||||
@rtype: bytes
|
||||
"""
|
||||
if obj is None:
|
||||
return convert_to_rawstring("None")
|
||||
if isnumber(obj):
|
||||
if sys.hexversion >= 0x3000000:
|
||||
return bytes(str(obj), from_enctype)
|
||||
else:
|
||||
return str(obj)
|
||||
if isinstance(obj, get_buffer()):
|
||||
if sys.hexversion >= 0x3000000:
|
||||
return obj.tobytes()
|
||||
else:
|
||||
return str(obj)
|
||||
if not isunicode(obj):
|
||||
return obj
|
||||
return obj.encode(from_enctype)
|
||||
|
||||
def get_buffer():
|
||||
"""
|
||||
Return generic buffer object (supporting both Python 2.x and Python 3.x)
|
||||
"""
|
||||
if sys.hexversion >= 0x3000000:
|
||||
return memoryview
|
||||
else:
|
||||
return buffer
|
||||
|
||||
def isfileobj(obj):
|
||||
"""
|
||||
Return whether obj is a file object
|
||||
"""
|
||||
if sys.hexversion >= 0x3000000:
|
||||
import io
|
||||
return isinstance(obj, io.IOBase)
|
||||
else:
|
||||
return isinstance(obj, file)
|
||||
|
||||
def isnumber(obj):
|
||||
"""
|
||||
Return whether obj is an int, long object.
|
||||
"""
|
||||
if sys.hexversion >= 0x3000000:
|
||||
return isinstance(obj, int)
|
||||
else:
|
||||
return isinstance(obj, (int, long,))
|
||||
@@ -1,5 +1,4 @@
|
||||
#!/usr/bin/python -O
|
||||
# -*- coding: iso-8859-1 -*-
|
||||
# -*- coding: utf-8 -*-
|
||||
# Molecule Disc Image builder for Sabayon Linux
|
||||
# Copyright (C) 2009 Fabio Erculiani
|
||||
#
|
||||
@@ -17,13 +16,15 @@
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
|
||||
from molecule.compat import get_stringtype
|
||||
|
||||
class MoleculeException(Exception):
|
||||
"""General superclass for Entropy exceptions"""
|
||||
def __init__(self,value):
|
||||
def __init__(self, value):
|
||||
self.value = value[:]
|
||||
|
||||
def __str__(self):
|
||||
if isinstance(self.value, basestring):
|
||||
if isinstance(self.value, get_stringtype()):
|
||||
return self.value
|
||||
else:
|
||||
return repr(self.value)
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#!/usr/bin/python -O
|
||||
# -*- coding: utf-8 -*-
|
||||
# Molecule Disc Image builder for Sabayon Linux
|
||||
# Copyright (C) 2009 Fabio Erculiani
|
||||
@@ -16,6 +15,7 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
|
||||
from molecule.i18n import _
|
||||
from molecule.output import brown, darkgreen
|
||||
from molecule.specs.skel import GenericExecutionStep
|
||||
@@ -35,20 +35,20 @@ class Runner(GenericExecutionStep):
|
||||
count = 0
|
||||
maxcount = len(self.execution_order)
|
||||
self._output.output( "[%s|%s] %s" % (
|
||||
darkgreen("Runner"),brown(self.spec_name),
|
||||
_("preparing execution"),), count = (count,maxcount,)
|
||||
darkgreen("Runner"), brown(self.spec_name),
|
||||
_("preparing execution"),), count = (count, maxcount,)
|
||||
)
|
||||
for myclass in self.execution_order:
|
||||
|
||||
count += 1
|
||||
self._output.output( "[%s|%s] %s %s" % (
|
||||
darkgreen("Runner"),brown(self.spec_name),_("executing"),
|
||||
str(myclass),), count = (count,maxcount,)
|
||||
darkgreen("Runner"), brown(self.spec_name), _("executing"),
|
||||
str(myclass),), count = (count, maxcount,)
|
||||
)
|
||||
my = myclass(self.spec_path, self.metadata)
|
||||
|
||||
rc = 0
|
||||
while 1:
|
||||
while True:
|
||||
|
||||
try:
|
||||
|
||||
@@ -79,7 +79,7 @@ class Runner(GenericExecutionStep):
|
||||
return rc
|
||||
|
||||
self._output.output( "[%s|%s] %s" % (
|
||||
darkgreen("Runner"),brown(self.spec_name),
|
||||
darkgreen("Runner"), brown(self.spec_name),
|
||||
_("All done"),
|
||||
)
|
||||
)
|
||||
|
||||
+4
-6
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
@@ -13,17 +13,15 @@
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
"""
|
||||
License: GPL
|
||||
Author: Fabio Erculiani <lxnay@sabayonlinux.org>
|
||||
"""
|
||||
from molecule.compat import get_gettext_kwargs
|
||||
|
||||
_LOCALE = None
|
||||
try:
|
||||
import gettext
|
||||
import os
|
||||
gettext.bindtextdomain('molecule', '/usr/share/locale')
|
||||
gettext.textdomain('molecule')
|
||||
gettext.install('molecule', unicode = True)
|
||||
gettext.install('molecule', *get_gettext_kwargs())
|
||||
_ = _
|
||||
|
||||
_LOCALE_FULL = os.getenv('LC_ALL')
|
||||
|
||||
+11
-8
@@ -1,5 +1,4 @@
|
||||
#!/usr/bin/python -O
|
||||
# -*- coding: iso-8859-1 -*-
|
||||
# -*- coding: utf-8 -*-
|
||||
# Molecule Disc Image builder for Sabayon Linux
|
||||
# Copyright (C) 2009 Fabio Erculiani
|
||||
#
|
||||
@@ -21,9 +20,13 @@
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
|
||||
from molecule.i18n import _
|
||||
import sys, os
|
||||
import sys
|
||||
import os
|
||||
import curses
|
||||
|
||||
from molecule.compat import get_stringtype
|
||||
from molecule.i18n import _
|
||||
|
||||
stuff = {}
|
||||
stuff['cols'] = 30
|
||||
try:
|
||||
@@ -108,7 +111,7 @@ codes["blink"] = esc_seq + "05m"
|
||||
codes["overline"] = esc_seq + "06m" # Who made this up? Seriously.
|
||||
|
||||
ansi_color_codes = []
|
||||
for x in xrange(30, 38):
|
||||
for x in range(30, 38):
|
||||
ansi_color_codes.append("%im" % x)
|
||||
ansi_color_codes.append("%i;01m" % x)
|
||||
|
||||
@@ -116,7 +119,7 @@ rgb_ansi_colors = ['0x000000', '0x555555', '0xAA0000', '0xFF5555', '0x00AA00',
|
||||
'0x55FF55', '0xAA5500', '0xFFFF55', '0x0000AA', '0x5555FF', '0xAA00AA',
|
||||
'0xFF55FF', '0x00AAAA', '0x55FFFF', '0xAAAAAA', '0xFFFFFF']
|
||||
|
||||
for x in xrange(len(rgb_ansi_colors)):
|
||||
for x in range(len(rgb_ansi_colors)):
|
||||
codes[rgb_ansi_colors[x]] = esc_seq + ansi_color_codes[x]
|
||||
|
||||
del x
|
||||
@@ -544,7 +547,7 @@ def _flush_stdouterr():
|
||||
return
|
||||
|
||||
def _stdout_write(msg):
|
||||
if not isinstance(msg, basestring):
|
||||
if not isinstance(msg, get_stringtype()):
|
||||
msg = repr(msg)
|
||||
try:
|
||||
sys.stdout.write(msg)
|
||||
@@ -645,7 +648,7 @@ def writechar(char):
|
||||
try:
|
||||
sys.stdout.write(char)
|
||||
sys.stdout.flush()
|
||||
except IOError, e:
|
||||
except IOError as e:
|
||||
if e.errno == 32:
|
||||
return
|
||||
raise
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
|
||||
import os
|
||||
from molecule.compat import get_stringtype
|
||||
from molecule.exception import SpecFileError
|
||||
from molecule.specs.skel import GenericSpec
|
||||
from molecule.version import VERSION
|
||||
@@ -138,7 +139,7 @@ class SpecPreprocessor:
|
||||
|
||||
with open(path, "r") as spec_f:
|
||||
lines = ''
|
||||
for line in spec_f.xreadlines():
|
||||
for line in spec_f.readlines():
|
||||
# call recursively
|
||||
split_line = line.split(" ", 1)
|
||||
if split_line:
|
||||
@@ -153,7 +154,7 @@ class SpecPreprocessor:
|
||||
|
||||
content = []
|
||||
with open(self._spec_path, "r") as spec_f:
|
||||
for line in spec_f.xreadlines():
|
||||
for line in spec_f.readlines():
|
||||
split_line = line.split(" ", 1)
|
||||
if split_line:
|
||||
expander = self.__builtin_expanders.get(split_line[0])
|
||||
@@ -239,7 +240,7 @@ class SpecParser:
|
||||
if key is None:
|
||||
continue
|
||||
old_key = key
|
||||
elif isinstance(old_key, basestring):
|
||||
elif isinstance(old_key, get_stringtype()):
|
||||
key = old_key
|
||||
value = line.strip()
|
||||
if not value:
|
||||
@@ -251,7 +252,7 @@ class SpecParser:
|
||||
if not check_dict['cb'](value):
|
||||
continue
|
||||
if key in mydict:
|
||||
if isinstance(value, basestring):
|
||||
if isinstance(value, get_stringtype()):
|
||||
mydict[key] += " %s" % (value,)
|
||||
elif isinstance(value, list):
|
||||
mydict[key] += value
|
||||
@@ -269,7 +270,7 @@ class SpecParser:
|
||||
raise SpecFileError(
|
||||
"SpecFileError: '%s' missing or invalid"
|
||||
" '%s' parameter, it's vital. Your specification"
|
||||
" file is incomplete!" % (self.filepath,param,)
|
||||
" file is incomplete!" % (self.filepath, param,)
|
||||
)
|
||||
|
||||
def _generic_parser(self):
|
||||
|
||||
@@ -293,7 +293,10 @@ class PluginFactory:
|
||||
def _get_spec():
|
||||
if PluginFactory._SPEC_FACTORY is None:
|
||||
from molecule.specs.skel import GenericSpec
|
||||
from . import plugins as plugs
|
||||
try:
|
||||
from .. import plugins as plugs
|
||||
except ImportError:
|
||||
from . import plugins as plugs
|
||||
PluginFactory._SPEC_FACTORY = PluginFactory(GenericSpec, plugs)
|
||||
return PluginFactory._SPEC_FACTORY
|
||||
|
||||
@@ -302,5 +305,5 @@ class PluginFactory:
|
||||
factory = PluginFactory._get_spec()
|
||||
plugins = factory.get_available_plugins()
|
||||
spec_plugins = dict((y.execution_strategy(), y) for x, y \
|
||||
in plugins.items())
|
||||
in list(plugins.items()))
|
||||
return spec_plugins
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
import os
|
||||
import shutil
|
||||
from molecule.compat import get_stringtype
|
||||
from molecule.i18n import _
|
||||
from molecule.output import red, brown, blue, green, purple, darkgreen, \
|
||||
darkred, bold, darkblue, readtext
|
||||
@@ -38,7 +39,7 @@ class BuiltinHandlerMixin:
|
||||
if cdroot_dir:
|
||||
os.environ['CDROOT_DIR'] = cdroot_dir
|
||||
self._output.output("[%s|%s] %s: %s" % (
|
||||
blue("BuiltinHandler"),darkred(self.spec_name),
|
||||
blue("BuiltinHandler"), darkred(self.spec_name),
|
||||
_("spawning"), error_script,
|
||||
)
|
||||
)
|
||||
@@ -51,7 +52,7 @@ class BuiltinHandlerMixin:
|
||||
|
||||
def _exec_inner_script(self, exec_script, dest_chroot):
|
||||
|
||||
while 1:
|
||||
while True:
|
||||
tmp_dir = os.path.join(dest_chroot,
|
||||
str(molecule.utils.get_random_number()))
|
||||
if not os.path.lexists(tmp_dir):
|
||||
@@ -60,20 +61,20 @@ class BuiltinHandlerMixin:
|
||||
os.makedirs(tmp_dir)
|
||||
tmp_exec = os.path.join(tmp_dir, "inner_exec")
|
||||
shutil.copy2(exec_script[0], tmp_exec)
|
||||
os.chmod(tmp_exec, 0755)
|
||||
os.chmod(tmp_exec, 0o755)
|
||||
dest_exec = tmp_exec[len(dest_chroot):]
|
||||
if not dest_exec.startswith("/"):
|
||||
dest_exec = "/%s" % (dest_exec,)
|
||||
|
||||
rc = molecule.utils.exec_chroot_cmd([dest_exec] + exec_script[1:],
|
||||
dest_chroot, self.metadata.get('prechroot',[]))
|
||||
dest_chroot, self.metadata.get('prechroot', []))
|
||||
os.remove(tmp_exec)
|
||||
os.rmdir(tmp_dir)
|
||||
|
||||
if rc != 0:
|
||||
self._output.output("[%s|%s] %s: %s" % (
|
||||
blue("BuiltinHandler"),darkred(self.spec_name),
|
||||
_("inner chroot hook failed"),rc,
|
||||
blue("BuiltinHandler"), darkred(self.spec_name),
|
||||
_("inner chroot hook failed"), rc,
|
||||
)
|
||||
)
|
||||
return rc
|
||||
@@ -87,15 +88,15 @@ class MirrorHandler(GenericExecutionStep, BuiltinHandlerMixin):
|
||||
# creating destination chroot dir
|
||||
self.source_dir = self.metadata['source_chroot']
|
||||
self.dest_dir = os.path.join(
|
||||
self.metadata['destination_chroot'],"chroot",
|
||||
self.metadata['destination_chroot'], "chroot",
|
||||
os.path.basename(self.source_dir)
|
||||
)
|
||||
if not os.path.isdir(self.dest_dir):
|
||||
os.makedirs(self.dest_dir,0755)
|
||||
os.makedirs(self.dest_dir, 0o755)
|
||||
|
||||
def pre_run(self):
|
||||
self._output.output("[%s|%s] %s" % (
|
||||
blue("MirrorHandler"),darkred(self.spec_name),
|
||||
blue("MirrorHandler"), darkred(self.spec_name),
|
||||
_("executing pre_run"),
|
||||
)
|
||||
)
|
||||
@@ -115,7 +116,7 @@ class MirrorHandler(GenericExecutionStep, BuiltinHandlerMixin):
|
||||
|
||||
|
||||
self._output.output("[%s|%s] %s" % (
|
||||
blue("MirrorHandler"),darkred(self.spec_name),
|
||||
blue("MirrorHandler"), darkred(self.spec_name),
|
||||
_("pre_run completed successfully"),
|
||||
)
|
||||
)
|
||||
@@ -124,7 +125,7 @@ class MirrorHandler(GenericExecutionStep, BuiltinHandlerMixin):
|
||||
|
||||
def post_run(self):
|
||||
self._output.output("[%s|%s] %s" % (
|
||||
blue("MirrorHandler"),darkred(self.spec_name),
|
||||
blue("MirrorHandler"), darkred(self.spec_name),
|
||||
_("executing post_run"),
|
||||
)
|
||||
)
|
||||
@@ -134,7 +135,7 @@ class MirrorHandler(GenericExecutionStep, BuiltinHandlerMixin):
|
||||
if not success:
|
||||
self._run_error_script(self.source_dir, self.dest_dir, None)
|
||||
self._output.output("[%s|%s] %s" % (
|
||||
blue("MirrorHandler"),darkred(self.spec_name),
|
||||
blue("MirrorHandler"), darkred(self.spec_name),
|
||||
_("executing kill"),
|
||||
)
|
||||
)
|
||||
@@ -143,31 +144,31 @@ class MirrorHandler(GenericExecutionStep, BuiltinHandlerMixin):
|
||||
def run(self):
|
||||
|
||||
self._output.output("[%s|%s] %s" % (
|
||||
blue("MirrorHandler"),darkred(self.spec_name),
|
||||
blue("MirrorHandler"), darkred(self.spec_name),
|
||||
_("mirroring running"),
|
||||
)
|
||||
)
|
||||
# running sync
|
||||
args = [self._config['mirror_syncer']]
|
||||
args.extend(self._config['mirror_syncer_builtin_args'])
|
||||
args.extend(self.metadata.get('extra_rsync_parameters',[]))
|
||||
args.extend([self.source_dir+"/*",self.dest_dir])
|
||||
args.extend(self.metadata.get('extra_rsync_parameters', []))
|
||||
args.extend([self.source_dir+"/*", self.dest_dir])
|
||||
self._output.output("[%s|%s] %s: %s" % (
|
||||
blue("MirrorHandler"),darkred(self.spec_name),
|
||||
_("spawning"),args,
|
||||
blue("MirrorHandler"), darkred(self.spec_name),
|
||||
_("spawning"), args,
|
||||
)
|
||||
)
|
||||
rc = molecule.utils.exec_cmd(args)
|
||||
if rc != 0:
|
||||
self._output.output("[%s|%s] %s: %s" % (
|
||||
blue("MirrorHandler"),darkred(self.spec_name),
|
||||
_("mirroring failed"),rc,
|
||||
blue("MirrorHandler"), darkred(self.spec_name),
|
||||
_("mirroring failed"), rc,
|
||||
)
|
||||
)
|
||||
return rc
|
||||
|
||||
self._output.output("[%s|%s] %s" % (
|
||||
blue("MirrorHandler"),darkred(self.spec_name),
|
||||
blue("MirrorHandler"), darkred(self.spec_name),
|
||||
_("mirroring completed successfully"),
|
||||
)
|
||||
)
|
||||
@@ -187,7 +188,7 @@ class ChrootHandler(GenericExecutionStep, BuiltinHandlerMixin):
|
||||
|
||||
def pre_run(self):
|
||||
self._output.output("[%s|%s] %s" % (
|
||||
blue("ChrootHandler"),darkred(self.spec_name),
|
||||
blue("ChrootHandler"), darkred(self.spec_name),
|
||||
_("executing pre_run"),
|
||||
)
|
||||
)
|
||||
@@ -204,8 +205,8 @@ class ChrootHandler(GenericExecutionStep, BuiltinHandlerMixin):
|
||||
rc = molecule.utils.exec_cmd(exec_script)
|
||||
if rc != 0:
|
||||
self._output.output("[%s|%s] %s: %s" % (
|
||||
blue("ChrootHandler"),darkred(self.spec_name),
|
||||
_("outer chroot hook failed"),rc,
|
||||
blue("ChrootHandler"), darkred(self.spec_name),
|
||||
_("outer chroot hook failed"), rc,
|
||||
)
|
||||
)
|
||||
return rc
|
||||
@@ -214,25 +215,25 @@ class ChrootHandler(GenericExecutionStep, BuiltinHandlerMixin):
|
||||
|
||||
def post_run(self):
|
||||
self._output.output("[%s|%s] %s" % (
|
||||
blue("ChrootHandler"),darkred(self.spec_name),
|
||||
blue("ChrootHandler"), darkred(self.spec_name),
|
||||
_("executing post_run"),
|
||||
)
|
||||
)
|
||||
|
||||
# now remove paths to empty
|
||||
empty_paths = self.metadata.get('paths_to_empty',[])
|
||||
empty_paths = self.metadata.get('paths_to_empty', [])
|
||||
for mypath in empty_paths:
|
||||
mypath = self.dest_dir+mypath
|
||||
self._output.output("[%s|%s] %s: %s" % (
|
||||
blue("ChrootHandler"),darkred(self.spec_name),
|
||||
_("emptying dir"),mypath,
|
||||
blue("ChrootHandler"), darkred(self.spec_name),
|
||||
_("emptying dir"), mypath,
|
||||
)
|
||||
)
|
||||
if os.path.isdir(mypath):
|
||||
molecule.utils.empty_dir(mypath)
|
||||
|
||||
# now remove paths to remove (...)
|
||||
remove_paths = self.metadata.get('paths_to_remove',[])
|
||||
remove_paths = self.metadata.get('paths_to_remove', [])
|
||||
|
||||
# setup sandbox
|
||||
sb_dirs = [self.dest_dir]
|
||||
@@ -245,46 +246,47 @@ class ChrootHandler(GenericExecutionStep, BuiltinHandlerMixin):
|
||||
for mypath in remove_paths:
|
||||
mypath = self.dest_dir+mypath
|
||||
self._output.output("[%s|%s] %s: %s" % (
|
||||
blue("ChrootHandler"),darkred(self.spec_name),
|
||||
_("removing dir"),mypath,
|
||||
blue("ChrootHandler"), darkred(self.spec_name),
|
||||
_("removing dir"), mypath,
|
||||
)
|
||||
)
|
||||
rc = molecule.utils.remove_path_sandbox(mypath, sb_env)
|
||||
if rc != 0:
|
||||
self._output.output("[%s|%s] %s: %s: %s" % (
|
||||
blue("ChrootHandler"),darkred(self.spec_name),
|
||||
_("removal failed for"),mypath,rc,
|
||||
blue("ChrootHandler"), darkred(self.spec_name),
|
||||
_("removal failed for"), mypath, rc,
|
||||
)
|
||||
)
|
||||
return rc
|
||||
|
||||
# write release file
|
||||
release_file = self.metadata.get('release_file')
|
||||
if isinstance(release_file,basestring) and release_file:
|
||||
if release_file[0] == os.sep: release_file = release_file[len(os.sep):]
|
||||
release_file = os.path.join(self.dest_dir,release_file)
|
||||
if isinstance(release_file, get_stringtype()) and release_file:
|
||||
if release_file[0] == os.sep:
|
||||
release_file = release_file[len(os.sep):]
|
||||
release_file = os.path.join(self.dest_dir, release_file)
|
||||
if os.path.lexists(release_file) and not os.path.isfile(release_file):
|
||||
self._output.output("[%s|%s] %s: %s" % (
|
||||
blue("ChrootHandler"),darkred(self.spec_name),
|
||||
blue("ChrootHandler"), darkred(self.spec_name),
|
||||
_("release file creation failed, not a file"),
|
||||
release_file,
|
||||
)
|
||||
)
|
||||
return 1
|
||||
release_string = self.metadata.get('release_string','')
|
||||
release_version = self.metadata.get('release_version','')
|
||||
release_desc = self.metadata.get('release_desc','')
|
||||
file_string = "%s %s %s\n" % (release_string,release_version,release_desc,)
|
||||
release_string = self.metadata.get('release_string', '')
|
||||
release_version = self.metadata.get('release_version', '')
|
||||
release_desc = self.metadata.get('release_desc', '')
|
||||
file_string = "%s %s %s\n" % (release_string, release_version, release_desc,)
|
||||
try:
|
||||
f = open(release_file,"w")
|
||||
f = open(release_file, "w")
|
||||
f.write(file_string)
|
||||
f.flush()
|
||||
f.close()
|
||||
except (IOError,OSError,), e:
|
||||
except (IOError, OSError,) as e:
|
||||
self._output.output("[%s|%s] %s: %s: %s" % (
|
||||
blue("ChrootHandler"),darkred(self.spec_name),
|
||||
blue("ChrootHandler"), darkred(self.spec_name),
|
||||
_("release file creation failed, system error"),
|
||||
release_file,e,
|
||||
release_file, e,
|
||||
)
|
||||
)
|
||||
return 1
|
||||
@@ -301,8 +303,8 @@ class ChrootHandler(GenericExecutionStep, BuiltinHandlerMixin):
|
||||
rc = molecule.utils.exec_cmd(exec_script)
|
||||
if rc != 0:
|
||||
self._output.output("[%s|%s] %s: %s" % (
|
||||
blue("ChrootHandler"),darkred(self.spec_name),
|
||||
_("outer chroot hook (after inner) failed"),rc,
|
||||
blue("ChrootHandler"), darkred(self.spec_name),
|
||||
_("outer chroot hook (after inner) failed"), rc,
|
||||
)
|
||||
)
|
||||
return rc
|
||||
@@ -314,7 +316,7 @@ class ChrootHandler(GenericExecutionStep, BuiltinHandlerMixin):
|
||||
self._run_error_script(self.source_dir, self.dest_dir, None)
|
||||
self._output.output("[%s|%s] %s" % (
|
||||
blue("ChrootHandler"),
|
||||
darkred(self.spec_name),_("executing kill"),
|
||||
darkred(self.spec_name), _("executing kill"),
|
||||
)
|
||||
)
|
||||
return 0
|
||||
@@ -322,7 +324,7 @@ class ChrootHandler(GenericExecutionStep, BuiltinHandlerMixin):
|
||||
def run(self):
|
||||
|
||||
self._output.output("[%s|%s] %s" % (
|
||||
blue("ChrootHandler"),darkred(self.spec_name),
|
||||
blue("ChrootHandler"), darkred(self.spec_name),
|
||||
_("hooks running"),
|
||||
)
|
||||
)
|
||||
@@ -337,7 +339,7 @@ class ChrootHandler(GenericExecutionStep, BuiltinHandlerMixin):
|
||||
|
||||
|
||||
self._output.output("[%s|%s] %s" % (
|
||||
blue("ChrootHandler"),darkred(self.spec_name),
|
||||
blue("ChrootHandler"), darkred(self.spec_name),
|
||||
_("hooks completed succesfully"),
|
||||
)
|
||||
)
|
||||
@@ -350,27 +352,27 @@ class CdrootHandler(GenericExecutionStep, BuiltinHandlerMixin):
|
||||
|
||||
def setup(self):
|
||||
self.source_chroot = os.path.join(
|
||||
self.metadata['destination_chroot'],"chroot",
|
||||
self.metadata['destination_chroot'], "chroot",
|
||||
os.path.basename(self.metadata['source_chroot'])
|
||||
)
|
||||
self.dest_root = os.path.join(
|
||||
self.metadata['destination_livecd_root'],"livecd",
|
||||
self.metadata['destination_livecd_root'], "livecd",
|
||||
os.path.basename(self.metadata['source_chroot'])
|
||||
)
|
||||
if os.path.isdir(self.dest_root):
|
||||
molecule.utils.empty_dir(self.dest_root)
|
||||
if not os.path.isdir(self.dest_root):
|
||||
os.makedirs(self.dest_root, 0755)
|
||||
os.makedirs(self.dest_root, 0o755)
|
||||
|
||||
def pre_run(self):
|
||||
self._output.output("[%s|%s] %s" % (
|
||||
blue("CdrootHandler"),darkred(self.spec_name),
|
||||
blue("CdrootHandler"), darkred(self.spec_name),
|
||||
_("executing pre_run"),
|
||||
)
|
||||
)
|
||||
|
||||
self._output.output("[%s|%s] %s" % (
|
||||
blue("CdrootHandler"),darkred(self.spec_name),
|
||||
blue("CdrootHandler"), darkred(self.spec_name),
|
||||
_("preparing environment"),
|
||||
)
|
||||
)
|
||||
@@ -378,7 +380,7 @@ class CdrootHandler(GenericExecutionStep, BuiltinHandlerMixin):
|
||||
|
||||
def post_run(self):
|
||||
self._output.output("[%s|%s] %s" % (
|
||||
blue("CdrootHandler"),darkred(self.spec_name),
|
||||
blue("CdrootHandler"), darkred(self.spec_name),
|
||||
_("executing post_run"),
|
||||
)
|
||||
)
|
||||
@@ -389,7 +391,7 @@ class CdrootHandler(GenericExecutionStep, BuiltinHandlerMixin):
|
||||
self._run_error_script(None, self.source_chroot,
|
||||
self.dest_root)
|
||||
self._output.output("[%s|%s] %s" % (
|
||||
blue("CdrootHandler"),darkred(self.spec_name),
|
||||
blue("CdrootHandler"), darkred(self.spec_name),
|
||||
_("executing kill"),
|
||||
)
|
||||
)
|
||||
@@ -398,7 +400,7 @@ class CdrootHandler(GenericExecutionStep, BuiltinHandlerMixin):
|
||||
def run(self):
|
||||
|
||||
self._output.output("[%s|%s] %s" % (
|
||||
blue("CdrootHandler"),darkred(self.spec_name),
|
||||
blue("CdrootHandler"), darkred(self.spec_name),
|
||||
_("compressing chroot"),
|
||||
)
|
||||
)
|
||||
@@ -407,24 +409,24 @@ class CdrootHandler(GenericExecutionStep, BuiltinHandlerMixin):
|
||||
if "chroot_compressor_output_file" in self.metadata:
|
||||
comp_output = self.metadata.get('chroot_compressor_output_file')
|
||||
comp_output = os.path.join(self.dest_root, comp_output)
|
||||
args.extend([self.source_chroot,comp_output])
|
||||
args.extend([self.source_chroot, comp_output])
|
||||
args.extend(self._config['chroot_compressor_builtin_args'])
|
||||
args.extend(self.metadata.get('extra_mksquashfs_parameters',[]))
|
||||
args.extend(self.metadata.get('extra_mksquashfs_parameters', []))
|
||||
self._output.output("[%s|%s] %s: %s" % (
|
||||
blue("CdrootHandler"),darkred(self.spec_name),
|
||||
_("spawning"),args,
|
||||
blue("CdrootHandler"), darkred(self.spec_name),
|
||||
_("spawning"), args,
|
||||
)
|
||||
)
|
||||
rc = molecule.utils.exec_cmd(args)
|
||||
if rc != 0:
|
||||
self._output.output("[%s|%s] %s: %s" % (
|
||||
blue("CdrootHandler"),darkred(self.spec_name),
|
||||
_("chroot compression failed"),rc,
|
||||
blue("CdrootHandler"), darkred(self.spec_name),
|
||||
_("chroot compression failed"), rc,
|
||||
)
|
||||
)
|
||||
return rc
|
||||
self._output.output("[%s|%s] %s" % (
|
||||
blue("CdrootHandler"),darkred(self.spec_name),
|
||||
blue("CdrootHandler"), darkred(self.spec_name),
|
||||
_("chroot compressed successfully"),
|
||||
)
|
||||
)
|
||||
@@ -434,31 +436,31 @@ class CdrootHandler(GenericExecutionStep, BuiltinHandlerMixin):
|
||||
if merge_dir:
|
||||
if os.path.isdir(merge_dir):
|
||||
self._output.output("[%s|%s] %s %s" % (
|
||||
blue("CdrootHandler"),darkred(self.spec_name),
|
||||
_("merging livecd root"),merge_dir,)
|
||||
blue("CdrootHandler"), darkred(self.spec_name),
|
||||
_("merging livecd root"), merge_dir,)
|
||||
)
|
||||
import stat
|
||||
content = os.listdir(merge_dir)
|
||||
for mypath in content:
|
||||
mysource = os.path.join(merge_dir,mypath)
|
||||
mydest = os.path.join(self.dest_root,mypath)
|
||||
mysource = os.path.join(merge_dir, mypath)
|
||||
mydest = os.path.join(self.dest_root, mypath)
|
||||
copystat = False
|
||||
|
||||
if os.path.islink(mysource):
|
||||
tolink = os.readlink(mysource)
|
||||
os.symlink(tolink,mydest)
|
||||
os.symlink(tolink, mydest)
|
||||
elif os.path.isfile(mysource) or os.path.islink(mysource):
|
||||
copystat = True
|
||||
shutil.copy2(mysource,mydest)
|
||||
shutil.copy2(mysource, mydest)
|
||||
elif os.path.isdir(mysource):
|
||||
copystat = True
|
||||
shutil.copytree(mysource,mydest)
|
||||
shutil.copytree(mysource, mydest)
|
||||
|
||||
if copystat:
|
||||
user = os.stat(mysource)[stat.ST_UID]
|
||||
group = os.stat(mysource)[stat.ST_GID]
|
||||
os.chown(mydest,user,group)
|
||||
shutil.copystat(mysource,mydest)
|
||||
os.chown(mydest, user, group)
|
||||
shutil.copystat(mysource, mydest)
|
||||
|
||||
return 0
|
||||
|
||||
@@ -472,33 +474,33 @@ class IsoHandler(GenericExecutionStep, BuiltinHandlerMixin):
|
||||
def setup(self):
|
||||
# setup paths
|
||||
self.source_path = os.path.join(
|
||||
self.metadata['destination_livecd_root'],"livecd",
|
||||
self.metadata['destination_livecd_root'], "livecd",
|
||||
os.path.basename(self.metadata['source_chroot'])
|
||||
)
|
||||
dest_iso_dir = self.metadata['destination_iso_directory']
|
||||
if not os.path.isdir(dest_iso_dir):
|
||||
os.makedirs(dest_iso_dir,0755)
|
||||
os.makedirs(dest_iso_dir, 0o755)
|
||||
dest_iso_filename = self.metadata.get('destination_iso_image_name')
|
||||
release_string = self.metadata.get('release_string','')
|
||||
release_version = self.metadata.get('release_version','')
|
||||
release_desc = self.metadata.get('release_desc','')
|
||||
release_string = self.metadata.get('release_string', '')
|
||||
release_version = self.metadata.get('release_version', '')
|
||||
release_desc = self.metadata.get('release_desc', '')
|
||||
if not dest_iso_filename:
|
||||
dest_iso_filename = "%s_%s_%s.iso" % (
|
||||
release_string.replace(' ','_'),
|
||||
release_version.replace(' ','_'),
|
||||
release_desc.replace(' ','_'),
|
||||
release_string.replace(' ', '_'),
|
||||
release_version.replace(' ', '_'),
|
||||
release_desc.replace(' ', '_'),
|
||||
)
|
||||
self.dest_iso = os.path.join(dest_iso_dir, dest_iso_filename)
|
||||
self.iso_title = "%s %s %s" % (release_string, release_version, release_desc,)
|
||||
self.source_chroot = self.metadata['source_chroot']
|
||||
self.chroot_dir = os.path.join(
|
||||
self.metadata['destination_chroot'],"chroot",
|
||||
self.metadata['destination_chroot'], "chroot",
|
||||
os.path.basename(self.source_chroot)
|
||||
)
|
||||
|
||||
def pre_run(self):
|
||||
self._output.output("[%s|%s] %s" % (
|
||||
blue("IsoHandler"),darkred(self.spec_name),
|
||||
blue("IsoHandler"), darkred(self.spec_name),
|
||||
_("executing pre_run"),
|
||||
)
|
||||
)
|
||||
@@ -529,7 +531,7 @@ class IsoHandler(GenericExecutionStep, BuiltinHandlerMixin):
|
||||
|
||||
def post_run(self):
|
||||
self._output.output("[%s|%s] %s" % (
|
||||
blue("IsoHandler"),darkred(self.spec_name),
|
||||
blue("IsoHandler"), darkred(self.spec_name),
|
||||
_("executing post_run"),
|
||||
)
|
||||
)
|
||||
@@ -560,7 +562,7 @@ class IsoHandler(GenericExecutionStep, BuiltinHandlerMixin):
|
||||
self._run_error_script(self.source_chroot, self.chroot_dir,
|
||||
self.source_path)
|
||||
self._output.output("[%s|%s] %s" % (
|
||||
blue("IsoHandler"),darkred(self.spec_name),
|
||||
blue("IsoHandler"), darkred(self.spec_name),
|
||||
_("executing kill"),
|
||||
)
|
||||
)
|
||||
@@ -569,17 +571,17 @@ class IsoHandler(GenericExecutionStep, BuiltinHandlerMixin):
|
||||
def run(self):
|
||||
|
||||
self._output.output("[%s|%s] %s" % (
|
||||
blue("IsoHandler"),darkred(self.spec_name),
|
||||
blue("IsoHandler"), darkred(self.spec_name),
|
||||
_("building ISO image"),
|
||||
)
|
||||
)
|
||||
|
||||
args = [self._config['iso_builder']]
|
||||
args.extend(self._config['iso_builder_builtin_args'])
|
||||
args.extend(self.metadata.get('extra_mkisofs_parameters',[]))
|
||||
args.extend(self.metadata.get('extra_mkisofs_parameters', []))
|
||||
if self.iso_title.strip():
|
||||
args.extend(["-V", '"', self.iso_title[:30], '"'])
|
||||
args.extend(['-o',self.dest_iso, self.source_path])
|
||||
args.extend(['-o', self.dest_iso, self.source_path])
|
||||
self._output.output("[%s|%s] %s: %s" % (
|
||||
blue("IsoHandler"), darkred(self.spec_name),
|
||||
_("spawning"), args,
|
||||
@@ -588,18 +590,18 @@ class IsoHandler(GenericExecutionStep, BuiltinHandlerMixin):
|
||||
rc = molecule.utils.exec_cmd(args)
|
||||
if rc != 0:
|
||||
self._output.output("[%s|%s] %s: %s" % (
|
||||
blue("IsoHandler"),darkred(self.spec_name),
|
||||
_("ISO image build failed"),rc,
|
||||
blue("IsoHandler"), darkred(self.spec_name),
|
||||
_("ISO image build failed"), rc,
|
||||
)
|
||||
)
|
||||
return rc
|
||||
|
||||
self._output.output("[%s|%s] %s: %s" % (
|
||||
blue("IsoHandler"),darkred(self.spec_name),
|
||||
_("built ISO image"),self.dest_iso,
|
||||
blue("IsoHandler"), darkred(self.spec_name),
|
||||
_("built ISO image"), self.dest_iso,
|
||||
)
|
||||
)
|
||||
if os.path.isfile(self.dest_iso) and os.access(self.dest_iso,os.R_OK):
|
||||
if os.path.isfile(self.dest_iso) and os.access(self.dest_iso, os.R_OK):
|
||||
self._output.output("[%s|%s] %s: %s" % (
|
||||
blue("IsoHandler"), darkred(self.spec_name),
|
||||
_("generating md5 for"), self.dest_iso,
|
||||
@@ -607,8 +609,8 @@ class IsoHandler(GenericExecutionStep, BuiltinHandlerMixin):
|
||||
)
|
||||
digest = molecule.utils.md5sum(self.dest_iso)
|
||||
md5file = self.dest_iso + IsoHandler.MD5_EXT
|
||||
with open(md5file,"w") as f:
|
||||
f.write("%s %s\n" % (digest,os.path.basename(self.dest_iso),))
|
||||
with open(md5file, "w") as f:
|
||||
f.write("%s %s\n" % (digest, os.path.basename(self.dest_iso),))
|
||||
f.flush()
|
||||
|
||||
return 0
|
||||
|
||||
@@ -58,7 +58,7 @@ class IsoUnpackHandler(GenericExecutionStep, BuiltinHandlerMixin):
|
||||
|
||||
def pre_run(self):
|
||||
self._output.output("[%s|%s] %s" % (
|
||||
blue("IsoUnpackHandler"),darkred(self.spec_name),
|
||||
blue("IsoUnpackHandler"), darkred(self.spec_name),
|
||||
_("executing pre_run"),
|
||||
)
|
||||
)
|
||||
@@ -142,7 +142,7 @@ class IsoUnpackHandler(GenericExecutionStep, BuiltinHandlerMixin):
|
||||
|
||||
def post_run(self):
|
||||
self._output.output("[%s|%s] %s" % (
|
||||
blue("IsoUnpackHandler"),darkred(self.spec_name),
|
||||
blue("IsoUnpackHandler"), darkred(self.spec_name),
|
||||
_("executing post_run"),
|
||||
)
|
||||
)
|
||||
@@ -150,7 +150,7 @@ class IsoUnpackHandler(GenericExecutionStep, BuiltinHandlerMixin):
|
||||
|
||||
def kill(self, success = True):
|
||||
self._output.output("[%s|%s] %s" % (
|
||||
blue("IsoUnpackHandler"),darkred(self.spec_name),
|
||||
blue("IsoUnpackHandler"), darkred(self.spec_name),
|
||||
_("executing kill"),
|
||||
)
|
||||
)
|
||||
@@ -222,7 +222,7 @@ class ChrootHandler(BuiltinChrootHandler):
|
||||
self._config['pkgs_updater'])
|
||||
rc = molecule.utils.exec_chroot_cmd(update_cmd,
|
||||
self.source_dir,
|
||||
self.metadata.get('prechroot',[]))
|
||||
self.metadata.get('prechroot', []))
|
||||
if rc != 0:
|
||||
return rc
|
||||
|
||||
@@ -231,7 +231,7 @@ class ChrootHandler(BuiltinChrootHandler):
|
||||
return rc
|
||||
|
||||
self._output.output("[%s|%s] %s" % (
|
||||
blue("ChrootHandler"),darkred(self.spec_name),
|
||||
blue("ChrootHandler"), darkred(self.spec_name),
|
||||
_("hooks running"),
|
||||
)
|
||||
)
|
||||
@@ -244,7 +244,7 @@ class ChrootHandler(BuiltinChrootHandler):
|
||||
args = add_cmd + packages_to_add
|
||||
rc = molecule.utils.exec_chroot_cmd(args,
|
||||
self.source_dir,
|
||||
self.metadata.get('prechroot',[]))
|
||||
self.metadata.get('prechroot', []))
|
||||
if rc != 0:
|
||||
return rc
|
||||
|
||||
@@ -255,7 +255,7 @@ class ChrootHandler(BuiltinChrootHandler):
|
||||
args = rm_cmd + packages_to_remove
|
||||
rc = molecule.utils.exec_chroot_cmd(args,
|
||||
self.source_dir,
|
||||
self.metadata.get('prechroot',[]))
|
||||
self.metadata.get('prechroot', []))
|
||||
if rc != 0:
|
||||
return rc
|
||||
|
||||
|
||||
@@ -55,14 +55,14 @@ class TarHandler(GenericExecutionStep, BuiltinHandlerMixin):
|
||||
|
||||
def pre_run(self):
|
||||
self._output.output("[%s|%s] %s" % (
|
||||
blue("TarHandler"),darkred(self.spec_name),
|
||||
blue("TarHandler"), darkred(self.spec_name),
|
||||
_("executing pre_run"),
|
||||
)
|
||||
)
|
||||
|
||||
def run(self):
|
||||
self._output.output("[%s|%s] %s => %s" % (
|
||||
blue("TarHandler"),darkred(self.spec_name),
|
||||
blue("TarHandler"), darkred(self.spec_name),
|
||||
_("compressing chroot"),
|
||||
self.chroot_path,
|
||||
)
|
||||
@@ -70,7 +70,7 @@ class TarHandler(GenericExecutionStep, BuiltinHandlerMixin):
|
||||
dest_path_dir = os.path.dirname(self.dest_path)
|
||||
if not os.path.isdir(dest_path_dir) and not \
|
||||
os.path.lexists(dest_path_dir):
|
||||
os.makedirs(dest_path_dir, 0755)
|
||||
os.makedirs(dest_path_dir, 0o755)
|
||||
|
||||
current_dir = os.getcwd()
|
||||
# change dir to chroot dir
|
||||
@@ -92,7 +92,7 @@ class TarHandler(GenericExecutionStep, BuiltinHandlerMixin):
|
||||
|
||||
def post_run(self):
|
||||
self._output.output("[%s|%s] %s" % (
|
||||
blue("TarHandler"),darkred(self.spec_name),
|
||||
blue("TarHandler"), darkred(self.spec_name),
|
||||
_("executing post_run"),
|
||||
)
|
||||
)
|
||||
|
||||
@@ -15,7 +15,9 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
|
||||
import os
|
||||
from molecule.compat import convert_to_unicode
|
||||
import molecule.utils
|
||||
|
||||
class GenericSpecFunctions:
|
||||
@@ -39,10 +41,10 @@ class GenericSpecFunctions:
|
||||
return os.path.isdir(x)
|
||||
|
||||
def ve_string_stripper(self, x):
|
||||
return unicode(x,'raw_unicode_escape').strip()
|
||||
return convert_to_unicode(x).strip()
|
||||
|
||||
def ve_string_splitter(self, x):
|
||||
return unicode(x,'raw_unicode_escape').strip().split()
|
||||
return convert_to_unicode(x).strip().split()
|
||||
|
||||
def valid_exec(self, x):
|
||||
molecule.utils.is_exec_available(x)
|
||||
@@ -81,11 +83,11 @@ class GenericSpecFunctions:
|
||||
|
||||
def valid_comma_sep_list(self, x):
|
||||
return [y.strip() for y in \
|
||||
unicode(x,'raw_unicode_escape').split(",") if y.strip()]
|
||||
convert_to_unicode(x).split(",") if y.strip()]
|
||||
|
||||
def valid_path_list(self, x):
|
||||
return [y.strip() for y in \
|
||||
unicode(x,'raw_unicode_escape').split(",") if \
|
||||
convert_to_unicode(x).split(",") if \
|
||||
self.valid_path_string(y) and y.strip()]
|
||||
|
||||
class GenericExecutionStep:
|
||||
|
||||
+6
-7
@@ -1,4 +1,3 @@
|
||||
#!/usr/bin/python -O
|
||||
# -*- coding: utf-8 -*-
|
||||
# Molecule Disc Image builder for Sabayon Linux
|
||||
# Copyright (C) 2009 Fabio Erculiani
|
||||
@@ -29,7 +28,7 @@ def get_year():
|
||||
return time.strftime("%Y")
|
||||
|
||||
def valid_exec_check(path):
|
||||
with open("/dev/null","w") as f:
|
||||
with open("/dev/null", "w") as f:
|
||||
p = subprocess.Popen([path], stdout = f, stderr = f)
|
||||
rc = p.wait()
|
||||
if rc == 127:
|
||||
@@ -40,8 +39,8 @@ def is_exec_available(exec_name):
|
||||
if not paths: return False
|
||||
paths = paths.split(":")
|
||||
for path in paths:
|
||||
path = os.path.join(path,exec_name)
|
||||
if os.path.isfile(path) and os.access(path,os.X_OK):
|
||||
path = os.path.join(path, exec_name)
|
||||
if os.path.isfile(path) and os.access(path, os.X_OK):
|
||||
return True
|
||||
return False
|
||||
|
||||
@@ -60,17 +59,17 @@ def exec_chroot_cmd(args, chroot, pre_chroot = []):
|
||||
os._exit(rc)
|
||||
else:
|
||||
RUNNING_PIDS.add(pid)
|
||||
rcpid, rc = os.waitpid(pid,0)
|
||||
rcpid, rc = os.waitpid(pid, 0)
|
||||
RUNNING_PIDS.discard(pid)
|
||||
return rc
|
||||
|
||||
def empty_dir(dest_dir):
|
||||
for el in os.listdir(dest_dir):
|
||||
el = os.path.join(dest_dir,el)
|
||||
el = os.path.join(dest_dir, el)
|
||||
if os.path.isfile(el) or os.path.islink(el):
|
||||
os.remove(el)
|
||||
elif os.path.isdir(el):
|
||||
shutil.rmtree(el,True)
|
||||
shutil.rmtree(el, True)
|
||||
if os.path.isdir(el):
|
||||
os.rmdir(el)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user