copperNoSilkscreen.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. # usage:
  2. # copperNoSilkscreen.py -d <directory>
  3. #
  4. # <directory> is a folder, with subfolders, containing .fzp files. In each fzp file in the directory or its children
  5. # look for "copper" and "silkscreen"
  6. import getopt, sys, os, re
  7. def usage():
  8. print """
  9. usage:
  10. copperNoSilkscreen.py -d [directory]
  11. directory is a folder containing .fzp files.
  12. In each fzp file in the directory or its subfolders,
  13. look for "copper" and "silkscreen".
  14. """
  15. def main():
  16. try:
  17. opts, args = getopt.getopt(sys.argv[1:], "hd:", ["help", "directory"])
  18. except getopt.GetoptError, err:
  19. # print help information and exit:
  20. print str(err) # will print something like "option -a not recognized"
  21. usage()
  22. sys.exit(2)
  23. outputDir = None
  24. for o, a in opts:
  25. #print o
  26. #print a
  27. if o in ("-d", "--directory"):
  28. outputDir = a
  29. elif o in ("-h", "--help"):
  30. usage()
  31. sys.exit(2)
  32. else:
  33. assert False, "unhandled option"
  34. if(not(outputDir)):
  35. usage()
  36. sys.exit(2)
  37. for root, dirs, files in os.walk(outputDir, topdown=False):
  38. for filename in files:
  39. if (filename.endswith(".fzp")):
  40. infile = open(os.path.join(root, filename), "r")
  41. fzp = infile.read();
  42. infile.close();
  43. copperMatch = re.search('copper', fzp)
  44. silkscreenMatch = re.search('silkscreen', fzp)
  45. if (copperMatch == None):
  46. print "{0} {1}".format(os.path.join(root, filename), "no copper")
  47. elif (silkscreenMatch == None):
  48. print "{0} {1}".format(os.path.join(root, filename), "no silkscreen")
  49. if __name__ == "__main__":
  50. main()