Commits

Stefan Scherfke committed 6a289b1 Merge

Merged in ianare/django-sphinxdoc/commands (pull request #10)

Improvements to admin/commands

Comments (0)

Files changed (5)

 dist/*
 MANIFEST
 *.egg-info/*
+*swp
 - `Josiah Klassen <https://bitbucket.org/jkla>`_
 - `Andres Riancho <https://bitbucket.org/andresriancho>`_
 - `Ales Zabala Alava <https://bitbucket.org/shagi>`_
+- `Ianaré Sévi <https://bitbucket.org/ianare>`_

docs/quickstart.txt

     active, you must enable Django's
     `cache framework <https://docs.djangoproject.com/en/dev/topics/cache/>`_
 
+``SPHINXDOC_BUILD_DIR``:
+    Sets the name of target directory (within the project root) for the
+    sphinx builder and the sphinxdoc updater. If not set, defaults to
+    *_build*.
+
 
 Add a project
 -------------

sphinxdoc/admin.py

     the management command.
 
     """
-    pass
+    list_display = ('path', 'title', 'project',)
+    list_filter = ('project', )
 
 
 admin.site.register(Project, ProjectAdmin)

sphinxdoc/management/commands/updatedoc.py

 import os.path
 import subprocess
 
+from django.conf import settings
 from django.core.management import call_command
 from django.core.management.base import BaseCommand, CommandError
 
 from sphinxdoc.models import Project, Document
 
 
-BUILDDIR = '_build'
+BUILDDIR = getattr(settings, 'SPHINXDOC_BUILD_DIR', '_build')
 EXTENSION = '.fjson'
 SPECIAL_TITLES = {
     'genindex': 'General Index',
             dest='virtualenv',
             default='',
             help='Use this virtualenv to build project docs.',
-        )
+        ),
+        optparse.make_option(
+            '-a', '--all',
+            action='store_true',
+            dest='update_all',
+            default=False,
+            help='Update all projects.',
+        ),
     )
 
     def handle(self, *args, **options):
-        """Updates (and optionally builds) the documenation for all projects in
-        ``args``.
+        """Updates (and optionally builds) the documenation for all projects,
+        either as a list specifed in ``args``, or get all from database.
 
         """
+        update_all = options['update_all']
+
+        if update_all:
+            for project in Project.objects.all():
+                self.update_project(project, options)
+        elif args:
+            for slug in args:
+                try:
+                    project = Project.objects.get(slug=slug)
+                except Project.DoesNotExist:
+                    raise CommandError('Project "%s" does not exist' % slug)
+                else:
+                    self.update_project(project, options)
+        else:
+            raise CommandError('No project(s) specified.')
+
+    def update_project(self, project, options):
+        """
+        Updates (and optionally builds) the documenation for a given project.
+        
+        """
         build = options['build']
         virtualenv = options['virtualenv']
+        
+        if build:
+            print 'Running "sphinx--build" for "%s" ...' % project.slug
+            self.build(project, virtualenv)
 
-        for slug in args:
-            try:
-                project = Project.objects.get(slug=slug)
-            except Project.DoesNotExist:
-                raise CommandError('Project "%s" does not exist' % slug)
+        print 'Deleting old entries from database ...'
+        self.delete_documents(project)
+        
+        print 'Importing JSON files for "%s" ...' % project.slug
+        self.import_files(project)
 
-            if build:
-                print 'Running "sphinx--build" for "%s" ...' % slug
-                self.build(project, virtualenv)
+        print 'Updating search index for "%s" ...' % project.slug
+        self.update_haystack()
 
-            print 'Deleting old entries from database ...'
-            self.delete_documents(project)
-
-            print 'Importing JSON files for "%s" ...' % slug
-            self.import_files(project)
-
-            print 'Updating search index for "%s" ...' % slug
-            self.update_haystack()
-
-            print 'Done'
+        print 'Done'
 
     def build(self, project, virtualenv=''):
         """Runs ``sphinx-build`` for ``project``. You can also specify a path