PageRenderTime 57ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/tools/version_check.py

https://gitlab.com/mimizone/kolla
Python | 126 lines | 83 code | 26 blank | 17 comment | 17 complexity | 1575c511a5bce7d6d37efb5196447304 MD5 | raw file
  1. #!/usr/bin/env python
  2. # Licensed under the Apache License, Version 2.0 (the "License");
  3. # you may not use this file except in compliance with the License.
  4. # You may obtain a copy of the License at
  5. #
  6. # http://www.apache.org/licenses/LICENSE-2.0
  7. #
  8. # Unless required by applicable law or agreed to in writing, software
  9. # distributed under the License is distributed on an "AS IS" BASIS,
  10. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. # See the License for the specific language governing permissions and
  12. # limitations under the License.
  13. import collections
  14. import os
  15. import re
  16. import sys
  17. from bs4 import BeautifulSoup as bs
  18. from oslo_config import cfg
  19. import pkg_resources
  20. import requests
  21. PROJECT_ROOT = os.path.abspath(os.path.join(
  22. os.path.dirname(os.path.realpath(__file__)), '..'))
  23. # NOTE(SamYaple): Update the search patch to prefer PROJECT_ROOT as the source
  24. # of packages to import if we are using local tools/build.py
  25. # instead of pip installed kolla-build tool
  26. if PROJECT_ROOT not in sys.path:
  27. sys.path.insert(0, PROJECT_ROOT)
  28. from kolla.common import config as common_config
  29. # Filter list for non-projects
  30. NOT_PROJECTS = [
  31. 'nova-novncproxy',
  32. 'nova-spicehtml5proxy',
  33. 'openstack-base',
  34. 'profiles'
  35. ]
  36. TARBALLS_BASE_URL = 'http://tarballs.openstack.org'
  37. VERSIONS = {'local': dict()}
  38. def retrieve_upstream_versions():
  39. upstream_versions = dict()
  40. for project in VERSIONS['local']:
  41. winner = None
  42. series = VERSIONS['local'][project].split('.')[0]
  43. base = '{}/{}'.format(TARBALLS_BASE_URL, project)
  44. r = requests.get(base)
  45. s = bs(r.text, 'html.parser')
  46. for link in s.find_all('a'):
  47. version = link.get('href')
  48. if (version.endswith('.tar.gz') and
  49. version.startswith('{}-{}'.format(project, series))):
  50. split = '{}-|.tar.gz'.format(project)
  51. candidate = re.split(split, version)[1]
  52. # Ignore 2014, 2015 versions as they are older
  53. if candidate.startswith('201'):
  54. continue
  55. if not winner or more_recent(candidate, winner):
  56. winner = candidate
  57. if not winner:
  58. print('Could not find version for {}'.format(project))
  59. continue
  60. if '-' in winner:
  61. winner = winner.split('-')[1]
  62. upstream_versions[project] = winner
  63. VERSIONS['upstream'] = collections.OrderedDict(
  64. sorted(upstream_versions.items()))
  65. def retrieve_local_versions():
  66. for section in common_config.SOURCES:
  67. if section not in NOT_PROJECTS:
  68. project = section.split('-')[0]
  69. version = common_config.SOURCES[section]['location'].split(
  70. '/')[-1].split('.tar.gz')[0]
  71. if '-' in version:
  72. version = version.split('-')[1]
  73. VERSIONS['local'][project] = version
  74. def more_recent(candidate, reference):
  75. return pkg_resources.parse_version(candidate) > \
  76. pkg_resources.parse_version(reference)
  77. def diff_link(project, old_ref, new_ref):
  78. return "https://github.com/openstack/{}/compare/{}...{}".format(
  79. project, old_ref, new_ref)
  80. def compare_versions():
  81. up_to_date = True
  82. for project in VERSIONS['upstream']:
  83. if project in VERSIONS['local']:
  84. upstream_version = VERSIONS['upstream'][project]
  85. local_version = VERSIONS['local'][project]
  86. if more_recent(upstream_version, local_version):
  87. print("{} has newer version {} > {}, see diff at {}".format(
  88. project, upstream_version, local_version,
  89. diff_link(project, local_version, upstream_version)))
  90. up_to_date = False
  91. if up_to_date:
  92. print("Everything is up to date")
  93. def main():
  94. conf = cfg.ConfigOpts()
  95. common_config.parse(conf, sys.argv[1:], prog='kolla-build')
  96. retrieve_local_versions()
  97. retrieve_upstream_versions()
  98. compare_versions()
  99. if __name__ == '__main__':
  100. main()