[Thincrust-devel] Re: [PATCH] fixed problem with long move operations (#466278)
David Huff
dhuff at redhat.com
Fri Oct 10 21:42:50 UTC 2008
committed...
this also addes the ability of using a full path of in the appliance
name as final destination, which helps w/ scripting.
ie --name /home/david/appliances/aos-f9-test2
will name the appliance aos-f9-test2 however all output will be in
/home/david/appliances/
-D
David Huff wrote:
> ---
> appcreate/appliance.py | 56 ++++++++++++++++++++++++++++------------------
> tools/appliance-creator | 9 ++++++-
> 2 files changed, 41 insertions(+), 24 deletions(-)
>
> diff --git a/appcreate/appliance.py b/appcreate/appliance.py
> index 054c69a..c3af120 100644
> --- a/appcreate/appliance.py
> +++ b/appcreate/appliance.py
> @@ -332,22 +332,10 @@ class ApplianceImageCreator(ImageCreator):
> if rc != 0:
> raise CreatorError("Unable to convert disk to %s" % self.__format)
>
> - def _package_image(self):
> - #package image and metadata
> - if self.__package == "zip":
> - #dst = "%s/%s.zip" % (self.__imgdir, self.name) tmp dir
> - dst = "%s/%s.zip" % (self._outdir, self.name)
> - files = glob.glob('%s/*' % self.__imgdir)
> - logging.debug("creating %s" % (dst))
> - z = zipfile.ZipFile(dst, "w", compression=8, allowZip64="True")
> - for file in files:
> - if file != dst:
> - logging.debug("adding %s to %s" % (file,dst))
> - z.write(file, arcname=os.path.basename(file), compress_type=None)
> - z.close()
> -
>
> def _stage_final_image(self):
> + """Stage the final system image in _outdir.
> + """
> self._resparse()
> self._write_image_xml()
>
> @@ -358,16 +346,40 @@ class ApplianceImageCreator(ImageCreator):
> #else
> if self.__format != "raw":
> self._convert_image()
> +
> + if self.__package == "zip":
> + dst = "%s/%s.zip" % (self._outdir, self.name)
> + files = glob.glob('%s/*' % self.__imgdir)
> + logging.debug("creating %s" % (dst))
> + z = zipfile.ZipFile(dst, "w", compression=8, allowZip64="True")
> + for file in files:
> + if file != dst:
> + logging.debug("adding %s to %s" % (file,dst))
> + z.write(file, arcname=os.path.basename(file), compress_type=None)
> + z.close()
> +
> if self.__package == "none":
> logging.debug("moving disks to final location")
> for files in glob.glob('%s/*' % self.__imgdir):
> - logging.debug("moving %s to %s" % (files, self._outdir))
> - shutil.move(files, self._outdir)
> - else:
> - self._package_image()
> -
> - print("done")
> -
> -
> + logging.debug("moving %s to %s/%s" % (files, self._outdir, os.path.basename(files)))
> + try:
> + os.rename(files, '%s/%s' % (self._outdir, os.path.basename(files)))
> + except Exception, e:
> + shutil.move(files, '%s/%s' % (self._outdir, os.path.basename(files)))
> +
>
>
> + def package(self, destdir):
> + """Prepares the created image for final delivery.
> + """
> + self._stage_final_image()
> +
> + for f in os.listdir(self._outdir):
> + try:
> + os.rename(os.path.join(self._outdir, f),
> + os.path.join(destdir, f))
> + except Exception, e:
> + shutil.move(os.path.join(self._outdir, f),
> + os.path.join(destdir, f))
> +
> + print "Finished"
> diff --git a/tools/appliance-creator b/tools/appliance-creator
> index 6d990de..805771f 100755
> --- a/tools/appliance-creator
> +++ b/tools/appliance-creator
> @@ -99,7 +99,12 @@ def main():
>
> name = imgcreate.build_name(options.kscfg)
> if options.name:
> - name = options.name
> + if os.path.dirname(options.name):
> + destdir=os.path.dirname(options.name)
> + name=os.path.basename(options.name)
> + else:
> + name = options.name
> + destdir = "."
>
> creator = appcreate.ApplianceImageCreator(ks, name, options.format, options.package, options.vmem, options.vcpu)
> creator.tmpdir = options.tmpdir
> @@ -109,7 +114,7 @@ def main():
> creator.install()
> creator.configure()
> creator.unmount()
> - creator.package()
> + creator.package(destdir)
> except imgcreate.CreatorError, e:
> logging.error("Unable to create appliance : %s" % e)
> return 1
More information about the Thincrust-devel
mailing list