|
42 | 42 | from readthedocs.vcs_support.backends import backend_cls
|
43 | 43 | from readthedocs.vcs_support.utils import Lock, NonBlockingLock
|
44 | 44 |
|
| 45 | +from .constants import MEDIA_TYPES |
| 46 | + |
45 | 47 |
|
46 | 48 | log = logging.getLogger(__name__)
|
47 |
| -storage = get_storage_class()() |
48 | 49 |
|
49 | 50 |
|
50 | 51 | class ProjectRelationship(models.Model):
|
@@ -463,6 +464,29 @@ def save(self, *args, **kwargs): # pylint: disable=arguments-differ
|
463 | 464 | except Exception:
|
464 | 465 | log.exception('Error creating default branches')
|
465 | 466 |
|
| 467 | + def delete(self, *args, **kwargs): # pylint: disable=arguments-differ |
| 468 | + from readthedocs.projects import tasks |
| 469 | + |
| 470 | + # Remove local FS build artifacts on the web servers |
| 471 | + broadcast( |
| 472 | + type='app', |
| 473 | + task=tasks.remove_dirs, |
| 474 | + args=[(self.doc_path,)], |
| 475 | + ) |
| 476 | + |
| 477 | + # Remove build artifacts from storage |
| 478 | + storage_paths = [] |
| 479 | + for type_ in MEDIA_TYPES: |
| 480 | + storage_paths.append( |
| 481 | + '{}/{}'.format( |
| 482 | + type_, |
| 483 | + self.slug, |
| 484 | + ) |
| 485 | + ) |
| 486 | + tasks.remove_build_storage_paths.delay(storage_paths) |
| 487 | + |
| 488 | + super().delete(*args, **kwargs) |
| 489 | + |
466 | 490 | def get_absolute_url(self):
|
467 | 491 | return reverse('projects_detail', args=[self.slug])
|
468 | 492 |
|
@@ -750,28 +774,49 @@ def has_pdf(self, version_slug=LATEST):
|
750 | 774 | path = self.get_production_media_path(
|
751 | 775 | type_='pdf', version_slug=version_slug
|
752 | 776 | )
|
753 |
| - storage_path = self.get_storage_path( |
754 |
| - type_='pdf', version_slug=version_slug |
755 |
| - ) |
756 |
| - return os.path.exists(path) or storage.exists(storage_path) |
| 777 | + if os.path.exists(path): |
| 778 | + return True |
| 779 | + |
| 780 | + if settings.RTD_BUILD_MEDIA_STORAGE: |
| 781 | + storage = get_storage_class(settings.RTD_BUILD_MEDIA_STORAGE)() |
| 782 | + storage_path = self.get_storage_path( |
| 783 | + type_='pdf', version_slug=version_slug |
| 784 | + ) |
| 785 | + return storage.exists(storage_path) |
| 786 | + |
| 787 | + return False |
757 | 788 |
|
758 | 789 | def has_epub(self, version_slug=LATEST):
|
759 | 790 | path = self.get_production_media_path(
|
760 | 791 | type_='epub', version_slug=version_slug
|
761 | 792 | )
|
762 |
| - storage_path = self.get_storage_path( |
763 |
| - type_='epub', version_slug=version_slug |
764 |
| - ) |
765 |
| - return os.path.exists(path) or storage.exists(storage_path) |
| 793 | + if os.path.exists(path): |
| 794 | + return True |
| 795 | + |
| 796 | + if settings.RTD_BUILD_MEDIA_STORAGE: |
| 797 | + storage = get_storage_class(settings.RTD_BUILD_MEDIA_STORAGE)() |
| 798 | + storage_path = self.get_storage_path( |
| 799 | + type_='epub', version_slug=version_slug |
| 800 | + ) |
| 801 | + return storage.exists(storage_path) |
| 802 | + |
| 803 | + return False |
766 | 804 |
|
767 | 805 | def has_htmlzip(self, version_slug=LATEST):
|
768 | 806 | path = self.get_production_media_path(
|
769 | 807 | type_='htmlzip', version_slug=version_slug
|
770 | 808 | )
|
771 |
| - storage_path = self.get_storage_path( |
772 |
| - type_='htmlzip', version_slug=version_slug |
773 |
| - ) |
774 |
| - return os.path.exists(path) or storage.exists(storage_path) |
| 809 | + if os.path.exists(path): |
| 810 | + return True |
| 811 | + |
| 812 | + if settings.RTD_BUILD_MEDIA_STORAGE: |
| 813 | + storage = get_storage_class(settings.RTD_BUILD_MEDIA_STORAGE)() |
| 814 | + storage_path = self.get_storage_path( |
| 815 | + type_='htmlzip', version_slug=version_slug |
| 816 | + ) |
| 817 | + return storage.exists(storage_path) |
| 818 | + |
| 819 | + return False |
775 | 820 |
|
776 | 821 | @property
|
777 | 822 | def sponsored(self):
|
|
0 commit comments