Skip to content
Snippets Groups Projects
Commit 41a05be8 authored by Axel Farrugia's avatar Axel Farrugia
Browse files

[Feat](Exports) Add a copy_folder function and allow the copies to be done through simlinks

parent 19cd7d0f
No related branches found
No related tags found
No related merge requests found
This commit is part of merge request !369. Comments created here will be created in the context of that merge request.
from .node_export import ExportNode, ExportNodeCpp from .node_export import ExportNode, ExportNodeCpp
from .code_generation import generate_file, generate_str, copy_file from .code_generation import generate_file, generate_str, copy_file, copy_folder
from .export_registry import ExportLib from .export_registry import ExportLib
from .scheduler_export import scheduler_export from .scheduler_export import scheduler_export
from .tensor_export import tensor_to_c, generate_input_file from .tensor_export import tensor_to_c, generate_input_file
......
...@@ -44,10 +44,29 @@ def generate_str(template_path: Union[Path, str], **kwargs) -> str: ...@@ -44,10 +44,29 @@ def generate_str(template_path: Union[Path, str], **kwargs) -> str:
return Environment(loader=FileSystemLoader( return Environment(loader=FileSystemLoader(
template_path.parent), undefined=StrictUndefined, keep_trailing_newline=True).get_template(template_path.name).render(kwargs) template_path.parent), undefined=StrictUndefined, keep_trailing_newline=True).get_template(template_path.name).render(kwargs)
def copy_file(filename, dst_folder): def copy_file(filename, dst_folder, symlink=False):
"""Copy the given file into the given dst path
The symlink arg allows to make a symbolic link instead of copying the file.
"""
# If directory doesn't exist, create it # If directory doesn't exist, create it
if not os.path.exists(dst_folder): if not os.path.exists(dst_folder):
os.makedirs(dst_folder) os.makedirs(dst_folder)
shutil.copy(filename, dst_folder) if symlink:
dst_folder += "/" + os.path.basename(filename)
if not os.path.exists(dst_folder):
os.symlink(filename, dst_folder)
else:
shutil.copy(filename, dst_folder)
def copy_folder(foldername, dst_folder, symlink=False):
"""Copy the given folder into the given dst path
The symlink arg allows to make a symbolic link instead of copying the file.
"""
if symlink:
os.symlink(foldername, dst_folder)
else:
shutil.copytree(foldername, dst_folder, dirs_exist_ok=True)
\ No newline at end of file
...@@ -40,6 +40,9 @@ class ExportLib(aidge_core.OperatorImpl): ...@@ -40,6 +40,9 @@ class ExportLib(aidge_core.OperatorImpl):
# key: Path where static file is # key: Path where static file is
# Value: Path where to copy the file relative to the export root # Value: Path where to copy the file relative to the export root
static_files: Dict[str, str] = {} static_files: Dict[str, str] = {}
# key: Path where static folder is
# Value: Path where to copy the folder relative to the export root
static_folders: Dict[str, str] = {}
# Main memory section # Main memory section
mem_section = None mem_section = None
# Custom forward generation jinja file # Custom forward generation jinja file
......
...@@ -2,7 +2,7 @@ import aidge_core ...@@ -2,7 +2,7 @@ import aidge_core
import os import os
import shutil import shutil
from pathlib import Path from pathlib import Path
from aidge_core.export_utils import ExportLib, generate_file, copy_file from aidge_core.export_utils import ExportLib, generate_file, copy_file, copy_folder
from typing import List, Tuple from typing import List, Tuple
...@@ -208,4 +208,8 @@ def scheduler_export(scheduler, export_folder_path: str, export_lib: ExportLib = ...@@ -208,4 +208,8 @@ def scheduler_export(scheduler, export_folder_path: str, export_lib: ExportLib =
if export_lib is not None: if export_lib is not None:
# Copy all static files in the export # Copy all static files in the export
for source, destination in export_lib.static_files.items(): for source, destination in export_lib.static_files.items():
copy_file(source, str(export_folder / destination)) copy_file(source, str(export_folder / destination), test_mode)
# Copy all static folders in the export
for source, destination in export_lib.static_folders.items():
copy_folder(source, str(export_folder / destination), test_mode)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment