Commit ce914be4 authored by Arthur Shevchenko's avatar Arthur Shevchenko

Initial commit

parents
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
# C extensions
*.so
# Distribution / packaging
bin/
build/
develop-eggs/
dist/
eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
.tox/
.coverage
.cache
nosetests.xml
coverage.xml
# Translations
*.mo
# Mr Developer
.mr.developer.cfg
.project
.pydevproject
.settings
# Rope
.ropeproject
# Django stuff:
*.log
*.pot
# Sphinx documentation
docs/_build/
# Local virtualenvs used for testing.
/.env*
# PIP install version files.
/=*
Copyright (c) 2009, Ben Firshman
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* The names of its contributors may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Django Database Files 3000
==========================
This is a storage system for Django that stores uploaded
files in the database. Files can be served from the database
(usually a bad idea), the file system, or a CDN.
Installation
------------
Simply install via pip with:
pip install django-database-files-3000
Usage
-----
In `settings.py`, add `database_files` to your `INSTALLED_APPS` and add
this line:
DEFAULT_FILE_STORAGE = 'database_files.storage.DatabaseStorage'
Note, the `upload_to` parameter is still used to synchronize the files stored
in the database with those on the file system, so new and existing fields
should still have a value that makes sense from your base media directory.
If you're using South, the initial model migrations will scan through all
existing models for `FileFields` or `ImageFields` and will automatically
load them into the database.
If for any reason you want to re-run this bulk import task, run:
python manage.py database_files_load
Additionally, if you want to export all files in the database back to the file
system, run:
python manage.py database_files_dump
Note, that when a field referencing a file is cleared, the corresponding file
in the database and on the file system will not be automatically deleted.
To delete all files in the database and file system not referenced by any model
fields, run:
python manage.py database_files_cleanup
Settings
-------
* `DB_FILES_AUTO_EXPORT_DB_TO_FS` = `True`|`False` (default `True`)
If true, when a file is uploaded or read from the database, a copy will be
exported to your media directory corresponding to the FileField's upload_to
path, just as it would with the default Django file storage.
If false, the file will only exist in the database.
* `DATABASE_FILES_URL_METHOD` = `URL_METHOD_1`|`URL_METHOD_1` (default `URL_METHOD_1`)
Defines the method to use when rendering the web-accessible URL for a file.
If `URL_METHOD_1`, assumes all files have been exported to the filesystem and
uses the path corresponding to your `settings.MEDIA_URL`.
If `URL_METHOD_2`, uses the URL bound to the `database_file` view
to dynamically lookup and serve files from the filesystem or database.
Development
-----------
You can run unittests with:
python setup.py test
You can run unittests for a specific Python version using the `pv` parameter
like:
python setup.py test --pv=3.2
\ No newline at end of file
database_files @ bdd159cd
Subproject commit bdd159cd92386c496b94b078392002633bb6d93d
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
from setuptools import setup, find_packages, Command
import database_files
try:
from pypandoc import convert
read_md = lambda f: convert(f, 'rst')
except:
print("Warning: pypandoc module not found, could not convert "
"Markdown to RST")
read_md = lambda f: open(f, 'r').read()
def get_reqs(test=False, pv=None):
reqs = [
'Django>=1.4',
'six>=1.7.2',
]
if test:
#TODO:remove once Django 1.7 south integration becomes main-stream?
if not pv:
reqs.append('South>=1.0')
elif pv <= 3.2:
# Note, South dropped Python3 support after 0.8.4...
reqs.append('South==0.8.4')
return reqs
class TestCommand(Command):
description = "Runs unittests."
user_options = [
('name=', None,
'Name of the specific test to run.'),
('virtual-env-dir=', None,
'The location of the virtual environment to use.'),
('pv=', None,
'The version of Python to use. e.g. 2.7 or 3'),
]
def initialize_options(self):
self.name = None
self.virtual_env_dir = '.env%s'
self.pv = 0
self.versions = [
2.7,
3,
#3.3,#TODO?
]
def finalize_options(self):
pass
def build_virtualenv(self, pv):
virtual_env_dir = self.virtual_env_dir % pv
kwargs = dict(virtual_env_dir=virtual_env_dir, pv=pv)
if not os.path.isdir(virtual_env_dir):
cmd = 'virtualenv -p /usr/bin/python{pv} {virtual_env_dir}'.format(**kwargs)
print(cmd)
os.system(cmd)
cmd = '{virtual_env_dir}/bin/easy_install -U distribute'.format(**kwargs)
print(cmd)
os.system(cmd)
for package in get_reqs(test=True, pv=float(pv)):
kwargs['package'] = package
cmd = '{virtual_env_dir}/bin/pip install -U {package}'.format(**kwargs)
print(cmd)
os.system(cmd)
def run(self):
versions = self.versions
if self.pv:
versions = [self.pv]
for pv in versions:
self.build_virtualenv(pv)
kwargs = dict(
pv=pv,
virtual_env_dir=self.virtual_env_dir % pv,
name=self.name)
if self.name:
cmd = '{virtual_env_dir}/bin/django-admin.py test --pythonpath=. --settings=database_files.tests.settings database_files.tests.tests.{name}'.format(**kwargs)
else:
cmd = '{virtual_env_dir}/bin/django-admin.py test --pythonpath=. --settings=database_files.tests.settings database_files.tests'.format(**kwargs)
print(cmd)
ret = os.system(cmd)
if ret:
return
try:
long_description = read_md('README.md')
except:
long_description = ''
setup(
name='django-database-files-3000',
version=database_files.__version__,
description='A storage system for Django that stores uploaded files in both the database and file system.',
long_description=long_description,
author='Chris Spencer',
author_email='chrisspen@gmail.com',
url='http://github.com/chrisspen/django-database-files-3000',
packages=[
'database_files',
'database_files.management',
'database_files.management.commands',
'database_files.migrations',
],
#https://pypi.python.org/pypi?%3Aaction=list_classifiers
classifiers=[
'Development Status :: 4 - Beta',
'Framework :: Django',
'Intended Audience :: Developers',
'License :: OSI Approved :: BSD License',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.0',
'Programming Language :: Python :: 3.2',
],
install_requires = get_reqs(),
cmdclass={
'test': TestCommand,
},
)
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