mirror of
https://git.centos.org/centos-git-common.git
synced 2025-02-23 16:22:56 +00:00
Initial commit of script to get git repolist from git.centos.org.
This commit is contained in:
parent
f3a920b627
commit
7a56e5afa6
1 changed files with 57 additions and 0 deletions
57
centos.git.repolist.py
Executable file
57
centos.git.repolist.py
Executable file
|
@ -0,0 +1,57 @@
|
|||
#!/usr/bin/env python
|
||||
'''Get list of repos from gitblit RPC, to grab CentOS sources'''
|
||||
|
||||
import optparse
|
||||
import requests
|
||||
import simplejson as json
|
||||
import sys
|
||||
|
||||
RPCURL = "https://git.centos.org/rpc?req=LIST_REPOSITORIES"
|
||||
|
||||
def read_args():
|
||||
'''
|
||||
read in the command line args and set things up
|
||||
'''
|
||||
|
||||
desc = '''Get list of git repositories from the GitBlit json RPC
|
||||
'''
|
||||
|
||||
usage = "usage: %prog [options] "
|
||||
parser = optparse.OptionParser(usage=usage, description=desc)
|
||||
parser.add_option('-p', '--project', metavar="<PROJECTS>",
|
||||
help='''project path (default 'all', could be 'rpms', 'core-sig'...)''',
|
||||
default='rpms')
|
||||
|
||||
parser.add_option('-u', '--url', metavar="<URL>",
|
||||
help='URL to check (default %s)' % (RPCURL),
|
||||
default = RPCURL
|
||||
)
|
||||
|
||||
(options, args) = parser.parse_args()
|
||||
return options
|
||||
|
||||
def get_repo_list(url, projectpath):
|
||||
'''return a list of repo URLs'''
|
||||
try:
|
||||
req = requests.get(url)
|
||||
except requests.exceptions.RequestException as e:
|
||||
print e
|
||||
sys.exit(1)
|
||||
|
||||
payload = req.text
|
||||
repos = json.loads(payload)
|
||||
|
||||
if projectpath != 'all':
|
||||
for repo in repos.keys():
|
||||
if repos[repo]['projectPath'] != projectpath:
|
||||
del repos[repo]
|
||||
|
||||
return repos.keys()
|
||||
|
||||
def main():
|
||||
options = read_args()
|
||||
repos = get_repo_list(url=options.url, projectpath=options.project)
|
||||
print '\n'.join(repos)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
Loading…
Add table
Reference in a new issue