From 3e8875c532c45ae92ee74eb3ecbef808d6ccbea3 Mon Sep 17 00:00:00 2001 From: Benjamin Moody Date: Wed, 25 Sep 2024 13:44:59 -0400 Subject: [PATCH 1/3] loaddemo: don't install ".gitkeep" files. Files called ".gitkeep" are used as placeholders to tell git to create the directory. They shouldn't be copied as part of the demo project content (in fact, a file called ".gitkeep" would not be allowed by the file upload form.) For example, the demo active project AGlSZa5VTv5Dg09CSpoh contains no actual files, but the git repository includes the file demo-files/media/active-projects/AGlSZa5VTv5Dg09CSpoh/.gitkeep - so in this case, loaddemo should create an empty project directory media/active-projects/AGlSZa5VTv5Dg09CSpoh . --- physionet-django/user/management/commands/loaddemo.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/physionet-django/user/management/commands/loaddemo.py b/physionet-django/user/management/commands/loaddemo.py index ec452572b..4ae847c61 100644 --- a/physionet-django/user/management/commands/loaddemo.py +++ b/physionet-django/user/management/commands/loaddemo.py @@ -104,7 +104,8 @@ def copy_demo_media(): path = os.path.join(demo_subdir, item) if os.path.isdir(path): shutil.copytree(os.path.join(demo_subdir, item), - os.path.join(target_subdir, item)) + os.path.join(target_subdir, item), + ignore=shutil.ignore_patterns('.gitkeep')) else: shutil.copy(os.path.join(demo_subdir, item), os.path.join(target_subdir, item)) @@ -136,7 +137,8 @@ def copy_demo_static(): for item in [i for i in os.listdir(demo_subdir) if i != '.gitkeep']: shutil.copytree(os.path.join(demo_subdir, item), - os.path.join(target_subdir, item)) + os.path.join(target_subdir, item), + ignore=shutil.ignore_patterns('.gitkeep')) # Published project files should have been made read-only at # the time of publication From ca56a5c41ce48a614672f3eb7c069bbf78ae9306 Mon Sep 17 00:00:00 2001 From: Benjamin Moody Date: Wed, 25 Sep 2024 13:51:38 -0400 Subject: [PATCH 2/3] loaddemo: ignore directories that already exist. If a directory such as 'media/active-projects/AGlSZa5VTv5Dg09CSpoh' already exists, and we are trying to install a demo project there, don't raise an error. That directory isn't present in the git repository, but it might have been created in the past. --- physionet-django/user/management/commands/loaddemo.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/physionet-django/user/management/commands/loaddemo.py b/physionet-django/user/management/commands/loaddemo.py index 4ae847c61..14a90a026 100644 --- a/physionet-django/user/management/commands/loaddemo.py +++ b/physionet-django/user/management/commands/loaddemo.py @@ -105,7 +105,8 @@ def copy_demo_media(): if os.path.isdir(path): shutil.copytree(os.path.join(demo_subdir, item), os.path.join(target_subdir, item), - ignore=shutil.ignore_patterns('.gitkeep')) + ignore=shutil.ignore_patterns('.gitkeep'), + dirs_exist_ok=True) else: shutil.copy(os.path.join(demo_subdir, item), os.path.join(target_subdir, item)) @@ -138,7 +139,8 @@ def copy_demo_static(): for item in [i for i in os.listdir(demo_subdir) if i != '.gitkeep']: shutil.copytree(os.path.join(demo_subdir, item), os.path.join(target_subdir, item), - ignore=shutil.ignore_patterns('.gitkeep')) + ignore=shutil.ignore_patterns('.gitkeep'), + dirs_exist_ok=True) # Published project files should have been made read-only at # the time of publication From 7787c31af4b15a1d7c24d07391e45d249e962cc1 Mon Sep 17 00:00:00 2001 From: Benjamin Moody Date: Wed, 25 Sep 2024 13:53:53 -0400 Subject: [PATCH 3/3] TestMixin: don't install ".gitkeep" files. Files called ".gitkeep" are used as placeholders to tell git to create the directory. They shouldn't be copied as part of the demo project content (in fact, a file called ".gitkeep" would not be allowed by the file upload form.) For example, the demo active project AGlSZa5VTv5Dg09CSpoh contains no actual files, but the git repository includes the file demo-files/media/active-projects/AGlSZa5VTv5Dg09CSpoh/.gitkeep - so in this case, TestMixin should create an empty project directory. --- physionet-django/user/test_views.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/physionet-django/user/test_views.py b/physionet-django/user/test_views.py index f2c5f8167..a8b784200 100644 --- a/physionet-django/user/test_views.py +++ b/physionet-django/user/test_views.py @@ -140,12 +140,14 @@ def setUp(self): """ _force_delete_tree(settings.MEDIA_ROOT) shutil.copytree(os.path.abspath(os.path.join(settings.DEMO_FILE_ROOT, 'media')), - settings.MEDIA_ROOT) + settings.MEDIA_ROOT, + ignore=shutil.ignore_patterns('.gitkeep')) self.test_static_root = settings.STATIC_ROOT if settings.STATIC_ROOT else settings.STATICFILES_DIRS[0] _force_delete_tree(self.test_static_root) shutil.copytree(os.path.abspath(os.path.join(settings.DEMO_FILE_ROOT, 'static')), - self.test_static_root) + self.test_static_root, + ignore=shutil.ignore_patterns('.gitkeep')) if os.path.exists(ORIGINAL_DBCAL_FILE): os.symlink(ORIGINAL_DBCAL_FILE, DBCAL_FILE)