Created
March 17, 2023 23:57
-
-
Save snhobbs/d7f81534eb2409d41c0feb8b2a9eeb10 to your computer and use it in GitHub Desktop.
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
from shutil import copyfile | |
import glob | |
import os | |
_mapping = { | |
'macrofab': { | |
'Top Copper': '{project}.GTL', | |
'Top Silkscreen': '{project}.GTO', | |
'Top Soldermask': '{project}.GTS', | |
'Top Paste': '{project}.GTP', | |
'Bottom Copper': '{project}.GBL', | |
'Bottom Silkscreen': '{project}.GBO', | |
'Bottom Soldermask': '{project}.GBS', | |
'Bottom Paste': '{project}.GBP', | |
'Board Outline': '{project}.BOR', | |
'Inner 1': '{project}.G2L', | |
'Inner 2': '{project}.G3L', | |
'Inner 3': '{project}.G4L', | |
'Inner 4': '{project}.G5L', | |
'Inner 5': '{project}.G6L', | |
'Inner 6': '{project}.G7L', | |
'Inner 7': '{project}.G8L', | |
'Inner 8': '{project}.G9L', | |
'Inner 9': '{project}.G10L', | |
'Inner 10': '{project}.G11L', | |
'Excellon': '{project}.XLN', | |
}, | |
'kicad': { | |
'Top Copper': '{project}-F_Cu.gtl', | |
'Top Silkscreen': '{project}-F_Silkscreen.gto', | |
'Top Soldermask': '{project}-F_Mask.gts', | |
'Top Paste': '{project}-F_Paste.gtp', | |
'Bottom Copper': '{project}-B_Cu.gbl', | |
'Bottom Silkscreen': '{project}-B_Silkscreen.gbo', | |
'Bottom Soldermask': '{project}-B_Mask.gbs', | |
'Bottom Paste': '{project}-B_Paste.gbp', | |
'Board Outline': '{project}-Edge_Cuts.gm1', | |
'Inner 1': '{project}-In1_Cu.g2', | |
'Inner 2': '{project}-In2_Cu.g3', | |
'Inner 3': '{project}-In3_Cu.g4', | |
'Inner 4': '{project}-In4_Cu.g5', | |
'Inner 5': '{project}-In5_Cu.g6', | |
'Inner 6': '{project}-In6_Cu.g7', | |
'Inner 7': '{project}-In7_Cu.g8', | |
'Inner 8': '{project}-In8_Cu.g9', | |
'Inner 9': '{project}-In9_Cu.g10', | |
'Inner 10': '{project}-In10_Cu.g11', | |
'Inner 11': '{project}-In11_Cu.g12', | |
'Excellon': 'drill.drl', | |
'Top Fab': '{project}-F_Fab.gbr', | |
'Bottom Fab': '{project}-B_Fab.gbr', | |
}, | |
} | |
def map_names(file_list, project_name, to="macrofab", source="kicad"): | |
out_names = {} | |
for key, value in _mapping[source].items(): | |
fname = value.format(project=project_name) | |
print(fname) | |
if fname in file_list: | |
try: | |
out_names[fname] = _mapping[to][key].format(project=project_name) | |
except KeyError: | |
pass | |
return out_names | |
''' | |
Takes an input and output directory, copies all the file names from one type to another | |
''' | |
def map_files(project, directory="./", output_directory="output", to="macrofab", source="kicad"): | |
fnames_path = glob.glob(os.path.join(directory, "*")) | |
fnames = [os.path.split(f)[-1] for f in fnames_path] | |
print(fnames) | |
name_map = map_names(fnames, project_name=project) | |
try: | |
os.mkdir(output_directory) | |
except FileExistsError: | |
pass | |
print(name_map) | |
for source_f, dest_f in name_map.items(): | |
print(source_f, dest_f) | |
copyfile(src=os.path.join(directory, source_f), dst=os.path.join(output_directory, dest_f)) | |
import click | |
@click.command() | |
@click.option("--project", required=True) | |
@click.option("--source", default="./") | |
@click.option("--dest", default="./output") | |
@click.option("--a", default="macrofab") | |
@click.option("--b", default="kicad") | |
def main(project, source, dest, a, b): | |
map_files(project, directory=source, output_directory=dest, to=a, source=b) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment