You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.8 KiB

4 years ago
  1. # -*- coding: utf-8 -*-
  2. #
  3. # This file is part of Glances.
  4. #
  5. # Copyright (C) 2018 Nicolargo <nicolas@nicolargo.com>
  6. #
  7. # Glances is free software; you can redistribute it and/or modify
  8. # it under the terms of the GNU Lesser General Public License as published by
  9. # the Free Software Foundation, either version 3 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # Glances is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU Lesser General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Lesser General Public License
  18. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. """Common objects shared by all Glances modules."""
  20. import errno
  21. import os
  22. import sys
  23. # OS constants (some libraries/features are OS-dependent)
  24. BSD = sys.platform.find('bsd') != -1
  25. LINUX = sys.platform.startswith('linux')
  26. MACOS = sys.platform.startswith('darwin')
  27. SUNOS = sys.platform.startswith('sunos')
  28. WINDOWS = sys.platform.startswith('win')
  29. # Set the AMPs, plugins and export modules path
  30. work_path = os.path.realpath(os.path.dirname(__file__))
  31. amps_path = os.path.realpath(os.path.join(work_path, 'amps'))
  32. plugins_path = os.path.realpath(os.path.join(work_path, 'plugins'))
  33. exports_path = os.path.realpath(os.path.join(work_path, 'exports'))
  34. sys_path = sys.path[:]
  35. sys.path.insert(1, exports_path)
  36. sys.path.insert(1, plugins_path)
  37. sys.path.insert(1, amps_path)
  38. def safe_makedirs(path):
  39. """A safe function for creating a directory tree."""
  40. try:
  41. os.makedirs(path)
  42. except OSError as err:
  43. if err.errno == errno.EEXIST:
  44. if not os.path.isdir(path):
  45. raise
  46. else:
  47. raise