diff mbox

[1/3] pwclient: handle missing ~/.pwclientrc better

Message ID 1445030131-24566-1-git-send-email-vapier@gentoo.org
State Accepted
Headers show

Commit Message

Mike Frysinger Oct. 16, 2015, 9:15 p.m. UTC
From: Mike Frysinger <vapier@chromium.org>

The upgrade path will crash if ~/.pwclientrc doesn't exist, so add an
explicit check for the file before we try to "upgrade" it.

The default error messages don't mention the config file, so it can be
a bit confusing what pwclient is complaining about when running.

Signed-off-by: Mike Frysinger <vapier@chromium.org>
---
 patchwork/bin/pwclient | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Brian Norris Oct. 16, 2015, 9:56 p.m. UTC | #1
On Fri, Oct 16, 2015 at 05:15:29PM -0400, Mike Frysinger wrote:
> From: Mike Frysinger <vapier@chromium.org>
> 
> The upgrade path will crash if ~/.pwclientrc doesn't exist, so add an
> explicit check for the file before we try to "upgrade" it.
> 
> The default error messages don't mention the config file, so it can be
> a bit confusing what pwclient is complaining about when running.
> 
> Signed-off-by: Mike Frysinger <vapier@chromium.org>

Acked-by: Brian Norris <computersforpeace@gmail.com>

> ---
>  patchwork/bin/pwclient | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/patchwork/bin/pwclient b/patchwork/bin/pwclient
> index 8d1f476..46d11fb 100755
> --- a/patchwork/bin/pwclient
> +++ b/patchwork/bin/pwclient
> @@ -569,7 +569,7 @@ def main():
>      config = ConfigParser.ConfigParser()
>      config.read([CONFIG_FILE])
>  
> -    if not config.has_section('options'):
> +    if not config.has_section('options') and os.path.exists(CONFIG_FILE):
>          sys.stderr.write('~/.pwclientrc is in the old format. Migrating it...')
>  
>          old_project = config.get('base','project')
> @@ -607,10 +607,10 @@ def main():
>              sys.exit(1)
>  
>      if not config.has_section(project_str):
> -        sys.stderr.write("No section for project %s\n" % project_str)
> +        sys.stderr.write('No section for project %s in ~/.pwclientrc\n' % project_str)
>          sys.exit(1)
>      if not config.has_option(project_str, 'url'):
> -        sys.stderr.write("No URL for project %s\n" % project_str)
> +        sys.stderr.write('No URL for project %s in ~/.pwclientrc\n' % project_str)
>          sys.exit(1)
>      if not do_signoff and config.has_option('options', 'signoff'):
>          do_signoff = config.getboolean('options', 'signoff')
> -- 
> 2.5.2
>
Stephen Finucane Oct. 16, 2015, 10:05 p.m. UTC | #2
> From: Mike Frysinger <vapier@chromium.org>

> 

> The upgrade path will crash if ~/.pwclientrc doesn't exist, so add an

> explicit check for the file before we try to "upgrade" it.

> 

> The default error messages don't mention the config file, so it can be

> a bit confusing what pwclient is complaining about when running.

> 

> Signed-off-by: Mike Frysinger <vapier@chromium.org>


LGTM

Reviewed-by: Stephen Finucane <stephen.finucane@hotmail.com>
Stephen Finucane Oct. 16, 2015, 10:25 p.m. UTC | #3
> > From: Mike Frysinger <vapier@chromium.org>

> >

> > The upgrade path will crash if ~/.pwclientrc doesn't exist, so add an

> > explicit check for the file before we try to "upgrade" it.

> >

> > The default error messages don't mention the config file, so it can be

> > a bit confusing what pwclient is complaining about when running.

> >

> > Signed-off-by: Mike Frysinger <vapier@chromium.org>

> 

> LGTM

> 

> Reviewed-by: Stephen Finucane <stephen.finucane@hotmail.com>


Merged.
diff mbox

Patch

diff --git a/patchwork/bin/pwclient b/patchwork/bin/pwclient
index 8d1f476..46d11fb 100755
--- a/patchwork/bin/pwclient
+++ b/patchwork/bin/pwclient
@@ -569,7 +569,7 @@  def main():
     config = ConfigParser.ConfigParser()
     config.read([CONFIG_FILE])
 
-    if not config.has_section('options'):
+    if not config.has_section('options') and os.path.exists(CONFIG_FILE):
         sys.stderr.write('~/.pwclientrc is in the old format. Migrating it...')
 
         old_project = config.get('base','project')
@@ -607,10 +607,10 @@  def main():
             sys.exit(1)
 
     if not config.has_section(project_str):
-        sys.stderr.write("No section for project %s\n" % project_str)
+        sys.stderr.write('No section for project %s in ~/.pwclientrc\n' % project_str)
         sys.exit(1)
     if not config.has_option(project_str, 'url'):
-        sys.stderr.write("No URL for project %s\n" % project_str)
+        sys.stderr.write('No URL for project %s in ~/.pwclientrc\n' % project_str)
         sys.exit(1)
     if not do_signoff and config.has_option('options', 'signoff'):
         do_signoff = config.getboolean('options', 'signoff')