forked from ros/rosdistro
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add check for valid url patterns of known hosting platforms
- Loading branch information
1 parent
b7a09ce
commit b271b96
Showing
2 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |