patman: Handle creation of patman config
PATCH v3 1/1 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 | 37 ++++++++++++++++++++++++++++++++++--- 2 files changed, 52 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 +34 -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,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(',')
Signature · 1 line
1.7.4.1
PATCH v3 1/1 patman: Handle creation of patman config
Quoted 8 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]>
Quoted 103 lines
--- tools/patman/gitutil.py | 18 ++++++++++++++++++ tools/patman/settings.py | 37 ++++++++++++++++++++++++++++++++++--- 2 files changed, 52 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 +34
-4@@ -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
PATCH v3 1/1 patman: Handle creation of patman config
Hello Wolfgang,
Quoted 9 lines · Simon Glass
On Mon, Apr 30, 2012 at 8:46 PM, 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.
Quoted 6 lines
Signed-off-by Vikram Narayanan <[email protected]<mailto:[email protected]>>
Cc: Simon Glass <sjg at chromium.org <mailto:[email protected]>>Acked-by Simon Glass <sjg at chromium.org <mailto:[email protected]>>
Can you please take this patch in?
Thanks,
Vikram
PATCH v3 1/1 patman: Handle creation of patman config
In reply to Vikram NarayananDear Vikram Narayanan,
Quoted 7 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.
Signed-off-by Vikram Narayanan <[email protected]>Cc Simon Glass <[email protected]>
We discussed before that patman should not place or use any files from the ~/.config/ directory. The agreement wat that this would be changed, please see:
http://article.gmane.org/gmane.comp.boot-loaders.u-boot/130553
Best regards,
Wolfgang Denk
Signature · 4 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 grep me no patterns and I'll tell you no lines.
PATCH v3 1/1 patman: Handle creation of patman config
Hi,
Quoted 8 lines · Wolfgang Denk
Dear Vikram Narayanan,
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 9 lines
Quoted 2 lines
Signed-off-by Vikram Narayanan <[email protected]>Cc Simon Glass <[email protected]>We discussed before that patman should not place or use any files from the ~/.config/ directory. The agreement wat that this would be changed, please see:
http://article.gmane.org/gmane.comp.boot-loaders.u-boot/130553
OK, so if this goes in after the .config change, it will need rebasing and adjusting.
Regards,
Simon
Quoted 14 lines
Best regards,
Wolfgang Denk
--
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 grep me no patterns and I'll tell you no lines.
_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot