Better resilience for the genconfig function thanks to happy path and @Zykino suggestion!

This commit is contained in:
LecygneNoir 2021-02-28 10:27:40 +01:00
parent 85f0fe9b6f
commit cf3d4c32c3

View file

@ -6,17 +6,16 @@ logger = logging.getLogger('Prismedia')
from . import utils from . import utils
def genconfig(): def genconfig():
path = join(dirname(__file__), 'config') path = join(dirname(__file__), 'config')
files = [f for f in listdir(path) if isfile(join(path, f))] files = [f for f in listdir(path) if isfile(join(path, f))]
for f in files: for f in files:
final_f = f.replace(".sample", "") final_f = f.replace(".sample", "")
overwrite = True if exists(final_f) and not utils.ask_overwrite(final_f + " already exists. Do you want to overwrite it?"):
if exists(final_f): continue
overwrite = utils.ask_overwrite(final_f + " already exists. Do you want to overwrite it?")
if overwrite:
copyfile(join(path, f), final_f) copyfile(join(path, f), final_f)
logger.info(str(final_f) + " correctly generated, you may now edit it to fill your credentials.") logger.info(str(final_f) + " correctly generated, you may now edit it to fill your credentials.")