|
@@ -9,12 +9,20 @@ Example usage:
|
|
./gerrit_client.py [command] [args]
|
|
./gerrit_client.py [command] [args]
|
|
"""
|
|
"""
|
|
|
|
|
|
|
|
+from __future__ import print_function
|
|
|
|
+
|
|
import json
|
|
import json
|
|
import logging
|
|
import logging
|
|
import optparse
|
|
import optparse
|
|
import subcommand
|
|
import subcommand
|
|
import sys
|
|
import sys
|
|
-import urllib.parse
|
|
|
|
|
|
+
|
|
|
|
+if sys.version_info.major == 2:
|
|
|
|
+ import urlparse
|
|
|
|
+ from urllib import quote_plus
|
|
|
|
+else:
|
|
|
|
+ from urllib.parse import quote_plus
|
|
|
|
+ import urllib.parse as urlparse
|
|
|
|
|
|
import fix_encoding
|
|
import fix_encoding
|
|
import gerrit_util
|
|
import gerrit_util
|
|
@@ -41,7 +49,7 @@ def CMDmovechanges(parser, args):
|
|
assert opt.destination_branch, "--destination_branch not defined"
|
|
assert opt.destination_branch, "--destination_branch not defined"
|
|
for p in opt.params:
|
|
for p in opt.params:
|
|
assert '=' in p, '--param is key=value, not "%s"' % p
|
|
assert '=' in p, '--param is key=value, not "%s"' % p
|
|
- host = urllib.parse.urlparse(opt.host).netloc
|
|
|
|
|
|
+ host = urlparse.urlparse(opt.host).netloc
|
|
|
|
|
|
limit = 100
|
|
limit = 100
|
|
while True:
|
|
while True:
|
|
@@ -64,9 +72,9 @@ def CMDbranchinfo(parser, args):
|
|
parser.add_option('--branch', dest='branch', help='branch name')
|
|
parser.add_option('--branch', dest='branch', help='branch name')
|
|
|
|
|
|
(opt, args) = parser.parse_args(args)
|
|
(opt, args) = parser.parse_args(args)
|
|
- host = urllib.parse.urlparse(opt.host).netloc
|
|
|
|
- project = urllib.parse.quote_plus(opt.project)
|
|
|
|
- branch = urllib.parse.quote_plus(opt.branch)
|
|
|
|
|
|
+ host = urlparse.urlparse(opt.host).netloc
|
|
|
|
+ project = quote_plus(opt.project)
|
|
|
|
+ branch = quote_plus(opt.branch)
|
|
result = gerrit_util.GetGerritBranch(host, project, branch)
|
|
result = gerrit_util.GetGerritBranch(host, project, branch)
|
|
logging.info(result)
|
|
logging.info(result)
|
|
write_result(result, opt)
|
|
write_result(result, opt)
|
|
@@ -86,7 +94,7 @@ def CMDrawapi(parser, args):
|
|
(opt, args) = parser.parse_args(args)
|
|
(opt, args) = parser.parse_args(args)
|
|
assert opt.path, "--path not defined"
|
|
assert opt.path, "--path not defined"
|
|
|
|
|
|
- host = urllib.parse.urlparse(opt.host).netloc
|
|
|
|
|
|
+ host = urlparse.urlparse(opt.host).netloc
|
|
kwargs = {}
|
|
kwargs = {}
|
|
if opt.method:
|
|
if opt.method:
|
|
kwargs['reqtype'] = opt.method.upper()
|
|
kwargs['reqtype'] = opt.method.upper()
|
|
@@ -114,9 +122,9 @@ def CMDbranch(parser, args):
|
|
assert opt.branch, "--branch not defined"
|
|
assert opt.branch, "--branch not defined"
|
|
assert opt.commit, "--commit not defined"
|
|
assert opt.commit, "--commit not defined"
|
|
|
|
|
|
- project = urllib.parse.quote_plus(opt.project)
|
|
|
|
- host = urllib.parse.urlparse(opt.host).netloc
|
|
|
|
- branch = urllib.parse.quote_plus(opt.branch)
|
|
|
|
|
|
+ project = quote_plus(opt.project)
|
|
|
|
+ host = urlparse.urlparse(opt.host).netloc
|
|
|
|
+ branch = quote_plus(opt.branch)
|
|
result = gerrit_util.GetGerritBranch(host, project, branch)
|
|
result = gerrit_util.GetGerritBranch(host, project, branch)
|
|
if result:
|
|
if result:
|
|
if not opt.allow_existent_branch:
|
|
if not opt.allow_existent_branch:
|
|
@@ -153,9 +161,9 @@ def CMDtag(parser, args):
|
|
assert opt.tag, "--tag not defined"
|
|
assert opt.tag, "--tag not defined"
|
|
assert opt.commit, "--commit not defined"
|
|
assert opt.commit, "--commit not defined"
|
|
|
|
|
|
- project = urllib.parse.quote_plus(opt.project)
|
|
|
|
- host = urllib.parse.urlparse(opt.host).netloc
|
|
|
|
- tag = urllib.parse.quote_plus(opt.tag)
|
|
|
|
|
|
+ project = quote_plus(opt.project)
|
|
|
|
+ host = urlparse.urlparse(opt.host).netloc
|
|
|
|
+ tag = quote_plus(opt.tag)
|
|
result = gerrit_util.CreateGerritTag(host, project, tag, opt.commit)
|
|
result = gerrit_util.CreateGerritTag(host, project, tag, opt.commit)
|
|
logging.info(result)
|
|
logging.info(result)
|
|
write_result(result, opt)
|
|
write_result(result, opt)
|
|
@@ -170,9 +178,9 @@ def CMDhead(parser, args):
|
|
assert opt.project, "--project not defined"
|
|
assert opt.project, "--project not defined"
|
|
assert opt.branch, "--branch not defined"
|
|
assert opt.branch, "--branch not defined"
|
|
|
|
|
|
- project = urllib.parse.quote_plus(opt.project)
|
|
|
|
- host = urllib.parse.urlparse(opt.host).netloc
|
|
|
|
- branch = urllib.parse.quote_plus(opt.branch)
|
|
|
|
|
|
+ project = quote_plus(opt.project)
|
|
|
|
+ host = urlparse.urlparse(opt.host).netloc
|
|
|
|
+ branch = quote_plus(opt.branch)
|
|
result = gerrit_util.UpdateHead(host, project, branch)
|
|
result = gerrit_util.UpdateHead(host, project, branch)
|
|
logging.info(result)
|
|
logging.info(result)
|
|
write_result(result, opt)
|
|
write_result(result, opt)
|
|
@@ -185,8 +193,8 @@ def CMDheadinfo(parser, args):
|
|
(opt, args) = parser.parse_args(args)
|
|
(opt, args) = parser.parse_args(args)
|
|
assert opt.project, "--project not defined"
|
|
assert opt.project, "--project not defined"
|
|
|
|
|
|
- project = urllib.parse.quote_plus(opt.project)
|
|
|
|
- host = urllib.parse.urlparse(opt.host).netloc
|
|
|
|
|
|
+ project = quote_plus(opt.project)
|
|
|
|
+ host = urlparse.urlparse(opt.host).netloc
|
|
result = gerrit_util.GetHead(host, project)
|
|
result = gerrit_util.GetHead(host, project)
|
|
logging.info(result)
|
|
logging.info(result)
|
|
write_result(result, opt)
|
|
write_result(result, opt)
|
|
@@ -216,7 +224,7 @@ def CMDchanges(parser, args):
|
|
assert '=' in p, '--param is key=value, not "%s"' % p
|
|
assert '=' in p, '--param is key=value, not "%s"' % p
|
|
|
|
|
|
result = gerrit_util.QueryChanges(
|
|
result = gerrit_util.QueryChanges(
|
|
- urllib.parse.urlparse(opt.host).netloc,
|
|
|
|
|
|
+ urlparse.urlparse(opt.host).netloc,
|
|
list(tuple(p.split('=', 1)) for p in opt.params),
|
|
list(tuple(p.split('=', 1)) for p in opt.params),
|
|
first_param=opt.query,
|
|
first_param=opt.query,
|
|
start=opt.start, # Default: None
|
|
start=opt.start, # Default: None
|
|
@@ -236,7 +244,7 @@ def CMDrelatedchanges(parser, args):
|
|
(opt, args) = parser.parse_args(args)
|
|
(opt, args) = parser.parse_args(args)
|
|
|
|
|
|
result = gerrit_util.GetRelatedChanges(
|
|
result = gerrit_util.GetRelatedChanges(
|
|
- urllib.parse.urlparse(opt.host).netloc,
|
|
|
|
|
|
+ urlparse.urlparse(opt.host).netloc,
|
|
change=opt.change,
|
|
change=opt.change,
|
|
revision=opt.revision,
|
|
revision=opt.revision,
|
|
)
|
|
)
|
|
@@ -274,7 +282,7 @@ def CMDcreatechange(parser, args):
|
|
params.append(('notify_details', {'CC': {'accounts': opt.cc_list}}))
|
|
params.append(('notify_details', {'CC': {'accounts': opt.cc_list}}))
|
|
|
|
|
|
result = gerrit_util.CreateChange(
|
|
result = gerrit_util.CreateChange(
|
|
- urllib.parse.urlparse(opt.host).netloc,
|
|
|
|
|
|
+ urlparse.urlparse(opt.host).netloc,
|
|
opt.project,
|
|
opt.project,
|
|
branch=opt.branch,
|
|
branch=opt.branch,
|
|
subject=opt.subject,
|
|
subject=opt.subject,
|
|
@@ -296,7 +304,7 @@ def CMDchangeedit(parser, args):
|
|
with open(opt.file) as f:
|
|
with open(opt.file) as f:
|
|
data = f.read()
|
|
data = f.read()
|
|
result = gerrit_util.ChangeEdit(
|
|
result = gerrit_util.ChangeEdit(
|
|
- urllib.parse.urlparse(opt.host).netloc, opt.change, opt.path, data)
|
|
|
|
|
|
+ urlparse.urlparse(opt.host).netloc, opt.change, opt.path, data)
|
|
logging.info(result)
|
|
logging.info(result)
|
|
write_result(result, opt)
|
|
write_result(result, opt)
|
|
|
|
|
|
@@ -310,7 +318,7 @@ def CMDpublishchangeedit(parser, args):
|
|
(opt, args) = parser.parse_args(args)
|
|
(opt, args) = parser.parse_args(args)
|
|
|
|
|
|
result = gerrit_util.PublishChangeEdit(
|
|
result = gerrit_util.PublishChangeEdit(
|
|
- urllib.parse.urlparse(opt.host).netloc, opt.change, opt.notify)
|
|
|
|
|
|
+ urlparse.urlparse(opt.host).netloc, opt.change, opt.notify)
|
|
logging.info(result)
|
|
logging.info(result)
|
|
write_result(result, opt)
|
|
write_result(result, opt)
|
|
|
|
|
|
@@ -321,7 +329,7 @@ def CMDsubmitchange(parser, args):
|
|
parser.add_option('-c', '--change', type=int, help='change number')
|
|
parser.add_option('-c', '--change', type=int, help='change number')
|
|
(opt, args) = parser.parse_args(args)
|
|
(opt, args) = parser.parse_args(args)
|
|
result = gerrit_util.SubmitChange(
|
|
result = gerrit_util.SubmitChange(
|
|
- urllib.parse.urlparse(opt.host).netloc, opt.change)
|
|
|
|
|
|
+ urlparse.urlparse(opt.host).netloc, opt.change)
|
|
logging.info(result)
|
|
logging.info(result)
|
|
write_result(result, opt)
|
|
write_result(result, opt)
|
|
|
|
|
|
@@ -332,7 +340,7 @@ def CMDchangesubmittedtogether(parser, args):
|
|
parser.add_option('-c', '--change', type=int, help='change number')
|
|
parser.add_option('-c', '--change', type=int, help='change number')
|
|
(opt, args) = parser.parse_args(args)
|
|
(opt, args) = parser.parse_args(args)
|
|
result = gerrit_util.GetChangesSubmittedTogether(
|
|
result = gerrit_util.GetChangesSubmittedTogether(
|
|
- urllib.parse.urlparse(opt.host).netloc, opt.change)
|
|
|
|
|
|
+ urlparse.urlparse(opt.host).netloc, opt.change)
|
|
logging.info(result)
|
|
logging.info(result)
|
|
write_result(result, opt)
|
|
write_result(result, opt)
|
|
|
|
|
|
@@ -343,7 +351,7 @@ def CMDgetcommitincludedin(parser, args):
|
|
parser.add_option('--commit', dest='commit', help='commit hash')
|
|
parser.add_option('--commit', dest='commit', help='commit hash')
|
|
(opt, args) = parser.parse_args(args)
|
|
(opt, args) = parser.parse_args(args)
|
|
result = gerrit_util.GetCommitIncludedIn(
|
|
result = gerrit_util.GetCommitIncludedIn(
|
|
- urllib.parse.urlparse(opt.host).netloc, opt.project, opt.commit)
|
|
|
|
|
|
+ urlparse.urlparse(opt.host).netloc, opt.project, opt.commit)
|
|
logging.info(result)
|
|
logging.info(result)
|
|
write_result(result, opt)
|
|
write_result(result, opt)
|
|
|
|
|
|
@@ -353,10 +361,11 @@ def CMDsetbotcommit(parser, args):
|
|
"""Sets bot-commit+1 to a bot generated change."""
|
|
"""Sets bot-commit+1 to a bot generated change."""
|
|
parser.add_option('-c', '--change', type=int, help='change number')
|
|
parser.add_option('-c', '--change', type=int, help='change number')
|
|
(opt, args) = parser.parse_args(args)
|
|
(opt, args) = parser.parse_args(args)
|
|
- result = gerrit_util.SetReview(urllib.parse.urlparse(opt.host).netloc,
|
|
|
|
- opt.change,
|
|
|
|
- labels={'Bot-Commit': 1},
|
|
|
|
- ready=True)
|
|
|
|
|
|
+ result = gerrit_util.SetReview(
|
|
|
|
+ urlparse.urlparse(opt.host).netloc,
|
|
|
|
+ opt.change,
|
|
|
|
+ labels={'Bot-Commit': 1},
|
|
|
|
+ ready=True)
|
|
logging.info(result)
|
|
logging.info(result)
|
|
write_result(result, opt)
|
|
write_result(result, opt)
|
|
|
|
|
|
@@ -370,7 +379,7 @@ def CMDsetlabel(parser, args):
|
|
nargs=2,
|
|
nargs=2,
|
|
metavar=('label_name', 'label_value'))
|
|
metavar=('label_name', 'label_value'))
|
|
(opt, args) = parser.parse_args(args)
|
|
(opt, args) = parser.parse_args(args)
|
|
- result = gerrit_util.SetReview(urllib.parse.urlparse(opt.host).netloc,
|
|
|
|
|
|
+ result = gerrit_util.SetReview(urlparse.urlparse(opt.host).netloc,
|
|
opt.change,
|
|
opt.change,
|
|
labels={opt.label[0]: opt.label[1]})
|
|
labels={opt.label[0]: opt.label[1]})
|
|
logging.info(result)
|
|
logging.info(result)
|
|
@@ -386,7 +395,8 @@ def CMDabandon(parser, args):
|
|
(opt, args) = parser.parse_args(args)
|
|
(opt, args) = parser.parse_args(args)
|
|
assert opt.change, "-c not defined"
|
|
assert opt.change, "-c not defined"
|
|
result = gerrit_util.AbandonChange(
|
|
result = gerrit_util.AbandonChange(
|
|
- urllib.parse.urlparse(opt.host).netloc, opt.change, opt.message)
|
|
|
|
|
|
+ urlparse.urlparse(opt.host).netloc,
|
|
|
|
+ opt.change, opt.message)
|
|
logging.info(result)
|
|
logging.info(result)
|
|
write_result(result, opt)
|
|
write_result(result, opt)
|
|
|
|
|
|
@@ -429,7 +439,7 @@ def CMDmass_abandon(parser, args):
|
|
search_query.append(('status', 'open'))
|
|
search_query.append(('status', 'open'))
|
|
logging.info("Searching for: %s" % search_query)
|
|
logging.info("Searching for: %s" % search_query)
|
|
|
|
|
|
- host = urllib.parse.urlparse(opt.host).netloc
|
|
|
|
|
|
+ host = urlparse.urlparse(opt.host).netloc
|
|
|
|
|
|
result = gerrit_util.QueryChanges(
|
|
result = gerrit_util.QueryChanges(
|
|
host,
|
|
host,
|