Files
project-config/nodepool/elements/openstack-repos/extra-data.d/50-create-repo-list
Hervé Beraud 95c01abf38 Stop to use the __future__ module.
The __future__ module [1] was used in this context to ensure compatibility
between python 2 and python 3.

We previously dropped the support of python 2.7 [2] and now we only support
python 3 so we don't need to continue to use this module and the imports
listed below.

Imports commonly used and their related PEPs:
- `division` is related to PEP 238 [3]
- `print_function` is related to PEP 3105 [4]
- `unicode_literals` is related to PEP 3112 [5]
- `with_statement` is related to PEP 343 [6]
- `absolute_import` is related to PEP 328 [7]

[1] https://docs.python.org/3/library/__future__.html
[2] https://governance.openstack.org/tc/goals/selected/ussuri/drop-py27.html
[3] https://www.python.org/dev/peps/pep-0238
[4] https://www.python.org/dev/peps/pep-3105
[5] https://www.python.org/dev/peps/pep-3112
[6] https://www.python.org/dev/peps/pep-0343
[7] https://www.python.org/dev/peps/pep-0328

Change-Id: Icc115b2271a6fd84f3952b03406250367babd273
2020-06-02 20:44:50 +02:00

79 lines
2.4 KiB
Python
Executable File

#!/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 yaml
from six.moves.urllib.request import urlopen
from six.moves.urllib.error import URLError
URL = ('https://opendev.org/openstack/project-config/'
'raw/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', 'https://opendev.org')
CUSTOM_PROJECTS_LIST_URL = os.environ.get('DIB_CUSTOM_PROJECTS_LIST_URL')
def get_project_list(url):
try:
projects = []
for f in yaml.load(urlopen(url)):
# Skip repos that are inactive
project = f['project']
dirname = os.path.dirname(project)
if 'attic' in dirname or dirname == 'stackforge':
continue
acl = f.get('acl-config')
# Ignore retired repositories
if acl and os.path.basename(acl) == 'retired.config':
continue
projects.append(project)
return projects
except URLError:
print("Could not open project list url: '%s'" % url)
raise
def main():
projects = []
if CUSTOM_PROJECTS_LIST_URL:
projects = get_project_list(CUSTOM_PROJECTS_LIST_URL)
if not projects:
projects = get_project_list(URL)
with open(PROJECTS_REPOS, 'w') as projects_list:
for project in projects:
args = dict(
name=os.path.basename(project),
location=os.path.join('/opt/git/opendev.org', project),
url='%s/%s.git' % (GIT_BASE, project),
ref='*')
projects_list.write("%(name)s git %(location)s "
"%(url)s %(ref)s\n" % args)
if __name__ == '__main__':
main()