From patchwork Thu Aug 11 22:00:12 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Westby X-Patchwork-Id: 3397 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 28291241DC for ; Thu, 11 Aug 2011 22:00:18 +0000 (UTC) Received: from mail-qy0-f180.google.com (mail-qy0-f180.google.com [209.85.216.180]) by fiordland.canonical.com (Postfix) with ESMTP id C5C0FA1831D for ; Thu, 11 Aug 2011 22:00:17 +0000 (UTC) Received: by qyk31 with SMTP id 31so1789150qyk.11 for ; Thu, 11 Aug 2011 15:00:17 -0700 (PDT) Received: by 10.229.135.13 with SMTP id l13mr91496qct.288.1313100015308; Thu, 11 Aug 2011 15:00:15 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.229.190.71 with SMTP id dh7cs130272qcb; Thu, 11 Aug 2011 15:00:14 -0700 (PDT) Received: from mr.google.com ([10.227.152.146]) by 10.227.152.146 with SMTP id g18mr131970wbw.79.1313100014414 (num_hops = 1); Thu, 11 Aug 2011 15:00:14 -0700 (PDT) Received: by 10.227.152.146 with SMTP id g18mr103974wbw.79.1313100013477; Thu, 11 Aug 2011 15:00:13 -0700 (PDT) Received: from adelie.canonical.com (adelie.canonical.com [91.189.90.139]) by mx.google.com with ESMTP id fi20si6675528wbb.48.2011.08.11.15.00.13; Thu, 11 Aug 2011 15:00:13 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of bounces@canonical.com designates 91.189.90.139 as permitted sender) client-ip=91.189.90.139; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of bounces@canonical.com designates 91.189.90.139 as permitted sender) smtp.mail=bounces@canonical.com Received: from ackee.canonical.com ([91.189.89.26]) by adelie.canonical.com with esmtp (Exim 4.71 #1 (Debian)) id 1QrdIS-00035d-PY for ; Thu, 11 Aug 2011 22:00:12 +0000 Received: from ackee.canonical.com (localhost [127.0.0.1]) by ackee.canonical.com (Postfix) with ESMTP id B7898E14F8 for ; Thu, 11 Aug 2011 22:00:12 +0000 (UTC) MIME-Version: 1.0 X-Launchpad-Project: linaro-image-tools X-Launchpad-Branch: ~linaro-image-tools/linaro-image-tools/trunk X-Launchpad-Message-Rationale: Subscriber X-Launchpad-Branch-Revision-Number: 404 X-Launchpad-Notification-Type: branch-revision To: Linaro Patch Tracker From: noreply@launchpad.net Subject: [Branch ~linaro-image-tools/linaro-image-tools/trunk] Rev 404: hwpack-replace: allow the caller to specify a prefix of packages to remove. Message-Id: <20110811220012.9497.8275.launchpad@ackee.canonical.com> Date: Thu, 11 Aug 2011 22:00:12 -0000 Reply-To: noreply@launchpad.net Sender: bounces@canonical.com Errors-To: bounces@canonical.com Precedence: bulk X-Generated-By: Launchpad (canonical.com); Revision="13662"; Instance="initZopeless config overlay" X-Launchpad-Hash: 38179fc2f864c4cf1853f6ac52f007d5c1cea9e6 Merge authors: Deepti B. Kalakeri (deeptik) Related merge proposals: https://code.launchpad.net/~deeptik/linaro-image-tools/fix_bug_Bug816767/+merge/70465 proposed by: Deepti B. Kalakeri (deeptik) review: Approve - James Westby (james-w) ------------------------------------------------------------ revno: 404 [merge] committer: James Westby branch nick: trunk timestamp: Thu 2011-08-11 17:57:55 -0400 message: hwpack-replace: allow the caller to specify a prefix of packages to remove. 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 === modified file 'linaro-hwpack-replace' --- linaro-hwpack-replace 2011-08-03 11:29:43 +0000 +++ linaro-hwpack-replace 2011-08-11 06:33:07 +0000 @@ -4,7 +4,9 @@ # Author: Deepti B. Kalakeri # # This file is part of Linaro Image Tools. It adds the feature -# to include/replace a debian package into the given hwpack +# to include/replace a debian package into the given hwpack. +# We might need to change the manifest and Packages file in the +# future to match the hardware pack v2 changes when available. # # Linaro Image Tools is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -36,10 +38,13 @@ parser = argparse.ArgumentParser() -parser.add_argument("-t", "--hwpack_name", dest="hwpack_name", - help="Specific hwpack_name to use (default: None)") -parser.add_argument("-p", "--deb_pack", dest="deb_pack", +parser.add_argument("-t", "--hwpack-name", dest="hwpack_name", + help="Specific hwpack-name to use (default: None)") +parser.add_argument("-p", "--deb-pack", dest="deb_pack", help="Specific debian package to replace (default: None).") +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("-d", "--debug-output", action="store_true", dest="debug", help="Verbose messages are displayed when specified") @@ -76,74 +81,67 @@ return('_'.join(hwpack_name_parts[:2] + timestamp + hwpack_name_parts[3:])) -def verify_existing_debians(debpack_dirname, new_debpack_info): +def should_remove(package_name, prefix_pkg_remove): + # hwpack-* Package is a metadata package that contain reference to the + # linux-linaro-omap that was previously present in the hwpack. + # We need to make sure we dont write the hwpack-* related + # package information into Package, otherwise it would try to download the old + # kernel package that was present in the hwpack than installing the new one. + if (package_name.startswith(prefix_pkg_remove) or + package_name.startswith("hwpack-")): + return True + return False + +def verify_existing_debians(debpack_dirname, prefix_pkg_remove): """ Find if the debian file with the same name exists, if it exists then remove it and replace with the new deb file If similar debian file exists then remove it """ - old_debpack_info = None deb_file_to_remove = None try: for deb_filename in os.listdir(debpack_dirname): root, ext = os.path.splitext(deb_filename) - root = root + '_' - if root.startswith("%s_" %new_debpack_info.name) and ext == '.deb': + if should_remove(root, prefix_pkg_remove) and ext == '.deb': deb_file_to_remove = os.path.join(debpack_dirname, deb_filename) - old_debpack_info = FetchedPackage.from_deb(deb_file_to_remove) os.remove(deb_file_to_remove) except Exception, details: logger.error("Error Details: %s", details) - return old_debpack_info - - -def modify_manifest_info(tempdir, new_debpack_info, deb_pack_found): + +def modify_manifest_info(tempdir, new_debpack_info, prefix_pkg_remove): """ Modify the manifest file to include the new debian information """ debpack_manifest_fname = os.path.join(tempdir, "manifest") new_debpack_line = '%s=%s\n' % (new_debpack_info.name, new_debpack_info.version) for line in fileinput.FileInput(debpack_manifest_fname, inplace=1): - if '=' in line: - package_name, version = line.split('=') - old_debpack = '%s=%s' % (package_name, version) - else: - package_name = line.rstrip("\n") - old_debpack = '%s' % package_name - - if new_debpack_info.name == package_name: - deb_pack_found = 1 - line = new_debpack_line - sys.stdout.write(line) - - if deb_pack_found == 0: - logger.debug("Adding the new debian package info to manifest") - fout = open(debpack_manifest_fname, "a") - fout.write(new_debpack_line) - fout.close() - else: - logger.debug("Replaced the old debian package information "\ - "with the new information") - - -def modify_Packages_info(debpack_dirname, new_debpack_info): + if not should_remove(line, prefix_pkg_remove): + sys.stdout.write(line) + + logger.debug("Adding the new debian package info to manifest") + fout = open(debpack_manifest_fname, "a") + fout.write(new_debpack_line) + fout.close() + + +def modify_Packages_info(debpack_dirname, new_debpack_info, prefix_pkg_remove): """ Modify the Packages file to include the new debian information """ debpack_Packages_fname = os.path.join(debpack_dirname, "Packages") - f = open(debpack_Packages_fname, "r+") try: output = [] - def should_remove(package_name): - return package_name == new_debpack_info.name + + f = open(debpack_Packages_fname, "r+") for stanza in Packages.iter_paragraphs(f): - if not should_remove(stanza["Package"]): + if not should_remove(stanza["Package"], prefix_pkg_remove): output.append(stanza) output.append(DummyStanza(new_debpack_info)) + f.seek(0,0) - + f.truncate() for stanza in output: stanza.dump(f) f.write("\n") @@ -154,7 +152,8 @@ def main(): # Validate that all the required information is passed on the command line args = parser.parse_args() - if args.hwpack_name == None or args.deb_pack == None: + if (args.hwpack_name == None or args.deb_pack == None or + args.prefix_pkg_remove == None): parser.print_help() parser.error("You must specify both hwpack name "\ "and the debian package information\n") @@ -162,10 +161,9 @@ set_logging_param(args) - deb_pack_found = 0 - old_debpack_info = None old_hwpack = args.hwpack_name new_deb_file_to_copy = args.deb_pack + prefix_pkg_remove = args.prefix_pkg_remove status = 0 try: @@ -190,14 +188,14 @@ new_debpack_info = FetchedPackage.from_deb(new_deb_file_to_copy) - old_debpack_info = verify_existing_debians(debpack_dirname, new_debpack_info) + verify_existing_debians(debpack_dirname, prefix_pkg_remove) # Copy the new debian file to the pkgs dir, shutil.copy2(new_deb_file_to_copy, debpack_dirname) - modify_manifest_info(tempdir, new_debpack_info, deb_pack_found) + modify_manifest_info(tempdir, new_debpack_info, prefix_pkg_remove) - modify_Packages_info(debpack_dirname, new_debpack_info) + 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") @@ -212,6 +210,7 @@ if status == 0: logger.info("The debian package '%s' has been been included in '%s'", new_deb_file_to_copy, hwpack_name) + print hwpack_name else: logger.error("Injecting the debian package '%s' failed", new_deb_file_to_copy)