From 880c528c4804ca2a296f223822056be61175bb62 Mon Sep 17 00:00:00 2001 From: Seblu <sebastien.luttringer@smartjog.com> Date: Mon, 27 Jun 2011 13:05:19 +0200 Subject: [PATCH] Adding script is now done one by one and not recursively --- installsystems/image.py | 42 ++++++++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/installsystems/image.py b/installsystems/image.py index 3bf16ea..cd41d6f 100644 --- a/installsystems/image.py +++ b/installsystems/image.py @@ -162,12 +162,9 @@ class SourceImage(Image): arrow("Add format") tarball.add_str("format", self.format, tarfile.REGTYPE, 0444) # add parser scripts - arrow("Add parser scripts") - tarball.add(self.parser_path, arcname="parser", - recursive=True, filter=self._tar_scripts_filter) + self._add_scripts(tarball, self.parser_path) # add setup scripts - tarball.add(self.setup_path, arcname="setup", - recursive=True, filter=self._tar_scripts_filter) + self._add_scripts(tarball, self.setup_path) # closing tarball file tarball.close() arrowlevel(-1) @@ -245,16 +242,35 @@ class SourceImage(Image): fsource.close() fdest.close() - def _tar_scripts_filter(self, tinfo): + def _add_scripts(self, tarball, directory): ''' - Filter files which can be included in scripts tarball + Add scripts inside a directory into a tarball ''' - if not re.match("(parser|setup)(/\d+-.*\.py)?$", tinfo.name): - return None - tinfo.mode = 0755 - tinfo.uid = tinfo.gid = 0 - tinfo.uname = tinfo.gname = "root" - return tinfo + basedirectory = os.path.basename(directory) + arrow("Add %s scripts" % basedirectory) + arrowlevel(1) + # adding base directory + ti = tarball.gettarinfo(directory, arcname=basedirectory) + ti.mode = 0755 + ti.uid = ti.gid = 0 + ti.uname = ti.gname = "root" + tarball.addfile(ti) + # adding each file + for fi in os.listdir(directory): + # check name + if not re.match("\d+-.*\.py$", fi): + debug("name %s skipped: invalid name" % fi) + continue + # adding file + ti = tarball.gettarinfo(os.path.join(directory, fi), + arcname=os.path.join(basedirectory, + os.path.basename(fi))) + ti.mode = 0755 + ti.uid = ti.gid = 0 + ti.uname = ti.gname = "root" + tarball.addfile(ti) + arrow("%s added" % fi) + arrowlevel(-1) def generate_json_description(self, payloads): ''' -- GitLab