All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vikram Narayanan <vikram186@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v3] patman: Handle creation of patman config
Date: Tue, 01 May 2012 09:16:30 +0530	[thread overview]
Message-ID: <4F9F5C96.3020001@gmail.com> (raw)

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 <vikram186@gmail.com>
Cc: Simon Glass <sjg@chromium.org>

---
 tools/patman/gitutil.py  |   18 ++++++++++++++++++
 tools/patman/settings.py |   37 ++++++++++++++++++++++++++++++++++---
 2 files changed, 52 insertions(+), 3 deletions(-)

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 049c709..9b7e75d 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)/.config/ if it can't find one.
+
+    Args:
+        config_fname: Default config filename i.e., $(HOME)/.config/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/.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(',')
-- 
1.7.4.1

             reply	other threads:[~2012-05-01  3:46 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-01  3:46 Vikram Narayanan [this message]
2012-05-01  5:07 ` [U-Boot] [PATCH v3] patman: Handle creation of patman config Simon Glass
2012-05-21 14:35   ` Vikram Narayanan
2012-05-22 16:00 ` Wolfgang Denk
2012-05-22 16:59   ` Simon Glass

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4F9F5C96.3020001@gmail.com \
    --to=vikram186@gmail.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.