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