]> git.ozlabs.org Git - patchwork/commitdiff
Use config file for pwclient settings
authorJeremy Kerr <jk@ozlabs.org>
Mon, 8 Sep 2008 01:38:39 +0000 (11:38 +1000)
committerJeremy Kerr <jk@ozlabs.org>
Mon, 8 Sep 2008 01:38:39 +0000 (11:38 +1000)
Add a ConfigParser-style config file for patchwork settings, rather
than the environment. At present, only the XMLRPC URL and current
project are included.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
apps/patchwork/bin/pwclient.py

index 765e66b3db277d81b1dc5b45ed30e2372e40d9b5..a50df732bbfd61437bcef5378db06c618db55cba 100755 (executable)
@@ -26,16 +26,14 @@ import getopt
 import string
 import tempfile
 import subprocess
 import string
 import tempfile
 import subprocess
+import ConfigParser
 
 # Default Patchwork remote XML-RPC server URL
 # This script will check the PW_XMLRPC_URL environment variable
 # for the URL to access.  If that is unspecified, it will fallback to
 # the hardcoded default value specified here.
 
 # Default Patchwork remote XML-RPC server URL
 # This script will check the PW_XMLRPC_URL environment variable
 # for the URL to access.  If that is unspecified, it will fallback to
 # the hardcoded default value specified here.
-DEFAULT_URL = "http://patchwork:80/xmlrpc/"
-
-PW_XMLRPC_URL = os.getenv("PW_XMLRPC_URL")
-if not PW_XMLRPC_URL:
-    PW_XMLRPC_URL = DEFAULT_URL
+DEFAULT_URL = "http://patchwork/xmlrpc/"
+CONFIG_FILES = [os.path.expanduser('~/.pwclientrc')]
 
 class Filter:
     """Filter for selecting patches."""
 
 class Filter:
     """Filter for selecting patches."""
@@ -249,15 +247,28 @@ def main():
 
     action = sys.argv[1].lower()
 
 
     action = sys.argv[1].lower()
 
+    # set defaults
     filt = Filter()
     submitter_str = ""
     delegate_str = ""
     filt = Filter()
     submitter_str = ""
     delegate_str = ""
+    project_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':
             filt.add("state", value)
         elif name == '-p':
 
     for name, value in opts:
         if name == '-s':
             filt.add("state", value)
         elif name == '-p':
-            filt.add("project", value)
+            project_str = value
         elif name == '-w':
             submitter_str = value
         elif name == '-d':
         elif name == '-w':
             submitter_str = value
         elif name == '-d':
@@ -276,10 +287,13 @@ def main():
         sys.stderr.write("Too many arguments specified\n")
         usage()
 
         sys.stderr.write("Too many arguments specified\n")
         usage()
 
+    if project_str:
+        filt.add("project", project_str)
+
     try:
     try:
-        rpc = xmlrpclib.Server(PW_XMLRPC_URL)
+        rpc = xmlrpclib.Server(url)
     except:
     except:
-        sys.stderr.write("Unable to connect to %s\n" % PW_XMLRPC_URL)
+        sys.stderr.write("Unable to connect to %s\n" % url)
         sys.exit(1)
 
     if action == 'list' or action == 'search':
         sys.exit(1)
 
     if action == 'list' or action == 'search':