Skip to content

Commit

Permalink
Fix copy of media files
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustry committed Feb 14, 2025
1 parent 1022918 commit 3f29698
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
11 changes: 8 additions & 3 deletions dynamic_layers/core/generate_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ def process(self) -> bool:
if self.feedback:
if self.feedback.isCanceled():
break
self.feedback.pushDebugInfo(tr('Feature : {}').format(feature.id()))
self.feedback.pushDebugInfo(tr(
'Feature ID : {} → "{}" = \'{}\'').format(feature.id(), self.field, feature[self.field]))

if hasattr(self.feedback, 'widget'):
# It's the own Feedback object
Expand Down Expand Up @@ -119,6 +120,7 @@ def process(self) -> bool:
feature=feature,
)
new_path = Path(f"{self.destination}/{new_file}")
new_file_name = new_path.stem

# The new path can contain new folder, specific to the evaluated expression
if not new_path.parent.exists():
Expand All @@ -144,17 +146,20 @@ def process(self) -> bool:
from lizmap.toolbelt.lizmap import sidecar_media_dirs
dirs = sidecar_media_dirs(base_path_obj)
log_message(
tr('List of side-car files 2/2 : {}').format(str([str(f) for f in files])),
tr('List of side-car files 2/2 : {}').format(str([str(f) for f in dirs])),
Qgis.Info,
self.feedback
)
for a_dir in dirs:
rel_path = a_dir.relative_to(base_path_obj.parent)

# Quick and replace "media/js/project_A/foo.js" to "media/js/project_B/foo.js"
rel_path = Path(str(rel_path).replace(base_path_obj.stem, new_file_name))

new_dir_path = new_path.parent.joinpath(rel_path)
new_dir_path.mkdir(parents=True, exist_ok=True)

copytree(a_dir, new_dir_path.parent.joinpath(a_dir.stem), dirs_exist_ok=True)
copytree(a_dir, new_dir_path, dirs_exist_ok=True)

# log_message(
# tr('Copy of directory : {}').format(str(rel_path)),
Expand Down
2 changes: 1 addition & 1 deletion dynamic_layers/generate_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def __init__(self, parent: QDialog = None):
# DEBUG
# self.file_name.setText('"schema" || \'/test_\' || "schema" || \'.qgs\'')
# self.destination.setFilePath('/tmp/demo_cartophyl')
# self.debug_limit.setValue(5)
# self.debug_limit.setValue(1)

def layer_changed(self):
self.field.setLayer(self.coverage.currentLayer())
Expand Down
3 changes: 3 additions & 0 deletions dynamic_layers/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ def side_car_files(file_path: Path) -> List[Path]:
""" Return a list of all side-car files, having the extension included. """
results = []
for iter_file in file_path.parent.iterdir():
if iter_file.suffix.endswith('~'):
continue

if iter_file.name.startswith(file_path.name) and iter_file != file_path:
results.append(iter_file)

Expand Down

0 comments on commit 3f29698

Please # to comment.