Skip to content

Commit

Permalink
Moved fs creation into the apps.py
Browse files Browse the repository at this point in the history
  • Loading branch information
palewire committed Dec 24, 2017
1 parent 759ae07 commit 78e9c9c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
5 changes: 3 additions & 2 deletions bakery/apps.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from django.apps import AppConfig
import fs
from django.conf import settings
from django.apps import AppConfig


class BakeryConfig(AppConfig):
name = 'bakery'
verbose_name = "Bakery"

def ready(self):
pass
self.filesystem = fs.open_fs(getattr(settings, 'BAKERY_FILESYSTEM', "osfs:///"))
6 changes: 3 additions & 3 deletions bakery/management/commands/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
import gzip
import logging
import mimetypes
from fs import path
import multiprocessing
from fs import open_fs, path
from django.apps import apps
from django.conf import settings
from django.core import management
from multiprocessing.pool import ThreadPool
Expand Down Expand Up @@ -118,10 +119,9 @@ def set_options(self, *args, **options):
self.build_dir = six.u(self.build_dir)
self.static_root = six.u(settings.STATIC_ROOT)
self.media_root = settings.MEDIA_ROOT
self.filesystem = getattr(settings, 'BAKERY_FILESYSTEM', "osfs:///")

# Connect the BUILD_DIR with our filesystem backend
self.fs = open_fs(self.filesystem)
self.fs = apps.get_app_config("bakery").filesystem

# If the build dir doesn't exist make it
if not self.fs.exists(self.build_dir):
Expand Down
7 changes: 3 additions & 4 deletions bakery/views/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import gzip
import logging
import mimetypes
from fs import open_fs
from django.apps import apps
from django.conf import settings
from bakery import DEFAULT_GZIP_CONTENT_TYPES
from django.test.client import RequestFactory
Expand All @@ -28,8 +28,6 @@ class BuildableMixin(object):
"""
Common methods we will use in buildable views.
"""
filesystem = open_fs(getattr(settings, 'BAKERY_FILESYSTEM', "osfs:///"))

def create_request(self, path):
"""
Returns a GET request object for use when building views.
Expand Down Expand Up @@ -70,7 +68,8 @@ def write_file(self, path, html):
Writes out the provided HTML to the provided path.
"""
logger.debug("Building HTML file to %s" % path)
with self.filesystem.open(six.u(path), 'wb') as outfile:
fs = apps.get_app_config("bakery").filesystem
with fs.open(six.u(path), 'wb') as outfile:
outfile.write(six.binary_type(html))
outfile.close()

Expand Down

0 comments on commit 78e9c9c

Please sign in to comment.