Aucune description
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

check-files.py 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/usr/bin/env python
  2. from __future__ import print_function
  3. from os import listdir
  4. from os.path import dirname, isfile, join, isdir
  5. ROOT_DIR = join(dirname(__file__), '..')
  6. FILES_FOLDER = join(ROOT_DIR, 'files')
  7. def get_file_lists():
  8. if not isdir(FILES_FOLDER):
  9. print("! no file lists found")
  10. return {}
  11. list_files = [f for f in listdir(FILES_FOLDER) if isfile(join(FILES_FOLDER, f))]
  12. file_lists = {}
  13. for list_file in list_files:
  14. with open(join(FILES_FOLDER, list_file)) as lf:
  15. file_lists[list_file] = [f.strip() for f in lf.readlines() if len(f.strip()) > 0]
  16. return file_lists
  17. def check_files(file_list):
  18. optional_folders = []
  19. errors = 0
  20. for f in file_list:
  21. # optional dir
  22. if f.startswith('?'):
  23. optional_folders.append(f[1:].strip())
  24. # else not a file -> error
  25. elif not isfile(f):
  26. # ignore if path starts with optional folder path
  27. if len(filter(lambda x: f.startswith(x), optional_folders)) > 0:
  28. continue
  29. print("! '{}' is missing".format(f))
  30. errors += 1
  31. if errors == 0:
  32. print(" -> All Files found.")
  33. def main():
  34. for f, file_list in get_file_lists().items():
  35. print(f)
  36. check_files(file_list)
  37. if __name__ == '__main__':
  38. main()