Skip to content
This repository has been archived by the owner on Jan 16, 2023. It is now read-only.

implement filesystem strategy (closes #139) #156

Merged
merged 1 commit into from
Oct 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ A faster collectstatic command.
- ``storages.backends.s3boto.S3BotoStorage`` (deprecated)
- ``storages.backends.s3boto3.S3Boto3Storage``
- ``storages.backends.gcloud.GoogleCloudStorage``
- ``django.core.files.storage.FileSystemStorage``

Running Django's ``collectstatic`` command can become painfully slow as more
and more files are added to a project, especially when heavy libraries such as
Expand Down Expand Up @@ -54,15 +55,17 @@ Make sure you have this in your settings file and add ``'collectfast'`` to your
Supported Strategies
~~~~~~~~~~~~~~~~~~~~

+-----------------------------------------------------+-----------------------------------------------+
|Strategy class |Storage class |
+=====================================================+===============================================+
|``collectfast.strategies.boto.BotoStrategy`` |``storages.backends.s3boto.S3BotoStorage`` |
+-----------------------------------------------------+-----------------------------------------------+
|``collectfast.strategies.boto3.Boto3Strategy`` |``storages.backends.s3boto3.S3Boto3Storage`` |
+-----------------------------------------------------+-----------------------------------------------+
|``collectfast.strategies.gcloud.GoogleCloudStrategy``|``storages.backends.gcloud.GoogleCloudStorage``|
+-----------------------------------------------------+-----------------------------------------------+
+--------------------------------------------------------+-----------------------------------------------+
|Strategy class |Storage class |
+========================================================+===============================================+
|``collectfast.strategies.boto.BotoStrategy`` |``storages.backends.s3boto.S3BotoStorage`` |
+--------------------------------------------------------+-----------------------------------------------+
|``collectfast.strategies.boto3.Boto3Strategy`` |``storages.backends.s3boto3.S3Boto3Storage`` |
+--------------------------------------------------------+-----------------------------------------------+
|``collectfast.strategies.gcloud.GoogleCloudStrategy`` |``storages.backends.gcloud.GoogleCloudStorage``|
+--------------------------------------------------------+-----------------------------------------------+
|``collectfast.strategies.filesystem.FileSystemStrategy``|``django.core.files.storage.FileSystemStorage``|
+--------------------------------------------------------+-----------------------------------------------+


Usage
Expand Down
2 changes: 1 addition & 1 deletion collectfast/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.2.0"
__version__ = "1.3.0"
14 changes: 14 additions & 0 deletions collectfast/strategies/filesystem.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from typing import Optional

from django.core.files.storage import FileSystemStorage

from .base import HashStrategy


class FileSystemStrategy(HashStrategy[FileSystemStorage]):
def get_remote_file_hash(self, prefixed_path):
# type: (str) -> Optional[str]
try:
return self.get_local_file_hash(prefixed_path, self.remote_storage)
except FileNotFoundError:
return None
1 change: 1 addition & 0 deletions collectfast/tests/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
INSTALLED_APPS = ("collectfast", "django.contrib.staticfiles")
STATIC_URL = "/staticfiles/"
STATIC_ROOT = str(base_path / "static_root")
MEDIA_ROOT = str(base_path / "fs_remote")
STATICFILES_DIRS = [str(base_path / "static")]
STATICFILES_STORAGE = "storages.backends.s3boto3.S3Boto3Storage"
COLLECTFAST_STRATEGY = "collectfast.strategies.boto3.Boto3Strategy"
Expand Down
8 changes: 6 additions & 2 deletions collectfast/tests/test_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,14 @@
all_backend_confs = aws_backend_confs.copy()
all_backend_confs.update(
{
"google": override_django_settings(
"gcloud": override_django_settings(
STATICFILES_STORAGE="storages.backends.gcloud.GoogleCloudStorage",
COLLECTFAST_STRATEGY="collectfast.strategies.gcloud.GoogleCloudStrategy",
)
),
"filesystem": override_django_settings(
STATICFILES_STORAGE="django.core.files.storage.FileSystemStorage",
COLLECTFAST_STRATEGY="collectfast.strategies.filesystem.FileSystemStrategy",
),
}
)

Expand Down
10 changes: 10 additions & 0 deletions collectfast/tests/test_storages/filesystem_subtype.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import pathlib

from django.core.files.storage import FileSystemStorage


class TestFileSystemStorage(FileSystemStorage):
def __init__(self):
# type: () -> None
output = str(pathlib.Path(__file__).parent / "fs-remote")
super().__init__(location=output)
6 changes: 5 additions & 1 deletion runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,16 @@ def main():
parent_dir, app_name = os.path.split(app_path)
sys.path.insert(0, parent_dir)

# create static dir
# create static dirs
staticfiles_dir = test_settings.STATICFILES_DIRS[0]
staticroot_dir = test_settings.STATIC_ROOT
fs_remote = test_settings.MEDIA_ROOT
if not os.path.exists(staticfiles_dir):
os.makedirs(staticfiles_dir)
if not os.path.exists(staticroot_dir):
os.makedirs(staticroot_dir)
if not os.path.exists(fs_remote):
os.makedirs(fs_remote)

if options.target is not None:
test_arg = "%s.%s" % (app_name, options.target)
Expand All @@ -54,6 +57,7 @@ def main():
# delete static dirs
shutil.rmtree(staticfiles_dir)
shutil.rmtree(staticroot_dir)
shutil.rmtree(fs_remote)


if __name__ == "__main__":
Expand Down