collect.py 1.1 KB

123456789101112131415161718192021222324252627282930
  1. import os
  2. DEFAULT_CONFIG_PATHS = ['/etc/borgmatic/config.yaml', '/etc/borgmatic.d']
  3. def collect_config_filenames(config_paths):
  4. '''
  5. Given a sequence of config paths, both filenames and directories, resolve that to just an
  6. iterable of files. Accomplish this by listing any given directories looking for contained config
  7. files. This is non-recursive, so any directories within the given directories are ignored.
  8. Return paths even if they don't exist on disk, so the user can find out about missing
  9. configuration paths. However, skip /etc/borgmatic.d if it's missing, so the user doesn't have to
  10. create it unless they need it.
  11. '''
  12. for path in config_paths:
  13. exists = os.path.exists(path)
  14. if os.path.realpath(path) in DEFAULT_CONFIG_PATHS and not exists:
  15. continue
  16. if not os.path.isdir(path) or not exists:
  17. yield path
  18. continue
  19. for filename in os.listdir(path):
  20. full_filename = os.path.join(path, filename)
  21. if not os.path.isdir(full_filename):
  22. yield full_filename