50-create-repo-list 2.74 KB
Newer Older
Thiago Paiva's avatar
Thiago Paiva committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/usr/bin/env python

# Copyright (C) 2011-2013 OpenStack Foundation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
#
# See the License for the specific language governing permissions and
# limitations under the License.

import os
import urllib2
Ricardo Araujo's avatar
Ricardo Araujo committed
21
from urllib2 import URLError
Thiago Paiva's avatar
Thiago Paiva committed
22
23
24
25
26
27
28
29
30
import yaml

URL = ('https://git.openstack.org/cgit/openstack-infra/project-config/'
       'plain/gerrit/projects.yaml')

TMP_HOOKS_PATH=os.environ['TMP_HOOKS_PATH']
PROJECTS_REPOS=os.path.join(TMP_HOOKS_PATH, 'source-repository-projects-yaml')
GIT_BASE=os.environ.get('GIT_BASE', 'git://git.openstack.org')

Ricardo Araujo's avatar
Ricardo Araujo committed
31
32
33
34
35
36
37
38
39
CUSTOM_PROJECTS_LIST_URL=os.environ.get('DIB_CUSTOM_PROJECTS_LIST_URL')

def get_project_list(url):
    try:
        projects = [f['project'] for f in yaml.load(urllib2.urlopen(url))]
        return projects
    except URLError:
        print "Could not open project list url: '%s'" % url
        raise
Thiago Paiva's avatar
Thiago Paiva committed
40
41

def main():
Ricardo Araujo's avatar
Ricardo Araujo committed
42
43
44
45
46
47
48
    projects = []
    if CUSTOM_PROJECTS_LIST_URL:
        projects = get_project_list(CUSTOM_PROJECTS_LIST_URL)

    if not projects:
        projects = get_project_list(URL)

Thiago Paiva's avatar
Thiago Paiva committed
49
50
    with open(PROJECTS_REPOS, 'w') as projects_list:
        for project in projects:
51
52
            # Skip repos that are inactive
            dirname = os.path.dirname(project)
Ricardo Araujo's avatar
Ricardo Araujo committed
53
54
55
56
57
58
59
60
61
62
63
64
65
66
            if ('attic' in dirname or dirname == 'stackforge'):
                continue
            # Skip the /deb- git repo copies
            if ('/deb-' in project):
                continue

            args = dict(
                name=os.path.basename(project),
                location=os.path.join('/opt/git', project),
                url='%s/%s.git' % (GIT_BASE, project),
                ref='*')

            projects_list.write("%(name)s git %(location)s "
                                "%(url)s %(ref)s\n" % args)
Thiago Paiva's avatar
Thiago Paiva committed
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
        # Clone openstack-infra/system-config again so that we can use it to
        # build the image without interferring with the slave repo cache.
        project = 'openstack-infra/system-config'
        args = dict(
            name='config_tmp',
            location=os.path.join('/opt/build_git', project),
            url=os.environ.get('CONFIG_SOURCE',
                               '%s/%s.git' % (GIT_BASE, project)),
            ref=os.environ.get('CONFIG_REF', '*'))
        projects_list.write(
                "%(name)s git %(location)s %(url)s %(ref)s\n" % args)


if __name__ == '__main__':
    main()