diff options
author | Vikram Narayanan <vikram186@gmail.com> | 2012-05-23 09:01:06 +0000 |
---|---|---|
committer | Wolfgang Denk <wd@denx.de> | 2012-06-19 22:51:55 +0200 |
commit | 87d65558efe50bb2cc3617bafd8399695212c0e5 (patch) | |
tree | 0b21809e60f6408fd84c0eda3029a841176a39ce /tools/patman/settings.py | |
parent | 2b36c75d7b930a860ec17f2af3321faa5811593b (diff) | |
download | u-boot-imx-87d65558efe50bb2cc3617bafd8399695212c0e5.zip u-boot-imx-87d65558efe50bb2cc3617bafd8399695212c0e5.tar.gz u-boot-imx-87d65558efe50bb2cc3617bafd8399695212c0e5.tar.bz2 |
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 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>
Diffstat (limited to 'tools/patman/settings.py')
-rw-r--r-- | tools/patman/settings.py | 37 |
1 files changed, 34 insertions, 3 deletions
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(',') |