Message ID | 4F9ACBD1.1080003@gmail.com |
---|---|
State | Accepted |
Delegated to: | Wolfgang Denk |
Headers | show |
Dear Vikram & Simon, In message <4F9ACBD1.1080003@gmail.com> 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
Hello Wolfgang, On 4/30/2012 2:14 PM, Wolfgang Denk wrote: > Dear Vikram& Simon, > > In message<4F9ACBD1.1080003@gmail.com> 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? Your argument is right. But Simon is the right person for answering this as he is the one who pushed patman. Regards, Vikram
Hi Wolfgang, Vikram, On Mon, Apr 30, 2012 at 6:37 AM, Vikram Narayanan <vikram186@gmail.com>wrote: > Hello Wolfgang, > > On 4/30/2012 2:14 PM, Wolfgang Denk wrote: > >> Dear Vikram& Simon, >> >> >> In message<4F9ACBD1.1080003@**gmail.com <4F9ACBD1.1080003@gmail.com>> >> 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? >> > > 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? > Regards, > Vikram > Regards, Simon
Hi Vikram, On Fri, Apr 27, 2012 at 9:39 AM, Vikram Narayanan <vikram186@gmail.com>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 <vikram186@gmail.com> > Cc: Simon Glass <sjg@chromium.org> > Acked-by: Simon Glass <sjg@chromium.org> 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. > --- > tools/patman/gitutil.py | 18 ++++++++++++++++++ > tools/patman/settings.py | 34 +++++++++++++++++++++++++++++++--- > 2 files changed, 49 insertions(+), 3 deletions(-) > > diff --git a/tools/patman/gitutil.py b/tools/patman/gitutil.py > index 48ca998..2eacb13 100644 > --- a/tools/patman/gitutil.py > +++ b/tools/patman/gitutil.py > @@ -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('') > diff --git a/tools/patman/settings.py b/tools/patman/settings.py > index 049c709..03ea307 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,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, > + > + 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 > > Regards, Simon
On 4/30/2012 11:07 PM, Simon Glass wrote: > Hi Vikram, > > On Fri, Apr 27, 2012 at 9:39 AM, Vikram Narayanan <vikram186@gmail.com > <mailto:vikram186@gmail.com>> 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 <vikram186@gmail.com > <mailto:vikram186@gmail.com>> > Cc: Simon Glass <sjg@chromium.org <mailto:sjg@chromium.org>> > > > Acked-by: Simon Glass <sjg@chromium.org <mailto:sjg@chromium.org>> > > 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
diff --git a/tools/patman/gitutil.py b/tools/patman/gitutil.py index 48ca998..2eacb13 100644 --- a/tools/patman/gitutil.py +++ b/tools/patman/gitutil.py @@ -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('') diff --git a/tools/patman/settings.py b/tools/patman/settings.py index 049c709..03ea307 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,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(',')
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 <vikram186@gmail.com> Cc: Simon Glass <sjg@chromium.org> --- tools/patman/gitutil.py | 18 ++++++++++++++++++ tools/patman/settings.py | 34 +++++++++++++++++++++++++++++++--- 2 files changed, 49 insertions(+), 3 deletions(-)