Commits

Stefan Scherfke  committed e7e2cf6

Some code clean-up.

  • Participants
  • Parent commits 91eb254

Comments (0)

Files changed (8)

File sphinxdoc/admin.py

-# encoding: utf-8
 """
 Admin interface for the sphinxdoc app.
 
 
 
 class DocumentAdmin(admin.ModelAdmin):
-    """
-    Admin interface for :class:`~sphinxdoc.models.Document`.
+    """Admin interface for :class:`~sphinxdoc.models.Document`.
 
-    Normally, you shouldnt need this, since you create new documents via
+    Normally, you shouldn't need this, since you create new documents via
     the management command.
 
     """

File sphinxdoc/forms.py

-# encoding: utf-8
 """
 Forms for the sphinxdoc app.
 
 
 
 class ProjectSearchForm(SearchForm):
-    """
-    Custom search form for Haystack.
+    """Custom search form for Haystack.
 
     It narrows the search query set to instances of
     :class:`~sphinxdoc.models.Document` that belong to the current
         slug = kwargs.pop('slug')
         project = Project.objects.get(slug=slug)
         kwargs['searchqueryset'] = (kwargs.get('searchqueryset') or
-                SearchQuerySet()).models(Document).filter(project=project.id)
+            SearchQuerySet()).models(Document).filter(project=project.id)
 
         SearchForm.__init__(self, *args, **kwargs)

File sphinxdoc/management/commands/updatedoc.py

-# encoding: utf-8
 """
 Management command for updading the documentation of one or more projects.
 
 
 
 class Command(BaseCommand):
-    """
-    Update (and optionally build) the *Sphinx* documentation for one ore more
-    projects.
+    """Update (and optionally build) the *Sphinx* documentation for one ore
+    more projects.
 
     You need to pass the slug of at least one project. If you pass the optional
     parameter ``-b``, the command ``sphinx-build`` will be run for each project
     help = ('Updates the documentation and the search index for the specified '
             'projects.')
     option_list = BaseCommand.option_list + (
-        optparse.make_option('-b', '--build',
+        optparse.make_option(
+            '-b', '--build',
             action='store_true',
             dest='build',
             default=False,
             help='Run "sphinx-build" for each project before updating it.'),
-        optparse.make_option('--virtualenv',
+        optparse.make_option(
+            '--virtualenv',
             dest='virtualenv',
             default='',
             help='Use this virtualenv to build project docs.',
     )
 
     def handle(self, *args, **options):
-        """
-        Updates (and optionally builds) the documenation for all projects in
+        """Updates (and optionally builds) the documenation for all projects in
         ``args``.
 
         """
             print 'Done'
 
     def build(self, project, virtualenv=''):
-        """
-        Runs ``sphinx-build`` for ``project``. You can also specify a path to
-        the bin-directory of a ``virtualenv``, if your project requires it.
+        """Runs ``sphinx-build`` for ``project``. You can also specify a path
+        to the bin-directory of a ``virtualenv``, if your project requires it.
 
         """
         cmd = 'sphinx-build'
             cmd = os.path.expanduser(os.path.join(virtualenv, cmd))
         cmd = [
             cmd,
+            '-n',
             '-b',
             'json',
             '-d',
         Document.objects.filter(project=project).delete()
 
     def import_files(self, project):
-        """
-        Creates a :class:`~sphinxdoc.models.Document` instance for each JSON
+        """Creates a :class:`~sphinxdoc.models.Document` instance for each JSON
         file of ``project``.
+
         """
         path = os.path.join(project.path, BUILDDIR, 'json')
         for dirpath, dirnames, filenames in os.walk(path):
                 d.save()
 
     def update_haystack(self):
-        """Updates Haystacks search index."""
+        """Updates Haystack's search index."""
         call_command('rebuild_index', interactive=False)

File sphinxdoc/models.py

 
 
 class Project(models.Model):
-    """
-    Represents a Sphinx project. Each ``Project`` has a name, a slug and a path
-    to the root directory of a Sphinx project (where Sphinx’ ``conf.py``) is
-    located).
+    """Represents a Sphinx project. Each ``Project`` has a name, a slug and
+    a path to the root directory of a Sphinx project (where Sphinx’
+    ``conf.py``) is located).
 
     """
     name = models.CharField(max_length=100)
     slug = models.SlugField(unique=True,
-            help_text=_(u'Used in the URL for the project. Must be unique.'))
+                            help_text=_(u'Used in the URL for the project. '
+                                        'Must be unique.'))
     path = models.CharField(max_length=255, validators=[validate_isdir],
-            help_text=_(u'Directory that contains Sphinx’ <tt>conf.py</tt>.'))
+                            help_text=_(u'Directory that contains Sphinx’ '
+                                        '<tt>conf.py</tt>.'))
 
     class Meta:
         verbose_name = _('project')
 
 
 class Document(models.Model):
-    """
-    Represents a JSON encoded Sphinx document. The attributes ``title`` and
+    """Represents a JSON encoded Sphinx document. The attributes ``title`` and
     ``body`` dubicate the corresponding keys in ``content`` and are used for
     the Haystack search.
 

File sphinxdoc/search_indexes.py

-# encoding: utf-8
 """
 Search indexes for Haystack.
 

File sphinxdoc/urls.py

-# encoding: utf-8
 """
 URL conf for django-sphinxdoc.
 
     # static HTML files work correctly and that browsers know how to name files
     # for download
     url(
-        r'^(?P<slug>[\w-]+)/(?P<type_>_images|_static|_downloads|_source)/'
-        r'(?P<path>.+)$',
+        (r'^(?P<slug>[\w-]+)/(?P<type_>_images|_static|_downloads|_source)/'
+         r'(?P<path>.+)$'),
         'sphinx_serve',
     ),
     url(

File sphinxdoc/validators.py

-# encoding: utf-8
 """
 Custom form validators for this app.
 

File sphinxdoc/views.py

-# encoding: utf-8
 """
 Views for django-shinxdoc.
 
 
 @cache_page(60 * CACHE_MINUTES)
 def documentation(request, slug, path):
-    """
-    Displays the contents of a :class:`sphinxdoc.models.Document`.
+    """Displays the contents of a :class:`sphinxdoc.models.Document`.
 
     ``slug`` specifies the project, the document belongs to, ``path`` is the
     path to the original JSON file relative to the builddir and without the
     )
 
     try:
-        env = json.load(open(os.path.join(project.path, BUILDDIR, 'globalcontext.json'), 'rb'))
+        env = json.load(open(os.path.join(project.path, BUILDDIR,
+                                          'globalcontext.json'), 'rb'))
     except IOError:
-        # It is possible that file does not exist anymore (for example, because make clean to
-        # prepare for running make again), we do not want to display an error to the user in this case
+        # It is possible that file does not exist anymore (for example, because
+        # make clean to prepare for running make again), we do not want to
+        # display an error to the user in this case
         env = None
 
     try:
-        update_date = datetime.datetime.fromtimestamp(os.path.getmtime(os.path.join(project.path, BUILDDIR, 'last_build')))
-        # It is possible that file does not exist anymore (for example, because make clean to
-        # prepare for running make again), we do not want to display an error to the user in this case
+        update_date = datetime.datetime.fromtimestamp(os.path.getmtime(
+            os.path.join(project.path, BUILDDIR, 'last_build')))
     except OSError:
+        # It is possible that file does not exist anymore (for example, because
+        # make clean to prepare for running make again), we do not want to
+        # display an error to the user in this case
         update_date = datetime.datetime.fromtimestamp(0)
 
     data = {
     }
 
     return render_to_response(templates, data,
-            context_instance=RequestContext(request))
+                              context_instance=RequestContext(request))
 
 
 @cache_page(60 * CACHE_MINUTES)
 def objects_inventory(request, slug):
-    """
-    Renders the ``objects.inv`` as plain text.
-
-    """
+    """Renders the ``objects.inv`` as plain text."""
     project = get_object_or_404(Project, slug=slug)
     response = serve(
         request,
 
 @cache_page(60 * CACHE_MINUTES)
 def sphinx_serve(request, slug, type_, path):
-    """
-    Serves sphinx static and other files.
-
-    """
+    """Serves sphinx static and other files."""
     project = get_object_or_404(Project, slug=slug)
     return serve(
         request,
 
 
 class ProjectSearchView(SearchView):
-    """
-    Inherits :class:`SearchView` and handles a search request and displays the
-    results as a simple list.
+    """Inherits :class:`~haystack.views.SearchView` and handles a search
+    request and displays the results as a simple list.
 
     """
     def __init__(self):
         SearchView.__init__(self, form_class=ProjectSearchForm,
-                template='sphinxdoc/search.html')
+                            template='sphinxdoc/search.html')
 
     def __call__(self, request, slug):
         self.slug = slug
         return SearchView.__call__(self, request)
 
     def build_form(self):
-        """
-        Instantiates the form that should be used to process the search query.
+        """Instantiates the form that should be used to process the search
+        query.
 
         """
         return self.form_class(self.request.GET, slug=self.slug,
-                searchqueryset=self.searchqueryset, load_all=self.load_all)
+                               searchqueryset=self.searchqueryset,
+                               load_all=self.load_all)
 
     def extra_context(self):
-        """
-        Adds the *project*, the contents of ``globalcontext.json`` (*env*) and
-        the *update_date* as extra context.
+        """Adds the *project*, the contents of ``globalcontext.json`` (*env*)
+        and the *update_date* as extra context.
 
         """
         project = Project.objects.get(slug=self.slug)
 
         try:
-            env = json.load(open(os.path.join(project.path, BUILDDIR, 'globalcontext.json'), 'rb'))
+            env = json.load(open(os.path.join(project.path, BUILDDIR,
+                                              'globalcontext.json'), 'rb'))
         except IOError:
-            # It is possible that file does not exist anymore (for example, because make clean to
-            # prepare for running make again), we do not want to display an error to the user in this case
+            # It is possible that file does not exist anymore (for example,
+            # because make clean to prepare for running make again), we do not
+            # want to display an error to the user in this case
             env = None
 
         try:
-            update_date = datetime.datetime.fromtimestamp(os.path.getmtime(os.path.join(project.path, BUILDDIR, 'last_build')))
+            update_date = datetime.datetime.fromtimestamp(os.path.getmtime(
+                os.path.join(project.path, BUILDDIR, 'last_build')))
         except OSError:
-            # It is possible that file does not exist anymore (for example, because make clean to
-            # prepare for running make again), we do not want to display an error to the user in this case
+            # It is possible that file does not exist anymore (for example,
+            # because make clean to prepare for running make again), we do not
+            # want to display an error to the user in this case
             update_date = datetime.datetime.fromtimestamp(0)
 
         return {