Пример #1
0
 def list(self, ignore_patterns):
     result = []
     for prefix, path in logo_paths.items():
         if not path:
             continue
         basedir, filename = os.path.split(path)
         storage = FileSystemStorage(location=basedir)
         storage.prefix = prefix
         result.append((filename, storage))
     if settings.FAVICON_PACKAGE and os.path.isdir(settings.FAVICON_PACKAGE):
         storage = FileSystemStorage(location=settings.FAVICON_PACKAGE)
         storage.prefix = 'favicon_package'
         result += [(filename, storage) for filename in favicon_package_files]
     return result
Пример #2
0
    def list(self, ignore_patterns):
        re_patterns = []

        for pattern in ignore_patterns:
            if pattern.startswith('*'):
                re_pattern = re.compile(pattern[1:].replace('.', '\\.') + '$')
            elif pattern.endswith('*'):
                re_pattern = re.compile('^' + pattern[:-1].replace('.', '\\.'))
            else:
                re_pattern = re.compile(pattern)

            if re_pattern is not None:
                re_patterns.append(re_pattern)

        for helio_static_dir in self.helio_static_dirs:
            storage = FileSystemStorage(location=helio_static_dir)
            for static_file in listdir(helio_static_dir):
                yield (static_file, storage)

        for component_base_dir in self.component_base_directories:
            for (dir_root, dir_list, file_list) in walk_component_base_dir(component_base_dir):
                for static_file in file_list:
                    if should_ignore_file(static_file, re_patterns):
                        continue

                    full_static_path = join(dir_root, static_file)

                    res = re.search(r'/(.*)/static', full_static_path)
                    if res is None:
                        continue

                    storage = FileSystemStorage(location=dir_root)
                    storage.prefix = res.group(1)
                    yield (static_file, storage)
Пример #3
0
 def __init__(self, apps=None, *args, **kwargs):
     from staticpreprocessor.conf import settings
     # List of locations with static files
     self.locations = []
     # Maps dir paths to an appropriate storage instance
     self.storages = SortedDict()
     if not isinstance(settings.STATIC_PREPROCESSOR_DIRS, (list, tuple)):
         raise ImproperlyConfigured(
             'Your STATIC_PREPROCESSOR_DIRS setting is not a tuple or '
             'list; perhaps you forgot a trailing comma?')
     for root in settings.STATIC_PREPROCESSOR_DIRS:
         if isinstance(root, (list, tuple)):
             prefix, root = root
         else:
             prefix = ''
         if os.path.abspath(settings.STATIC_PREPROCESSOR_ROOT) == \
                 os.path.abspath(root):
             raise ImproperlyConfigured(
                 'The STATIC_PREPROCESSOR_DIRS setting should '
                 'not contain the STATIC_PREPROCESSOR_ROOT setting')
         if (prefix, root) not in self.locations:
             self.locations.append((prefix, root))
     for prefix, root in self.locations:
         filesystem_storage = FileSystemStorage(location=root)
         filesystem_storage.prefix = prefix
         self.storages[root] = filesystem_storage
Пример #4
0
    def __init__(self, apps=None, *args, **kwargs):
        self.locations = [("", self._get_bower_components_location())]
        self.storages = collections.OrderedDict()

        filesystem_storage = FileSystemStorage(location=self.locations[0][1])
        filesystem_storage.prefix = self.locations[0][0]
        self.storages[self.locations[0][1]] = filesystem_storage
Пример #5
0
 def __init__(self, apps=None, *args, **kwargs):
     # List of locations with static files
     self.locations = []
     # Maps dir paths to an appropriate storage instance
     self.storages = SortedDict()
     if not isinstance(settings.STATICFILES_DIRS, (list, tuple)):
         raise ImproperlyConfigured(
             "Your STATICFILES_DIRS setting is not a tuple or list; "
             "perhaps you forgot a trailing comma?")
     for root in settings.STATICFILES_DIRS:
         if isinstance(root, (list, tuple)):
             prefix, root = root
         else:
             prefix = ''
         if settings.STATIC_ROOT and os.path.abspath(settings.STATIC_ROOT) == os.path.abspath(root):
             raise ImproperlyConfigured(
                 "The STATICFILES_DIRS setting should "
                 "not contain the STATIC_ROOT setting")
         if (prefix, root) not in self.locations:
             self.locations.append((prefix, root))
     for prefix, root in self.locations:
         filesystem_storage = FileSystemStorage(location=root)
         filesystem_storage.prefix = prefix
         self.storages[root] = filesystem_storage
     super(FileSystemFinder, self).__init__(*args, **kwargs)
Пример #6
0
    def __init__(self, apps=None, *args, **kwargs):
        self.locations = [
            ('', self._get_upload_media_location()),
        ]
        self.storages = SortedDict()

        filesystem_storage = FileSystemStorage(location=self.locations[0][1])
        filesystem_storage.prefix = self.locations[0][0]
        self.storages[self.locations[0][1]] = filesystem_storage
Пример #7
0
    def __init__(self, apps=None, *args, **kwargs):
        files = get_files(getattr(settings, "NPM_EXECUTABLE_PATH", None), getattr(settings, "NPM_PREFIX_PATH", None))
        destination = getattr(settings, "NPM_DESTINATION_PREFIX", "")
        self.locations = [(destination, files)]
        self.storages = OrderedDict()

        filesystem_storage = FileSystemStorage(location=self.locations[0][1])
        filesystem_storage.prefix = self.locations[0][0]
        self.storages[self.locations[0][1]] = filesystem_storage
Пример #8
0
 def list(self, ignore_patterns):
     storyfiles_dir = settings.HOMESTUCK_STORYFILES_DIR
     dirs = glob(os.path.join(storyfiles_dir, "*", "img")) + \
            glob(os.path.join(storyfiles_dir, "*", "*", "img"))
     for directory in dirs:
         storage = FileSystemStorage(location=directory)
         storage.prefix = "storyfiles"
         for path in utils.get_files(storage, ignore_patterns):
            yield path, storage
Пример #9
0
    def __init__(self, apps=None, *args, **kwargs):
        self.themes = {}

        for theme in get_available_themes():
            prefix = "theme%s%s" % (os.sep, theme)
            self.themes[theme] = []
            theme_chain = get_theme_chain(theme)
            for theme_module in theme_chain:
                storage = FileSystemStorage(get_theme_dir(theme_module, "static"))
                storage.prefix = prefix
                self.themes[theme].append(storage)
Пример #10
0
 def __init__(self, apps=None, *args, **kwargs):
     location = getattr(settings, 'SASS_PROCESSOR_ROOT', settings.STATIC_ROOT)
     if not os.path.isdir(location):
         return
     self.locations = [
         ('', location),
     ]
     self.storages = OrderedDict()
     filesystem_storage = FileSystemStorage(location=location)
     filesystem_storage.prefix = self.locations[0][0]
     self.storages[location] = filesystem_storage
Пример #11
0
    def __init__(self, apps=None, *args, **kwargs):
        self.locations = []
        self.storages = OrderedDict()

        root = self._get_bower_components_location()
        if root is not None:
            prefix = ''
            self.locations.append((prefix, root))

            filesystem_storage = FileSystemStorage(location=root)
            filesystem_storage.prefix = prefix
            self.storages[root] = filesystem_storage
Пример #12
0
 def __init__(self, apps=None, *args, **kwargs):
     nodebow_root = getattr(settings, 'NODEBOW_ROOT', settings.STATIC_ROOT)
     bower_components = os.path.abspath(os.path.join(nodebow_root, 'bower_components'))
     if not os.path.isdir(bower_components):
         return
     self.locations = [
         ('', bower_components),
     ]
     self.storages = OrderedDict()
     filesystem_storage = FileSystemStorage(location=bower_components)
     filesystem_storage.prefix = self.locations[0][0]
     self.storages[bower_components] = filesystem_storage
Пример #13
0
    def __init__(self, apps=None, *args, **kwargs):
        # List of locations with static files
        self.locations = [('', settings.VERSIONED_STATIC_ROOT), ]
        # Maps dir paths to an appropriate storage instance
        self.storages = SortedDict()

        for prefix, root in self.locations:
            filesystem_storage = FileSystemStorage(location=root)
            filesystem_storage.prefix = prefix
            self.storages[root] = filesystem_storage

        super(FileSystemFinder, self).__init__(*args, **kwargs)
Пример #14
0
 def __init__(self, app_names=None, *args, **kwargs):
     self.locations = []
     self.storages = collections.OrderedDict()
     for dependency in self.dependencies:
         module = __import__(dependency)
         path = '{0}/static'.format(os.path.dirname(module.__file__))
         self.locations.append(('', path))
     for prefix, root in self.locations:
         filesystem_storage = FileSystemStorage(location=root)
         filesystem_storage.prefix = prefix
         self.storages[root] = filesystem_storage
     super(FileSystemFinder, self).__init__(*args, **kwargs)
Пример #15
0
    def __init__(self, apps=None, *args, **kwargs):
        self.locations = [
            ('', self._get_bower_components_location()),
        ]
        try:
            self.storages = collections.OrderedDict()
        except AttributeError:
            from ordereddict import OrderedDict
            self.storages = OrderedDict()

        filesystem_storage = FileSystemStorage(location=self.locations[0][1])
        filesystem_storage.prefix = self.locations[0][0]
        self.storages[self.locations[0][1]] = filesystem_storage
Пример #16
0
    def __init__(self, apps=None, *args, **kwargs):
        self.npm_executable_path = getattr(settings, 'NPM_EXECUTABLE_PATH', 'npm')
        self.npm_prefix_path = getattr(settings, 'NPM_PREFIX_PATH', '')
        files = self.__get_files()
        destination = getattr(settings, 'NPM_DESTINATION_PREFIX', '')
        self.locations = [
            (destination, files),
        ]
        self.storages = OrderedDict()

        filesystem_storage = FileSystemStorage(location=self.locations[0][1])
        filesystem_storage.prefix = self.locations[0][0]
        self.storages[self.locations[0][1]] = filesystem_storage
Пример #17
0
    def __init__(self, apps=None, *args, **kwargs):
        # List of locations with static files
        self.locations = get_directories_in_tethys(('static', 'public'), with_app_name=True)

        # Maps dir paths to an appropriate storage instance
        self.storages = SortedDict()

        for prefix, root in self.locations:
            filesystem_storage = FileSystemStorage(location=root)
            filesystem_storage.prefix = prefix
            self.storages[root] = filesystem_storage

        super().__init__(*args, **kwargs)
Пример #18
0
    def __init__(self, apps=None, *args, **kwargs):
        self.node_modules_path = get_yarn_root_path()
        self.destination = getattr(settings, 'YARN_STATIC_FILES_PREFIX', '')
        self.cache_enabled = getattr(settings, 'YARN_FINDER_USE_CACHE', True)
        self.cached_list = None

        self.match_patterns = flatten_patterns(getattr(settings, 'YARN_FILE_PATTERNS', None)) or ['*']
        self.locations = [(self.destination, os.path.join(self.node_modules_path, 'node_modules'))]
        self.storages = OrderedDict()

        filesystem_storage = FileSystemStorage(location=self.locations[0][1])
        filesystem_storage.prefix = self.locations[0][0]
        self.storages[self.locations[0][1]] = filesystem_storage
Пример #19
0
 def __init__(self, *args, **kwargs):
     # The list of plugins that are handled
     self.locations = []
     # Mapping of plugin module paths to storage instances
     self.storages = SortedDict()
     plugins_dir = self.get_immediate_subdirs(settings.PLUGIN_DIR)
     for root in plugins_dir:
         if not os.path.exists(root) or not os.path.isdir(root):
             continue
         if ('', root) not in self.locations:
             self.locations.append(('', root))
     for _, root in self.locations:
         filesystem_storage = FileSystemStorage(location=root)
         filesystem_storage.prefix = ''
         self.storages[root] = filesystem_storage
Пример #20
0
    def __init__(self, apps=None, *args, **kwargs):
        files_settings = {}
        if hasattr(settings, 'NPM_EXECUTABLE_PATH'):
            files_settings['npm_executable_path'] = settings.NPM_EXECUTABLE_PATH
        if hasattr(settings, 'NPM_PREFIX_PATH'):
            files_settings['npm_prefix_path'] = settings.NPM_PREFIX_PATH
        files = get_node_modules_files(**files_settings)
        destination = getattr(settings, 'NPM_DESTINATION_PREFIX', '')
        self.locations = [
            (destination, files),
        ]
        self.storages = OrderedDict()

        filesystem_storage = FileSystemStorage(location=self.locations[0][1])
        filesystem_storage.prefix = self.locations[0][0]
        self.storages[self.locations[0][1]] = filesystem_storage
Пример #21
0
 def __init__(self, app_names=None, *args, **kwargs):
     # List of locations with static files
     self.locations = []
     # Maps dir paths to an appropriate storage instance
     self.storages = {}
     for root in settings.STATICFILES_DIRS:
         if isinstance(root, (list, tuple)):
             prefix, root = root
         else:
             prefix = ""
         if (prefix, root) not in self.locations:
             self.locations.append((prefix, root))
     for prefix, root in self.locations:
         filesystem_storage = FileSystemStorage(location=root)
         filesystem_storage.prefix = prefix
         self.storages[root] = filesystem_storage
     super().__init__(*args, **kwargs)
Пример #22
0
 def __init__(self, app_names=None, *args, **kwargs):
     # List of locations with static files
     self.locations = []
     # Maps dir paths to an appropriate storage instance
     self.storages = OrderedDict()
     for root in settings.STATICFILES_DIRS:
         if isinstance(root, (list, tuple)):
             prefix, root = root
         else:
             prefix = ''
         if (prefix, root) not in self.locations:
             self.locations.append((prefix, root))
     for prefix, root in self.locations:
         filesystem_storage = FileSystemStorage(location=root)
         filesystem_storage.prefix = prefix
         self.storages[root] = filesystem_storage
     super().__init__(*args, **kwargs)
Пример #23
0
 def get_locations(self):
     #pylint:disable=too-many-locals
     locations = []
     storages = OrderedDict()
     roots = []
     site = get_current_site()
     if site is not None:
         # ``site`` could be ``None`` when this code is used through
         # a manage.py command (ex: collectstatic).
         #
         # Here we are inserting the *theme* at a natural place,
         # i.e. before the path postfix matching STATIC_URL.
         url_parts = []
         for part in django_settings.STATIC_URL.split('/'):
             if part:
                 url_parts.append(part)
         for static_dir in STATICFILES_DIRS:
             drive, path = os.path.splitdrive(static_dir)
             dir_parts = path.split(os.sep)
             nb_dir_parts = len(dir_parts)
             nb_url_parts = len(url_parts)
             cut_point = nb_dir_parts - nb_url_parts
             if cut_point > 0:
                 for dir_part, url_part in zip(dir_parts[cut_point:],
                                               url_parts):
                     if dir_part != url_part:
                         cut_point = nb_dir_parts
                         break
             else:
                 cut_point = nb_dir_parts
             for theme in get_current_site().get_templates():
                 roots.append(
                     os.path.join(
                         drive, os.sep,
                         *(dir_parts[:cut_point] + [theme] +
                           dir_parts[cut_point:])))
     for root in roots:
         prefix = ''
         if (prefix, root) not in locations:
             locations.append((prefix, root))
             filesystem_storage = FileSystemStorage(location=root)
             filesystem_storage.prefix = prefix
             storages[root] = filesystem_storage
     locations = locations + self.locations
     storages.update(self.storages)
     return locations, storages
Пример #24
0
    def __init__(self, apps=None, *args, **kwargs):
        super(AppDirectoriesFinder, self).__init__(apps, *args, **kwargs)

        # Extends apps, add to storages
        layers = list(get_current_layer_stack(get_current_request()))
        layers.reverse()
        processed = []
        for k, v in list(self.storages.items()):
            for layer in layers:
                pth = os.path.join(v.location, layer)
                if os.path.exists(pth) and (pth not in processed):
                    processed.append(pth)
                    # We're not really adding an app, but the superclass
                    # attaches no app specific logic to it so it is safe.
                    self.apps.append(pth)
                    filesystem_storage = FileSystemStorage(location=pth)
                    filesystem_storage.prefix = ""
                    self.storages[pth] = filesystem_storage
Пример #25
0
    def __init__(self, apps=None, *args, **kwargs):
        # Maps dir paths to an appropriate storage instance
        self.storages = SortedDict()
        # Set of locations with static files
        self.locations = set()
        for root in settings.STATICFILES_DIRS:
            if isinstance(root, (list, tuple)):
                prefix, root = root
            else:
                prefix = ''
            self.locations.add((prefix, root))
        # Don't initialize multiple storages for the same location
        for prefix, root in self.locations:
            filesystem_storage = FileSystemStorage(location=root)
            filesystem_storage.prefix = prefix
            self.storages[root] = filesystem_storage

        super(FileSystemFinder, self).__init__(*args, **kwargs)
Пример #26
0
    def __init__(self, apps=None, *args, **kwargs):
        super(AppDirectoriesFinder, self).__init__(apps, *args, **kwargs)

        # Extends apps, add to storages
        layers = list(get_current_layer_stack(get_current_request()))
        layers.reverse()
        processed = []
        for k, v in self.storages.items():
            for layer in layers:
                pth = os.path.join(v.location, layer)
                if os.path.exists(pth) and (pth not in processed):
                    processed.append(pth)
                    # We're not really adding an app, but the superclass
                    # attaches no app specific logic to it so it is safe.
                    self.apps.append(pth)
                    filesystem_storage = FileSystemStorage(location=pth)
                    filesystem_storage.prefix = ""
                    self.storages[pth] = filesystem_storage
Пример #27
0
    def __init__(self, apps=None, *args, **kwargs):
        # Maps dir paths to an appropriate storage instance
        self.storages = SortedDict()
        # Set of locations with static files
        self.locations = set()
        for root in settings.STATICFILES_DIRS:
            if isinstance(root, (list, tuple)):
                prefix, root = root
            else:
                prefix = ''
            self.locations.add((prefix, root))
        # Don't initialize multiple storages for the same location
        for prefix, root in self.locations:
            filesystem_storage = FileSystemStorage(location=root)
            filesystem_storage.prefix = prefix
            self.storages[root] = filesystem_storage

        super(FileSystemFinder, self).__init__(*args, **kwargs)
Пример #28
0
 def get_locations(self):
     #pylint:disable=too-many-locals
     locations = []
     storages = OrderedDict()
     roots = []
     site = get_current_site()
     if site is not None:
         # ``site`` could be ``None`` when this code is used through
         # a manage.py command (ex: collectstatic).
         #
         # Here we are inserting the *theme* at a natural place,
         # i.e. before the path postfix matching STATIC_URL.
         url_parts = []
         for part in django_settings.STATIC_URL.split('/'):
             if part:
                 url_parts.append(part)
         for static_dir in STATICFILES_DIRS:
             drive, path = os.path.splitdrive(static_dir)
             dir_parts = path.split(os.sep)
             nb_dir_parts = len(dir_parts)
             nb_url_parts = len(url_parts)
             cut_point = nb_dir_parts - nb_url_parts
             if cut_point > 0:
                 for dir_part, url_part in zip(
                     dir_parts[cut_point:], url_parts):
                     if dir_part != url_part:
                         cut_point = nb_dir_parts
                         break
             else:
                 cut_point = nb_dir_parts
             for theme in get_current_site().get_templates():
                 roots.append(os.path.join(drive, os.sep,
                     *(dir_parts[:cut_point] + [theme]
                       + dir_parts[cut_point:])))
     for root in roots:
         prefix = ''
         if (prefix, root) not in locations:
             locations.append((prefix, root))
             filesystem_storage = FileSystemStorage(location=root)
             filesystem_storage.prefix = prefix
             storages[root] = filesystem_storage
     locations = locations + self.locations
     storages.update(self.storages)
     return locations, storages
Пример #29
0
 def __init__(self, apps=None, *args, **kwargs):
     location = getattr(settings, 'SASS_PROCESSOR_ROOT',
                        settings.STATIC_ROOT)
     if not location:
         msg = "Neither 'SASS_PROCESSOR_ROOT' nor 'STATIC_ROOT' has been declared in project settings."
         raise ImproperlyConfigured(msg)
     if not os.path.isdir(location):
         try:
             location = getattr(settings, 'SASS_PROCESSOR_ROOT')
             os.makedirs(location)
         except (AttributeError, OSError):
             return
     self.locations = [
         ('', location),
     ]
     self.storages = OrderedDict()
     filesystem_storage = FileSystemStorage(location=location)
     filesystem_storage.prefix = self.locations[0][0]
     self.storages[location] = filesystem_storage
Пример #30
0
    def __init__(self, apps=None, *args, **kwargs):
        # List of locations with static files
        self.locations = []
        # Maps dir paths to an appropriate storage instance
        self.storages = SortedDict()

        for theme_name in os.listdir('{}/themes/'.format(settings.BOOKTYPE_ROOT)):
            theme_dir = '{}/themes/{}'.format(settings.BOOKTYPE_ROOT, theme_name)
            static_dir = '{}/static/'.format(theme_dir)

            if os.path.isdir(static_dir):
                theme_prefix = 'themes/{}'.format(theme_name)
                self.locations.append((theme_prefix, static_dir))

                filesystem_storage = FileSystemStorage(location=static_dir)
                filesystem_storage.prefix = theme_prefix
                self.storages[static_dir] = filesystem_storage

        super(ThemeFinder, self).__init__(*args, **kwargs)
Пример #31
0
 def __init__(self, app_names=None, *args, **kwargs):
     # List of locations with static files
     self.locations = []
     # Maps dir paths to an appropriate storage instance
     self.storages = OrderedDict()
     if not isinstance(settings.STATICFILES, (list, tuple)):
         raise ImproperlyConfigured("Your STATICFILES setting is not a tuple or list; ")
     for root in settings.STATICFILES:
         if isinstance(root, (list, tuple)):
             prefix, root = root
         else:
             prefix = ''
         if (prefix, root) not in self.locations:
             self.locations.append((prefix, root))
     for prefix, root in self.locations:
         filesystem_storage = FileSystemStorage(location=os.path.dirname(root))
         filesystem_storage.prefix = prefix
         self.storages[root] = filesystem_storage
     super(SpecificFileStaticFinder, self).__init__(*args, **kwargs)
Пример #32
0
 def __init__(self, apps=None, *args, **kwargs):
     # List of locations with static files
     self.locations = []
     paths = [
         '%s/themes/%s/static' % (settings.BASE_PATH, get_active_theme()),
     ]
     # Maps dir paths to an appropriate storage instance
     self.storages = SortedDict()
     for root in paths:
         if isinstance(root, (list, tuple)):
             prefix, root = root
         else:
             prefix = ''
         if (prefix, root) not in self.locations:
             self.locations.append((prefix, root))
     for prefix, root in self.locations:
         filesystem_storage = FileSystemStorage(location=root)
         filesystem_storage.prefix = prefix
         self.storages[root] = filesystem_storage
     super(FileSystemFinder, self).__init__(*args, **kwargs)
Пример #33
0
    def __init__(self, apps=None, *args, **kwargs):
        self.locations = []
        self.storages = SortedDict()

        layers = list(settings.FOUNDRY['layers'])

        processed = []
        for app in settings.INSTALLED_APPS:
            mod = import_module(app)
            for layer in layers:
                pth = os.path.join(os.path.dirname(mod.__file__), 'static', layer)
                if os.path.exists(pth) and (pth not in processed):
                    processed.append(pth)
                    self.locations.append(('', pth))

        for prefix, location in self.locations:
            filesystem_storage = FileSystemStorage(location=location)
            filesystem_storage.prefix = prefix
            self.storages[location] = filesystem_storage

        super(BaseFinder, self).__init__(*args, **kwargs)
Пример #34
0
    def __init__(self, apps=None, *args, **kwargs):
        super(FileSystemFinder, self).__init__(apps, *args, **kwargs)

        # Extend locations
        layers = list(get_current_layer_stack(get_current_request()))
        layers.reverse()
        processed = []
        new_locations = []
        for prefix, location in self.locations:
            for layer in layers:
                pth = os.path.join(location, layer)
                if os.path.exists(pth) and (pth not in processed):
                    processed.append(pth)
                    new_locations.append(('', pth))
        for location in reversed(new_locations):
            self.locations.insert(0, location)

        for prefix, location in new_locations:
            filesystem_storage = FileSystemStorage(location=location)
            filesystem_storage.prefix = prefix
            self.storages[location] = filesystem_storage
Пример #35
0
    def __init__(self, apps=None, *args, **kwargs):
        super(FileSystemFinder, self).__init__(apps, *args, **kwargs)

        # Extend locations
        layers = list(get_current_layer_stack(get_current_request()))
        layers.reverse()
        processed = []
        new_locations = []
        for prefix, location in self.locations:
            for layer in layers:
                pth = os.path.join(location, layer)
                if os.path.exists(pth) and (pth not in processed):
                    processed.append(pth)
                    new_locations.append(('', pth))
        for location in reversed(new_locations):
            self.locations.insert(0, location)

        for prefix, location in new_locations:
            filesystem_storage = FileSystemStorage(location=location)
            filesystem_storage.prefix = prefix
            self.storages[location] = filesystem_storage
Пример #36
0
 def __init__(self, locations):
     # List of locations with static files
     self.locations = []
     self.prefixes = set()
     # Maps dir paths to an appropriate storage instance
     self.storages = OrderedDict()
     if not isinstance(locations, (list, tuple)):
         raise TypeError("locations argument is not a tuple or list")
     for root in locations:
         prefix, root = root
         if not prefix:
             raise ValueError(
                 "Cannot use unprefixed locations for dynamic locations")
         else:
             prefix = prefix.rstrip("/")
         if (prefix, root) not in self.locations:
             self.locations.append((prefix, root))
         self.prefixes.add(prefix)
     for prefix, root in self.locations:
         filesystem_storage = FileSystemStorage(location=root)
         filesystem_storage.prefix = prefix
         self.storages[root] = filesystem_storage
Пример #37
0
    def __init__(self):
        # get all registered apps

        self.locations = []
        self.storages = OrderedDict()

        self.ignore_patterns = ["*.py", "*.pyc",]

        for app_config in apps.get_app_configs():

            path_directory = os.path.join(app_config.path, 'assets')

            if os.path.isdir(path_directory):

                storage = FileSystemStorage(location=path_directory)

                storage.prefix = full_asset_path(app_config.name, "")

                self.locations.append(app_config.name)
                self.storages[app_config.name] = storage

        super().__init__()
Пример #38
0
    def __init__(self, apps=None, theme=None, *args, **kwargs):
        # List of locations with static files
        self.locations = []
        # Maps dir paths to an appropriate storage instance
        self.storages = SortedDict()

        prefix = None
        root = safe_join(
            defaults.THEMES_PATH, theme or utils.get_siteskin_settings().theme,
            'static')

        if os.path.abspath(settings.STATIC_ROOT) == os.path.abspath(root):
            raise ImproperlyConfigured(
                "The STATICFILES_DIRS setting should not contain the "
                "STATIC_ROOT setting")
        if (prefix, root) not in self.locations:
            self.locations.append((prefix, root))

        for prefix, root in self.locations:
            filesystem_storage = FileSystemStorage(location=root)
            filesystem_storage.prefix = prefix
            self.storages[root] = filesystem_storage
Пример #39
0
    def __init__(self):

        # Ensure urls are loaded
        root_urls = settings.ROOT_URLCONF
        importlib.import_module(root_urls)

        # Get all registered django dash apps

        self.apps = all_apps()

        self.locations = []
        self.storages = OrderedDict()

        self.ignore_patterns = [
            "*.py",
            "*.pyc",
        ]

        added_locations = {}

        for app_slug, obj in self.apps.items():

            caller_module = obj.caller_module
            location = obj.caller_module_location
            subdir = obj.assets_folder

            path_directory = os.path.join(os.path.dirname(location), subdir)

            if os.path.isdir(path_directory):

                component_name = app_slug
                storage = FileSystemStorage(location=path_directory)
                path = full_asset_path(obj.caller_module.__name__, "")
                storage.prefix = path

                self.locations.append(component_name)
                self.storages[component_name] = storage

        super(DashAssetFinder, self).__init__()
Пример #40
0
    def list(self, ignore_patterns):
        """
        Given an optional list of paths to ignore, this should return
        a two item iterable consisting of the relative path and storage
        instance.
        """

        for component in os.listdir(settings.THIRDPARTY_DIR):
            # We are looking forward symlinks only
            component_path = os.path.join(settings.THIRDPARTY_DIR, component)
            if not os.path.islink(component_path) or not os.path.isdir(component_path):
                continue
                
            for (path, dirs, files) in os.walk(component_path):
                for file in files:
                    name, extension = os.path.splitext(file)

                    for type, extensions in self.extensions.items():
                        if not extension in extensions:
                            continue
                        filesystem_storage = FileSystemStorage(location=path)
                        filesystem_storage.prefix = type
                        yield file, filesystem_storage
Пример #41
0
    def list(self, ignore_patterns):
        """
        Given an optional list of paths to ignore, this should return
        a two item iterable consisting of the relative path and storage
        instance.
        """
        for component in os.listdir(settings.THIRDPARTY_DIR):
            # We are looking forward symlinks only
            component_path = os.path.join(settings.THIRDPARTY_DIR, component)
            if not os.path.islink(component_path) or not os.path.isdir(
                    component_path):
                continue

            for (path, dirs, files) in os.walk(component_path):
                for file in files:
                    name, extension = os.path.splitext(file)

                    for type, extensions in self.extensions.items():
                        if not extension in extensions:
                            continue
                        filesystem_storage = FileSystemStorage(location=path)
                        filesystem_storage.prefix = type
                        yield file, filesystem_storage
Пример #42
0
    def __init__(self):

        self.locations = []
        self.storages = OrderedDict()
        self.components = {}

        self.ignore_patterns = [
            "*.py",
            "*.pyc",
        ]

        try:
            components = settings.PLOTLY_COMPONENTS
        except:
            components = []

        for component_name in components:

            module = importlib.import_module(component_name)
            path_directory = os.path.dirname(module.__file__)

            root = path_directory
            storage = FileSystemStorage(location=root)
            path = "dash/component/%s" % component_name

            # Path_directory is where from
            # path is desired url mount point of the content of path_directory
            # component_name is the name of the component

            storage.prefix = path

            self.locations.append(component_name)

            self.storages[component_name] = storage
            self.components[path] = component_name

        super(DashComponentFinder, self).__init__()
Пример #43
0
    def __init__(self, app_names=None, *args, **kwargs):

        self.locations = []
        self.storages = OrderedDict()

        TenantModel = get_tenant_model()
        all_tenants = TenantModel.objects.values_list('schema_name', flat=True)
        # print "=========== all_tenants ============"
        # print all_tenants

        try:
            CURRENT_SCHEMA_TO_SERVER_STATICFILES = \
                settings.CURRENT_SCHEMA_TO_SERVER_STATICFILES
        except AttributeError:
            raise ImproperlyConfigured(
                'To use %s.%s you must '
                'define the CURRENT_SCHEMA_TO_SERVER_STATICFILES '
                'in your settings' %
                (__name__, TenantFileSystemFinder.__name__))

        if not CURRENT_SCHEMA_TO_SERVER_STATICFILES:
            raise ImproperlyConfigured(
                "Your CURRENT_SCHEMA_TO_SERVER_STATICFILES setting can't be empty; "
                "it must have the value of the schema_name in which you are "
                "currently working on")
        else:
            if CURRENT_SCHEMA_TO_SERVER_STATICFILES not in all_tenants:
                raise ImproperlyConfigured(
                    "The value of CURRENT_SCHEMA_TO_SERVER_STATICFILES setting "
                    "doesnt correspond to a valid schema_name tentant")

        schema_name = connection.schema_name if connection.schema_name != "public" \
            else CURRENT_SCHEMA_TO_SERVER_STATICFILES
        """
        if not hasattr(settings, "MULTITENANT_RELATIVE_STATIC_ROOT") or \
                not settings.MULTITENANT_RELATIVE_STATIC_ROOT:
            raise ImproperlyConfigured("You're using the TenantStaticFilesStorage "
                                       "without having set the MULTITENANT_RELATIVE_STATIC_ROOT "
                                       "setting to a filesystem path.")
        """

        multitenant_relative_static_root = ""
        if hasattr(settings, "MULTITENANT_RELATIVE_STATIC_ROOT"):
            if '%s' in settings.MULTITENANT_RELATIVE_STATIC_ROOT:
                multitenant_relative_static_root = \
                    settings.MULTITENANT_RELATIVE_STATIC_ROOT % \
                    schema_name
            else:
                multitenant_relative_static_root = \
                    os.path.join(settings.MULTITENANT_RELATIVE_STATIC_ROOT,
                                 schema_name)
        else:
            multitenant_relative_static_root = schema_name

        multitenant_static_root = os.path.join(
            settings.STATIC_ROOT, multitenant_relative_static_root)

        # print "multitenant_relative_static_root"
        # print multitenant_relative_static_root
        # print "multitenant_static_root"
        # print multitenant_static_root

        try:
            multitenant_staticfiles_dirs = settings.MULTITENANT_STATICFILES_DIRS
        except AttributeError:
            raise ImproperlyConfigured(
                'To use %s.%s you must '
                'define the MULTITENANT_STATICFILES_DIRS '
                'in your settings' %
                (__name__, TenantFileSystemFinder.__name__))

        if not isinstance(multitenant_staticfiles_dirs, (list, tuple)):
            raise ImproperlyConfigured(
                "Your MULTITENANT_STATICFILES_DIRS setting is not a tuple or list; "
                "perhaps you forgot a trailing comma?")

        tenant_paths = []
        for template_dir in multitenant_staticfiles_dirs:
            if '%s' in template_dir:
                tenant_paths.append(template_dir % schema_name)
            else:
                tenant_paths.append(os.path.join(template_dir, schema_name))

        dirs = tenant_paths

        for root in dirs:
            if isinstance(root, (list, tuple)):
                prefix, root = root
            else:
                prefix = ''

            # print "=========================================="
            # print os.path.abspath(multitenant_static_root)
            # print os.path.abspath(root)

            if os.path.abspath(multitenant_static_root) == os.path.abspath(
                    root):
                raise ImproperlyConfigured(
                    "The MULTITENANT_STATICFILES_DIRS setting should "
                    "not contain the (STATIC_ROOT + MULTITENANT_RELATIVE_STATIC_ROOT) path"
                )
            if (prefix, root) not in self.locations:
                self.locations.append((prefix, root))

        for prefix, root in self.locations:
            filesystem_storage = FileSystemStorage(location=root)
            filesystem_storage.prefix = prefix
            self.storages[root] = filesystem_storage
Пример #44
0
    def config_by_tenant_dir(self):
        self.locations = []
        self.storages = OrderedDict()

        multitenant_relative_static_root = ""
        if hasattr(settings, "MULTITENANT_RELATIVE_STATIC_ROOT"):
            if '%s' in settings.MULTITENANT_RELATIVE_STATIC_ROOT:
                multitenant_relative_static_root = \
                    settings.MULTITENANT_RELATIVE_STATIC_ROOT % \
                    self.current_tenant_dir_name
            else:
                multitenant_relative_static_root = \
                    os.path.join(settings.MULTITENANT_RELATIVE_STATIC_ROOT,
                                 self.current_tenant_dir_name)
        else:
            multitenant_relative_static_root = self.current_tenant_dir_name

        multitenant_static_root = os.path.join(settings.STATIC_ROOT,
                                               multitenant_relative_static_root)

        # print "multitenant_relative_static_root"
        # print multitenant_relative_static_root
        # print "multitenant_static_root"
        # print multitenant_static_root

        try:
            multitenant_staticfiles_dirs = settings.MULTITENANT_STATICFILES_DIRS
        except AttributeError:
            raise ImproperlyConfigured('To use %s.%s you must '
                                       'define the MULTITENANT_STATICFILES_DIRS '
                                       'in your settings' %
                                       (__name__, TenantFileSystemFinder.__name__))

        if not isinstance(multitenant_staticfiles_dirs, (list, tuple)):
            raise ImproperlyConfigured(
                "Your MULTITENANT_STATICFILES_DIRS setting is not a tuple or list; "
                "perhaps you forgot a trailing comma?")

        tenant_paths = []
        for staticfile_dir in multitenant_staticfiles_dirs:
            if '%s' in staticfile_dir:
                tenant_paths.append(staticfile_dir % self.current_tenant_dir_name)
            else:
                tenant_paths.append(os.path.join(staticfile_dir, self.current_tenant_dir_name))

        dirs = tenant_paths

        # print "----------- dirs -------------"
        # print dirs

        for root in dirs:
            if isinstance(root, (list, tuple)):
                prefix, root = root
            else:
                prefix = ''

            # print "=========================================="
            # print os.path.abspath(multitenant_static_root)
            # print os.path.abspath(root)

            if os.path.abspath(multitenant_static_root) == os.path.abspath(root):
                raise ImproperlyConfigured(
                    "The MULTITENANT_STATICFILES_DIRS setting should "
                    "not contain the (STATIC_ROOT + MULTITENANT_RELATIVE_STATIC_ROOT) path")
            if (prefix, root) not in self.locations:
                self.locations.append((prefix, root))

        for prefix, root in self.locations:
            filesystem_storage = FileSystemStorage(location=root)
            filesystem_storage.prefix = prefix
            self.storages[root] = filesystem_storage