diff mbox

[1/2] pwclient: Unhardcode prints to ~/.pwclientrc

Message ID 1472155412-7666-1-git-send-email-f.fainelli@gmail.com
State Superseded
Headers show

Commit Message

Florian Fainelli Aug. 25, 2016, 8:03 p.m. UTC
Even though the default location is ~/.pwclientrc, we can change it, so
use CONFIG_FILE wherever we can to make the prints match the actual file
location.

Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
---
 patchwork/bin/pwclient | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

Comments

Daniel Axtens Aug. 26, 2016, 10:47 a.m. UTC | #1
Florian Fainelli <f.fainelli@gmail.com> writes:

> Even though the default location is ~/.pwclientrc, we can change it, so
> use CONFIG_FILE wherever we can to make the prints match the actual file
> location.
>
> Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>

Hi Florian,

I'm getting the following error with this patch applied.

----
Traceback (most recent call last):
  File "bin/pwclient", line 807, in <module>
    main()
  File "bin/pwclient", line 660, in main
    'No section for project %s in ' + CONFIG_FILE + '\n' % project_str)
TypeError: not all arguments converted during string formatting
----

I think the whole string needs to be bracketed, or make CONFIG_FILE
another string parameter?

Anyway, once I fix that, I get strings like this:

"No section for project xyzzy2 in /home/dja/.pwclientrc"

I'm not sure the full path is an improvement over "~/", but I'm not that
fussed either way, and I can see that your patch fixes a bug if you
change CONFIG_FILE.

Regards,
Daniel

> ---
>  patchwork/bin/pwclient | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/patchwork/bin/pwclient b/patchwork/bin/pwclient
> index a931dc904a39..531ad846b3b4 100755
> --- a/patchwork/bin/pwclient
> +++ b/patchwork/bin/pwclient
> @@ -616,7 +616,7 @@ def main():
>      config.read([CONFIG_FILE])
>  
>      if not config.has_section('options') and os.path.exists(CONFIG_FILE):
> -        sys.stderr.write('~/.pwclientrc is in the old format. Migrating it...')
> +        sys.stderr.write(CONFIG_FILE + ' is in the old format. Migrating it...')
>  
>          old_project = config.get('base', 'project')
>  
> @@ -642,7 +642,7 @@ def main():
>  
>          sys.stderr.write(' Done.\n')
>          sys.stderr.write(
> -            'Your old ~/.pwclientrc was saved to %s\n' % old_config_file)
> +            'Your old ' + CONFIG_FILE + ' was saved to %s\n' % old_config_file)
>          sys.stderr.write(
>              'and was converted to the new format. You may want to\n')
>          sys.stderr.write('inspect it before continuing.\n')
> @@ -653,15 +653,15 @@ def main():
>              project_str = config.get('options', 'default')
>          except:
>              action_parser.error(
> -                "No default project configured in ~/.pwclientrc")
> +                "No default project configured in " + CONFIG_FILE)
>  
>      if not config.has_section(project_str):
>          sys.stderr.write(
> -            'No section for project %s in ~/.pwclientrc\n' % project_str)
> +            'No section for project %s in ' + CONFIG_FILE + '\n' % project_str)
>          sys.exit(1)
>      if not config.has_option(project_str, 'url'):
>          sys.stderr.write(
> -            'No URL for project %s in ~/.pwclientrc\n' % project_str)
> +            'No URL for project %s in ' + CONFIG_FILE + '\n' % project_str)
>          sys.exit(1)
>      if not do_signoff and config.has_option('options', 'signoff'):
>          do_signoff = config.getboolean('options', 'signoff')
> -- 
> 2.7.4
>
> _______________________________________________
> Patchwork mailing list
> Patchwork@lists.ozlabs.org
> https://lists.ozlabs.org/listinfo/patchwork
Stephen Finucane Aug. 29, 2016, 10:56 p.m. UTC | #2
On 26 Aug 20:47, Daniel Axtens wrote:
> Florian Fainelli <f.fainelli@gmail.com> writes:
> 
> > Even though the default location is ~/.pwclientrc, we can change it, so
> > use CONFIG_FILE wherever we can to make the prints match the actual file
> > location.
> >
> > Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
> 
> Hi Florian,
> 
> I'm getting the following error with this patch applied.
> 
> ----
> Traceback (most recent call last):
>   File "bin/pwclient", line 807, in <module>
>     main()
>   File "bin/pwclient", line 660, in main
>     'No section for project %s in ' + CONFIG_FILE + '\n' % project_str)
> TypeError: not all arguments converted during string formatting
> ----
> 
> I think the whole string needs to be bracketed, or make CONFIG_FILE
> another string parameter?

Yes, could you pass these as string parameters instead? Examples below.

> Anyway, once I fix that, I get strings like this:
> 
> "No section for project xyzzy2 in /home/dja/.pwclientrc"
> 
> I'm not sure the full path is an improvement over "~/", but I'm not that
> fussed either way, and I can see that your patch fixes a bug if you
> change CONFIG_FILE.

For the sake of solving the bug, I'm happy to put up with the slightly
more verbose output.

> Regards,
> Daniel
> 
> > ---
> >  patchwork/bin/pwclient | 10 +++++-----
> >  1 file changed, 5 insertions(+), 5 deletions(-)
> >
> > diff --git a/patchwork/bin/pwclient b/patchwork/bin/pwclient
> > index a931dc904a39..531ad846b3b4 100755
> > --- a/patchwork/bin/pwclient
> > +++ b/patchwork/bin/pwclient
> > @@ -616,7 +616,7 @@ def main():
> >      config.read([CONFIG_FILE])
> >  
> >      if not config.has_section('options') and os.path.exists(CONFIG_FILE):
> > -        sys.stderr.write('~/.pwclientrc is in the old format. Migrating it...')
> > +        sys.stderr.write(CONFIG_FILE + ' is in the old format. Migrating it...')

Try this instead:

    sys.stderr.write('%s is in the old format. Migrating it...' % CONFIG_FILE)

> >          old_project = config.get('base', 'project')
> >  
> > @@ -642,7 +642,7 @@ def main():
> >  
> >          sys.stderr.write(' Done.\n')
> >          sys.stderr.write(
> > -            'Your old ~/.pwclientrc was saved to %s\n' % old_config_file)
> > +            'Your old ' + CONFIG_FILE + ' was saved to %s\n' % old_config_file)
> >          sys.stderr.write(
> >              'and was converted to the new format. You may want to\n')
> >          sys.stderr.write('inspect it before continuing.\n')
> > @@ -653,15 +653,15 @@ def main():
> >              project_str = config.get('options', 'default')
> >          except:
> >              action_parser.error(
> > -                "No default project configured in ~/.pwclientrc")
> > +                "No default project configured in " + CONFIG_FILE)
> >  
> >      if not config.has_section(project_str):
> >          sys.stderr.write(
> > -            'No section for project %s in ~/.pwclientrc\n' % project_str)
> > +            'No section for project %s in ' + CONFIG_FILE + '\n' % project_str)
> >          sys.exit(1)
> >      if not config.has_option(project_str, 'url'):
> >          sys.stderr.write(
> > -            'No URL for project %s in ~/.pwclientrc\n' % project_str)
> > +            'No URL for project %s in ' + CONFIG_FILE + '\n' % project_str)
> >          sys.exit(1)
> >      if not do_signoff and config.has_option('options', 'signoff'):
> >          do_signoff = config.getboolean('options', 'signoff')
> > -- 
> > 2.7.4
> >
> > _______________________________________________
> > Patchwork mailing list
> > Patchwork@lists.ozlabs.org
> > https://lists.ozlabs.org/listinfo/patchwork



> _______________________________________________
> Patchwork mailing list
> Patchwork@lists.ozlabs.org
> https://lists.ozlabs.org/listinfo/patchwork
diff mbox

Patch

diff --git a/patchwork/bin/pwclient b/patchwork/bin/pwclient
index a931dc904a39..531ad846b3b4 100755
--- a/patchwork/bin/pwclient
+++ b/patchwork/bin/pwclient
@@ -616,7 +616,7 @@  def main():
     config.read([CONFIG_FILE])
 
     if not config.has_section('options') and os.path.exists(CONFIG_FILE):
-        sys.stderr.write('~/.pwclientrc is in the old format. Migrating it...')
+        sys.stderr.write(CONFIG_FILE + ' is in the old format. Migrating it...')
 
         old_project = config.get('base', 'project')
 
@@ -642,7 +642,7 @@  def main():
 
         sys.stderr.write(' Done.\n')
         sys.stderr.write(
-            'Your old ~/.pwclientrc was saved to %s\n' % old_config_file)
+            'Your old ' + CONFIG_FILE + ' was saved to %s\n' % old_config_file)
         sys.stderr.write(
             'and was converted to the new format. You may want to\n')
         sys.stderr.write('inspect it before continuing.\n')
@@ -653,15 +653,15 @@  def main():
             project_str = config.get('options', 'default')
         except:
             action_parser.error(
-                "No default project configured in ~/.pwclientrc")
+                "No default project configured in " + CONFIG_FILE)
 
     if not config.has_section(project_str):
         sys.stderr.write(
-            'No section for project %s in ~/.pwclientrc\n' % project_str)
+            'No section for project %s in ' + CONFIG_FILE + '\n' % project_str)
         sys.exit(1)
     if not config.has_option(project_str, 'url'):
         sys.stderr.write(
-            'No URL for project %s in ~/.pwclientrc\n' % project_str)
+            'No URL for project %s in ' + CONFIG_FILE + '\n' % project_str)
         sys.exit(1)
     if not do_signoff and config.has_option('options', 'signoff'):
         do_signoff = config.getboolean('options', 'signoff')