schemmatch.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import getopt, sys, os, re
  2. def usage():
  3. print """
  4. usage:
  5. schemmatch.py -f <fritzing parts folder>
  6. looks for all svgs in fritzing parts/whatever and tries to find a matching obsolete/0.3.schem. file
  7. ignore the ones that start with sparkfun-
  8. """
  9. def main():
  10. try:
  11. opts, args = getopt.getopt(sys.argv[1:], "f:", ["fritzing"])
  12. except getopt.GetoptError, err:
  13. # print help information and exit:
  14. print str(err) # will print something like "option -a not recognized"
  15. usage()
  16. return
  17. fritzingDir = None
  18. for o, a in opts:
  19. #print o
  20. #print a
  21. if o in ("-f", "--fritzing"):
  22. fritzingDir = a
  23. else:
  24. print "unhandled option", o
  25. usage()
  26. return
  27. if not fritzingDir:
  28. usage()
  29. return
  30. for root, dirs, files in os.walk(fritzingDir, topdown=False):
  31. for name in files:
  32. if not name.endswith("svg"):
  33. continue
  34. if name.startswith("sparkfun-"):
  35. continue
  36. fullname = os.path.join(root, name)
  37. pathlist = fullname.split(os.sep)
  38. if pathlist[-4] != "svg":
  39. continue
  40. if pathlist[-3] == "obsolete":
  41. continue
  42. if pathlist[-2] != "schematic":
  43. continue
  44. pathlist[-3] = "obsolete"
  45. pathlist[-1] = "0.3.schem." + pathlist[-1]
  46. try:
  47. with open(os.sep.join(pathlist)):
  48. pass
  49. except IOError:
  50. print "no 0.3.schem for", fullname
  51. if __name__ == "__main__":
  52. main()