]> git.kernelconcepts.de Git - karo-tx-uboot.git/commitdiff
patman: Handle creation of patman config file
authorVikram Narayanan <vikram186@gmail.com>
Wed, 23 May 2012 09:01:06 +0000 (09:01 +0000)
committerWolfgang Denk <wd@denx.de>
Tue, 19 Jun 2012 20:51:55 +0000 (22:51 +0200)
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 <vikram186@gmail.com>
Acked-by: Simon Glass <sjg@chromium.org>
Cc: Simon Glass <sjg@chromium.org>
Cc: Wolfgang Denk <wd@denx.de>
tools/patman/README
tools/patman/gitutil.py
tools/patman/settings.py

index 1af86654db1332666834ba9c86b1912bd2846fcd..86ede78d35c8d3967970159c663ec0b7b8c6c940 100644 (file)
@@ -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:
 
 >>>>
index 48ca998650592ec275453dbb43e4e7067a6aeac0..59eca99341371a5cca58d80cac721d330a2c13e7 100644 (file)
@@ -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('')
index f9800714899d145e9eb7e8a35d5cde823e10dc64..4dda17bf516d15ebab877f2d1e1f61b13bfe5cc8 100644 (file)
@@ -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(',')