Skip to content

Commit 278db8a

Browse files
authored
Merge pull request readthedocs#5418 from stsewd/refactor-move-files
Refactor move_files
2 parents 0bfccf1 + e565fce commit 278db8a

File tree

1 file changed

+12
-49
lines changed

1 file changed

+12
-49
lines changed

readthedocs/projects/tasks.py

+12-49
Original file line numberDiff line numberDiff line change
@@ -998,64 +998,28 @@ def move_files(
998998
return
999999

10001000
# This is False if we have already synced media files to blob storage
1001-
# We set `epub=False` for example so data doesn't get re-uploaded on each web,
1002-
# so we need this to protect against deleting in those cases
1001+
# We set `epub=False` for example so data doesn't get re-uploaded on each
1002+
# web, so we need this to protect against deleting in those cases
10031003
if delete_unsynced_media:
1004-
1005-
if not pdf:
1006-
1007-
remove_dirs([
1008-
version.project.get_production_media_path(
1009-
type_='pdf',
1010-
version_slug=version.slug,
1011-
include_file=False,
1012-
),
1013-
])
1014-
1015-
if getattr(storage, 'write_build_media', False):
1016-
# Remove PDF from remote storage if it exists
1017-
storage_path = version.project.get_storage_path(
1018-
type_='pdf',
1019-
version_slug=version.slug,
1020-
)
1021-
if storage.exists(storage_path):
1022-
log.info('Removing %s from media storage', storage_path)
1023-
storage.delete(storage_path)
1024-
1025-
if not epub:
1026-
1027-
remove_dirs([
1028-
version.project.get_production_media_path(
1029-
type_='epub',
1030-
version_slug=version.slug,
1031-
include_file=False,
1032-
),
1033-
])
1034-
1035-
if getattr(storage, 'write_build_media', False):
1036-
# Remove ePub from remote storage if it exists
1037-
storage_path = version.project.get_storage_path(
1038-
type_='epub',
1039-
version_slug=version.slug,
1040-
)
1041-
if storage.exists(storage_path):
1042-
log.info('Removing %s from media storage', storage_path)
1043-
storage.delete(storage_path)
1044-
1045-
if not localmedia:
1046-
1004+
downloads = {
1005+
'pdf': pdf,
1006+
'epub': epub,
1007+
'htmlzip': localmedia,
1008+
}
1009+
unsync_downloads = (k for k, v in downloads.items() if not v)
1010+
for media_type in unsync_downloads:
10471011
remove_dirs([
10481012
version.project.get_production_media_path(
1049-
type_='htmlzip',
1013+
type_=media_type,
10501014
version_slug=version.slug,
10511015
include_file=False,
10521016
),
10531017
])
10541018

10551019
if getattr(storage, 'write_build_media', False):
1056-
# Remove ePub from remote storage if it exists
1020+
# Remove the media from remote storage if it exists
10571021
storage_path = version.project.get_storage_path(
1058-
type_='htmlzip',
1022+
type_=media_type,
10591023
version_slug=version.slug,
10601024
)
10611025
if storage.exists(storage_path):
@@ -1104,7 +1068,6 @@ def move_files(
11041068
include_file=True,
11051069
)
11061070
Syncer.copy(from_path, to_path, host=hostname, is_file=True)
1107-
# Always move PDF's because the return code lies.
11081071
if pdf:
11091072
from_path = os.path.join(
11101073
version.project.artifact_path(

0 commit comments

Comments
 (0)