From patchwork Wed Jun 15 05:33:51 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 70083 Delivered-To: patch@linaro.org Received: by 10.140.106.246 with SMTP id e109csp2398654qgf; Tue, 14 Jun 2016 22:51:14 -0700 (PDT) X-Received: by 10.28.144.80 with SMTP id s77mr8162914wmd.41.1465969874646; Tue, 14 Jun 2016 22:51:14 -0700 (PDT) Return-Path: Received: from theia.denx.de (theia.denx.de. [85.214.87.163]) by mx.google.com with ESMTP id m73si8643502wmg.40.2016.06.14.22.51.14; Tue, 14 Jun 2016 22:51:14 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 85.214.87.163 as permitted sender) client-ip=85.214.87.163; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@nifty.com; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 85.214.87.163 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 4CF41A776A; Wed, 15 Jun 2016 07:49:31 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 8iqRrqkhIk2n; Wed, 15 Jun 2016 07:49:31 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 090A8A7770; Wed, 15 Jun 2016 07:48:35 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 09781A751B for ; Wed, 15 Jun 2016 07:33:44 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id fgcKgXE-jPjI for ; Wed, 15 Jun 2016 07:33:24 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from conuserg-08.nifty.com (conuserg-08.nifty.com [210.131.2.75]) by theia.denx.de (Postfix) with ESMTPS id 8F3EAA7519 for ; Wed, 15 Jun 2016 07:33:01 +0200 (CEST) Received: from beagle.diag.org (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-08.nifty.com with ESMTP id u5F5WZeD021857; Wed, 15 Jun 2016 14:32:37 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-08.nifty.com u5F5WZeD021857 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1465968757; bh=sDyZ8UwbjArIevH9cjqGxdp5i+MmZkyqn15/RL6i4KE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YrgZ2VP1T2uvknnmXtemAtNV9AvJO2KY0/mSxOUScUwlTuTaxBaN8KUlfv/7x0KOf qgkfYlBUzBelrPXpm9OeXGlJE3P6JPx+CDl+RZm4wIRNWo4XiD5X4edi9z4YBtlbmQ ouSvIGxRw2lwpt1V/2Inu7W555JObhpQJPCYvxM4yAvW5NaYzaRLyHXgBm5KusPT+J LpT/umDbIjPe01qdP9p0M6zPcDXXa7GjAjeU0ZsoHqaOJ5njEeOBtDgKHYQUnRfcME Sbm3CEAFYLFCJCNI2CN+n4IvXtNzUtxjgvNkT07rE3FfGTCyORFfRaIyV0avkaSTve Tyi1Ys9yKAMoQ== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: u-boot@lists.denx.de Date: Wed, 15 Jun 2016 14:33:51 +0900 Message-Id: <1465968834-17361-3-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1465968834-17361-1-git-send-email-yamada.masahiro@socionext.com> References: <1465968834-17361-1-git-send-email-yamada.masahiro@socionext.com> Cc: Joe Hershberger Subject: [U-Boot] [PATCH 2/5] tools: moveconfig: change class WorkDir to class ReferenceSource X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" The class WorkDir can be used in a very generic way, but currently it is only used for containing a reference source directory. This commit changes it for a more dedicated use. The move_config function can be more readable by enclosing the git-clone and git- checkout in the class constructor. Signed-off-by: Masahiro Yamada --- tools/moveconfig.py | 49 ++++++++++++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 21 deletions(-) -- 1.9.1 _______________________________________________ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot diff --git a/tools/moveconfig.py b/tools/moveconfig.py index 06ff4d9..f4e2580 100755 --- a/tools/moveconfig.py +++ b/tools/moveconfig.py @@ -880,23 +880,39 @@ class Slots: for board in failed_boards: f.write(board + '\n') -class WorkDir: - def __init__(self): - """Create a new working directory.""" - self.work_dir = tempfile.mkdtemp() +class ReferenceSource: + + """Reference source against which original configs should be parsed.""" + + def __init__(self, commit): + """Create a reference source directory based on a specified commit. + + Arguments: + commit: commit to git-clone + """ + self.src_dir = tempfile.mkdtemp() + print "Cloning git repo to a separate work directory..." + subprocess.check_output(['git', 'clone', os.getcwd(), '.'], + cwd=self.src_dir) + print "Checkout '%s' to build the original autoconf.mk." % \ + subprocess.check_output(['git', 'rev-parse', '--short', commit]).strip() + subprocess.check_output(['git', 'checkout', commit], + stderr=subprocess.STDOUT, cwd=self.src_dir) def __del__(self): - """Delete the working directory + """Delete the reference source directory This function makes sure the temporary directory is cleaned away even if Python suddenly dies due to error. It should be done in here because it is guaranteed the destructor is always invoked when the instance of the class gets unreferenced. """ - shutil.rmtree(self.work_dir) + shutil.rmtree(self.src_dir) + + def get_dir(self): + """Return the absolute path to the reference source directory.""" - def get(self): - return self.work_dir + return self.src_dir def move_config(configs, options): """Move config options to defconfig files. @@ -914,20 +930,11 @@ def move_config(configs, options): print 'Move ' + ', '.join(configs), print '(jobs: %d)\n' % options.jobs - reference_src_dir = '' - if options.git_ref: - work_dir = WorkDir() - reference_src_dir = work_dir.get() - print "Cloning git repo to a separate work directory..." - subprocess.check_output(['git', 'clone', os.getcwd(), '.'], - cwd=reference_src_dir) - print "Checkout '%s' to build the original autoconf.mk." % \ - subprocess.check_output(['git', 'rev-parse', '--short', - options.git_ref]).strip() - subprocess.check_output(['git', 'checkout', options.git_ref], - stderr=subprocess.STDOUT, - cwd=reference_src_dir) + reference_src = ReferenceSource(options.git_ref) + reference_src_dir = reference_src.get_dir() + else: + reference_src_dir = '' if options.defconfigs: defconfigs = [line.strip() for line in open(options.defconfigs)]