Skip to content

Commit

Permalink
loaddemo: fix copying files from demo/media.
Browse files Browse the repository at this point in the history
If demo files are placed in first-level subdirectories of the media
directory, they were not being copied correctly when loading the demo.
For example, "demo-files/media/ethics/Ethics_Approval_....txt" was
incorrectly copied as "media/ethics" rather than
"media/ethics/Ethics_Approval_....txt".

Additionally, ensure that the destination directories are created if
they don't already exist.
  • Loading branch information
Benjamin Moody committed Sep 19, 2024
1 parent 93ad99a commit 3db9223
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion physionet-django/user/management/commands/loaddemo.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,15 @@ def copy_demo_media():
for subdir in os.listdir(demo_media_root):
demo_subdir = os.path.join(demo_media_root, subdir)
target_subdir = os.path.join(settings.MEDIA_ROOT, subdir)
os.makedirs(target_subdir, exist_ok=True)
for item in [i for i in os.listdir(demo_subdir) if i != '.gitkeep']:
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))
else:
shutil.copy(path, target_subdir)
shutil.copy(os.path.join(demo_subdir, item),
os.path.join(target_subdir, item))

# Published project files should have been made read-only at
# the time of publication
Expand Down

0 comments on commit 3db9223

Please sign in to comment.