예제 #1
0
    def get_filename(self, basename):
        """
        Returns full path to a file, for example:

        get_filename('css/one.css') -> '/full/path/to/static/css/one.css'
        """
        filename = None
        # First try finding the file using the storage class.
        # This is skipped in DEBUG mode as files might be outdated in
        # compressor's final destination (COMPRESS_ROOT) during development
        if not settings.DEBUG:
            try:
                # call path first so remote storages don't make it to exists,
                # which would cause network I/O
                filename = self.storage.path(basename)
                if not self.storage.exists(basename):
                    filename = None
            except NotImplementedError:
                # remote storages don't implement path, access the file locally
                if compressor_file_storage.exists(basename):
                    filename = compressor_file_storage.path(basename)
        # secondly try to find it with staticfiles
        if not filename and self.finders:
            filename = self.finders.find(url2pathname(basename))
        if filename:
            return filename
        # or just raise an exception as the last resort
        raise UncompressableFileError(
            "'%s' could not be found in the COMPRESS_ROOT '%s'%s" %
            (basename, settings.COMPRESS_ROOT,
             self.finders and " or with staticfiles." or "."))
예제 #2
0
    def get_filename(self, basename):
        """
        Returns full path to a file, for example:

        get_filename('css/one.css') -> '/full/path/to/static/css/one.css'
        """
        filename = None
        # First try finding the file using the storage class.
        # This is skipped in DEBUG mode as files might be outdated in
        # compressor's final destination (COMPRESS_ROOT) during development
        if not settings.DEBUG:
            try:
                # call path first so remote storages don't make it to exists,
                # which would cause network I/O
                filename = self.storage.path(basename)
                if not self.storage.exists(basename):
                    filename = None
            except NotImplementedError:
                # remote storages don't implement path, access the file locally
                if compressor_file_storage.exists(basename):
                    filename = compressor_file_storage.path(basename)
        # secondly try to find it with staticfiles
        if not filename and self.finders:
            filename = self.finders.find(url2pathname(basename))
        if filename:
            return filename
        # or just raise an exception as the last resort
        raise UncompressableFileError(
            "'%s' could not be found in the COMPRESS_ROOT '%s'%s" %
            (basename, settings.COMPRESS_ROOT,
             self.finders and " or with staticfiles." or "."))
예제 #3
0
 def get_filename(self, basename):
     filename = None
     if self.finders:
         filename = self.finders.find(urllib.url2pathname(basename))
     if not filename and self.storage.exists(basename):
         try:
             filename = self.storage.path(basename)
         except NotImplementedError:
             # remote storages don't implement path, access the file locally
             filename = compressor_file_storage.path(basename)
     if filename:
         return filename
     # or just raise an exception as the last resort
     raise UncompressableFileError(
         "'%s' could not be found in the COMPRESS_ROOT '%s'%s" %
         (basename, settings.COMPRESS_ROOT,
          self.finders and " or with staticfiles." or "."))
예제 #4
0
 def get_filename(self, basename):
     filename = None
     # first try finding the file in the root
     if self.storage.exists(basename):
         try:
             filename = self.storage.path(basename)
         except NotImplementedError:
             # remote storages don't implement path, access the file locally
             filename = compressor_file_storage.path(basename)
     # secondly try to find it with staticfiles (in debug mode)
     elif self.finders:
         filename = self.finders.find(urllib.url2pathname(basename))
     if filename:
         return filename
     # or just raise an exception as the last resort
     raise UncompressableFileError(
         "'%s' could not be found in the COMPRESS_ROOT '%s'%s" %
         (basename, settings.COMPRESS_ROOT,
          self.finders and " or with staticfiles." or "."))
예제 #5
0
 def get_filename(self, basename):
     filename = None
     # first try finding the file in the root
     try:
         # call path first so remote storages don't make it to exists,
         # which would cause network I/O
         filename = self.storage.path(basename)
         if not self.storage.exists(basename):
             filename = None
     except NotImplementedError:
         # remote storages don't implement path, access the file locally
         if compressor_file_storage.exists(basename):
             filename = compressor_file_storage.path(basename)
     # secondly try to find it with staticfiles (in debug mode)
     if not filename and self.finders:
         filename = self.finders.find(urllib.url2pathname(basename))
     if filename:
         return filename
     # or just raise an exception as the last resort
     raise UncompressableFileError(
         "'%s' could not be found in the COMPRESS_ROOT '%s'%s" %
         (basename, settings.COMPRESS_ROOT,
          self.finders and " or with staticfiles." or "."))