Commit 87d65558 authored by Vikram Narayanan's avatar Vikram Narayanan Committed by Wolfgang Denk

patman: Handle creation of patman config file

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 and 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: default avatarVikram Narayanan <>
Acked-by: default avatarSimon Glass <>
Cc: Simon Glass <>
Cc: Wolfgang Denk <>
parent 2b36c75d
......@@ -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:
......@@ -357,6 +357,24 @@ def GetAliasFile():
fname = os.path.join(GetTopLevel(), fname.strip())
return fname
def GetDefaultUserName():
"""Gets the from .gitconfig file.
User name found in .gitconfig file, or None if none
uname = command.OutputOneLine('git', 'config', '--global', '')
return uname
def GetDefaultUserEmail():
"""Gets the from the global .gitconfig file.
User's email found in .gitconfig file, or None if none
uemail = command.OutputOneLine('git', 'config', '--global', '')
return uemail
def Setup():
"""Set up git utils, by reading the alias files."""
......@@ -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):
def CreatePatmanConfigFile(config_fname):
"""Creates a config file under $(HOME)/.patman if it can't find one.
config_fname: Default config filename i.e., $(HOME)/.patman
name = gitutil.GetDefaultUserName()
if name == None:
name = raw_input("Enter name: ")
email = gitutil.GetDefaultUserEmail()
if email == None:
email = raw_input("Enter email: ")
f = open(config_fname, 'w')
except IOError:
print "Couldn't create patman config file\n"
print >>f, "[alias]\nme: %s <%s>" % (name, email)
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:
if not os.path.exists(config_fname):
print "No config file found ~/.patman\nCreating one...\n"
for name, value in settings.items('alias'):
alias[name] = value.split(',')
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment