Skip to content

Commit e78ee09

Browse files
committed
FIX: A real bug caught by mypy
1 parent cf62853 commit e78ee09

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

MethodicConfigurator/backend_filesystem.py

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -450,17 +450,28 @@ def new_vehicle_dir(base_dir: str, new_dir: str) -> str:
450450
def directory_exists(directory: str) -> bool:
451451
return os_path.exists(directory) and os_path.isdir(directory)
452452

453-
def copy_template_files_to_new_vehicle_dir(self, template_dir: str, new_vehicle_dir: str) -> None:
453+
def copy_template_files_to_new_vehicle_dir(self, template_dir: str, new_vehicle_dir: str) -> str:
454454
# Copy the template files to the new vehicle directory
455-
for item in os_listdir(template_dir):
456-
if item in {"apm.pdef.xml", "vehicle.jpg", "last_uploaded_filename.txt", "tempcal_acc.png", "tempcal_gyro.png"}:
457-
continue
458-
s = os_path.join(template_dir, item)
459-
d = os_path.join(new_vehicle_dir, item)
460-
if os_path.isdir(s):
461-
shutil_copytree(s, d)
462-
else:
463-
shutil_copy2(s, d)
455+
try:
456+
for item in os_listdir(template_dir):
457+
if item in {
458+
"apm.pdef.xml",
459+
"vehicle.jpg",
460+
"last_uploaded_filename.txt",
461+
"tempcal_acc.png",
462+
"tempcal_gyro.png",
463+
}:
464+
continue
465+
s = os_path.join(template_dir, item)
466+
d = os_path.join(new_vehicle_dir, item)
467+
if os_path.isdir(s):
468+
shutil_copytree(s, d)
469+
else:
470+
shutil_copy2(s, d)
471+
except Exception as _e: # pylint: disable=broad-except
472+
error_msg = _("Error copying template files to new vehicle directory: {_e}")
473+
return error_msg.format(**locals())
474+
return ""
464475

465476
@staticmethod
466477
def getcwd() -> str:

0 commit comments

Comments
 (0)