Gerrit http://code.google.com/p/gerrit/フックの作成にいくつか問題があります。Python + getopt - 構文解析に関する問題
http://gerrit.googlecode.com/svn/documentation/2.2.0/config-hooks.html
私は パッチセットが作成した--change --change-urlには、コマンドラインを解析した場合--project --branch --uploader --commit --patchset
def main():
if (len(sys.argv) < 2):
showUsage()
exit()
if (sys.argv[1] == 'update-projects'):
updateProjects()
exit()
need = ['action=', 'change=', 'change-url=', 'commit=', 'project=', 'branch=', 'uploader=',
'patchset=', 'abandoner=', 'reason=', 'submitter=', 'comment=', 'CRVW=', 'VRIF=' , 'patchset=' , 'restorer=', 'author=']
print sys.argv[1:]
print '-----'
optlist, args = getopt.getopt(sys.argv[1:], '', need)
id = url = hash = who = comment = reason = codeReview = verified = restorer = ''
print optlist
for o, a in optlist:
if o == '--change': id = a
elif o == '--change-url': url = a
elif o == '--commit': hash = a
elif o == '--action': what = a
elif o == '--uploader': who = a
elif o == '--submitter': who = a
elif o == '--abandoner': who = a
elif o == '--author' : who = a
elif o == '--branch': branch = a
elif o == '--comment': comment = a
elif o == '--CRVW' : codeReview = a
elif o == '--VRIF' : verified = a
elif o == '--patchset' : patchset = a
elif o == '--restorer' : who = a
elif o == '--reason' : reason = a
コマンドライン入力:
--change I87f7802d438d5640779daa9ac8196aeb3eec8c2a
--change-url http://<hostname>:8080/308
--project private/bar
--branch master
--uploader xxxxxxx-xxxxx xxxxxxx ([email protected])
--commit 49aae9befaf27a5fede51b498f0660199f47b899 --patchset 1
印刷sys.argvの[1]
['--action', 'new',
'--change','I87f7802d438d5640779daa9ac8196aeb3eec8c2a',
'--change-url',
'http://<hostname>:8080/308',
'--project', 'private/bar',
'--branch', 'master',
'--uploader', 'xxxxxxx-xxxxx', 'xxxxxxx', '([email protected])',
'--commit', '49aae9befaf27a5fede51b498f0660199f47b899',
'--patchset', '1']
印刷optlistの
[('--action', 'new'),
('--change', 'I87f7802d438d5640779daa9ac8196aeb3eec8c2a'),
('--change-url', 'http://<hostname>:8080/308'),
('--project', 'private/bar'),
('--branch', 'master'),
('--uploader', 'xxxxxxx-xxxxx')]
スクリプトが
'--uploader', 'xxxxxxx-xxxxx', 'xxxxxxx', '([email protected])'
and not
'--uploader', 'xxxxxxx-xxxxx xxxxxxx ([email protected])'
を生成し、なぜスクリプトが解析--commit --patchset dont'tので、私は...知らない
コメントを解析すると、すべてが動作します:
コマンドライン入力:
-change I87f7802d438d5640779daa9ac8196aeb3eec8c2a
--change-url http://<hostname>.intra:8080/308
--project private/bar
--branch master
--author xxxxxxx-xxxxx xxxxxxx ([email protected])
--commit 49aae9befaf27a5fede51b498f0660199f47b899
--comment asdf
--CRVW 0
--VRIF 0
印刷sys.argvの[1:]それは、すべてのコマンドラインツールのように、スペースが含まれている場合は、引数を引用符で囲む必要があります
'--action', 'comment',
'--change', 'I87f7802d438d5640779daa9ac8196aeb3eec8c2a',
'--change-url',
'http://<hostname>:8080/308',
'--project', 'private/bar',
'--branch', 'master',
'--author', 'xxxxxxx-xxxxx xxxxxxx ([email protected])', <<< That's right!
'--commit', '49aae9befaf27a5fede51b498f0660199f47b899',
'--comment', 'asdf',
'--CRVW', '0',
'--VRIF', '0']
Gerritからこのストリームを取得しますが、Gerritでコメントを追加したときになぜこの問題が発生するのですか?それは私が理解できない問題です – Philippxp
なぜやらないのですか''' .join(a)' --uploader'の引数はありますか?ジェリットも同じことをしていると思います。それほど難しいことではありません。 – neurino
スクリプトが始まる前に引数を移動し、この回避策を実行します。 – Philippxp