Blame centos.git.repolist.py

bonniek 7a56e5
#!/usr/bin/env python
bonniek 7a56e5
'''Get list of repos from gitblit RPC, to grab CentOS sources'''
bonniek 7a56e5
bonniek 7a56e5
import optparse
bonniek 7a56e5
import requests
bonniek 7a56e5
import simplejson as json
bonniek 7a56e5
import sys
bonniek 7a56e5
bonniek 7a56e5
RPCURL = "https://git.centos.org/rpc?req=LIST_REPOSITORIES"
bonniek 7a56e5
bonniek 7a56e5
def read_args():
bonniek 7a56e5
    '''
bonniek 7a56e5
        read in the command line args and set things up
bonniek 7a56e5
    '''
bonniek 7a56e5
bonniek 7a56e5
    desc = '''Get list of git repositories from the GitBlit json RPC
bonniek 7a56e5
           '''
bonniek 7a56e5
bonniek 7a56e5
    usage = "usage: %prog [options] "
bonniek 7a56e5
    parser = optparse.OptionParser(usage=usage, description=desc)
bonniek 7a56e5
    parser.add_option('-p', '--project', metavar="<PROJECTS>",
bonniek dbddad
                      help='''project path (default 'rpms', could be 'all', 'core-sig'...)''',
bonniek 7a56e5
                      default='rpms')
bonniek 7a56e5
bonniek 7a56e5
    parser.add_option('-u', '--url', metavar="<URL>",
bonniek 7a56e5
                      help='URL to check (default %s)' % (RPCURL),
bonniek 7a56e5
                      default = RPCURL
bonniek 7a56e5
                      )
bonniek 7a56e5
bonniek 7a56e5
    (options, args) = parser.parse_args()
bonniek 7a56e5
    return options
bonniek 7a56e5
bonniek 7a56e5
def get_repo_list(url, projectpath):
bonniek 7a56e5
    '''return a list of repo URLs'''
bonniek 7a56e5
    try:
bonniek 7a56e5
        req = requests.get(url)
bonniek 7a56e5
    except requests.exceptions.RequestException as e:
bonniek 7a56e5
        print e
bonniek 7a56e5
        sys.exit(1)
bonniek 7a56e5
bonniek 7a56e5
    payload = req.text
bonniek 7a56e5
    repos = json.loads(payload)
bonniek 7a56e5
bonniek 7a56e5
    if projectpath != 'all':
bonniek 7a56e5
        for repo in repos.keys():
bonniek 7a56e5
            if repos[repo]['projectPath'] != projectpath:
bonniek 7a56e5
                del repos[repo]
bonniek 7a56e5
bonniek 7a56e5
    return repos.keys()
bonniek 7a56e5
bonniek 7a56e5
def main():
bonniek 7a56e5
    options = read_args()
bonniek 7a56e5
    repos = get_repo_list(url=options.url, projectpath=options.project)
bonniek 7a56e5
    print '\n'.join(repos)
bonniek 7a56e5
    
bonniek 7a56e5
if __name__ == "__main__":
bonniek 7a56e5
    main()