--- centos.git.repolist.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/centos.git.repolist.py b/centos.git.repolist.py index 75122ae..e135ca7 100755 --- a/centos.git.repolist.py +++ b/centos.git.repolist.py @@ -13,7 +13,7 @@ import requests import simplejson as json import sys
-RPCURL = "https://git.centos.org/rpc?req=LIST_REPOSITORIES" +RPCURL = "https://git.centos.org/rpc/?req=LIST_REPOSITORIES"
def read_args(): ''' @@ -48,6 +48,11 @@ def get_repo_list(url, branch, projectpath): print err_msg sys.exit(1)
+ if req.status_code != 200: + print "Unable to access gitblit api at " + url + sys.exit(1) + + payload = req.text repos = json.loads(payload) branchname = 'refs/heads/' + branch @@ -68,6 +73,6 @@ def main(): repos = get_repo_list(url=options.url, branch=options.branch, projectpath=options.project) if repos: print '\n'.join(repos) - + if __name__ == "__main__": main()
That looks good. Perhaps we could use requests.codes.ok instead of 200, but maybe that's just splitting hairs about magical constants... :)
On 23/06/17 20:36, Pat Riehecky wrote:
centos.git.repolist.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/centos.git.repolist.py b/centos.git.repolist.py index 75122ae..e135ca7 100755 --- a/centos.git.repolist.py +++ b/centos.git.repolist.py @@ -13,7 +13,7 @@ import requests import simplejson as json import sys
-RPCURL = "https://git.centos.org/rpc?req=LIST_REPOSITORIES" +RPCURL = "https://git.centos.org/rpc/?req=LIST_REPOSITORIES"
def read_args(): ''' @@ -48,6 +48,11 @@ def get_repo_list(url, branch, projectpath): print err_msg sys.exit(1)
- if req.status_code != 200:
print "Unable to access gitblit api at " + url
sys.exit(1)
payload = req.text repos = json.loads(payload) branchname = 'refs/heads/' + branch
@@ -68,6 +73,6 @@ def main(): repos = get_repo_list(url=options.url, branch=options.branch, projectpath=options.project) if repos: print '\n'.join(repos)
- if __name__ == "__main__": main()
On Jun 23 13:36, Pat Riehecky wrote:
centos.git.repolist.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/centos.git.repolist.py b/centos.git.repolist.py index 75122ae..e135ca7 100755 --- a/centos.git.repolist.py +++ b/centos.git.repolist.py @@ -13,7 +13,7 @@ import requests import simplejson as json import sys
-RPCURL = "https://git.centos.org/rpc?req=LIST_REPOSITORIES" +RPCURL = "https://git.centos.org/rpc/?req=LIST_REPOSITORIES"
def read_args(): ''' @@ -48,6 +48,11 @@ def get_repo_list(url, branch, projectpath): print err_msg sys.exit(1)
- if req.status_code != 200:
print "Unable to access gitblit api at " + url
sys.exit(1)
- payload = req.text repos = json.loads(payload) branchname = 'refs/heads/' + branch
@@ -68,6 +73,6 @@ def main(): repos = get_repo_list(url=options.url, branch=options.branch, projectpath=options.project) if repos: print '\n'.join(repos)
if __name__ == "__main__": main() -- 1.8.3.1
CentOS-devel mailing list CentOS-devel@centos.org https://lists.centos.org/mailman/listinfo/centos-devel
This looks workable to me, happy to see this merged. Just curious though, any reason to not call req.raise_for_status() in the try block (after L46) instead of checking the exit code directly?
--Brian
Hi Brian,
On 26/06/17 15:29, Brian Stinson wrote:
This looks workable to me, happy to see this merged. Just curious though, any reason to not call req.raise_for_status() in the try block (after L46) instead of checking the exit code directly?
Not that it matters, but I would have also gone for using req.raise_for_status() because:
- it simplifies the error handling code and makes the entire script more readable - it centralizes what we do when something goes wrong, whether socket, SSL cert or HTTP errors - it would display a clearer error message including the HTTP error code (which the current code doesn't)
As a minor nitpick, requests.get(url) returns a requests.Response object, so I'd probably store it in a variable called "resp", not "req".
Best regards, Laurențiu
On 06/23/2017 01:36 PM, Pat Riehecky wrote:
centos.git.repolist.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/centos.git.repolist.py b/centos.git.repolist.py index 75122ae..e135ca7 100755 --- a/centos.git.repolist.py +++ b/centos.git.repolist.py @@ -13,7 +13,7 @@ import requests import simplejson as json import sys
-RPCURL = "https://git.centos.org/rpc?req=LIST_REPOSITORIES" +RPCURL = "https://git.centos.org/rpc/?req=LIST_REPOSITORIES"
def read_args(): ''' @@ -48,6 +48,11 @@ def get_repo_list(url, branch, projectpath): print err_msg sys.exit(1)
- if req.status_code != 200:
print "Unable to access gitblit api at " + url
sys.exit(1)
- payload = req.text repos = json.loads(payload) branchname = 'refs/heads/' + branch
@@ -68,6 +73,6 @@ def main(): repos = get_repo_list(url=options.url, branch=options.branch, projectpath=options.project) if repos: print '\n'.join(repos)
if __name__ == "__main__": main()
OK guys, I pushed this in
On 06/26/2017 10:29 AM, Johnny Hughes wrote:
On 06/23/2017 01:36 PM, Pat Riehecky wrote:
centos.git.repolist.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/centos.git.repolist.py b/centos.git.repolist.py index 75122ae..e135ca7 100755 --- a/centos.git.repolist.py +++ b/centos.git.repolist.py @@ -13,7 +13,7 @@ import requests import simplejson as json import sys
-RPCURL = "https://git.centos.org/rpc?req=LIST_REPOSITORIES" +RPCURL = "https://git.centos.org/rpc/?req=LIST_REPOSITORIES"
def read_args(): ''' @@ -48,6 +48,11 @@ def get_repo_list(url, branch, projectpath): print err_msg sys.exit(1)
- if req.status_code != 200:
print "Unable to access gitblit api at " + url
sys.exit(1)
- payload = req.text repos = json.loads(payload) branchname = 'refs/heads/' + branch
@@ -68,6 +73,6 @@ def main(): repos = get_repo_list(url=options.url, branch=options.branch, projectpath=options.project) if repos: print '\n'.join(repos)
if __name__ == "__main__": main()
OK guys, I pushed this into the repo.