[Cryptech-Commits] [user/ft/alpha_to_kicad] 14/15: init

git at cryptech.is git at cryptech.is
Wed May 9 15:08:01 UTC 2018


This is an automated email from the git hooks/post-receive script.

fredrik at thulin.net pushed a commit to branch master
in repository user/ft/alpha_to_kicad.

commit 1f342938585b1cd3b4def00f62e53a5da18a9718
Author: Fredrik Thulin <fredrik at thulin.net>
AuthorDate: Wed May 9 17:07:10 2018 +0200

    init
---
 remap-symbols.py | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 66 insertions(+)

diff --git a/remap-symbols.py b/remap-symbols.py
new file mode 100755
index 0000000..eb1bdf6
--- /dev/null
+++ b/remap-symbols.py
@@ -0,0 +1,66 @@
+#!/usr/bin/env python
+
+"""
+Remap symbols to suit KiCad nightly
+"""
+
+import os
+import re
+import sys
+import pprint
+
+
+def remap_symbols(fn_in, fn_out, refdes):
+    in_ = open(fn_in)
+    out = open(fn_out, 'w')
+    fn = os.path.basename(fn_in)
+    print('Remapping symbols in in {}'.format(fn))
+    for line in in_.readlines():
+        #print('R: {!r}'.format(line))
+        if line.startswith('EESchema Schematic File Version 2'):
+            line = 'EESchema Schematic File Version 4\n'
+        elif line.startswith('EELAYER 27 0'):
+            line = 'EELAYER 26 0\n'
+        elif line.startswith('LIBS:'):
+            continue
+        elif line.startswith('L '):
+            while line.endswith('\n'):
+                line = line[:-1]
+            _l, name, des = line.split(' ')
+            if des.startswith('#'):
+                # KiCad replaces designators like #PWR?58023E19 with VCC_5V0_6
+                des = name
+            if des in refdes:
+                refdes[des] += 1
+                des = '{}_{}'.format(des, refdes[des])
+            else:
+                refdes[des] = 1
+            if name == 'GND':
+                line = 'L power:GND {}\n'.format(des)
+            else:
+                line = 'L Cryptech_Alpha:{} {}\n'.format(name, des)
+        out.write(line)
+    return True
+
+
+def main(schemas):
+    refdes = {}
+    for this in sorted(schemas):
+        if remap_symbols(this, this + '.tmp', refdes):
+            os.rename(this + '.tmp', this)
+
+    return True
+
+
+if __name__ == '__main__':
+    try:
+        if len(sys.argv) == 0:
+            sys.stderr.write('Syntax: remap-symbols.py *.sch\n')
+            sys.exit(1)
+        schemas = [x for x in sys.argv if x.endswith('.sch')]
+        res = main(schemas)
+        if res:
+            sys.exit(0)
+        sys.exit(1)
+    except KeyboardInterrupt:
+        pass



More information about the Commits mailing list