├── tests ├── __init__.py ├── sample │ ├── __init__.py │ ├── migrations │ │ ├── __init__.py │ │ └── 0001_initial.py │ └── models.py ├── settings.py ├── test_formats.py ├── test_archive.py └── base.py ├── django_archive ├── util │ ├── __init__.py │ └── file.py ├── management │ ├── __init__.py │ └── commands │ │ ├── __init__.py │ │ └── archive.py ├── __init__.py ├── apps.py └── archivers │ ├── __init__.py │ ├── zipfile.py │ ├── registry.py │ └── tarball.py ├── setup.py ├── .gitignore ├── .travis.yml ├── tox.ini ├── docs ├── usage.rst ├── index.rst ├── installation.rst ├── settings.rst ├── Makefile ├── make.bat └── conf.py ├── LICENSE.txt ├── setup.cfg └── README.md /tests/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/sample/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /django_archive/util/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /django_archive/management/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/sample/migrations/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /django_archive/management/commands/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup 2 | 3 | 4 | setup() 5 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.py[co] 2 | __pycache__/ 3 | 4 | /.tox/ 5 | /dist/ 6 | /docs/_build/ 7 | MANIFEST 8 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: python 2 | python: 3 | - 3.7 4 | install: 5 | - pip install tox-travis 6 | script: 7 | - tox 8 | -------------------------------------------------------------------------------- /django_archive/__init__.py: -------------------------------------------------------------------------------- 1 | __title__ = 'django_archive' 2 | __version__ = '0.2.0' 3 | __author__ = 'Nathan Osman' 4 | 5 | default_app_config = 'django_archive.apps.DjangoArchiveConfig' 6 | -------------------------------------------------------------------------------- /tests/sample/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | 3 | 4 | class Sample(models.Model): 5 | """ 6 | A sample model that exists for testing 7 | """ 8 | 9 | attachment = models.FileField(upload_to='attachments') 10 | -------------------------------------------------------------------------------- /django_archive/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class DjangoArchiveConfig(AppConfig): 5 | """ 6 | Configuration for the django_archive app 7 | """ 8 | 9 | name = 'django_archive' 10 | verbose_name = "Django Archive" 11 | -------------------------------------------------------------------------------- /tox.ini: -------------------------------------------------------------------------------- 1 | [tox] 2 | envlist = 3 | py{37}-dj{30} 4 | 5 | [testenv] 6 | deps = 7 | dj30: Django>=3.0,<3.1 8 | coveralls 9 | passenv = TRAVIS TRAVIS_* 10 | setenv = 11 | DJANGO_SETTINGS_MODULE = tests.settings 12 | commands = 13 | coverage run --source=django_archive -m django test 14 | coveralls 15 | -------------------------------------------------------------------------------- /tests/settings.py: -------------------------------------------------------------------------------- 1 | SECRET_KEY = 'TEST' 2 | 3 | INSTALLED_APPS = ( 4 | 'django.contrib.auth', 5 | 'django.contrib.contenttypes', 6 | 'django.contrib.sessions', 7 | 'django_archive', 8 | 'tests.sample', 9 | ) 10 | 11 | DATABASES = { 12 | 'default': { 13 | 'ENGINE': 'django.db.backends.sqlite3', 14 | 'NAME': ':memory:', 15 | }, 16 | } 17 | -------------------------------------------------------------------------------- /docs/usage.rst: -------------------------------------------------------------------------------- 1 | Usage 2 | ===== 3 | 4 | Interacting with Django Archive is done through a set of management commands. 5 | 6 | Creating an Archive 7 | ------------------- 8 | 9 | To create an archive, use the ``archive`` management command:: 10 | 11 | python manage.py archive 12 | 13 | This will create a compressed archive in the current directory containing 14 | a single fixture in JSON format and all uploaded media. 15 | -------------------------------------------------------------------------------- /docs/index.rst: -------------------------------------------------------------------------------- 1 | Django Archive 2 | ============== 3 | 4 | Django Archive provides a management command that will create a compressed 5 | archive of database tables and uploaded media. 6 | 7 | Contents 8 | -------- 9 | 10 | .. toctree:: 11 | :maxdepth: 2 12 | 13 | installation 14 | usage 15 | settings 16 | 17 | Indices and tables 18 | ================== 19 | 20 | * :ref:`genindex` 21 | * :ref:`modindex` 22 | * :ref:`search` 23 | 24 | -------------------------------------------------------------------------------- /docs/installation.rst: -------------------------------------------------------------------------------- 1 | Installation 2 | ============ 3 | 4 | Django Archive is distributed as a Python package through 5 | `PyPI `_. 6 | 7 | PyPI Package 8 | ------------ 9 | 10 | Installation on most platforms consists of running the following command:: 11 | 12 | pip install django-archive 13 | 14 | Project Setup 15 | ------------- 16 | 17 | Once the package is installed, it must be added to ``INSTALLED_APPS``:: 18 | 19 | INSTALLED_APPS = ( 20 | # ... 21 | 'django_archive', 22 | ) 23 | -------------------------------------------------------------------------------- /tests/sample/migrations/0001_initial.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 3.0.8 on 2020-07-18 16:04 2 | 3 | from django.db import migrations, models 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | initial = True 9 | 10 | dependencies = [ 11 | ] 12 | 13 | operations = [ 14 | migrations.CreateModel( 15 | name='Sample', 16 | fields=[ 17 | ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 18 | ('attachment', models.FileField(upload_to='attachments')), 19 | ], 20 | ), 21 | ] 22 | -------------------------------------------------------------------------------- /tests/test_formats.py: -------------------------------------------------------------------------------- 1 | from django.core.management import call_command 2 | from django_archive import archivers 3 | 4 | from .base import BaseTestCase 5 | 6 | 7 | class FormatsTestCase(BaseTestCase): 8 | """ 9 | Test that the archive command works with all available formats 10 | """ 11 | 12 | _FORMATS = ( 13 | archivers.TARBALL, 14 | archivers.TARBALL_GZ, 15 | archivers.TARBALL_BZ2, 16 | archivers.TARBALL_XZ, 17 | archivers.ZIP, 18 | ) 19 | 20 | def test_archive(self): 21 | """ 22 | Test each format 23 | """ 24 | for fmt in self._FORMATS: 25 | with self.subTest(fmt=fmt): 26 | with self.settings(ARCHIVE_FORMAT=fmt): 27 | call_command('archive') 28 | -------------------------------------------------------------------------------- /django_archive/archivers/__init__.py: -------------------------------------------------------------------------------- 1 | from .registry import registry 2 | from .tarball import TarballArchiver 3 | from .zipfile import ZipArchiver 4 | 5 | 6 | TARBALL = TarballArchiver.UNCOMPRESSED 7 | TARBALL_GZ = TarballArchiver.GZ 8 | TARBALL_BZ2 = TarballArchiver.BZ2 9 | TARBALL_XZ = TarballArchiver.XZ 10 | ZIP = ZipArchiver.ZIP 11 | 12 | 13 | def get_archiver(fmt): 14 | """ 15 | Return the class corresponding with the provided archival format 16 | (this method is deprecated in favor of the registry) 17 | """ 18 | # pylint: disable=import-outside-toplevel 19 | from warnings import warn 20 | warn( 21 | "get_archiver() is deprecated; use the registry instead", 22 | DeprecationWarning, 23 | stacklevel=2, 24 | ) 25 | return registry.get(fmt) 26 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2020 Nathan Osman 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [metadata] 2 | name = django_archive 3 | version = attr: django_archive.__version__ 4 | description = Management command for creating compressed archives of DB tables and uploaded media 5 | author = Nathan Osman 6 | author_email = nathan@quickmediasolutions.com 7 | url = https://github.com/nathan-osman/django-archive 8 | license = MIT 9 | classifiers = 10 | Development Status :: 4 - Beta 11 | Environment :: Web Environment 12 | Framework :: Django 13 | Framework :: Django :: 3.0 14 | Intended Audience :: Developers 15 | License :: OSI Approved :: MIT License 16 | Operating System :: OS Independent 17 | Programming Language :: Python 18 | Programming Language :: Python :: 3 19 | Programming Language :: Python :: 3 :: Only 20 | Topic :: Internet :: WWW/HTTP 21 | Topic :: Internet :: WWW/HTTP :: Dynamic Content 22 | 23 | [options] 24 | python_requires = >=3.6 25 | packages = 26 | django_archive 27 | django_archive.archivers 28 | django_archive.management 29 | django_archive.management.commands 30 | django_archive.util 31 | install_requires = 32 | Django >= 3.0 33 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Django Archive 2 | 3 | [![Build Status](https://travis-ci.org/nathan-osman/django-archive.svg?branch=master)](https://travis-ci.org/nathan-osman/django-archive) 4 | [![Coverage Status](https://coveralls.io/repos/github/nathan-osman/django-archive/badge.svg?branch=master)](https://coveralls.io/github/nathan-osman/django-archive?branch=master) 5 | [![Latest Documentation](https://readthedocs.org/projects/django-archive/badge/?version=latest)](http://django-archive.readthedocs.org/en/latest/) 6 | [![PyPI Version](http://img.shields.io/pypi/v/django-archive.svg?style=flat)](https://pypi.python.org/pypi/django-archive) 7 | [![PyPI Downloads](http://img.shields.io/pypi/dm/django-archive.svg?style=flat)](https://pypi.python.org/pypi/django-archive) 8 | [![License](http://img.shields.io/badge/license-MIT-red.svg?style=flat)](http://opensource.org/licenses/MIT) 9 | 10 | Django Archive provides a management command that will create a compressed archive of database tables and uploaded media. 11 | 12 | ### Documentation 13 | 14 | For installation instructions and usage, please consult the documentation: 15 | 16 | > http://django-archive.readthedocs.org/en/latest/ 17 | -------------------------------------------------------------------------------- /django_archive/util/file.py: -------------------------------------------------------------------------------- 1 | """ 2 | Utility class for working with temporary files 3 | """ 4 | 5 | import os 6 | 7 | from tempfile import mkstemp 8 | 9 | 10 | class MixedModeTemporaryFile: 11 | """ 12 | Temporary file that can be opened multiple times in different modes 13 | """ 14 | 15 | def __init__(self): 16 | self._fd, self._filename = mkstemp() 17 | 18 | def __enter__(self): 19 | return self 20 | 21 | def __exit__(self, exc_type, exc_val, traceback): 22 | self.close() 23 | 24 | def open(self, mode): 25 | """ 26 | Open the file in the specified mode 27 | """ 28 | return os.fdopen(self._fd, mode, closefd=False) 29 | 30 | def close(self): 31 | """ 32 | Close the temporary file (and delete it) 33 | """ 34 | os.close(self._fd) 35 | os.unlink(self._filename) 36 | 37 | def rewind(self): 38 | """ 39 | Seek to the beginning of the file 40 | """ 41 | os.lseek(self._fd, 0, os.SEEK_SET) 42 | 43 | def size(self): 44 | """ 45 | Return the size of the file 46 | """ 47 | return os.stat(self._fd).st_size 48 | -------------------------------------------------------------------------------- /django_archive/archivers/zipfile.py: -------------------------------------------------------------------------------- 1 | from zipfile import ZipFile 2 | 3 | from .registry import registry 4 | 5 | 6 | class ZipArchiver: 7 | """ 8 | Archiver for creating ZIP files 9 | """ 10 | 11 | ZIP = 'zip' 12 | 13 | # pylint: disable=unused-argument 14 | def __init__(self, fileobj, fmt): 15 | self._fileobj = fileobj 16 | 17 | def __enter__(self): 18 | # pylint: disable=attribute-defined-outside-init 19 | self._zipfile = ZipFile( 20 | file=self._fileobj, 21 | mode='w', 22 | ) 23 | 24 | def __exit__(self, exc_type, exc_val, exc_tb): 25 | self._zipfile.close() 26 | 27 | def add(self, filename, size, fileobj): 28 | """ 29 | Add the provided file to the archive 30 | """ 31 | # Loop through the contents of the fileobj, 32 | # writing them to the zipfile in chunks 33 | bytes_remaining = size 34 | with self._zipfile.open(filename, 'w') as cfile: 35 | while bytes_remaining: 36 | chunk_size = min(65536, bytes_remaining) 37 | cfile.write(fileobj.read(chunk_size)) 38 | bytes_remaining -= chunk_size 39 | 40 | 41 | registry.add( 42 | ZipArchiver.ZIP, 43 | ZipArchiver, 44 | "ZIP archive (.zip)", 45 | ('zip',), 46 | ) 47 | -------------------------------------------------------------------------------- /django_archive/archivers/registry.py: -------------------------------------------------------------------------------- 1 | from collections import namedtuple 2 | 3 | 4 | class Registry: 5 | """ 6 | A set of methods for finding and enumerating supported archivers 7 | """ 8 | 9 | Format = namedtuple("Format", ('archiver', 'description', 'extensions')) 10 | 11 | def __init__(self): 12 | self._formats = {} 13 | 14 | def list(self): 15 | """ 16 | Return a list of format IDs 17 | """ 18 | return self._formats.keys() 19 | 20 | # pylint: disable=invalid-name,redefined-builtin 21 | def add(self, id, archiver, description, extensions): 22 | """ 23 | Add a format to the registry 24 | """ 25 | self._formats[id] = self.Format(archiver, description, extensions) 26 | 27 | # pylint: disable=invalid-name,redefined-builtin 28 | def get(self, id): 29 | """ 30 | Retrieve a format by its ID 31 | """ 32 | return self._formats[id] 33 | 34 | def find_by_extension(self, extension): 35 | """ 36 | Find a format by its extension 37 | """ 38 | for fmt in self._formats.values(): 39 | for ext in fmt.extensions: 40 | if ext == extension: 41 | return fmt 42 | raise KeyError("No archiver exists for '{}'".format(extension)) 43 | 44 | 45 | registry = Registry() 46 | -------------------------------------------------------------------------------- /django_archive/archivers/tarball.py: -------------------------------------------------------------------------------- 1 | from tarfile import TarInfo, TarFile 2 | 3 | from .registry import registry 4 | 5 | 6 | class TarballArchiver: 7 | """ 8 | Archiver for creating tarballs (compressed and uncompressed) 9 | """ 10 | 11 | UNCOMPRESSED = 'tar' 12 | GZ = 'gz' 13 | BZ2 = 'bz2' 14 | XZ = 'xz' 15 | 16 | def __init__(self, fileobj, fmt): 17 | self._fileobj = fileobj 18 | self._fmt = fmt 19 | 20 | def __enter__(self): 21 | # pylint: disable=attribute-defined-outside-init 22 | self._tarfile = TarFile.open( 23 | mode='w:{}'.format(self._fmt), 24 | fileobj=self._fileobj, 25 | ) 26 | 27 | def __exit__(self, exc_type, exc_val, exc_tb): 28 | self._tarfile.close() 29 | 30 | def add(self, filename, size, fileobj): 31 | """ 32 | Add the provided file to the archive 33 | """ 34 | tarinfo = TarInfo(filename) 35 | tarinfo.size = size 36 | self._tarfile.addfile(tarinfo, fileobj) 37 | 38 | 39 | registry.add( 40 | TarballArchiver.UNCOMPRESSED, 41 | TarballArchiver, 42 | "Tarball (.tar)", 43 | ('tar',), 44 | ) 45 | 46 | registry.add( 47 | TarballArchiver.GZ, 48 | TarballArchiver, 49 | "gzip-compressed Tarball (.tar.gz)", 50 | ('tar.gz', 'tgz'), 51 | ) 52 | 53 | registry.add( 54 | TarballArchiver.BZ2, 55 | TarballArchiver, 56 | "bzip2-compressed Tarball (.tar.bz2)", 57 | ('tar.bz2', 'tbz2'), 58 | ) 59 | 60 | registry.add( 61 | TarballArchiver.XZ, 62 | TarballArchiver, 63 | "xz-compressed Tarball (.tar.xz)", 64 | ('tar.xz', 'txz'), 65 | ) 66 | -------------------------------------------------------------------------------- /tests/test_archive.py: -------------------------------------------------------------------------------- 1 | from json import load 2 | 3 | from django.core.files.base import ContentFile 4 | from django.core.management import call_command 5 | from django_archive import __version__ 6 | 7 | from .base import BaseArchiveTestCase 8 | from .sample.models import Sample 9 | 10 | 11 | class ArchiveTestCase(BaseArchiveTestCase): 12 | """ 13 | Test that the archive command includes correct data in the archive 14 | """ 15 | 16 | _ATTACHMENT_FILENAME = 'sample.txt' 17 | _ATTACHMENT_CONTENT = b'sample' 18 | 19 | def setUp(self): 20 | super().setUp() 21 | sample = Sample() 22 | sample.attachment.save( 23 | self._ATTACHMENT_FILENAME, 24 | ContentFile(self._ATTACHMENT_CONTENT), 25 | ) 26 | call_command('archive') 27 | self.open_archive() 28 | 29 | def test_data(self): 30 | """ 31 | Confirm that the model and attached files were archived 32 | """ 33 | with self.tarfile.extractfile('data.json') as fileobj: 34 | data = load(fileobj) 35 | self.assertEqual(len(data), 1) 36 | self.assertEqual(data[0]['model'], 'sample.sample') 37 | with self.tarfile.extractfile(data[0]['fields']['attachment']) as fileobj: 38 | content = fileobj.read() 39 | self.assertEqual(content, self._ATTACHMENT_CONTENT) 40 | 41 | def test_meta(self): 42 | """ 43 | Confirm that meta information is present 44 | """ 45 | with self.tarfile.extractfile('meta.json') as fileobj: 46 | data = load(fileobj) 47 | self.assertEqual(data['version'], __version__) 48 | self.assertEqual(data['migrations']['sample'], '0001_initial') 49 | -------------------------------------------------------------------------------- /docs/settings.rst: -------------------------------------------------------------------------------- 1 | Settings 2 | ======== 3 | 4 | Django Archive provides a number of settings that can be used to customize its 5 | behavior. These settings are optional, but may be modified on a per-project 6 | basis in the project's ``settings.py``. 7 | 8 | .. attribute:: ARCHIVE_DIRECTORY 9 | 10 | :default: *empty* 11 | 12 | Path to a directory where the archives will be stored. The default behavior 13 | is to create the archive in the current directory. 14 | 15 | .. attribute:: ARCHIVE_FILENAME 16 | 17 | :default: ``'%Y-%m-%d--%H-%M-%S'`` 18 | 19 | String passed to ``strftime()`` to determine the filename of the archive 20 | that will be generated. 21 | 22 | .. attribute:: ARCHIVE_FORMAT 23 | 24 | :default: ``django_archive.archivers.TARBALL_BZ2`` 25 | 26 | Format used for creating the compressed archive. The options currently 27 | available include: 28 | 29 | - ``django_archive.archivers.TARBALL`` 30 | - ``django_archive.archivers.TARBALL_GZ`` 31 | - ``django_archive.archivers.TARBALL_BZ2`` 32 | - ``django_archive.archivers.TARBALL_XZ`` 33 | - ``django_archive.archivers.ZIP`` 34 | 35 | The predefined constants enable you to easily specify the archive format in 36 | your ``settings.py``: 37 | 38 | .. code-block:: python 39 | 40 | from django_archive import archivers 41 | ARCHIVE_FORMAT = archivers.ZIP 42 | 43 | .. attribute:: ARCHIVE_EXCLUDE 44 | 45 | :default: 46 | 47 | :: 48 | 49 | ( 50 | 'contenttypes.ContentType', 51 | 'sessions.Session', 52 | 'auth.Permission', 53 | ) 54 | 55 | List of models to exclude from the archive. By default, this includes 56 | session data and models that are automatically populated. 57 | -------------------------------------------------------------------------------- /tests/base.py: -------------------------------------------------------------------------------- 1 | from contextlib import ExitStack 2 | from os import path 3 | from tarfile import TarFile 4 | from tempfile import TemporaryDirectory 5 | 6 | from django.test import TestCase 7 | from django_archive import archivers 8 | 9 | 10 | class BaseTestCase(TestCase): 11 | """ 12 | Base class for tests 13 | """ 14 | 15 | def setUp(self): 16 | """ 17 | Initialize the test by setting up a temporary directory 18 | 19 | The directory is available in self.directory. 20 | """ 21 | with ExitStack() as stack: 22 | self.directory = stack.enter_context(TemporaryDirectory()) 23 | stack.enter_context( 24 | self.settings( 25 | ARCHIVE_DIRECTORY=self.directory, 26 | MEDIA_ROOT=self.directory, 27 | ), 28 | ) 29 | self.addCleanup(stack.pop_all().close) 30 | 31 | 32 | class BaseArchiveTestCase(BaseTestCase): 33 | """ 34 | Base class for tests that require the creation of a single archive 35 | """ 36 | 37 | _FILENAME = 'test' 38 | _FORMAT_ID = archivers.TARBALL 39 | _FORMAT = archivers.registry.get(_FORMAT_ID) 40 | 41 | def setUp(self): 42 | """ 43 | Initialize the test by initializing settings for creating an archive 44 | """ 45 | super().setUp() 46 | stack = ExitStack() 47 | stack.enter_context( 48 | self.settings( 49 | ARCHIVE_FILENAME=self._FILENAME, 50 | ARCHIVE_FORMAT=self._FORMAT_ID, 51 | ), 52 | ) 53 | self.addCleanup(stack.close) 54 | 55 | def open_archive(self): 56 | """ 57 | The archive is available for reading in self.tarfile. To populate the 58 | database, override this method and call super().setUp() after. 59 | """ 60 | stack = ExitStack() 61 | # pylint: disable=attribute-defined-outside-init 62 | self.tarfile = stack.enter_context( 63 | TarFile.open( 64 | path.join( 65 | self.directory, 66 | '{}.{}'.format( 67 | self._FILENAME, 68 | self._FORMAT.extensions[0], 69 | ), 70 | ), 71 | ), 72 | ) 73 | self.addCleanup(stack.close) 74 | -------------------------------------------------------------------------------- /django_archive/management/commands/archive.py: -------------------------------------------------------------------------------- 1 | """ 2 | Create an archive 3 | """ 4 | 5 | from contextlib import contextmanager 6 | from datetime import datetime 7 | from json import dump 8 | from os import path 9 | 10 | from django.apps import apps 11 | from django.conf import settings 12 | from django.core.management import call_command 13 | from django.core.management.base import BaseCommand 14 | from django.db import connection, models 15 | from django.db.migrations.recorder import MigrationRecorder 16 | 17 | from ... import __version__ 18 | from ...archivers import registry, TARBALL_BZ2 19 | from ...util.file import MixedModeTemporaryFile 20 | 21 | 22 | class Command(BaseCommand): 23 | """ 24 | Create a compressed archive of database tables and uploaded media. 25 | """ 26 | 27 | help = "Create a compressed archive of database tables and uploaded media." 28 | 29 | _DEFAULT_ARCHIVE_EXCLUDE = ( 30 | 'auth.Permission', 31 | 'contenttypes.ContentType', 32 | 'sessions.Session', 33 | ) 34 | 35 | @staticmethod 36 | def _get_filename(fmt): 37 | return path.join( 38 | getattr(settings, 'ARCHIVE_DIRECTORY', ''), 39 | "{}.{}".format( 40 | datetime.today().strftime( 41 | getattr( 42 | settings, 43 | 'ARCHIVE_FILENAME', 44 | '%Y-%m-%d--%H-%M-%S', 45 | ), 46 | ), 47 | fmt.extensions[0], 48 | ), 49 | ) 50 | 51 | @staticmethod 52 | @contextmanager 53 | def _write_to_archive(archive, filename): 54 | with MixedModeTemporaryFile() as tempfile: 55 | with tempfile.open('w') as fileobj: 56 | yield fileobj 57 | tempfile.rewind() 58 | with tempfile.open('rb') as fileobj: 59 | archive.add(filename, tempfile.size(), fileobj) 60 | 61 | @staticmethod 62 | def _dump_meta(archive): 63 | with Command._write_to_archive(archive, 'meta.json') as fileobj: 64 | dump( 65 | { 66 | 'version': __version__, 67 | 'migrations': dict( 68 | MigrationRecorder(connection) 69 | .applied_migrations() 70 | .keys() 71 | ), 72 | }, 73 | fileobj, 74 | indent=2, 75 | ) 76 | 77 | @staticmethod 78 | def _dump_db(archive): 79 | with Command._write_to_archive(archive, 'data.json') as fileobj: 80 | call_command( 81 | 'dumpdata', 82 | all=True, 83 | format='json', 84 | exclude=getattr( 85 | settings, 86 | 'ARCHIVE_EXCLUDE', 87 | Command._DEFAULT_ARCHIVE_EXCLUDE, 88 | ), 89 | stdout=fileobj, 90 | ) 91 | 92 | @staticmethod 93 | def _dump_files(archive): 94 | for app_config in apps.get_app_configs(): 95 | for model in app_config.get_models(): 96 | field_names = [] 97 | for field in model._meta.fields: 98 | if isinstance(field, models.FileField): 99 | field_names.append(field.name) 100 | if not field_names: 101 | continue 102 | for row in model.objects.all(): 103 | for field_name in field_names: 104 | field = getattr(row, field_name) 105 | if field: 106 | with field as field: 107 | archive.add(field.name, field.size, field) 108 | 109 | # pylint: disable=unused-argument 110 | def handle(self, *args, **kwargs): 111 | """ 112 | Process the command 113 | """ 114 | fmt_id = getattr(settings, 'ARCHIVE_FORMAT', TARBALL_BZ2) 115 | fmt = registry.get(fmt_id) 116 | filename = Command._get_filename(fmt) 117 | with open(filename, 'wb') as fileobj: 118 | archive = fmt.archiver(fileobj, fmt_id) 119 | with archive: 120 | Command._dump_meta(archive) 121 | Command._dump_db(archive) 122 | Command._dump_files(archive) 123 | self.stdout.write( 124 | self.style.SUCCESS( 125 | "Successfully wrote {}".format(filename), 126 | ), 127 | ) 128 | -------------------------------------------------------------------------------- /docs/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line. 5 | SPHINXOPTS = 6 | SPHINXBUILD = sphinx-build 7 | PAPER = 8 | BUILDDIR = _build 9 | 10 | # User-friendly check for sphinx-build 11 | ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1) 12 | $(error The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don't have Sphinx installed, grab it from http://sphinx-doc.org/) 13 | endif 14 | 15 | # Internal variables. 16 | PAPEROPT_a4 = -D latex_paper_size=a4 17 | PAPEROPT_letter = -D latex_paper_size=letter 18 | ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . 19 | # the i18n builder cannot share the environment and doctrees with the others 20 | I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . 21 | 22 | .PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext 23 | 24 | help: 25 | @echo "Please use \`make ' where is one of" 26 | @echo " html to make standalone HTML files" 27 | @echo " dirhtml to make HTML files named index.html in directories" 28 | @echo " singlehtml to make a single large HTML file" 29 | @echo " pickle to make pickle files" 30 | @echo " json to make JSON files" 31 | @echo " htmlhelp to make HTML files and a HTML help project" 32 | @echo " qthelp to make HTML files and a qthelp project" 33 | @echo " devhelp to make HTML files and a Devhelp project" 34 | @echo " epub to make an epub" 35 | @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" 36 | @echo " latexpdf to make LaTeX files and run them through pdflatex" 37 | @echo " latexpdfja to make LaTeX files and run them through platex/dvipdfmx" 38 | @echo " text to make text files" 39 | @echo " man to make manual pages" 40 | @echo " texinfo to make Texinfo files" 41 | @echo " info to make Texinfo files and run them through makeinfo" 42 | @echo " gettext to make PO message catalogs" 43 | @echo " changes to make an overview of all changed/added/deprecated items" 44 | @echo " xml to make Docutils-native XML files" 45 | @echo " pseudoxml to make pseudoxml-XML files for display purposes" 46 | @echo " linkcheck to check all external links for integrity" 47 | @echo " doctest to run all doctests embedded in the documentation (if enabled)" 48 | 49 | clean: 50 | rm -rf $(BUILDDIR)/* 51 | 52 | html: 53 | $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html 54 | @echo 55 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." 56 | 57 | dirhtml: 58 | $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml 59 | @echo 60 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." 61 | 62 | singlehtml: 63 | $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml 64 | @echo 65 | @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." 66 | 67 | pickle: 68 | $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle 69 | @echo 70 | @echo "Build finished; now you can process the pickle files." 71 | 72 | json: 73 | $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json 74 | @echo 75 | @echo "Build finished; now you can process the JSON files." 76 | 77 | htmlhelp: 78 | $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp 79 | @echo 80 | @echo "Build finished; now you can run HTML Help Workshop with the" \ 81 | ".hhp project file in $(BUILDDIR)/htmlhelp." 82 | 83 | qthelp: 84 | $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp 85 | @echo 86 | @echo "Build finished; now you can run "qcollectiongenerator" with the" \ 87 | ".qhcp project file in $(BUILDDIR)/qthelp, like this:" 88 | @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/DjangoArchive.qhcp" 89 | @echo "To view the help file:" 90 | @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/DjangoArchive.qhc" 91 | 92 | devhelp: 93 | $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp 94 | @echo 95 | @echo "Build finished." 96 | @echo "To view the help file:" 97 | @echo "# mkdir -p $$HOME/.local/share/devhelp/DjangoArchive" 98 | @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/DjangoArchive" 99 | @echo "# devhelp" 100 | 101 | epub: 102 | $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub 103 | @echo 104 | @echo "Build finished. The epub file is in $(BUILDDIR)/epub." 105 | 106 | latex: 107 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 108 | @echo 109 | @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." 110 | @echo "Run \`make' in that directory to run these through (pdf)latex" \ 111 | "(use \`make latexpdf' here to do that automatically)." 112 | 113 | latexpdf: 114 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 115 | @echo "Running LaTeX files through pdflatex..." 116 | $(MAKE) -C $(BUILDDIR)/latex all-pdf 117 | @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." 118 | 119 | latexpdfja: 120 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 121 | @echo "Running LaTeX files through platex and dvipdfmx..." 122 | $(MAKE) -C $(BUILDDIR)/latex all-pdf-ja 123 | @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." 124 | 125 | text: 126 | $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text 127 | @echo 128 | @echo "Build finished. The text files are in $(BUILDDIR)/text." 129 | 130 | man: 131 | $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man 132 | @echo 133 | @echo "Build finished. The manual pages are in $(BUILDDIR)/man." 134 | 135 | texinfo: 136 | $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo 137 | @echo 138 | @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." 139 | @echo "Run \`make' in that directory to run these through makeinfo" \ 140 | "(use \`make info' here to do that automatically)." 141 | 142 | info: 143 | $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo 144 | @echo "Running Texinfo files through makeinfo..." 145 | make -C $(BUILDDIR)/texinfo info 146 | @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." 147 | 148 | gettext: 149 | $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale 150 | @echo 151 | @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." 152 | 153 | changes: 154 | $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes 155 | @echo 156 | @echo "The overview file is in $(BUILDDIR)/changes." 157 | 158 | linkcheck: 159 | $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck 160 | @echo 161 | @echo "Link check complete; look for any errors in the above output " \ 162 | "or in $(BUILDDIR)/linkcheck/output.txt." 163 | 164 | doctest: 165 | $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest 166 | @echo "Testing of doctests in the sources finished, look at the " \ 167 | "results in $(BUILDDIR)/doctest/output.txt." 168 | 169 | xml: 170 | $(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml 171 | @echo 172 | @echo "Build finished. The XML files are in $(BUILDDIR)/xml." 173 | 174 | pseudoxml: 175 | $(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml 176 | @echo 177 | @echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml." 178 | -------------------------------------------------------------------------------- /docs/make.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | REM Command file for Sphinx documentation 4 | 5 | if "%SPHINXBUILD%" == "" ( 6 | set SPHINXBUILD=sphinx-build 7 | ) 8 | set BUILDDIR=_build 9 | set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% . 10 | set I18NSPHINXOPTS=%SPHINXOPTS% . 11 | if NOT "%PAPER%" == "" ( 12 | set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS% 13 | set I18NSPHINXOPTS=-D latex_paper_size=%PAPER% %I18NSPHINXOPTS% 14 | ) 15 | 16 | if "%1" == "" goto help 17 | 18 | if "%1" == "help" ( 19 | :help 20 | echo.Please use `make ^` where ^ is one of 21 | echo. html to make standalone HTML files 22 | echo. dirhtml to make HTML files named index.html in directories 23 | echo. singlehtml to make a single large HTML file 24 | echo. pickle to make pickle files 25 | echo. json to make JSON files 26 | echo. htmlhelp to make HTML files and a HTML help project 27 | echo. qthelp to make HTML files and a qthelp project 28 | echo. devhelp to make HTML files and a Devhelp project 29 | echo. epub to make an epub 30 | echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter 31 | echo. text to make text files 32 | echo. man to make manual pages 33 | echo. texinfo to make Texinfo files 34 | echo. gettext to make PO message catalogs 35 | echo. changes to make an overview over all changed/added/deprecated items 36 | echo. xml to make Docutils-native XML files 37 | echo. pseudoxml to make pseudoxml-XML files for display purposes 38 | echo. linkcheck to check all external links for integrity 39 | echo. doctest to run all doctests embedded in the documentation if enabled 40 | goto end 41 | ) 42 | 43 | if "%1" == "clean" ( 44 | for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i 45 | del /q /s %BUILDDIR%\* 46 | goto end 47 | ) 48 | 49 | 50 | %SPHINXBUILD% 2> nul 51 | if errorlevel 9009 ( 52 | echo. 53 | echo.The 'sphinx-build' command was not found. Make sure you have Sphinx 54 | echo.installed, then set the SPHINXBUILD environment variable to point 55 | echo.to the full path of the 'sphinx-build' executable. Alternatively you 56 | echo.may add the Sphinx directory to PATH. 57 | echo. 58 | echo.If you don't have Sphinx installed, grab it from 59 | echo.http://sphinx-doc.org/ 60 | exit /b 1 61 | ) 62 | 63 | if "%1" == "html" ( 64 | %SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html 65 | if errorlevel 1 exit /b 1 66 | echo. 67 | echo.Build finished. The HTML pages are in %BUILDDIR%/html. 68 | goto end 69 | ) 70 | 71 | if "%1" == "dirhtml" ( 72 | %SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml 73 | if errorlevel 1 exit /b 1 74 | echo. 75 | echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml. 76 | goto end 77 | ) 78 | 79 | if "%1" == "singlehtml" ( 80 | %SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml 81 | if errorlevel 1 exit /b 1 82 | echo. 83 | echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml. 84 | goto end 85 | ) 86 | 87 | if "%1" == "pickle" ( 88 | %SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle 89 | if errorlevel 1 exit /b 1 90 | echo. 91 | echo.Build finished; now you can process the pickle files. 92 | goto end 93 | ) 94 | 95 | if "%1" == "json" ( 96 | %SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json 97 | if errorlevel 1 exit /b 1 98 | echo. 99 | echo.Build finished; now you can process the JSON files. 100 | goto end 101 | ) 102 | 103 | if "%1" == "htmlhelp" ( 104 | %SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp 105 | if errorlevel 1 exit /b 1 106 | echo. 107 | echo.Build finished; now you can run HTML Help Workshop with the ^ 108 | .hhp project file in %BUILDDIR%/htmlhelp. 109 | goto end 110 | ) 111 | 112 | if "%1" == "qthelp" ( 113 | %SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp 114 | if errorlevel 1 exit /b 1 115 | echo. 116 | echo.Build finished; now you can run "qcollectiongenerator" with the ^ 117 | .qhcp project file in %BUILDDIR%/qthelp, like this: 118 | echo.^> qcollectiongenerator %BUILDDIR%\qthelp\DjangoArchive.qhcp 119 | echo.To view the help file: 120 | echo.^> assistant -collectionFile %BUILDDIR%\qthelp\DjangoArchive.ghc 121 | goto end 122 | ) 123 | 124 | if "%1" == "devhelp" ( 125 | %SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp 126 | if errorlevel 1 exit /b 1 127 | echo. 128 | echo.Build finished. 129 | goto end 130 | ) 131 | 132 | if "%1" == "epub" ( 133 | %SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub 134 | if errorlevel 1 exit /b 1 135 | echo. 136 | echo.Build finished. The epub file is in %BUILDDIR%/epub. 137 | goto end 138 | ) 139 | 140 | if "%1" == "latex" ( 141 | %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex 142 | if errorlevel 1 exit /b 1 143 | echo. 144 | echo.Build finished; the LaTeX files are in %BUILDDIR%/latex. 145 | goto end 146 | ) 147 | 148 | if "%1" == "latexpdf" ( 149 | %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex 150 | cd %BUILDDIR%/latex 151 | make all-pdf 152 | cd %BUILDDIR%/.. 153 | echo. 154 | echo.Build finished; the PDF files are in %BUILDDIR%/latex. 155 | goto end 156 | ) 157 | 158 | if "%1" == "latexpdfja" ( 159 | %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex 160 | cd %BUILDDIR%/latex 161 | make all-pdf-ja 162 | cd %BUILDDIR%/.. 163 | echo. 164 | echo.Build finished; the PDF files are in %BUILDDIR%/latex. 165 | goto end 166 | ) 167 | 168 | if "%1" == "text" ( 169 | %SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text 170 | if errorlevel 1 exit /b 1 171 | echo. 172 | echo.Build finished. The text files are in %BUILDDIR%/text. 173 | goto end 174 | ) 175 | 176 | if "%1" == "man" ( 177 | %SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man 178 | if errorlevel 1 exit /b 1 179 | echo. 180 | echo.Build finished. The manual pages are in %BUILDDIR%/man. 181 | goto end 182 | ) 183 | 184 | if "%1" == "texinfo" ( 185 | %SPHINXBUILD% -b texinfo %ALLSPHINXOPTS% %BUILDDIR%/texinfo 186 | if errorlevel 1 exit /b 1 187 | echo. 188 | echo.Build finished. The Texinfo files are in %BUILDDIR%/texinfo. 189 | goto end 190 | ) 191 | 192 | if "%1" == "gettext" ( 193 | %SPHINXBUILD% -b gettext %I18NSPHINXOPTS% %BUILDDIR%/locale 194 | if errorlevel 1 exit /b 1 195 | echo. 196 | echo.Build finished. The message catalogs are in %BUILDDIR%/locale. 197 | goto end 198 | ) 199 | 200 | if "%1" == "changes" ( 201 | %SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes 202 | if errorlevel 1 exit /b 1 203 | echo. 204 | echo.The overview file is in %BUILDDIR%/changes. 205 | goto end 206 | ) 207 | 208 | if "%1" == "linkcheck" ( 209 | %SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck 210 | if errorlevel 1 exit /b 1 211 | echo. 212 | echo.Link check complete; look for any errors in the above output ^ 213 | or in %BUILDDIR%/linkcheck/output.txt. 214 | goto end 215 | ) 216 | 217 | if "%1" == "doctest" ( 218 | %SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest 219 | if errorlevel 1 exit /b 1 220 | echo. 221 | echo.Testing of doctests in the sources finished, look at the ^ 222 | results in %BUILDDIR%/doctest/output.txt. 223 | goto end 224 | ) 225 | 226 | if "%1" == "xml" ( 227 | %SPHINXBUILD% -b xml %ALLSPHINXOPTS% %BUILDDIR%/xml 228 | if errorlevel 1 exit /b 1 229 | echo. 230 | echo.Build finished. The XML files are in %BUILDDIR%/xml. 231 | goto end 232 | ) 233 | 234 | if "%1" == "pseudoxml" ( 235 | %SPHINXBUILD% -b pseudoxml %ALLSPHINXOPTS% %BUILDDIR%/pseudoxml 236 | if errorlevel 1 exit /b 1 237 | echo. 238 | echo.Build finished. The pseudo-XML files are in %BUILDDIR%/pseudoxml. 239 | goto end 240 | ) 241 | 242 | :end 243 | -------------------------------------------------------------------------------- /docs/conf.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # 3 | # Django Archive documentation build configuration file, created by 4 | # sphinx-quickstart on Sun Jan 4 15:34:28 2015. 5 | # 6 | # This file is execfile()d with the current directory set to its 7 | # containing dir. 8 | # 9 | # Note that not all possible configuration values are present in this 10 | # autogenerated file. 11 | # 12 | # All configuration values have a default; values that are commented out 13 | # serve to show the default. 14 | 15 | import sys 16 | import os 17 | 18 | # If extensions (or modules to document with autodoc) are in another directory, 19 | # add these directories to sys.path here. If the directory is relative to the 20 | # documentation root, use os.path.abspath to make it absolute, like shown here. 21 | #sys.path.insert(0, os.path.abspath('.')) 22 | 23 | # -- General configuration ------------------------------------------------ 24 | 25 | # If your documentation needs a minimal Sphinx version, state it here. 26 | #needs_sphinx = '1.0' 27 | 28 | # Add any Sphinx extension module names here, as strings. They can be 29 | # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom 30 | # ones. 31 | extensions = [ 32 | 'sphinx.ext.autodoc', 33 | ] 34 | 35 | # Add any paths that contain templates here, relative to this directory. 36 | templates_path = ['_templates'] 37 | 38 | # The suffix of source filenames. 39 | source_suffix = '.rst' 40 | 41 | # The encoding of source files. 42 | #source_encoding = 'utf-8-sig' 43 | 44 | # The master toctree document. 45 | master_doc = 'index' 46 | 47 | # General information about the project. 48 | project = u'Django Archive' 49 | copyright = u'2020, Nathan Osman' 50 | 51 | # The version info for the project you're documenting, acts as replacement for 52 | # |version| and |release|, also used in various other places throughout the 53 | # built documents. 54 | 55 | # Import the version from the package 56 | sys.path.append(os.path.join(os.path.dirname(__file__), '..')) 57 | from django_archive import __version__ 58 | 59 | # The short X.Y version. 60 | version = __version__ 61 | # The full version, including alpha/beta/rc tags. 62 | release = __version__ 63 | 64 | # The language for content autogenerated by Sphinx. Refer to documentation 65 | # for a list of supported languages. 66 | #language = None 67 | 68 | # There are two options for replacing |today|: either, you set today to some 69 | # non-false value, then it is used: 70 | #today = '' 71 | # Else, today_fmt is used as the format for a strftime call. 72 | #today_fmt = '%B %d, %Y' 73 | 74 | # List of patterns, relative to source directory, that match files and 75 | # directories to ignore when looking for source files. 76 | exclude_patterns = ['_build'] 77 | 78 | # The reST default role (used for this markup: `text`) to use for all 79 | # documents. 80 | #default_role = None 81 | 82 | # If true, '()' will be appended to :func: etc. cross-reference text. 83 | #add_function_parentheses = True 84 | 85 | # If true, the current module name will be prepended to all description 86 | # unit titles (such as .. function::). 87 | #add_module_names = True 88 | 89 | # If true, sectionauthor and moduleauthor directives will be shown in the 90 | # output. They are ignored by default. 91 | #show_authors = False 92 | 93 | # The name of the Pygments (syntax highlighting) style to use. 94 | pygments_style = 'sphinx' 95 | 96 | # A list of ignored prefixes for module index sorting. 97 | #modindex_common_prefix = [] 98 | 99 | # If true, keep warnings as "system message" paragraphs in the built documents. 100 | #keep_warnings = False 101 | 102 | 103 | # -- Options for HTML output ---------------------------------------------- 104 | 105 | # The theme to use for HTML and HTML Help pages. See the documentation for 106 | # a list of builtin themes. 107 | html_theme = 'default' 108 | 109 | # Theme options are theme-specific and customize the look and feel of a theme 110 | # further. For a list of options available for each theme, see the 111 | # documentation. 112 | #html_theme_options = {} 113 | 114 | # Add any paths that contain custom themes here, relative to this directory. 115 | #html_theme_path = [] 116 | 117 | # The name for this set of Sphinx documents. If None, it defaults to 118 | # " v documentation". 119 | #html_title = None 120 | 121 | # A shorter title for the navigation bar. Default is the same as html_title. 122 | #html_short_title = None 123 | 124 | # The name of an image file (relative to this directory) to place at the top 125 | # of the sidebar. 126 | #html_logo = None 127 | 128 | # The name of an image file (within the static path) to use as favicon of the 129 | # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 130 | # pixels large. 131 | #html_favicon = None 132 | 133 | # Add any paths that contain custom static files (such as style sheets) here, 134 | # relative to this directory. They are copied after the builtin static files, 135 | # so a file named "default.css" will overwrite the builtin "default.css". 136 | html_static_path = ['_static'] 137 | 138 | # Add any extra paths that contain custom files (such as robots.txt or 139 | # .htaccess) here, relative to this directory. These files are copied 140 | # directly to the root of the documentation. 141 | #html_extra_path = [] 142 | 143 | # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, 144 | # using the given strftime format. 145 | #html_last_updated_fmt = '%b %d, %Y' 146 | 147 | # If true, SmartyPants will be used to convert quotes and dashes to 148 | # typographically correct entities. 149 | #html_use_smartypants = True 150 | 151 | # Custom sidebar templates, maps document names to template names. 152 | #html_sidebars = {} 153 | 154 | # Additional templates that should be rendered to pages, maps page names to 155 | # template names. 156 | #html_additional_pages = {} 157 | 158 | # If false, no module index is generated. 159 | #html_domain_indices = True 160 | 161 | # If false, no index is generated. 162 | #html_use_index = True 163 | 164 | # If true, the index is split into individual pages for each letter. 165 | #html_split_index = False 166 | 167 | # If true, links to the reST sources are added to the pages. 168 | #html_show_sourcelink = True 169 | 170 | # If true, "Created using Sphinx" is shown in the HTML footer. Default is True. 171 | #html_show_sphinx = True 172 | 173 | # If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. 174 | #html_show_copyright = True 175 | 176 | # If true, an OpenSearch description file will be output, and all pages will 177 | # contain a tag referring to it. The value of this option must be the 178 | # base URL from which the finished HTML is served. 179 | #html_use_opensearch = '' 180 | 181 | # This is the file name suffix for HTML files (e.g. ".xhtml"). 182 | #html_file_suffix = None 183 | 184 | # Output file base name for HTML help builder. 185 | htmlhelp_basename = 'DjangoArchivedoc' 186 | 187 | 188 | # -- Options for LaTeX output --------------------------------------------- 189 | 190 | latex_elements = { 191 | # The paper size ('letterpaper' or 'a4paper'). 192 | #'papersize': 'letterpaper', 193 | 194 | # The font size ('10pt', '11pt' or '12pt'). 195 | #'pointsize': '10pt', 196 | 197 | # Additional stuff for the LaTeX preamble. 198 | #'preamble': '', 199 | } 200 | 201 | # Grouping the document tree into LaTeX files. List of tuples 202 | # (source start file, target name, title, 203 | # author, documentclass [howto, manual, or own class]). 204 | latex_documents = [ 205 | ('index', 'DjangoArchive.tex', u'Django Archive Documentation', 206 | u'Nathan Osman', 'manual'), 207 | ] 208 | 209 | # The name of an image file (relative to this directory) to place at the top of 210 | # the title page. 211 | #latex_logo = None 212 | 213 | # For "manual" documents, if this is true, then toplevel headings are parts, 214 | # not chapters. 215 | #latex_use_parts = False 216 | 217 | # If true, show page references after internal links. 218 | #latex_show_pagerefs = False 219 | 220 | # If true, show URL addresses after external links. 221 | #latex_show_urls = False 222 | 223 | # Documents to append as an appendix to all manuals. 224 | #latex_appendices = [] 225 | 226 | # If false, no module index is generated. 227 | #latex_domain_indices = True 228 | 229 | 230 | # -- Options for manual page output --------------------------------------- 231 | 232 | # One entry per manual page. List of tuples 233 | # (source start file, name, description, authors, manual section). 234 | man_pages = [ 235 | ('index', 'djangoarchive', u'Django Archive Documentation', 236 | [u'Nathan Osman'], 1) 237 | ] 238 | 239 | # If true, show URL addresses after external links. 240 | #man_show_urls = False 241 | 242 | 243 | # -- Options for Texinfo output ------------------------------------------- 244 | 245 | # Grouping the document tree into Texinfo files. List of tuples 246 | # (source start file, target name, title, author, 247 | # dir menu entry, description, category) 248 | texinfo_documents = [ 249 | ('index', 'DjangoArchive', u'Django Archive Documentation', 250 | u'Nathan Osman', 'DjangoArchive', 'One line description of project.', 251 | 'Miscellaneous'), 252 | ] 253 | 254 | # Documents to append as an appendix to all manuals. 255 | #texinfo_appendices = [] 256 | 257 | # If false, no module index is generated. 258 | #texinfo_domain_indices = True 259 | 260 | # How to display URL addresses: 'footnote', 'no', or 'inline'. 261 | #texinfo_show_urls = 'footnote' 262 | 263 | # If true, do not generate a @detailmenu in the "Top" node's menu. 264 | #texinfo_no_detailmenu = False 265 | --------------------------------------------------------------------------------