From patchwork Fri Apr 27 16:39:45 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Narayanan X-Patchwork-Id: 155546 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 9310CB6FAC for ; Sat, 28 Apr 2012 02:40:07 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 84D672839A; Fri, 27 Apr 2012 18:40:02 +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 D9aY7cBde5Jp; Fri, 27 Apr 2012 18:40:02 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id A2A1F2839F; Fri, 27 Apr 2012 18:39:59 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 0013628391 for ; Fri, 27 Apr 2012 18:39:56 +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 YQHl0VhUg71i for ; Fri, 27 Apr 2012 18:39:56 +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 C5CFF283B6 for ; Fri, 27 Apr 2012 18:39:54 +0200 (CEST) Received: by mail-pb0-f44.google.com with SMTP id rp16so1029793pbb.3 for ; Fri, 27 Apr 2012 09:39:54 -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 :content-type:content-transfer-encoding; bh=LbvqsUiGerUx6zL3BnrW3Mr+bNhUYw2xM1aVK2E/zFU=; b=F961nPMtFlk7kbDBn9X29IMnQklAz6GgfYfCQLuVEOnjEn+zRDEN0mj0A6Pz6jdgTx +gsoPsuni8t/atfHiNgDcBwStlCOTt3yVx1VlzTq5u5A3EUN5nwXTejnS9SyZ8025j7X 4nVsdtKNbJrihIqYKqPV5bHYFW673Yxa3/6RI143+G2/U4oMy86mqaRP/IWOf17uBiP7 oRzhRhpQSlydmJiw62S6wwTO0Gf+FeGxel3bd7hz+AwmSdaj7xyvI0c+1+hUdihmf26a ypOCrSrZIEZ7zbPGlfEeW3pEpgjXJUEeHOtnS0CuZwZ+HkVZsas+e2vOsrkvLhW28jqs QE8g== Received: by 10.68.219.226 with SMTP id pr2mr16739928pbc.66.1335544794042; Fri, 27 Apr 2012 09:39:54 -0700 (PDT) Received: from [101.63.221.145] ([101.63.221.145]) by mx.google.com with ESMTPS id y3sm6918466pbh.59.2012.04.27.09.39.50 (version=SSLv3 cipher=OTHER); Fri, 27 Apr 2012 09:39:53 -0700 (PDT) Message-ID: <4F9ACBD1.1080003@gmail.com> Date: Fri, 27 Apr 2012 22:09:45 +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 Subject: [U-Boot] [PATCH v2 4/4] patman: Handle creation of patman config 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)/.config/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 those. Signed-off-by: Vikram Narayanan Cc: Simon Glass Acked-by: Simon Glass --- tools/patman/gitutil.py | 18 ++++++++++++++++++ tools/patman/settings.py | 34 +++++++++++++++++++++++++++++++--- 2 files changed, 49 insertions(+), 3 deletions(-) diff --git a/tools/patman/gitutil.py b/tools/patman/gitutil.py index 48ca998..2eacb13 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 049c709..03ea307 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,30 @@ def ReadGitAliases(fname): fd.close() +def CreatePatmanConfigFile(config_fname): + """ Creates a config file under $(HOME)/.config/ if it can't find one. + + 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 +94,12 @@ def Setup(config_fname=''): settings = ConfigParser.SafeConfigParser() if config_fname == '': config_fname = '%s/.config/patman' % os.getenv('HOME') - if config_fname: - settings.read(config_fname) + + if not os.path.exists(config_fname): + print "No config file found under ~/.config/\nCreating one...\n" + CreatePatmanConfigFile(config_fname) + + settings.read(config_fname) for name, value in settings.items('alias'): alias[name] = value.split(',')