ppCheck.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #!/usr/bin/env python
  2. from __future__ import print_function
  3. import os, sys
  4. if not len(sys.argv) is 2 or not os.path.exists(sys.argv[1]):
  5. print("\nYou did not supply a valid path to check.")
  6. exit(1)
  7. else:
  8. print("\nChecking for un-preprocessed files...", end = ' ')
  9. DIST_PATH = sys.argv[1]
  10. PP_FILE_TYPES = (
  11. '.css',
  12. '.dtd',
  13. '.html',
  14. '.js',
  15. '.jsm',
  16. '.xhtml',
  17. '.xml',
  18. '.xul',
  19. '.manifest',
  20. '.properties',
  21. '.rdf'
  22. )
  23. PP_SPECIAL_TYPES = ('.css')
  24. PP_DIRECTIVES = [
  25. 'define',
  26. 'if',
  27. 'ifdef',
  28. 'ifndef',
  29. 'elif',
  30. 'elifdef',
  31. 'endif',
  32. 'error',
  33. 'expand',
  34. 'filter',
  35. 'include',
  36. 'literal',
  37. 'undef',
  38. 'unfilter'
  39. ]
  40. PP_FILES = []
  41. PP_BAD_FILES = []
  42. for root, directories, filenames in os.walk(DIST_PATH):
  43. for filename in filenames:
  44. if filename.endswith(PP_FILE_TYPES):
  45. PP_FILES += [ os.path.join(root, filename).replace(os.sep, '/') ]
  46. for file in PP_FILES:
  47. with open(file) as fp:
  48. marker = '%' if file.endswith(PP_SPECIAL_TYPES) else '#'
  49. directives = tuple(marker + directive for directive in PP_DIRECTIVES)
  50. for line in fp:
  51. if line.startswith(directives):
  52. PP_BAD_FILES += [ file.replace(DIST_PATH + '/', '') ]
  53. fp.close()
  54. PP_BAD_FILES = list(dict.fromkeys(PP_BAD_FILES))
  55. print('Done!')
  56. if len(PP_BAD_FILES) > 0:
  57. print("\nWARNING: The following {0} file(s) in {1} may require preprocessing:\n".format(len(PP_BAD_FILES), DIST_PATH))
  58. for file in PP_BAD_FILES:
  59. print(file)
  60. exit(0)