check_platform.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. Checks whether the given platform is supported for building Apache Hadoop
  19. """
  20. import json
  21. import sys
  22. def get_platforms():
  23. """
  24. :return: A list of the supported platforms managed by pkg-resolver.
  25. """
  26. with open('pkg-resolver/platforms.json', encoding='utf-8', mode='r') as platforms_file:
  27. return json.loads(platforms_file.read())
  28. def is_supported_platform(platform):
  29. """
  30. :param platform: The name of the platform
  31. :return: Whether the platform is supported
  32. """
  33. return platform in get_platforms()
  34. if __name__ == '__main__':
  35. if len(sys.argv) != 2:
  36. print('ERROR: Expecting 1 argument, {} were provided'.format(len(sys.argv) - 1),
  37. file=sys.stderr)
  38. sys.exit(1)
  39. sys.exit(0 if is_supported_platform(sys.argv[1]) else 1)