Funktionierender Prototyp des Serious Games zur Vermittlung von Wissen zu Software-Engineering-Arbeitsmodellen.
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.

config.py 1.7KB

1 year ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import json
  2. import logging
  3. import os
  4. from ..constants import IS_WINDOWS_PLATFORM
  5. DOCKER_CONFIG_FILENAME = os.path.join('.docker', 'config.json')
  6. LEGACY_DOCKER_CONFIG_FILENAME = '.dockercfg'
  7. log = logging.getLogger(__name__)
  8. def find_config_file(config_path=None):
  9. paths = list(filter(None, [
  10. config_path, # 1
  11. config_path_from_environment(), # 2
  12. os.path.join(home_dir(), DOCKER_CONFIG_FILENAME), # 3
  13. os.path.join(home_dir(), LEGACY_DOCKER_CONFIG_FILENAME), # 4
  14. ]))
  15. log.debug(f"Trying paths: {repr(paths)}")
  16. for path in paths:
  17. if os.path.exists(path):
  18. log.debug(f"Found file at path: {path}")
  19. return path
  20. log.debug("No config file found")
  21. return None
  22. def config_path_from_environment():
  23. config_dir = os.environ.get('DOCKER_CONFIG')
  24. if not config_dir:
  25. return None
  26. return os.path.join(config_dir, os.path.basename(DOCKER_CONFIG_FILENAME))
  27. def home_dir():
  28. """
  29. Get the user's home directory, using the same logic as the Docker Engine
  30. client - use %USERPROFILE% on Windows, $HOME/getuid on POSIX.
  31. """
  32. if IS_WINDOWS_PLATFORM:
  33. return os.environ.get('USERPROFILE', '')
  34. else:
  35. return os.path.expanduser('~')
  36. def load_general_config(config_path=None):
  37. config_file = find_config_file(config_path)
  38. if not config_file:
  39. return {}
  40. try:
  41. with open(config_file) as f:
  42. return json.load(f)
  43. except (OSError, ValueError) as e:
  44. # In the case of a legacy `.dockercfg` file, we won't
  45. # be able to load any JSON data.
  46. log.debug(e)
  47. log.debug("All parsing attempts failed - returning empty config")
  48. return {}