Skip to content

Commit

Permalink
changed output_dir function
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewI26 committed Nov 11, 2024
1 parent 37459d0 commit ed9d002
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions scripts/cangen/cangen/can_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,12 @@ def _camel_to_snake(text):
return re.sub("([a-z0-9])([A-Z])", r"\1_\2", s1).lower()


def _create_output_file_name(bus_name: str, template_file_name: str) -> str:
def _create_output_file_name(output_dir: str, bus_name: str, template_file_name: str) -> str:
return os.path.join(
bus_name.lower() + "_" + template_file_name.removesuffix(".jninja2")
output_dir, bus_name.lower() + "_" + template_file_name.removesuffix(".jninja2")
)


def _generate_code(bus: Bus):
def _generate_code(bus: Bus, output_dir: str):
"""
Parses DBC files, extracts information, and generates code using Jinja2
templates.
Expand Down Expand Up @@ -213,8 +212,8 @@ def _generate_code(bus: Bus):
template = env.get_template(template_file_name)
rendered_code = template.render(**context)

output_file_name = _create_output_file_name(bus.bus_name, template_file_name)
with open(_create_output_file_name, "w") as output_file:
output_file_name = _create_output_file_name(output_dir, bus.bus_name, template_file_name)
with open(output_file_name, "w") as output_file:
output_file.write(rendered_code)
logger.info(f"Rendered code written to '{os.path.abspath(output_file_name)}'")

Expand Down Expand Up @@ -243,6 +242,5 @@ def generate_can_for_project(project_folder_name: str):

_prepare_output_directory(config.output_dir)

os.chdir(config.output_dir)
for bus in config.busses:
_generate_code(bus)
_generate_code(bus, config.output_dir)

0 comments on commit ed9d002

Please sign in to comment.