pathNoText.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. pathNoText.py -d [directory]
  11. directory is a folder containing .svg files.
  12. In each fzp file in the directory or its subfolders,
  13. look for "<path>" and no "<text>".
  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. return
  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. return
  32. else:
  33. assert False, "unhandled option"
  34. if not(outputDir) :
  35. usage()
  36. return
  37. for root, dirs, files in os.walk(outputDir, topdown=False):
  38. for filename in files:
  39. if filename.endswith(".svg"):
  40. infile = open(os.path.join(root, filename), "r")
  41. svg = infile.read()
  42. infile.close()
  43. textMatch = '<text' in svg
  44. pathMatch = '<path' in svg
  45. if not(textMatch) and pathMatch:
  46. print "{0} {1}".format(os.path.join(root, filename), "path no text")
  47. if __name__ == "__main__":
  48. main()