[PATCH 1/2] pwclient: accept more than one project in ~/.pwclientrc
Yann E. MORIN
yann.morin.1998 at free.fr
Sun Jun 29 05:32:12 EST 2014
From: "Yann E. MORIN" <yann.morin.1998 at free.fr>
Currently, given the format of ~/.pwclientrc, pwclient can only
really act on a single project, as ~/pwclientrc can only contain
the configuration for a single project.
Although the -p options comes in handy to specify a project
different from the one configured in ~/.pwclientrc, this only works
if it is hosted on the same server. As soon as one needs to switch
server, it is necessary to edit ~/pwclientrc.
This can be quite inefficient when dealing with many projects, hosted
on different servers.
Change the format of ~/.pwclientrc so it is possible to define more
than one project, and for each project, specify an URL and credentials.
The new format is like:
[options]
default=project-A
[project-A]
url=http://my.patchwork.server/path/to/xmlrpc
username=that-is-me
password=secret
[other-project]
url=http://you.get/the/idea
username=someone
password=1234
This has the advantage of not changing the options to pwclient, so
the user experience is unmodified.
Signed-off-by: "Yann E. MORIN" <yann.morin.1998 at free.fr>
---
apps/patchwork/bin/pwclient | 44 ++++++++++++++++++++++++++++--------------
templates/patchwork/pwclientrc | 16 +++++++--------
2 files changed, 38 insertions(+), 22 deletions(-)
diff --git a/apps/patchwork/bin/pwclient b/apps/patchwork/bin/pwclient
index 0c0ccaf..fef160d 100755
--- a/apps/patchwork/bin/pwclient
+++ b/apps/patchwork/bin/pwclient
@@ -350,16 +350,6 @@ def main():
msgid_str = ""
url = DEFAULT_URL
- config = ConfigParser.ConfigParser()
- config.read(CONFIG_FILES)
-
- # grab settings from config files
- if config.has_option('base', 'url'):
- url = config.get('base', 'url')
-
- if config.has_option('base', 'project'):
- project_str = config.get('base', 'project')
-
for name, value in opts:
if name == '-s':
state_str = value
@@ -389,17 +379,43 @@ def main():
sys.stderr.write("Too many arguments specified\n")
usage()
+ # grab settings from config files
+ config = ConfigParser.ConfigParser()
+ config.read(CONFIG_FILES)
+
+ if not config.has_section('options'):
+ sys.stderr.write('~/.pwclientrc is in the old format. Please upgrade it.\n')
+ sys.stderr.write('See templates/patchwork/pwclientrc in the the Patchwork sources .\n')
+ sys.exit(1)
+
+ if not project_str:
+ try:
+ project_str = config.get('options', 'default')
+ except:
+ sys.stderr.write("No default project configured in ~/.pwclientrc\n")
+ usage()
+
+ if not config.has_section(project_str):
+ sys.stderr.write("No section for project %s\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.exit(1)
+
+ url = config.get(project_str, 'url')
+
(username, password) = (None, None)
transport = None
if action in auth_actions:
- if config.has_option('auth', 'username') and \
- config.has_option('auth', 'password'):
+ if config.has_option(project_str, 'username') and \
+ config.has_option(project_str, 'password'):
use_https = url.startswith('https')
transport = BasicHTTPAuthTransport( \
- config.get('auth', 'username'),
- config.get('auth', 'password'),
+ config.get(project_str, 'username'),
+ config.get(project_str, 'password'),
use_https)
else:
diff --git a/templates/patchwork/pwclientrc b/templates/patchwork/pwclientrc
index 436a28b..d331003 100644
--- a/templates/patchwork/pwclientrc
+++ b/templates/patchwork/pwclientrc
@@ -1,15 +1,15 @@
# Sample .pwclientrc file for the {{ project.linkname }} project,
# running on {{ site.domain }}.
#
-# Save this file to ~/.pwclientrc
-#
-[base]
-url: {{scheme}}://{{site.domain}}{% url 'patchwork.views.xmlrpc.xmlrpc' %}
-project: {{ project.linkname }}
+# Just append this file to your existing ~/.pwclientrc
+# If you do not already have a ~/.pwclientrc, then copy this file to
+# ~/.pwclientrc, and uncomment the following two lines:
+# [options]
+# default={{ project.linkname }}
+
+[{{ project.linkname }}]
+url= {{scheme}}://{{site.domain}}{% url 'patchwork.views.xmlrpc.xmlrpc' %}
{% if user.is_authenticated %}
-# Adding authentication parameters will allow you to use the 'update'
-# command on patches that you are allowed to edit.
-[auth]
username: {{ user.username }}
password: <add your patchwork password here>
{% endif %}
--
1.8.3.2
More information about the Patchwork
mailing list