resolve.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #!/usr/bin/env python3
  2. # Licensed to the Apache Software Foundation (ASF) under one
  3. # or more contributor license agreements. See the NOTICE file
  4. # distributed with this work for additional information
  5. # regarding copyright ownership. The ASF licenses this file
  6. # to you under the Apache License, Version 2.0 (the
  7. # "License"); you may not use this file except in compliance
  8. # with the License. You may obtain a copy of the License at
  9. #
  10. # http://www.apache.org/licenses/LICENSE-2.0
  11. #
  12. # Unless required by applicable law or agreed to in writing, software
  13. # distributed under the License is distributed on an "AS IS" BASIS,
  14. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. # See the License for the specific language governing permissions and
  16. # limitations under the License.
  17. """
  18. Platform package dependency resolver for building Apache Hadoop.
  19. """
  20. import json
  21. import sys
  22. from check_platform import is_supported_platform
  23. def get_packages(platform):
  24. """
  25. Resolve and get the list of packages to install for the given platform.
  26. :param platform: The platform for which the packages needs to be resolved.
  27. :return: A list of resolved packages to install.
  28. """
  29. with open('pkg-resolver/packages.json', encoding='utf-8', mode='r') as pkg_file:
  30. pkgs = json.loads(pkg_file.read())
  31. packages = []
  32. for platforms in filter(lambda x: x.get(platform) is not None, pkgs.values()):
  33. if isinstance(platforms.get(platform), list):
  34. packages.extend(platforms.get(platform))
  35. else:
  36. packages.append(platforms.get(platform))
  37. return packages
  38. if __name__ == '__main__':
  39. if len(sys.argv) < 2:
  40. print('ERROR: Need at least 1 argument, {} were provided'.format(len(sys.argv) - 1),
  41. file=sys.stderr)
  42. sys.exit(1)
  43. platform_arg = sys.argv[1]
  44. if not is_supported_platform(platform_arg):
  45. print(
  46. 'ERROR: The given platform {} is not supported. '
  47. 'Please refer to platforms.json for a list of supported platforms'.format(
  48. platform_arg), file=sys.stderr)
  49. sys.exit(1)
  50. packages_to_install = get_packages(platform_arg)
  51. print(' '.join(packages_to_install))