platform.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. # Copyright 2011 Yesudeep Mangalapilly <yesudeep@gmail.com>
  5. # Copyright 2012 Google, Inc.
  6. #
  7. # Licensed under the Apache License, Version 2.0 (the "License");
  8. # you may not use this file except in compliance with the License.
  9. # You may obtain a copy of the License at
  10. #
  11. # http://www.apache.org/licenses/LICENSE-2.0
  12. #
  13. # Unless required by applicable law or agreed to in writing, software
  14. # distributed under the License is distributed on an "AS IS" BASIS,
  15. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. # See the License for the specific language governing permissions and
  17. # limitations under the License.
  18. import sys
  19. PLATFORM_WINDOWS = 'windows'
  20. PLATFORM_LINUX = 'linux'
  21. PLATFORM_BSD = 'bsd'
  22. PLATFORM_DARWIN = 'darwin'
  23. PLATFORM_UNKNOWN = 'unknown'
  24. def get_platform_name():
  25. if sys.platform.startswith("win"):
  26. return PLATFORM_WINDOWS
  27. elif sys.platform.startswith('darwin'):
  28. return PLATFORM_DARWIN
  29. elif sys.platform.startswith('linux'):
  30. return PLATFORM_LINUX
  31. elif sys.platform.startswith(('dragonfly', 'freebsd', 'netbsd', 'openbsd', 'bsd')):
  32. return PLATFORM_BSD
  33. else:
  34. return PLATFORM_UNKNOWN
  35. __platform__ = get_platform_name()
  36. def is_linux():
  37. return __platform__ == PLATFORM_LINUX
  38. def is_bsd():
  39. return __platform__ == PLATFORM_BSD
  40. def is_darwin():
  41. return __platform__ == PLATFORM_DARWIN
  42. def is_windows():
  43. return __platform__ == PLATFORM_WINDOWS