Created
October 16, 2015 11:30
-
-
Save nmz787/e76770c4617cf80819a0 to your computer and use it in GitHub Desktop.
Renames KiCad plot and drill files to the correct OSHpark file extensions, and also puts all these into a ZIP file.
This file contains 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
""" | |
Renames KiCad plot and drill files to the correct OSHpark file extensions, and also puts all these into a ZIP file. | |
usage: | |
python rename_kicad_gerbers.py path/to/my/project/plot_output | |
returns: | |
kicad_out.zip (in the directory you ran the script from) | |
""" | |
import os | |
import sys | |
import zipfile | |
# kicad_file_ending:OSHpark_extension | |
file_name_lookup = {'pcb-F_Cu.gbr':'.GTL', | |
'pcb-B_Cu.gbr': '.GBL', | |
'pcb-F_SilkS.gbr': '.GTO', | |
'pcb-B_SilkS.gbr': '.GBO', | |
'pcb-F_Mask.gbr': '.GTS', | |
'pcb-B_Mask.gbr': '.GBS', | |
'pcb-Edge_Cuts.gbr': '.GKO', | |
'pcb.drl': '.xln'} | |
path = sys.argv[1] | |
print 'renaming kicad files in path: {}'.format(path) | |
with zipfile.ZipFile('kicad_out.zip', 'w') as myzip: | |
for _file in os.listdir(path): | |
for ending in file_name_lookup: | |
if _file.endswith(ending): | |
new_path = os.path.splitext(_file)[0] + file_name_lookup[ending] | |
print 'moving: {} \n to: {}'.format(_file, new_path) | |
os.rename(os.path.join(path, _file), | |
os.path.join(path, new_path)) | |
myzip.write(os.path.join(path, new_path)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment