Add script to ensure a footprint's description matches filename
authorDan White <dan@whiteaudio.com>
Fri, 24 Feb 2012 21:08:26 +0000 (15:08 -0600)
committerDan White <dan@whiteaudio.com>
Fri, 24 Feb 2012 21:08:26 +0000 (15:08 -0600)
fpfixup.py [new file with mode: 0755]

diff --git a/fpfixup.py b/fpfixup.py
new file mode 100755 (executable)
index 0000000..c77184a
--- /dev/null
@@ -0,0 +1,27 @@
+#!/usr/bin/env python
+
+
+import sys
+from os.path import basename
+
+if len(sys.argv) < 2:
+    print 'usage: %s file0 [file1 [file2...]]' % sys.argv[0]
+    sys.exit(1)
+
+for fpath in sys.argv[1:]:
+    fname = basename(fpath)
+
+    fp = open(fpath)
+    lines = fp.readlines()
+    fp.close()
+    if lines[0][0:7] == 'Element':
+        fields = lines[0].split()
+        if fields[1] == fname or fields[1] == '"'+fname+'"':
+            print 'Not touching:', fpath
+        else:
+            fields[1] = '"%s"' % fname
+            #put back the split() trailing newline
+            lines[0] = ' '.join(fields) + '\n'
+            print 'Rewriting:', fpath
+            open(fpath, 'w').write(''.join(lines))
+