Commit 772ab14c authored by Sergio Durigan Junior's avatar Sergio Durigan Junior

Initial import of flask-multistatic_1.0.orig.tar.gz

parents
This diff is collapsed.
include LICENSE README.rst example.conf
Metadata-Version: 1.1
Name: flask-multistatic
Version: 1.0
Summary: Simple flask plugin to allow overriding static files
Home-page: https://pagure.io/flask-multistatic
Author: Pierre-Yves Chibon
Author-email: pingou@pingoured.fr
License: GPLv3+
Download-URL: https://pagure.io/releases/flask-multistatic/
Description: UNKNOWN
Platform: UNKNOWN
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 2.6
Classifier: Programming Language :: Python :: 2.7
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Software Development :: Libraries
flask-multistatic
=================
:Author: Pierre-Yves Chibon <pingou@pingoured.fr>
This project is a simple `flask`_ plugin to add support for overriding static
files.
Dependencies:
-------------
.. _python: http://www.python.org
.. _Flask: http://flask.pocoo.org/
The dependency list is therefore:
- `python`_ (2.5 minimum)
- `flask`_
Usage:
------
In your flask application:
::
import flask
from flask_multistatic import MultiStaticFlask
And replace the way you build you flask application from
::
APP = flask.Flask(__name__)
by
::
APP = MultiStaticFlask(__name__)
You can then specify multiple folder where static files are located, for
example:
::
APP.static_folder = [
os.path.join(APP.root_path, 'static', APP.config['THEME_FOLDER']),
os.path.join(APP.root_path, 'static', 'default')
]
.. note:: The order of the folder is important, the last folder should be the one
where most files are present, the other folders are where you override
the static files.
So in the example above, all the default static files are in
`/static/default/` and the files specific for one theme are under
`/static/<theme_name>/`.
Production:
-----------
Note that this is most likely less efficient than having apache serve the static
files itself, but even if you do that you might want to have multiple static
directories and have apache fallback.
In this case, you can use the example.conf file that is shipped as part of this
repository.
The example.conf file has an example configuration that will try to serve a file
from an instance-specific theme directory, and only if the file was not found, fall
back to the application default theme.
License:
--------
This project is licensed GPLv3+.
# Example httpd config with two fallbacks
#
# Distributed under the CC0 license.
# You can find a copy of this license at
# http://creativecommons.org/publicdomain/zero/1.0/
#
# To the extend possible under law, the author has
# waived all copyright and related or neighboring
# rights on this work.
#
RewriteEngine on
# First try the instance-specific theme
RewriteCond "/srv/approot/static/my_theme/$1" -f
RewriteRule "^/static/(.*)" "/srv/approot/static/my_theme/$1" [L]
# Use the application default theme for files not customized
RewriteRule "^/static/(.*)" "/srv/approot/static/default/$1" [L]
Metadata-Version: 1.1
Name: flask-multistatic
Version: 1.0
Summary: Simple flask plugin to allow overriding static files
Home-page: https://pagure.io/flask-multistatic
Author: Pierre-Yves Chibon
Author-email: pingou@pingoured.fr
License: GPLv3+
Download-URL: https://pagure.io/releases/flask-multistatic/
Description: UNKNOWN
Platform: UNKNOWN
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 2.6
Classifier: Programming Language :: Python :: 2.7
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Software Development :: Libraries
LICENSE
MANIFEST.in
README.rst
example.conf
flask_multistatic.py
setup.py
flask_multistatic.egg-info/PKG-INFO
flask_multistatic.egg-info/SOURCES.txt
flask_multistatic.egg-info/dependency_links.txt
flask_multistatic.egg-info/requires.txt
flask_multistatic.egg-info/top_level.txt
\ No newline at end of file
# -*- coding: utf-8 -*-
"""
(c) 2015 - Copyright Red Hat Inc.
Author: Pierre-Yves Chibon <pingou@pingoured.fr>
Distributed under License GPLv3 or later
You can find a copy of this license on the website
http://www.gnu.org/licenses/gpl.html
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA.
"""
import os
import sys
from flask import Flask
from flask.helpers import send_from_directory
from werkzeug.exceptions import NotFound
PY2 = sys.version_info[0] == 2
if PY2:
string_types = (str, unicode)
else:
string_types = (str,)
class MultiStaticFlask(Flask):
''' This class inherit from the main Flask application object and
override few methods to allow flask to support having multiple folders
serving static content.
'''
def _get_static_folder(self):
if self._static_folder is not None:
return [os.path.join(self.root_path, folder)
for folder in self._static_folder]
def _set_static_folder(self, value):
folders = value
if isinstance(folders, string_types):
folders = [value]
self._static_folder = folders
static_folder = property(_get_static_folder, _set_static_folder)
del _get_static_folder, _set_static_folder
# Use the last entry in the list of static folder as it should be what
# contains most of the files
def _get_static_url_path(self):
if self._static_url_path is not None:
return self._static_url_path
if self.static_folder is not None:
return '/' + os.path.basename(self.static_folder[-1])
def _set_static_url_path(self, value):
self._static_url_path = value
static_url_path = property(_get_static_url_path, _set_static_url_path)
del _get_static_url_path, _set_static_url_path
def send_static_file(self, filename):
"""Function used internally to send static files from the static
folder to the browser.
.. versionadded:: 0.5
"""
if not self.has_static_folder:
raise RuntimeError('No static folder for this object')
# Ensure get_send_file_max_age is called in all cases.
# Here, we ensure get_send_file_max_age is called for Blueprints.
cache_timeout = self.get_send_file_max_age(filename)
folders = self.static_folder
if isinstance(self.static_folder, string_types):
folders = [self.static_folder]
for directory in folders:
try:
return send_from_directory(
directory, filename, cache_timeout=cache_timeout)
except NotFound:
pass
raise NotFound()
[egg_info]
tag_build =
tag_date = 0
tag_svn_revision = 0
#!/usr/bin/env python
"""
Setup script
"""
from setuptools import setup
setup(
name='flask-multistatic',
description='Simple flask plugin to allow overriding static files',
version='1.0',
author='Pierre-Yves Chibon',
author_email='pingou@pingoured.fr',
license='GPLv3+',
download_url='https://pagure.io/releases/flask-multistatic/',
url='https://pagure.io/flask-multistatic',
py_modules=['flask_multistatic'],
install_requires=['flask'],
classifiers=[
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Developers',
'License :: OSI Approved :: GNU General Public License v3 or later '
'(GPLv3+)',
'Operating System :: OS Independent',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Topic :: Software Development :: Libraries',
],
)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment