From patchwork Tue Jan 25 12:53:31 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guilherme Salgado X-Patchwork-Id: 22 Return-Path: Delivered-To: unknown Received: from imap.gmail.com (74.125.159.109) by localhost6.localdomain6 with IMAP4-SSL; 08 Jun 2011 14:39:18 -0000 Delivered-To: patches@linaro.org Received: by 10.147.124.10 with SMTP id b10cs53371yan; Tue, 25 Jan 2011 04:53:37 -0800 (PST) Received: by 10.227.155.15 with SMTP id q15mr5792530wbw.133.1295960011863; Tue, 25 Jan 2011 04:53:31 -0800 (PST) Received: from adelie.canonical.com (adelie.canonical.com [91.189.90.139]) by mx.google.com with ESMTP id r3si22513349wbr.54.2011.01.25.04.53.31; Tue, 25 Jan 2011 04:53:31 -0800 (PST) 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 loganberry.canonical.com ([91.189.90.37]) by adelie.canonical.com with esmtp (Exim 4.71 #1 (Debian)) id 1PhiOp-0008Kd-6g for ; Tue, 25 Jan 2011 12:53:31 +0000 Received: from loganberry.canonical.com (localhost [127.0.0.1]) by loganberry.canonical.com (Postfix) with ESMTP id 30D012E8026 for ; Tue, 25 Jan 2011 12:53:31 +0000 (UTC) MIME-Version: 1.0 X-Launchpad-Project: linaro-image-tools X-Launchpad-Branch: ~linaro-maintainers/linaro-image-tools/trunk X-Launchpad-Message-Rationale: Subscriber X-Launchpad-Branch-Revision-Number: 258 X-Launchpad-Notification-Type: branch-revision To: Linaro Patch Tracker From: noreply@launchpad.net Subject: [Branch ~linaro-maintainers/linaro-image-tools/trunk] Rev 258: Do not try to clean stuff up when there's nothing to cleanup. Message-Id: <20110125125331.22770.44427.launchpad@loganberry.canonical.com> Date: Tue, 25 Jan 2011 12:53:31 -0000 Reply-To: noreply@launchpad.net Sender: bounces@canonical.com Errors-To: bounces@canonical.com Precedence: bulk X-Generated-By: Launchpad (canonical.com); Revision="12248"; Instance="initZopeless config overlay" X-Launchpad-Hash: 1664c2bdc10a2ca54673cefc59332bb84e82db96 ------------------------------------------------------------ revno: 258 fixes bug(s): https://launchpad.net/bugs/705549 committer: Guilherme Salgado branch nick: trunk timestamp: Tue 2011-01-25 10:51:19 -0200 message: Do not try to clean stuff up when there's nothing to cleanup. modified: linaro-media-create --- lp:linaro-image-tools https://code.launchpad.net/~linaro-maintainers/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-maintainers/linaro-image-tools/trunk/+edit-subscription === modified file 'linaro-media-create' --- linaro-media-create 2011-01-18 13:23:16 +0000 +++ linaro-media-create 2011-01-25 12:51:19 +0000 @@ -26,11 +26,11 @@ ) from linaro_media_create import get_args_parser - -TMP_DIR = tempfile.mkdtemp() -ROOTFS_DIR = os.path.join(TMP_DIR, 'binary') -BOOT_DISK = os.path.join(TMP_DIR, 'boot-disc') -ROOT_DISK = os.path.join(TMP_DIR, 'root-disc') +# Just define the global variables +TMP_DIR = None +ROOTFS_DIR = None +BOOT_DISK = None +ROOT_DISK = None # Registered as the first atexit handler as we want this to be the last @@ -44,13 +44,16 @@ devnull = open('/dev/null', 'w') # Use raw subprocess.Popen as we don't want to stop in case the # commands end with a non-zero return code. - Popen( - ['sudo', 'umount', BOOT_DISK], stdout=devnull, stderr=devnull).wait() - Popen( - ['sudo', 'umount', ROOT_DISK], stdout=devnull, stderr=devnull).wait() + if BOOT_DISK is not None: + Popen(['sudo', 'umount', BOOT_DISK], + stdout=devnull, stderr=devnull).wait() + if ROOT_DISK is not None: + Popen(['sudo', 'umount', ROOT_DISK], + stdout=devnull, stderr=devnull).wait() # Remove TMP_DIR as root because some files written there are # owned by root. - Popen(['sudo', 'rm', '-rf', TMP_DIR]).wait() + if TMP_DIR is not None: + Popen(['sudo', 'rm', '-rf', TMP_DIR]).wait() def ensure_required_commands(args): @@ -71,6 +74,14 @@ if __name__ == '__main__': parser = get_args_parser() args = parser.parse_args() + + # If --help was specified this won't execute. + # Create temp dir and initialize rest of path vars. + TMP_DIR = tempfile.mkdtemp() + ROOTFS_DIR = os.path.join(TMP_DIR, 'binary') + BOOT_DISK = os.path.join(TMP_DIR, 'boot-disc') + ROOT_DISK = os.path.join(TMP_DIR, 'root-disc') + board_config = board_configs[args.board] ensure_required_commands(args)