add some first versions of setup / code (untested)
This commit is contained in:
7
MANIFEST.in
Normal file
7
MANIFEST.in
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
include README.txt
|
||||||
|
|
||||||
|
global-exclude *.pyc
|
||||||
|
global-exclude *.pyo
|
||||||
|
global-exclude *.orig
|
||||||
|
global-exclude *.rej
|
||||||
|
|
8
README.txt
Normal file
8
README.txt
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
XStatic
|
||||||
|
-------
|
||||||
|
|
||||||
|
The goal of XStatic family of packages is to provide static file packages
|
||||||
|
with minimal overhead - without selling you some dependencies you don't want.
|
||||||
|
|
||||||
|
XStatic has some minimal support code for working with the XStatic-* packages.
|
||||||
|
|
23
setup.py
Normal file
23
setup.py
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
from setuptools import setup, find_packages
|
||||||
|
|
||||||
|
# The README.txt file should be written in reST so that PyPI can use
|
||||||
|
# it to generate your project's PyPI page.
|
||||||
|
long_description = open('README.txt').read()
|
||||||
|
|
||||||
|
|
||||||
|
setup(
|
||||||
|
name='XStatic',
|
||||||
|
version='0.0.1a0',
|
||||||
|
description='XStatic base package with minimal support code',
|
||||||
|
long_description=long_description,
|
||||||
|
classifiers=[],
|
||||||
|
keywords=[],
|
||||||
|
author='Thomas Waldmann',
|
||||||
|
author_email='tw@waldmann-edv.de',
|
||||||
|
license='MIT license',
|
||||||
|
packages=find_packages(),
|
||||||
|
include_package_data=True,
|
||||||
|
zip_safe=False,
|
||||||
|
install_requires=[], # there should never be a dependency!
|
||||||
|
)
|
||||||
|
|
47
xstatic/__init__.py
Normal file
47
xstatic/__init__.py
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
# http://remote_base/path
|
||||||
|
# http://local_base/path
|
||||||
|
|
||||||
|
class XStatic(object):
|
||||||
|
"""
|
||||||
|
minimal support code to access resources from xstatic.pkg.* files
|
||||||
|
or CDN locations.
|
||||||
|
"""
|
||||||
|
name = None # lowercase short name
|
||||||
|
base_dir = None # fs path to the files
|
||||||
|
locations = {} # CDN/remote locations
|
||||||
|
|
||||||
|
def __init__(self, root_url='/xstatic', provider='local', protocol='http'):
|
||||||
|
"""
|
||||||
|
:arg root_url: the common root url path for all local xstatic
|
||||||
|
resources
|
||||||
|
:arg provider: 'local' to get it from local server or
|
||||||
|
a name of another source (e.g. CDN)
|
||||||
|
:arg protocol: 'http' (default) or 'https'
|
||||||
|
"""
|
||||||
|
self.provider = provider
|
||||||
|
if provider == 'local':
|
||||||
|
self.base_url = "%s/%s" % (root_url, self.name)
|
||||||
|
else:
|
||||||
|
self.base_url = self.locations[(provider, protocol)]
|
||||||
|
|
||||||
|
def get_mapping(self):
|
||||||
|
"""
|
||||||
|
query the mapping url -> directory, use this to setup
|
||||||
|
your own static file serving.
|
||||||
|
"""
|
||||||
|
if self.provider == 'local':
|
||||||
|
return self.base_url, self.base_dir
|
||||||
|
|
||||||
|
def url_for(self, path):
|
||||||
|
"""
|
||||||
|
compute the url for some resource.
|
||||||
|
|
||||||
|
:arg path: a relative path into the data
|
||||||
|
"""
|
||||||
|
loc = self.base_url
|
||||||
|
if isinstance(loc, str):
|
||||||
|
loc = "%s/%s" % (loc, path)
|
||||||
|
elif isinstance(loc, dict):
|
||||||
|
loc = loc[path]
|
||||||
|
return loc
|
||||||
|
|
Reference in New Issue
Block a user