Skip to content

Commit

Permalink
add check for valid url patterns of known hosting platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
dirk-thomas committed Jan 25, 2014
1 parent b7a09ce commit b271b96
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
45 changes: 45 additions & 0 deletions scripts/check_rosdistro_urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/env python

from __future__ import print_function

import argparse
import sys

from rosdistro import get_distribution_file, get_index


def main(index_url, rosdistro_name):
index = get_index(index_url)
try:
distribution_file = get_distribution_file(index, rosdistro_name)
except RuntimeError as e:
print("Could not load distribution file for distro '%s': %s" % (rosdistro_name, e), file=sys.stderr)
return False

success = True
for repo_name in sorted(distribution_file.repositories.keys()):
sys.stdout.write('.')
sys.stdout.flush()
repo = distribution_file.repositories[repo_name]
repos = [repo.release_repository, repo.source_repository, repo.doc_repository]
for repo in [r for r in repos if r]:
if repo.type == 'git':
prefixes = ['https://github.com/', '[email protected]:']
for prefix in prefixes:
if repo.url.startswith(prefix):
print()
print("Repository '%s' with url '%s' must use 'https://github.com/%s' instead" % (repo_name, repo.url, repo.url[len(prefix):]), file=sys.stderr)
success = False
print()

return success


if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Checks whether the referenced URLs have the expected pattern for known hosts')
parser.add_argument('index_url', help='The url of the index.yaml file')
parser.add_argument('rosdistro_name', help='The ROS distro name')
args = parser.parse_args()

if not main(args.index_url, args.rosdistro_name):
sys.exit(1)
21 changes: 21 additions & 0 deletions test/rosdistro_check_urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env python

import os

from rosdistro import get_index
from scripts.check_rosdistro_urls import main as check_rosdistro_urls

FILES_DIR = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..'))


def test_rosdistro_urls():
index_url = 'file:https://' + FILES_DIR + '/index.yaml'
index = get_index(index_url)
success = True
for distro_name in index.distributions.keys():
print("""
Checking if distribution.yaml contains valid urls for known hosting services.
If this fails you can run 'scripts/check_rosdistro_urls.py file:https://`pwd`/%s %s' to perform the same check locally.
""" % ('index.yaml', distro_name))
success &= check_rosdistro_urls(index_url, distro_name)
assert success

0 comments on commit b271b96

Please sign in to comment.