Last active
March 4, 2019 19:54
-
-
Save TechplexEngineer/c24ee71db0fca57119140f9ac4544efc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# License MIT | |
import os, re, sys | |
where = '.' | |
try: | |
where = sys.argv[1] | |
except: | |
pass | |
# Maps the euffix of the filename to the OSHPark format | |
layerMapping = { | |
"F_Cu.gbr": "gtl", | |
"B_Cu.gbr": "gbl", | |
"F_Mask.gbr": "gts", | |
"B_Mask.gbr": "gbs", | |
"F_SilkS.gbr": "gto", | |
"B_SilkS.gbr": "gbo", | |
"Edge_Cuts.gbr": "gko", | |
'drl': "xln" | |
} | |
pattern = re.compile(r'^(?P<basename>.*)-(?P<ident>[^-]*)$') | |
p2 = re.compile(r'^(?P<basename>.*)\.(?P<ident>.*)$') | |
os.chdir(where) | |
for filename in os.listdir('.'): | |
match = False | |
if filename.endswith(".gbr"): | |
match = re.search(pattern,filename) | |
elif filename.endswith(".drl"): | |
match = re.search(p2,filename) | |
if match: | |
newFilename = match.group('basename')+'.'+layerMapping[match.group('ident')] | |
print 'Renaming \'{0}\' to \'{1}\''.format(filename, newFilename) | |
os.rename(filename, newFilename) | |
else: | |
print 'No match.', filename | |
sys.exit(0) | |
layerMapping = { | |
"top": "gtl", | |
"bottom": "gbl", | |
"topmask": "gts", | |
"bottommask": "gbs", | |
"topsilk": "gto", | |
"bottomsilk": "gbo", | |
"plated-drill": "drl",### DIFFERENT EXTENSION | |
"group2": "g2", | |
"group3": "g3", | |
"toppaste": "gtp", | |
"bottompaste": "gbp", | |
"outline": "outline", | |
} | |
pattern = re.compile(r'^(?P<basename>[^\.]*)\.(?P<layer>[^\.]*)\.(?P<ext>(gbr)|(cnc))$') | |
os.chdir(where) | |
for filename in os.listdir('.'): | |
if filename.endswith(".gbr") or filename.endswith(".cnc"): | |
match = re.search(pattern,filename) | |
if match: | |
if match.group('layer') in layerMapping: | |
newFilename = match.group('basename')+'.'+match.group('layer')+'.'+layerMapping[match.group('layer')] | |
print 'Renaming \'{0}\' to \'{1}\''.format(filename, newFilename) | |
os.rename(filename, newFilename) | |
else: | |
print 'No match.', filename | |
sys.exit(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
License MIT