Skip to content

Commit

Permalink
#74 some documentation for the management commands and some fixes for…
Browse files Browse the repository at this point in the history
… the actual commands..
  • Loading branch information
ephes committed Mar 27, 2023
1 parent bb2b48e commit 808b861
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 11 deletions.
3 changes: 2 additions & 1 deletion cast/management/commands/s3_media_sizes.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
class Command(BaseCommand):
help = "shows size of media on s3"

def show_usage(self, paths):
@staticmethod
def show_usage(paths):
video_endings = {"mov", "mp4"}
image_endings = {"jpg", "jpeg", "png"}
image, video, misc = 0, 0, 0
Expand Down
2 changes: 1 addition & 1 deletion cast/management/commands/s3_replace.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@


class Command(BaseCommand):
help = "replace paths on s3 with local versions - useful for" " compressed videos for example"
help = "replace paths on s3 with local versions - useful for compressed videos for example"

def add_arguments(self, parser):
parser.add_argument("paths", nargs="+", type=str)
Expand Down
4 changes: 2 additions & 2 deletions cast/management/commands/s3_restore.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from django.core.files.storage import default_storage, get_storage_class
from django.core.management.base import BaseCommand

from blogs.utils import storage_walk_paths
from cast.utils import storage_walk_paths


class Command(BaseCommand):
help = "restoremedia files from local media root to s3"
help = "restore media files from local media root to s3"

def handle(self, *args, **options):
s3 = get_storage_class("storages.backends.s3boto3.S3Boto3Storage")()
Expand Down
16 changes: 10 additions & 6 deletions cast/management/commands/s3_stale.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@


class Command(BaseCommand):
help = (
"show media files which are in the filesystem (s3, locale), " "but not in database and optionally delete them"
)
help = "show media files which are in the filesystem (s3, locale), but not in database and optionally delete them"

def add_arguments(self, parser):
parser.add_argument(
Expand All @@ -28,11 +26,17 @@ def get_paths(self, storage):
# print(path, size / 2 ** 20)
return paths

def get_models_paths(self):
@staticmethod
def get_image_paths() -> set[str]:
paths = set()
for image in Image.objects.all():
for path in image.get_all_paths():
paths.add(path)
paths.add(image.file.name)
for rendition in image.renditions.all():
paths.add(rendition.file.name)
return paths

def get_models_paths(self):
paths = self.get_image_paths()
for video in Video.objects.all():
for path in video.get_all_paths():
paths.add(path)
Expand Down
2 changes: 2 additions & 0 deletions docs/features.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,5 @@ using the Wagtail or Django-Admin interface, the Page and all its subpages
will be excluded from being indexed by search engines.

.. include:: themes.rst

.. include:: management-commands.rst
16 changes: 16 additions & 0 deletions docs/management-commands.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
*********************
Django-Admin Commands
*********************

There are some management-commands bundled with django-cast. Most of them
are dealing with the management of media files.

* ``recalc_video_posters``: Recalculate the poster images for all videos.
* ``s3_backup``: Backup media files from S3 to local media root.
* ``s3_media_sizes``: Print the sizes of all media files on S3.
* ``s3_replace``: Replace paths on s3 with versions from local media root.
This might be useful for videos for which you now have a better compressed
version, but you don't want to generate a new name.
* ``s3_restore``: Restore media files from local media root to S3.
* ``s3_stale``: Print the paths of all media files on S3 that are not
referenced in the database.
3 changes: 2 additions & 1 deletion docs/releases/0.2.11.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
-------------------

Htmx for filters
* ...

* #74 Added some documentation for django-admin commands and fixed ``s3_stale``
1 change: 1 addition & 0 deletions docs/releases/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Versions
.. toctree::
:maxdepth: 1

0.2.11
0.2.10
0.2.9
0.2.8
Expand Down

0 comments on commit 808b861

Please sign in to comment.