Skip to content

Commit

Permalink
Merge pull request #102 from matthewlai/check_single_file_test
Browse files Browse the repository at this point in the history
Check single file test
  • Loading branch information
matthewlai authored Nov 21, 2023
2 parents dfc9bb4 + 31e0ff2 commit 633af99
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 16 deletions.
2 changes: 1 addition & 1 deletion jlc_kicad_tools/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.0.5"
__version__ = "1.0.6"
49 changes: 34 additions & 15 deletions jlc_kicad_tools/generate_jlc_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,39 +126,58 @@ def main():

netlist_filename = project_name + ".xml"
cpl_filename = project_name + "-all-pos.csv"
netlist_path = None
cpl_path = None
netlist_paths = []
cpl_paths = []

for dir_name, subdir_list, file_list in os.walk(opts.project_dir):
for file_name in file_list:
if file_name == netlist_filename and not netlist_path:
netlist_path = os.path.join(dir_name, file_name)
elif file_name == cpl_filename and not cpl_path:
cpl_path = os.path.join(dir_name, file_name)
if netlist_path and cpl_path:
break

if netlist_path is None:
if file_name == netlist_filename:
netlist_paths.append(os.path.join(dir_name, file_name))
elif file_name == cpl_filename:
cpl_paths.append(os.path.join(dir_name, file_name))

if len(netlist_paths) < 1:
_LOGGER.logger.error(
(
"Failed to find netlist file: {} in {} (and sub-directories). "
f"Failed to find netlist file: {netlist_filename} in {opts.project_dir} (and sub-directories). "
"Is the input directory a KiCad project? "
"If so, run 'Tools -> Generate Bill of Materials' in Eeschema (any format). "
"It will generate an intermediate file we need. "
"Note that this is not the same as a netlist for Pcbnew."
).format(netlist_filename, opts.project_dir)
)
)
return errno.ENOENT

if len(netlist_paths) > 1:
_LOGGER.logger.error(
(
f"Multiple netlist files found - {*netlist_paths,}. "
"There should be exactly one."
)
)
return errno.ENOENT

if cpl_path is None:
if len(cpl_paths) < 1:
_LOGGER.logger.error(
(
"Failed to find CPL file: {} in {} (and sub-directories). "
f"Failed to find CPL file: {cpl_filename} in {opts.project_dir} (and sub-directories). "
"Run 'File -> Fabrication Outputs -> Footprint Position (.pos) File' in Pcbnew. "
"Settings: 'CSV', 'mm', 'single file for board'."
).format(cpl_filename, opts.project_dir)
)
)
return errno.ENOENT

if len(cpl_paths) > 1:
_LOGGER.logger.error(
(
f"Multiple CPL files found - {*cpl_paths,}. "
"There should be exactly one."
)
)
return errno.ENOENT

netlist_path = netlist_paths[0]
cpl_path = cpl_paths[0]

_LOGGER.logger.info("Netlist file found at: {}".format(netlist_path))
_LOGGER.logger.info("CPL file found at: {}".format(cpl_path))
Expand Down

0 comments on commit 633af99

Please sign in to comment.