PATCH 4/4] patman: Handle searching of patman config
patman shouts when it couldn't find a $(HOME)/.config/patman file. Also, it couldn't create patch files without the above config file. Handle it in a sane way by creating a new one for the user.
--- tools/patman/settings.py | 26 ++++++++++++++++++++++++-- 1 files changed, 24 insertions(+), 2 deletions(-)
tools/patman/settings.py +24 -2
@@ -61,6 +61,22 @@ def ReadGitAliases(fname): fd.close() +def CreatePatmanConfigFile(config_fname): + name = raw_input("Enter name: ") + email = raw_input("Enter email: ") + + try: + FILE = open(config_fname,"w") + except IOError: + print "Couldn't create patman config file\n" + + FILE.write("[alias]\nme: ") + FILE.write(name); + FILE.write(" <"); + FILE.write(email); + FILE.write(">") + FILE.close(); + def Setup(config_fname=''): """Set up the settings module by reading config files.
@@ -70,8 +86,14 @@ 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) + + exists = os.path.exists(config_fname) + + if exists == False: + 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
Hi Vikram,
Quoted 19 lines · Vikram Narayanan
patman shouts when it couldn't find a $(HOME)/.config/patman file. Also, it couldn't create patch files without the above config file. Handle it in a sane way by creating a new one for the user.
The title of this patch is misisng a [.
Signed-off-by Vikram Narayanan <[email protected]>Cc Simon Glass <[email protected]>--- tools/patman/settings.py | 26 ++++++++++++++++++++++++-- 1 files changed, 24 insertions(+), 2 deletions(-)tools/patman/settings.py +0
-0
tools/patman/settings.py def ReadGitAliases(fname): · line 67
Quoted 7 lines
tools/patman/settings.py +3
-0@@ -61,6 +61,22 @@ def ReadGitAliases(fname): fd.close() +def CreatePatmanConfigFile(config_fname): + name = raw_input("Enter name: ") + email = raw_input("Enter email: ")
This is fine, but for bonus points I wonder if you can pick these up from ~/.gitconfig by default, and use something like this:
readline.set_startup_hook(lambda: readline.insert_text('default email'))
(you would need 'import readline' somewhere, and the function to read the bits from .gitconfig should probably go in gitutil)
Anyway that's just an idea, feel free to ignore.
tools/patman/settings.py def ReadGitAliases(fname): · line 82
Quoted 4 lines
tools/patman/settings.py +3
-0+ + try: + FILE = open(config_fname,"w")
Low case variable please
Also please use single quote unless you need double quote (that's the code style). And space after comma.
tools/patman/settings.py def ReadGitAliases(fname): · line 82
Quoted 3 lines
tools/patman/settings.py +2
-0+ except IOError: + print "Couldn't create patman config file\n"
I think you should return or except in here, otherwise you fall through and get an undefined variable.
tools/patman/settings.py def ReadGitAliases(fname): · line 77
Quoted 7 lines
tools/patman/settings.py +6
-0+ + FILE.write("[alias]\nme: ") + FILE.write(name); + FILE.write(" <"); + FILE.write(email); + FILE.write(">")
How about something like:
print '[alias]\nme: %s <%email>' % (name, email)
Quoted 6 lines
tools/patman/settings.py +2
-0+ FILE.close(); +def
Setup(config_fname=''):
"""Set up the settings module by reading config files.
tools/patman/settings.py def Setup(config_fname=''): · line 93
Quoted 10 lines
tools/patman/settings.py +4
-2@@ -70,8 +86,14 @@ 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) + + exists = os.path.exists(config_fname) + + if exists == False:
if not os.path.exists(config_fname):
Quoted 11 lines
tools/patman/settings.py +4
-0+ 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
Regards,
Simon