summaryrefslogtreecommitdiff
path: root/rest_example.py
diff options
context:
space:
mode:
authorAndrey Devyatkin <andrey.a.devyatkin@gmail.com>2014-03-27 21:48:06 +0100
committerDavid Pursehouse <david.pursehouse@sonymobile.com>2014-04-11 16:52:45 +0900
commita76db4cfc83d4cf7a52d045e4df82ec8b1e3f562 (patch)
tree18b203f9c0af195c495c602011ee2807e1d97b7c /rest_example.py
parent254295fd70fd6637a98886937ef5f009cdd687cb (diff)
downloadpygerrit-a76db4cfc83d4cf7a52d045e4df82ec8b1e3f562.tar.gz
Update examples to use argparse instead of optparse
optparse was deprecated since 2.7 and removed in python 3 Change-Id: Ic5bccb171f45c4948dad47e8fc6fb5830d6dfcff
Diffstat (limited to 'rest_example.py')
-rwxr-xr-xrest_example.py47
1 files changed, 22 insertions, 25 deletions
diff --git a/rest_example.py b/rest_example.py
index 346689e..825ed7c 100755
--- a/rest_example.py
+++ b/rest_example.py
@@ -26,7 +26,7 @@
""" Example of using the Gerrit client REST API. """
import logging
-import optparse
+import argparse
import sys
from requests.auth import HTTPBasicAuth, HTTPDigestAuth
@@ -44,28 +44,28 @@ from pygerrit.rest.auth import HTTPDigestAuthFromNetrc, HTTPBasicAuthFromNetrc
def _main():
- usage = "usage: %prog [options]"
- parser = optparse.OptionParser(usage=usage)
-
- parser.add_option('-g', '--gerrit-url', dest='gerrit_url',
- help='gerrit server url')
- parser.add_option('-b', '--basic-auth', dest='basic_auth',
- action='store_true',
- help='use basic auth instead of digest')
+ descr = 'Send request using Gerrit HTTP API'
+ parser = argparse.ArgumentParser(description=descr)
+ parser.add_argument('-g', '--gerrit-url', dest='gerrit_url',
+ required=True,
+ help='gerrit server url')
+ parser.add_argument('-b', '--basic-auth', dest='basic_auth',
+ action='store_true',
+ help='use basic auth instead of digest')
if _kerberos_support:
- parser.add_option('-k', '--kerberos-auth', dest='kerberos_auth',
- action='store_true',
- help='use kerberos auth')
- parser.add_option('-u', '--username', dest='username',
- help='username')
- parser.add_option('-p', '--password', dest='password',
- help='password')
- parser.add_option('-n', '--netrc', dest='netrc',
- action='store_true',
- help='Use credentials from netrc')
- parser.add_option('-v', '--verbose', dest='verbose',
- action='store_true',
- help='enable verbose (debug) logging')
+ parser.add_argument('-k', '--kerberos-auth', dest='kerberos_auth',
+ action='store_true',
+ help='use kerberos auth')
+ parser.add_argument('-u', '--username', dest='username',
+ help='username')
+ parser.add_argument('-p', '--password', dest='password',
+ help='password')
+ parser.add_argument('-n', '--netrc', dest='netrc',
+ action='store_true',
+ help='Use credentials from netrc')
+ parser.add_argument('-v', '--verbose', dest='verbose',
+ action='store_true',
+ help='enable verbose (debug) logging')
(options, _args) = parser.parse_args()
@@ -73,9 +73,6 @@ def _main():
logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s',
level=level)
- if not options.gerrit_url:
- parser.error("Must specify Gerrit URL with --gerrit-url")
-
if _kerberos_support and options.kerberos_auth:
if options.username or options.password \
or options.basic_auth or options.netrc: