From patchwork Tue Jun 4 14:19:15 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Milo Casagrande X-Patchwork-Id: 17519 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qc0-f200.google.com (mail-qc0-f200.google.com [209.85.216.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 1986A25A2B for ; Tue, 4 Jun 2013 14:19:18 +0000 (UTC) Received: by mail-qc0-f200.google.com with SMTP id n10sf297049qcx.11 for ; Tue, 04 Jun 2013 07:19:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-beenthere:x-forwarded-to:x-forwarded-for:delivered-to :mime-version:x-launchpad-project:x-launchpad-branch :x-launchpad-message-rationale:x-launchpad-branch-revision-number :x-launchpad-notification-type:to:from:subject:message-id:date :reply-to:sender:errors-to:precedence:x-generated-by :x-launchpad-hash:x-gm-message-state:x-original-sender :x-original-authentication-results:mailing-list:list-id :x-google-group-id:list-post:list-help:list-archive:list-unsubscribe :content-type; bh=F2Ao4blV7cq2mDYbQrY5aVOA9Y9ALFjgn1bGnjOv1kE=; b=M9ySkOEYFlclAy/DcYplgxfRffUDVTHAxVlBJusDUZCAYppjPO6SIi/LT7lxJ8BMU6 lZ4eKtIA24Ggnju1X2huiBvQ9qZqmDA8qAoOicP49k9e6WfwVHvJmlkKbPqo0UfRtdm4 9v6BdiasS2XAVqZzH1M6f5HnGbeBvuLWUu7D7MlfFaevP2S5AHlbEWus889vXQhLcGKz mCo/G5+T8bqOKUDyLWWZQu/P48yjDcrcsrt3ASWXuvhJal0XKJklwLnWj3ZQqDKnX1pa QQJjzS/JRNx6FlJSAAXx/XApkh+RbJnWAE+NSJy3ILs4YuUUtaqfgTn0afaDmNAOEjq3 m9PA== X-Received: by 10.236.143.101 with SMTP id k65mr15227554yhj.45.1370355557861; Tue, 04 Jun 2013 07:19:17 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.0.78 with SMTP id 14ls274554qec.10.gmail; Tue, 04 Jun 2013 07:19:17 -0700 (PDT) X-Received: by 10.52.68.11 with SMTP id r11mr15815776vdt.93.1370355557580; Tue, 04 Jun 2013 07:19:17 -0700 (PDT) Received: from mail-vb0-x234.google.com (mail-vb0-x234.google.com [2607:f8b0:400c:c02::234]) by mx.google.com with ESMTPS id ha8si37672307vdb.87.2013.06.04.07.19.17 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 04 Jun 2013 07:19:17 -0700 (PDT) Received-SPF: neutral (google.com: 2607:f8b0:400c:c02::234 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=2607:f8b0:400c:c02::234; Received: by mail-vb0-f52.google.com with SMTP id q12so191991vbe.25 for ; Tue, 04 Jun 2013 07:19:17 -0700 (PDT) X-Received: by 10.52.155.67 with SMTP id vu3mr15914150vdb.94.1370355557345; Tue, 04 Jun 2013 07:19:17 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.221.10.206 with SMTP id pb14csp127823vcb; Tue, 4 Jun 2013 07:19:16 -0700 (PDT) X-Received: by 10.180.12.72 with SMTP id w8mr1806705wib.4.1370355556170; Tue, 04 Jun 2013 07:19:16 -0700 (PDT) Received: from indium.canonical.com (indium.canonical.com. [91.189.90.7]) by mx.google.com with ESMTPS id o7si1472112wiv.44.2013.06.04.07.19.15 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 04 Jun 2013 07:19:16 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of bounces@canonical.com designates 91.189.90.7 as permitted sender) client-ip=91.189.90.7; Received: from ackee.canonical.com ([91.189.89.26]) by indium.canonical.com with esmtp (Exim 4.71 #1 (Debian)) id 1Ujs4x-0002FS-JY for ; Tue, 04 Jun 2013 14:19:15 +0000 Received: from ackee.canonical.com (localhost [127.0.0.1]) by ackee.canonical.com (Postfix) with ESMTP id 88BADE07F1 for ; Tue, 4 Jun 2013 14:19:15 +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: 625 X-Launchpad-Notification-Type: branch-revision To: Linaro Patch Tracker From: noreply@launchpad.net Subject: [Branch ~linaro-image-tools/linaro-image-tools/trunk] Rev 625: Refactored PackageUnpacker class. Message-Id: <20130604141915.22877.45996.launchpad@ackee.canonical.com> Date: Tue, 04 Jun 2013 14:19:15 -0000 Reply-To: noreply@launchpad.net Sender: bounces@canonical.com Errors-To: bounces@canonical.com Precedence: list X-Generated-By: Launchpad (canonical.com); Revision="16660"; Instance="launchpad-lazr.conf" X-Launchpad-Hash: bb1efee06abe375aea9da807a891f37de6d9feed X-Gm-Message-State: ALoCoQk63WOb0D4HlIBpeBvobYMwm3+SI4rh7kDsLo6Swi2j84caEmQs/lnh5iHPfF4DCYxRm/gN X-Original-Sender: noreply@launchpad.net X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 2607:f8b0:400c:c02::234 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Merge authors: Milo Casagrande (milo) Related merge proposals: https://code.launchpad.net/~milo/linaro-image-tools/bug1081747/+merge/167265 proposed by: Milo Casagrande (milo) review: Approve - James Tunnicliffe (dooferlad) ------------------------------------------------------------ revno: 625 [merge] committer: Milo Casagrande branch nick: trunk timestamp: Tue 2013-06-04 16:17:48 +0200 message: Refactored PackageUnpacker class. * linaro-android-media-create does not depend anymore on python-debian, should be possible to easily use on non-Debian systems. added: linaro_image_tools/hwpack/package_unpacker.py modified: linaro_image_tools/hwpack/builder.py linaro_image_tools/hwpack/handler.py linaro_image_tools/hwpack/tests/test_builder.py --- 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_image_tools/hwpack/builder.py' --- linaro_image_tools/hwpack/builder.py 2013-02-18 13:05:58 +0000 +++ linaro_image_tools/hwpack/builder.py 2013-06-04 08:17:22 +0000 @@ -22,7 +22,6 @@ import logging import errno import subprocess -import tempfile import os import shutil from glob import iglob @@ -39,6 +38,7 @@ LocalArchiveMaker, PackageFetcher, ) +from linaro_image_tools.hwpack.package_unpacker import PackageUnpacker from linaro_image_tools.hwpack.hwpack_fields import ( PACKAGE_FIELD, @@ -59,44 +59,6 @@ "No such config file: '%s'" % self.filename) -class PackageUnpacker(object): - def __enter__(self): - self.tempdir = tempfile.mkdtemp() - return self - - def __exit__(self, type, value, traceback): - if self.tempdir is not None and os.path.exists(self.tempdir): - shutil.rmtree(self.tempdir) - - def get_path(self, package_file_name, file_name=''): - """Get package or file path in unpacker tmp dir.""" - package_dir = os.path.basename(package_file_name) - return os.path.join(self.tempdir, package_dir, file_name) - - def unpack_package(self, package_file_name): - # We could extract only a single file, but since dpkg will pipe - # the entire package through tar anyway we might as well extract all. - unpack_dir = self.get_path(package_file_name) - if not os.path.isdir(unpack_dir): - os.mkdir(unpack_dir) - p = cmd_runner.run(["tar", "-C", unpack_dir, "-xf", "-"], - stdin=subprocess.PIPE) - cmd_runner.run(["dpkg", "--fsys-tarfile", package_file_name], - stdout=p.stdin).communicate() - p.communicate() - - def get_file(self, package, file): - # File path passed here must not be absolute, or file from - # real filesystem will be referenced. - assert file and file[0] != '/' - self.unpack_package(package) - logger.debug("Unpacked package %s." % package) - temp_file = self.get_path(package, file) - assert os.path.exists(temp_file), "The file '%s' was " \ - "not found in the package '%s'." % (file, package) - return temp_file - - class HardwarePackBuilder(object): def __init__(self, config_path, version, local_debs, out_name=None): === modified file 'linaro_image_tools/hwpack/handler.py' --- linaro_image_tools/hwpack/handler.py 2013-02-18 13:05:58 +0000 +++ linaro_image_tools/hwpack/handler.py 2013-06-04 11:56:56 +0000 @@ -27,7 +27,7 @@ import tempfile from linaro_image_tools.hwpack.config import Config -from linaro_image_tools.hwpack.builder import PackageUnpacker +from linaro_image_tools.hwpack.package_unpacker import PackageUnpacker from linaro_image_tools.utils import DEFAULT_LOGGER_NAME === added file 'linaro_image_tools/hwpack/package_unpacker.py' --- linaro_image_tools/hwpack/package_unpacker.py 1970-01-01 00:00:00 +0000 +++ linaro_image_tools/hwpack/package_unpacker.py 2013-06-04 08:17:22 +0000 @@ -0,0 +1,66 @@ +# Copyright (C) 2010, 2011, 2013 Linaro +# +# This file is part of Linaro Image Tools. +# +# 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 the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# Linaro Image Tools is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Linaro Image Tools; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +# USA. + +import logging +import os +import tempfile + +from subprocess import PIPE +from shutil import rmtree + +from linaro_image_tools import cmd_runner + +logger = logging.getLogger(__name__) + + +class PackageUnpacker(object): + def __enter__(self): + self.tempdir = tempfile.mkdtemp() + return self + + def __exit__(self, type, value, traceback): + if self.tempdir is not None and os.path.exists(self.tempdir): + rmtree(self.tempdir) + + def get_path(self, package_file_name, file_name=''): + """Get package or file path in unpacker tmp dir.""" + package_dir = os.path.basename(package_file_name) + return os.path.join(self.tempdir, package_dir, file_name) + + def unpack_package(self, package_file_name): + # We could extract only a single file, but since dpkg will pipe + # the entire package through tar anyway we might as well extract all. + unpack_dir = self.get_path(package_file_name) + if not os.path.isdir(unpack_dir): + os.mkdir(unpack_dir) + p = cmd_runner.run(["tar", "-C", unpack_dir, "-xf", "-"], stdin=PIPE) + cmd_runner.run(["dpkg", "--fsys-tarfile", package_file_name], + stdout=p.stdin).communicate() + p.communicate() + + def get_file(self, package, file): + # File path passed here must not be absolute, or file from + # real filesystem will be referenced. + assert file and file[0] != '/' + self.unpack_package(package) + logger.debug("Unpacked package %s." % package) + temp_file = self.get_path(package, file) + assert os.path.exists(temp_file), "The file '%s' was " \ + "not found in the package '%s'." % (file, package) + return temp_file === modified file 'linaro_image_tools/hwpack/tests/test_builder.py' --- linaro_image_tools/hwpack/tests/test_builder.py 2013-02-17 13:53:41 +0000 +++ linaro_image_tools/hwpack/tests/test_builder.py 2013-06-04 11:56:56 +0000 @@ -27,10 +27,10 @@ from linaro_image_tools.hwpack.builder import ( ConfigFileMissing, - PackageUnpacker, HardwarePackBuilder, logger as builder_logger, ) +from linaro_image_tools.hwpack.package_unpacker import PackageUnpacker from linaro_image_tools.hwpack.config import HwpackConfigError from linaro_image_tools.hwpack.hardwarepack import Metadata from linaro_image_tools.hwpack.packages import (