patman: Handle creation of patman config
PATCH v2 4/4 patman: Handle creation of patman config
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.
--- tools/patman/gitutil.py | 18 ++++++++++++++++++ tools/patman/settings.py | 34 +++++++++++++++++++++++++++++++--- 2 files changed, 49 insertions(+), 3 deletions(-)
tools/patman/gitutil.py +18 -0
@@ -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('')
tools/patman/settings.py +31 -3
@@ -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(',')
Signature · 1 line
1.7.4.1
PATCH v2 4/4 patman: Handle creation of patman config
Dear Vikram & Simon,
Quoted 5 lines · In message <[email protected]> you wrote:
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.
I have a more general question here: Why is the config file in $(HOME)/.config/patman (instead for example $(HOME)/.patman) ?
My understanding is that $(HOME)/.config/ is defined by the XDG Base Directory Specification - but patman has nothign to do with the X11 desktop - or has it?
Best regards,
Wolfgang Denk
Signature · 5 lines
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de Another dream that failed. There's nothing sadder. -- Kirk, "This side of Paradise", stardate 3417.3
PATCH v2 4/4 patman: Handle creation of patman config
Hello Wolfgang,
Quoted 9 lines · Wolfgang Denk
Dear Vikram& Simon,
Quoted 5 lines · In message<[email protected]> you wrote:
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.
Quoted 6 lines
I have a more general question here: Why is the config file in $(HOME)/.config/patman (instead for example $(HOME)/.patman) ?
My understanding is that $(HOME)/.config/ is defined by the XDG Base Directory Specification - but patman has nothign to do with the X11 desktop - or has it?
Your argument is right. But Simon is the right person for answering this as he is the one who pushed patman.
Regards,
Vikram
PATCH v2 4/4 patman: Handle creation of patman config
Hi Wolfgang, Vikram,
Quoted 20 lines · Vikram Narayanan
Hello Wolfgang,
Quoted 16 lines · Wolfgang Denk
Dear Vikram& Simon,
In message<4F9ACBD1.1080003@**gmail.com <[email protected]>>
Quoted 6 lines · you
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.
I have a more general question here: Why is the config file in $(HOME)/.config/patman (instead for example $(HOME)/.patman) ?
Quoted 8 lines
Quoted 4 lines
My understanding is that $(HOME)/.config/ is defined by the XDG Base Directory Specification - but patman has nothign to do with the X11 desktop - or has it?
Your argument is right. But Simon is the right person for answering this as he is the one who pushed patman.
I agree also, it was an attempt to reduce clutter in home but I agree that .patman is more correct.
Vikram, let me check your series again and then would you mind inserting a patch to change this at the start of your series?
Quoted 3 lines
Regards,
Vikram
Regards,
Simon
PATCH v2 4/4 patman: Handle creation of patman config
In reply to Vikram NarayananHi Vikram,
Quoted 9 lines · Vikram Narayanan
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 <[email protected]>Cc Simon Glass <[email protected]>
In terms of changing the config file to ~/.patman, this could actually be a subsequent patch if you like. But there are a few nits below if you re-issue.
Quoted 50 lines
--- tools/patman/gitutil.py | 18 ++++++++++++++++++ tools/patman/settings.py | 34 +++++++++++++++++++++++++++++++--- 2 files changed, 49 insertions(+), 3 deletions(-)tools/patman/gitutil.py +18
-0@@ -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('')tools/patman/settings.py +1
-1@@ -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:
tools/patman/settings.py def ReadGitAliases(fname): · line 66
Quoted 6 lines
tools/patman/settings.py +2
-0@@ -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.
nits: Remove space before 'Creates' and add Args: to document config_fname,
Quoted 43 lines
tools/patman/settings.py +28
-3+ + 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(',') --1.7.4.1
Quoted 1 line
Regards,
Simon
PATCH v2 4/4 patman: Handle creation of patman config
Quoted 17 lines · Simon Glass
Hi Vikram,
On Fri, Apr 27, 2012 at 9:39 AM, Vikram Narayanan <[email protected] <mailto:[email protected]>> wrote:
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 <http://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 <[email protected]<mailto:[email protected]>>
Cc: Simon Glass <sjg at chromium.org <mailto:[email protected]>>
Quoted 6 lines
Acked-by Simon Glass <sjg at chromium.org <mailto:[email protected]>>In terms of changing the config file to ~/.patman, this could actually be a subsequent patch if you like. But there are a few nits below if you re-issue.
I feel that can be dealt in a separate patch which follows this. For the few nits, I'll send a v3 _only_ for this patch and not for the whole series as the other two are ACK'ed and one is decided not to be ACK'ed.
Thanks,
Vikram