resolve.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #!/usr/bin/env python
  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 os
  22. import sys
  23. from check_platform import is_supported_platform
  24. def get_packages(platform):
  25. """
  26. Resolve and get the list of packages to install for the given platform.
  27. :param platform: The platform for which the packages needs to be resolved.
  28. :return: A list of resolved packages to install.
  29. """
  30. with open('pkg-resolver/packages.json', mode='rb') as pkg_file:
  31. pkgs = json.loads(pkg_file.read().decode("UTF-8"))
  32. packages = []
  33. for platforms in [x for x in pkgs.values() if x.get(platform) is not None]:
  34. if isinstance(platforms.get(platform), list):
  35. packages.extend(platforms.get(platform))
  36. else:
  37. packages.append(platforms.get(platform))
  38. return packages
  39. if __name__ == '__main__':
  40. if len(sys.argv) < 2:
  41. sys.stderr.write('ERROR: Need at least 1 argument, {} were provided{}'.format(
  42. len(sys.argv) - 1, os.linesep))
  43. sys.exit(1)
  44. PLATFORM_ARG = sys.argv[1]
  45. if not is_supported_platform(PLATFORM_ARG):
  46. sys.stderr.write(
  47. 'ERROR: The given platform {} is not supported. '
  48. 'Please refer to platforms.json for a list of supported platforms{}'.format(
  49. PLATFORM_ARG, os.linesep))
  50. sys.exit(1)
  51. print ' '.join(get_packages(PLATFORM_ARG))