From 0aaf7f683a54e3ea1d5de88fd23152793caadefe Mon Sep 17 00:00:00 2001 From: Andrew Landau Date: Fri, 8 Dec 2023 17:45:25 +0000 Subject: [PATCH 1/2] If model_name exists, don't add it to list again --- cellpose/io.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/cellpose/io.py b/cellpose/io.py index d4d1ec6e..5d0f1dc2 100644 --- a/cellpose/io.py +++ b/cellpose/io.py @@ -140,13 +140,15 @@ def add_model(filename): """ add model to .cellpose models folder to use with GUI or CLI """ from . import models fname = os.path.split(filename)[-1] + overwrite = False try: shutil.copyfile(filename, os.fspath(models.MODEL_DIR.joinpath(fname))) except shutil.SameFileError: - pass + overwrite = True print(f'{filename} copied to models folder {os.fspath(models.MODEL_DIR)}') - with open(models.MODEL_LIST_PATH, 'a') as textfile: - textfile.write(fname + '\n') + if not overwrite: + with open(models.MODEL_LIST_PATH, 'a') as textfile: + textfile.write(fname + '\n') def imsave(filename, arr): ext = os.path.splitext(filename)[-1].lower() From ecad632375042bb8482ae420103a212c6482e613 Mon Sep 17 00:00:00 2001 From: Andrew Landau Date: Fri, 8 Dec 2023 17:55:18 +0000 Subject: [PATCH 2/2] Corrected method with intended function --- cellpose/io.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/cellpose/io.py b/cellpose/io.py index 5d0f1dc2..36117097 100644 --- a/cellpose/io.py +++ b/cellpose/io.py @@ -140,13 +140,12 @@ def add_model(filename): """ add model to .cellpose models folder to use with GUI or CLI """ from . import models fname = os.path.split(filename)[-1] - overwrite = False try: shutil.copyfile(filename, os.fspath(models.MODEL_DIR.joinpath(fname))) except shutil.SameFileError: - overwrite = True + pass print(f'{filename} copied to models folder {os.fspath(models.MODEL_DIR)}') - if not overwrite: + if fname not in models.get_user_models(): with open(models.MODEL_LIST_PATH, 'a') as textfile: textfile.write(fname + '\n')