Skip to content

Instantly share code, notes, and snippets.

@nmz787
Created October 16, 2015 11:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nmz787/e76770c4617cf80819a0 to your computer and use it in GitHub Desktop.
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.
"""
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