From 49e3bddc9164b1a4320e473856716f7f1324581b Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Mon, 19 Sep 2022 23:10:10 +0200 Subject: [PATCH] Fixed cpl g existing __init__.py overwrite #116 --- src/cpl_cli/command/generate_service.py | 26 +++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/cpl_cli/command/generate_service.py b/src/cpl_cli/command/generate_service.py index 4fb25a04..60cd897e 100644 --- a/src/cpl_cli/command/generate_service.py +++ b/src/cpl_cli/command/generate_service.py @@ -153,18 +153,24 @@ class GenerateService(CommandABC): if not os.path.isdir(os.path.dirname(file_path)): os.makedirs(os.path.dirname(file_path)) directory = '' + print() for subdir in template.path.split('/'): directory = os.path.join(directory, subdir) - if subdir != 'src': - file = InitTemplate(class_name, schematic, self._schematics[schematic]["Upper"], rel_path) - Console.spinner( - f'Creating {os.path.abspath(directory)}/{file.name}', - self._create_file, - os.path.join(os.path.abspath(directory), file.name), - file.value, - text_foreground_color=ForegroundColorEnum.green, - spinner_foreground_color=ForegroundColorEnum.cyan - ) + if subdir == 'src': + continue + + file = InitTemplate(class_name, schematic, self._schematics[schematic]["Upper"], rel_path) + if os.path.exists(os.path.join(os.path.abspath(directory), file.name)): + continue + + Console.spinner( + f'Creating {os.path.abspath(directory)}/{file.name}', + self._create_file, + os.path.join(os.path.abspath(directory), file.name), + file.value, + text_foreground_color=ForegroundColorEnum.green, + spinner_foreground_color=ForegroundColorEnum.cyan + ) if os.path.isfile(file_path): Console.error(f'{String.first_to_upper(schematic)} already exists!\n') -- 2.45.1