check_rosdistro_urls.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #!/usr/bin/env python
  2. # Copyright (c) 2017, Open Source Robotics Foundation
  3. # All rights reserved.
  4. #
  5. # Redistribution and use in source and binary forms, with or without
  6. # modification, are permitted provided that the following conditions are met:
  7. #
  8. # * Redistributions of source code must retain the above copyright
  9. # notice, this list of conditions and the following disclaimer.
  10. # * Redistributions in binary form must reproduce the above copyright
  11. # notice, this list of conditions and the following disclaimer in the
  12. # documentation and/or other materials provided with the distribution.
  13. # * Neither the name of the Willow Garage, Inc. nor the names of its
  14. # contributors may be used to endorse or promote products derived from
  15. # this software without specific prior written permission.
  16. #
  17. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  18. # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  19. # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  20. # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  21. # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  22. # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  23. # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  24. # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  25. # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  26. # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  27. # POSSIBILITY OF SUCH DAMAGE.
  28. from __future__ import print_function
  29. import argparse
  30. import sys
  31. from rosdistro import get_distribution_file, get_index
  32. def main(index_url, rosdistro_name):
  33. index = get_index(index_url)
  34. try:
  35. distribution_file = get_distribution_file(index, rosdistro_name)
  36. except RuntimeError as e:
  37. print("Could not load distribution file for distro '%s': %s" % (rosdistro_name, e), file=sys.stderr)
  38. return False
  39. success = True
  40. for repo_name in sorted(distribution_file.repositories.keys()):
  41. sys.stdout.write('.')
  42. sys.stdout.flush()
  43. repo = distribution_file.repositories[repo_name]
  44. repos = [repo.release_repository, repo.source_repository, repo.doc_repository]
  45. for repo in [r for r in repos if r]:
  46. if repo.url.startswith('file://'):
  47. print()
  48. print("Repository '%s' with url '%s' must not be a local 'file://' url" % (repo_name, repo.url), file=sys.stderr)
  49. success = False
  50. if repo.type == 'git':
  51. prefixes = ['http://github.com/', 'git@github.com:']
  52. for prefix in prefixes:
  53. if repo.url.startswith(prefix):
  54. print()
  55. print("Repository '%s' with url '%s' must use 'https://github.com/%s' instead" % (repo_name, repo.url, repo.url[len(prefix):]), file=sys.stderr)
  56. success = False
  57. for prefix in prefixes + ['https://github.com/']:
  58. if repo.url.startswith(prefix) and not repo.url.endswith('.git'):
  59. print()
  60. print("Repository '%s' with url '%s' should end with `.git` but does not." % (repo_name, repo.url))
  61. success = False
  62. print()
  63. return success
  64. if __name__ == '__main__':
  65. parser = argparse.ArgumentParser(description='Checks whether the referenced URLs have the expected pattern for known hosts')
  66. parser.add_argument('index_url', help='The url of the index.yaml file')
  67. parser.add_argument('rosdistro_name', help='The ROS distro name')
  68. args = parser.parse_args()
  69. if not main(args.index_url, args.rosdistro_name):
  70. sys.exit(1)