diff mbox

[Branch,~linaro-image-tools/linaro-image-tools/trunk] Rev 445: Add a -i, --in-place option to modify the specified hwpack rather than making a new one and also ...

Message ID 20111012073914.8063.31826.launchpad@ackee.canonical.com
State Accepted
Headers show

Commit Message

Deepti B. Kalakeri Oct. 12, 2011, 7:39 a.m. UTC
Merge authors:
  Paul Larson (pwlars)
Related merge proposals:
  https://code.launchpad.net/~pwlars/linaro-image-tools/linaro-hwpack-replace-in-place/+merge/79049
  proposed by: Paul Larson (pwlars)
  review: Approve - Deepti B. Kalakeri (deeptik)
------------------------------------------------------------
revno: 445 [merge]
committer: Deepti B. Kalakeri<deepti.kalakeri@linaro.org>
branch nick: linaro-image-tools
timestamp: Wed 2011-10-12 13:04:51 +0530
message:
  Add a -i, --in-place option to modify the specified hwpack rather than making a new one and also cleanup tempdir
modified:
  linaro-hwpack-replace


--
lp:linaro-image-tools
https://code.launchpad.net/~linaro-image-tools/linaro-image-tools/trunk

You are subscribed to branch lp:linaro-image-tools.
To unsubscribe from this branch go to https://code.launchpad.net/~linaro-image-tools/linaro-image-tools/trunk/+edit-subscription
diff mbox

Patch

=== modified file 'linaro-hwpack-replace'
--- linaro-hwpack-replace	2011-10-06 13:42:25 +0000
+++ linaro-hwpack-replace	2011-10-12 07:34:51 +0000
@@ -45,6 +45,8 @@ 
 parser.add_argument("-r", "--prefix-pkg-remove", dest="prefix_pkg_remove",
                     help="Specify the prefix of the old debian package to "\
                           "replace (default: None).")
+parser.add_argument("-i", "--in-place", action="store_true", dest="inplace",
+                    help="Modify the hwpack rather than creating a new one")
 parser.add_argument("-d", "--debug-output", action="store_true", dest="debug",
                     help="Verbose messages are displayed when specified")
 
@@ -182,6 +184,7 @@ 
         tar = tarfile.open(old_hwpack, "r:gz")
         tempdir = tempfile.mkdtemp()
         tar.extractall(tempdir)
+        tar.close()
 
         # Search if a similar package with the same name exists, if yes then
         # replace it. IF the old and new debian have the same name then we
@@ -206,15 +209,26 @@ 
         modify_Packages_info(debpack_dirname, new_debpack_info, prefix_pkg_remove)
 
         #tar the hardware pack with the new debian file included in it
-        tar = tarfile.open( hwpack_name , "w:gz")
+        tar = tarfile.open(hwpack_name , "w:gz")
+        origdir = os.getcwd()
         os.chdir(tempdir)
         for file_name in glob.glob('*'):
             tar.add(file_name, recursive=True)
         tar.close()
+
+        # Retain old hwpack name instead of using a new name
+        os.chdir(origdir)
+        if args.inplace:
+            os.rename(hwpack_name, old_hwpack)
+            hwpack_name = old_hwpack
+
     except Exception, details:
         logger.error("Error Details: %s", details)
         status = 1
 
+    finally:
+        shutil.rmtree(tempdir)
+
     if status == 0:
         logger.info("The debian package '%s' has been been included in '%s'",
                      new_deb_file_to_copy, hwpack_name)