Nessuna descrizione
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.

check-files.py 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #!/usr/bin/env python2
  2. from __future__ import print_function
  3. import re
  4. import sys
  5. from os import listdir
  6. from os.path import dirname, isfile, join, isdir
  7. ROOT_DIR = join(dirname(__file__), '..')
  8. FILES_FOLDER = join(ROOT_DIR, 'files')
  9. def natural_sort_key(value):
  10. return [int(s) if s.isdigit() else s.lower() for s in re.split(r"(\d+)", value)]
  11. def get_file_lists():
  12. if not isdir(FILES_FOLDER):
  13. print("! no file lists found")
  14. return {}
  15. list_files = [f for f in listdir(FILES_FOLDER) if isfile(join(FILES_FOLDER, f))]
  16. file_lists = {}
  17. for list_file in list_files:
  18. with open(join(FILES_FOLDER, list_file)) as lf:
  19. file_lists[list_file] = [f.strip() for f in lf.readlines() if len(f.strip()) > 0]
  20. return file_lists
  21. def check_files(file_list):
  22. optional_folders = []
  23. errors = 0
  24. for f in file_list:
  25. # optional dir
  26. if f.startswith('?'):
  27. optional_folders.append(f[1:].strip())
  28. # else not a file -> error
  29. elif not isfile(f):
  30. # ignore if path starts with optional folder path
  31. if len(filter(lambda x: f.startswith(x), optional_folders)) > 0:
  32. continue
  33. print("! '{}' is missing".format(f))
  34. errors += 1
  35. if errors == 0:
  36. return True
  37. print(" -> All Files found.")
  38. return False
  39. def main():
  40. file_lists = get_file_lists()
  41. newest_folder = sorted(file_lists.keys(), key=natural_sort_key)[-1]
  42. print(newest_folder)
  43. if not check_files(file_lists[newest_folder]):
  44. sys.exit(1)
  45. if __name__ == '__main__':
  46. main()