From patchwork Wed May 23 19:01:06 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Narayanan X-Patchwork-Id: 161024 X-Patchwork-Delegate: wd@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id AABE0B6FC2 for ; Thu, 24 May 2012 05:01:29 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id E88E528199; Wed, 23 May 2012 21:01:27 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de 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 fI4XW9PY5q1R; Wed, 23 May 2012 21:01:27 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id AB9E42817E; Wed, 23 May 2012 21:01:25 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 8A2162817E for ; Wed, 23 May 2012 21:01:23 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de 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 JqjQRPKjndnk for ; Wed, 23 May 2012 21:01:22 +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 mail-pb0-f44.google.com (mail-pb0-f44.google.com [209.85.160.44]) by theia.denx.de (Postfix) with ESMTPS id 7FF572817D for ; Wed, 23 May 2012 21:01:20 +0200 (CEST) Received: by pbcwy7 with SMTP id wy7so9368701pbc.3 for ; Wed, 23 May 2012 12:01:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; bh=NkjI+ZRyT8SHfPPsJkZwFnZ9XgzQz5ki/9zBCCYrEYQ=; b=G4wEl+XRuZUMwvY7bct2/Pl5awheNUAa6zSv+VKhvdhXloTVldWxjuZDvZyuuveP/y 3bV+KzBNtb7Kgh59Gl+uY6AdYkRYx7QLWsu/3xR0Fq+oVaaXofMfYA9lFXEZzNh8jVjO vpZ0f6axUsqipn1KF1r+c/7rHD5961OTIJuCLakLCTOb9QtS2mzk9IbtAxyfgcKS3o63 1/du1nXDQE9pdjhTENXKvkYtytknriUPuIu6ew2uDIyyNgAnvk2A43+jhU1aSsAsnTWO 3tc7cAqaGm0y8jRcccG7ykT/VC4V4sj0NXG/iVEJgXyY/6R2eE5CvKZVPgYb8ccctx7Y Mt6g== Received: by 10.68.196.201 with SMTP id io9mr12878241pbc.126.1337799678414; Wed, 23 May 2012 12:01:18 -0700 (PDT) Received: from [101.63.248.219] ([101.63.248.219]) by mx.google.com with ESMTPS id x1sm2679128pbp.50.2012.05.23.12.01.13 (version=SSLv3 cipher=OTHER); Wed, 23 May 2012 12:01:17 -0700 (PDT) Message-ID: <4FBD33F2.8000601@gmail.com> Date: Thu, 24 May 2012 00:31:06 +0530 From: Vikram Narayanan User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:10.0.2) Gecko/20120216 Thunderbird/10.0.2 MIME-Version: 1.0 To: u-boot@lists.denx.de References: <4FBD332B.7010400@gmail.com> In-Reply-To: <4FBD332B.7010400@gmail.com> Subject: [U-Boot] [PATCH 2/2] patman: Handle creation of patman config file X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de patman shouts when it couldn't find a $(HOME)/.patman file. Handle it in a sane way by creating a new one for the user. It looks for a user.name and user.email in the global .gitconfig file, waits for the user input if it can't find there. Update the same in the README Signed-off-by: Vikram Narayanan Acked-by: Simon Glass Cc: Simon Glass Cc: Wolfgang Denk --- tools/patman/README | 3 +++ tools/patman/gitutil.py | 18 ++++++++++++++++++ tools/patman/settings.py | 37 ++++++++++++++++++++++++++++++++++--- 3 files changed, 55 insertions(+), 3 deletions(-) diff --git a/tools/patman/README b/tools/patman/README index 1af8665..86ede78 100644 --- a/tools/patman/README +++ b/tools/patman/README @@ -68,6 +68,9 @@ How to configure it For most cases patman will locate and use the file 'doc/git-mailrc' in your U-Boot directory. This contains most of the aliases you will need. +During the first run patman creates a config file for you by taking the default +user name and email address from the global .gitconfig file. + To add your own, create a file ~/.patman like this: >>>> diff --git a/tools/patman/gitutil.py b/tools/patman/gitutil.py index 48ca998..59eca99 100644 --- a/tools/patman/gitutil.py +++ b/tools/patman/gitutil.py @@ -357,6 +357,24 @@ def GetAliasFile(): fname = os.path.join(GetTopLevel(), fname.strip()) return fname +def GetDefaultUserName(): + """Gets the user.name from .gitconfig file. + + Returns: + User name found in .gitconfig file, or None if none + """ + uname = command.OutputOneLine('git', 'config', '--global', 'user.name') + return uname + +def GetDefaultUserEmail(): + """Gets the user.email from the global .gitconfig file. + + Returns: + User's email found in .gitconfig file, or None if none + """ + uemail = command.OutputOneLine('git', 'config', '--global', 'user.email') + return uemail + def Setup(): """Set up git utils, by reading the alias files.""" settings.Setup('') diff --git a/tools/patman/settings.py b/tools/patman/settings.py index f980071..4dda17b 100644 --- a/tools/patman/settings.py +++ b/tools/patman/settings.py @@ -24,7 +24,7 @@ import os import re import command - +import gitutil def ReadGitAliases(fname): """Read a git alias file. This is in the form used by git: @@ -61,6 +61,33 @@ def ReadGitAliases(fname): fd.close() +def CreatePatmanConfigFile(config_fname): + """Creates a config file under $(HOME)/.patman if it can't find one. + + Args: + config_fname: Default config filename i.e., $(HOME)/.patman + + Returns: + None + """ + name = gitutil.GetDefaultUserName() + if name == None: + name = raw_input("Enter name: ") + + email = gitutil.GetDefaultUserEmail() + + if email == None: + email = raw_input("Enter email: ") + + try: + f = open(config_fname, 'w') + except IOError: + print "Couldn't create patman config file\n" + raise + + print >>f, "[alias]\nme: %s <%s>" % (name, email) + f.close(); + def Setup(config_fname=''): """Set up the settings module by reading config files. @@ -70,8 +97,12 @@ def Setup(config_fname=''): settings = ConfigParser.SafeConfigParser() if config_fname == '': config_fname = '%s/.patman' % os.getenv('HOME') - if config_fname: - settings.read(config_fname) + + if not os.path.exists(config_fname): + print "No config file found ~/.patman\nCreating one...\n" + CreatePatmanConfigFile(config_fname) + + settings.read(config_fname) for name, value in settings.items('alias'): alias[name] = value.split(',')