From 33ff6151a014757b942a2e9f246ab91029b192ec Mon Sep 17 00:00:00 2001
From: Matthieu Gonnet <matthieu.gonnet@smartjog.com>
Date: Tue, 18 Oct 2011 11:23:59 -0500
Subject: [PATCH] is extract -D generate a description file from the
 description.json file

Signed-off-by: Sebastien Luttringer <sebastien.luttringer@smartjog.com>
---
 bin/is                     |  5 ++++-
 installsystems/image.py    | 13 +++++++++++--
 installsystems/template.py |  8 ++++----
 3 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/bin/is b/bin/is
index d54e2a5..a472202 100755
--- a/bin/is
+++ b/bin/is
@@ -177,7 +177,8 @@ def c_extract(parser, args):
     '''
     repoman = load_repositories(args)
     img, repo = select_image(args.image, repoman, args.best)
-    img.extract(args.path, payload=args.payload, force=args.force)
+    img.extract(args.path, payload=args.payload, force=args.force,
+                gendescription=args.gendescription)
 
 def c_get(parser, args):
     '''
@@ -398,6 +399,8 @@ p_diff.set_defaults(func=c_diff)
 
 # extract command parser
 p_extract = subparsers.add_parser("extract", help=c_extract.__doc__.lower())
+p_extract.add_argument("-D", action="store_true", dest="gendescription", default=False,
+                       help="generate a description file from metadata")
 p_extract.add_argument("-p", action="store_true", dest="payload", default=False,
                        help="extract payloads")
 p_extract.add_argument("-f", "--force", action="store_true", default=False,
diff --git a/installsystems/image.py b/installsystems/image.py
index 4e3e52e..b80f3e5 100644
--- a/installsystems/image.py
+++ b/installsystems/image.py
@@ -83,7 +83,11 @@ class SourceImage(Image):
         # create dict of file to create
         examples = {}
         # create description example from template
-        examples["description"] = {"path": "description", "content": istemplate.description}
+        examples["description"] = {"path": "description",
+                                   "content": istemplate.description % {"name": "",
+                                                                        "version": "",
+                                                                        "description": "",
+                                                                        "author": ""}}
         # create changelog example from template
         examples["changelog"] = {"path": "changelog", "content": istemplate.changelog}
         # create parser example from template
@@ -618,7 +622,7 @@ class PackageImage(Image):
                 self.payload[payname].info
                 self.payload[payname].download(directory, force=force)
 
-    def extract(self, directory, force=False, payload=False):
+    def extract(self, directory, force=False, payload=False, gendescription=False):
         '''
         Extract content of the image inside a repository
         '''
@@ -630,6 +634,11 @@ class PackageImage(Image):
         # extract content
         arrow("Extracting image in %s" % directory)
         self._tarball.extractall(directory)
+        # generate description file from description.json
+        if gendescription:
+            arrow("Generating description file in %s" % directory)
+            with open(os.path.join(directory, "description"), "w") as f:
+                f.write(istemplate.description % self._metadata)
         # launch payload extract
         if payload:
             for payname in self.payload:
diff --git a/installsystems/template.py b/installsystems/template.py
index 0b9697e..b23caff 100644
--- a/installsystems/template.py
+++ b/installsystems/template.py
@@ -3,10 +3,10 @@
 # Started 12/05/2011 by Seblu <seblu@seblu.net>
 
 description = u"""[image]
-name =
-version =
-description =
-author =
+name = %(name)s
+version = %(version)s
+description = %(description)s
+author = %(author)s
 """
 
 changelog = u"""[1]
-- 
GitLab