Commit 07399204 authored by Sébastien Luttringer's avatar Sébastien Luttringer

Scripts and module execution reworked

This patch review how scripts are executed and modules loaded.

sys.module is preserved from modification by scripts and avoid conflict with
module loaded by scripts
parent 7044e206
......@@ -304,7 +304,7 @@ def c_install(args):
# install start time
t0 = time.time()
# run parser scripts with parser parser argument
image.run_parser({"parser": subparser})
# call parser again, with extended attributes
arrow("Parsing arguments")
# Catch exception in custom argparse action
......@@ -314,7 +314,7 @@ def c_install(args):
raise ISError("Parsing error", e)
# run setup scripts
if not args.dry_run:
image.run_setup({"namespace": args})
# compute building time
t1 = time.time()
dt = int(t1 - t0)
This diff is collapsed.
......@@ -16,10 +16,6 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Installsystems. If not, see <>.
Tarball wrapper
import os
import sys
import time
......@@ -30,16 +26,25 @@ import fnmatch
from installsystems.exception import *
class Tarball(tarfile.TarFile):
def add_str(self, name, content, ftype, mode):
Tarball wrapper
def add_str(self, name, content, ftype, mode, mtime=None,
uid=None, gid=None, uname=None, gname=None):
Add a string in memory as a file in tarball
if isinstance(name, unicode):
name = name.encode("UTF-8")
ti = tarfile.TarInfo(name)
ti.type = ftype
ti.mode = mode
ti.mtime = int(time.time())
ti.uid = ti.gid = 0
ti.uname = ti.gname = "root"
# set tarinfo attribute
for v in ("name", "ftype", "mode", "mtime", "uid", "gid", "uname", "gname"):
if vars()[v] is not None:
vars(ti)[v] = vars()[v]
# set mtime to current if not specified
if mtime is None:
ti.mtime = int(time.time())
# unicode char is encoded in UTF-8, has changelog must be in UTF-8
if isinstance(content, unicode):
content = content.encode("UTF-8")
......@@ -50,6 +55,8 @@ class Tarball(tarfile.TarFile):
Return a string from a filename in a tarball
if isinstance(name, unicode):
name = name.encode("UTF-8")
ti = self.getmember(name)
fd = self.extractfile(ti)
return if fd is not None else ""
......@@ -58,6 +65,8 @@ class Tarball(tarfile.TarFile):
Return an unicode string from a file encoded in UTF-8 inside tarball
if isinstance(name, unicode):
name = name.encode("UTF-8")
return unicode(self.get_str(name), "UTF-8")
except UnicodeDecodeError:
......@@ -74,7 +83,8 @@ class Tarball(tarfile.TarFile):
# dir filering
if not dir:
names = filter(lambda x: not self.getmember(x).isdir(), names)
return names
# unicode encoding
return map(lambda x: unicode(x, "UTF-8"), names)
def size(self):
......@@ -21,7 +21,6 @@ InstallSystems Generic Tools Library
import hashlib
import imp
import jinja2
import locale
import math
......@@ -670,21 +669,3 @@ def render_templates(target, context, tpl_ext=".istpl", force=False, keep=False)
os.chmod(file_path, st.st_mode)
if not keep:
def string2module(name, string, filename):
Create a python module from a string
# create an empty module
module = imp.new_module(name)
# compile module code
bytecode = compile(string, filename, "exec")
except Exception as e:
raise ISError(u"Unable to compile %s" % filename, e)
# Load module
exec bytecode in module.__dict__
except Exception as e:
raise ISError(u"Unable to load %s" % filename, e)
return module
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment