Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added support for updating docs from git.

  • Loading branch information...
commit 02f01dc9f5d6f2c85b4de21053ee08b0b2850853 1 parent b2dda8b
Jacob Kaplan-Moss jacobian authored
24 django_website/docs/management/commands/update_docs.py
View
@@ -4,6 +4,7 @@
"""
from __future__ import absolute_import
+import os
import json
import haystack
import optparse
@@ -53,6 +54,11 @@ def handle_noargs(self, **kwargs):
#
# Use Sphinx to build the release docs into JSON and HTML documents.
#
+ if release.docs_subdir:
+ source_dir = destdir.child(*release.docs_subdir.split('/'))
+ else:
+ source_dir = destdir
+
for builder in ('json', 'html'):
# Make the directory for the built files - sphinx-build doesn't
# do it for us, apparently.
@@ -66,7 +72,7 @@ def handle_noargs(self, **kwargs):
sphinx.cmdline.main(['sphinx-build',
'-b', builder,
'-q', # Be vewy qwiet
- destdir, # Source file directory
+ source_dir, # Source file directory
build_dir, # Destination directory
])
@@ -150,3 +156,19 @@ def zipfile_inclusion_filter(f):
def update_svn(self, url, destdir):
subprocess.call(['svn', 'checkout', '-q', url, destdir])
+
+ def update_git(self, url, destdir):
+ if '@' in url:
+ repo, branch = url.rsplit('@', 1)
+ else:
+ repo, branch = url, 'master'
+ if destdir.exists():
+ try:
+ cwd = os.getcwdu()
+ os.chdir(destdir)
+ subprocess.call(['git', 'fetch'])
+ subprocess.call(['git', 'reset', '--hard', branch])
+ finally:
+ os.chdir(cwd)
+ else:
+ subprocess.call(['git', 'clone', '-q', '--branch', branch, repo, destdir])
47 django_website/docs/migrations/0004_add_git_support.py
View
@@ -0,0 +1,47 @@
+# encoding: utf-8
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+class Migration(SchemaMigration):
+
+ def forwards(self, orm):
+
+ # Adding field 'DocumentRelease.docs_subdir'
+ db.add_column('docs_documentrelease', 'docs_subdir', self.gf('django.db.models.fields.CharField')(default='', max_length=200, blank=True), keep_default=False)
+
+ # Changing field 'DocumentRelease.scm_url'
+ db.alter_column('docs_documentrelease', 'scm_url', self.gf('django.db.models.fields.CharField')(max_length=200))
+
+
+ def backwards(self, orm):
+
+ # Deleting field 'DocumentRelease.docs_subdir'
+ db.delete_column('docs_documentrelease', 'docs_subdir')
+
+ # Changing field 'DocumentRelease.scm_url'
+ db.alter_column('docs_documentrelease', 'scm_url', self.gf('django.db.models.fields.URLField')(max_length=200))
+
+
+ models = {
+ 'docs.document': {
+ 'Meta': {'object_name': 'Document'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'path': ('django.db.models.fields.CharField', [], {'max_length': '500'}),
+ 'release': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'documents'", 'to': "orm['docs.DocumentRelease']"}),
+ 'title': ('django.db.models.fields.CharField', [], {'max_length': '500'})
+ },
+ 'docs.documentrelease': {
+ 'Meta': {'object_name': 'DocumentRelease'},
+ 'docs_subdir': ('django.db.models.fields.CharField', [], {'max_length': '200', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'is_default': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'lang': ('django.db.models.fields.CharField', [], {'default': "'en'", 'max_length': '2'}),
+ 'scm': ('django.db.models.fields.CharField', [], {'max_length': '10'}),
+ 'scm_url': ('django.db.models.fields.CharField', [], {'max_length': '200'}),
+ 'version': ('django.db.models.fields.CharField', [], {'max_length': '20'})
+ }
+ }
+
+ complete_apps = ['docs']
17 django_website/docs/models.py
View
@@ -12,25 +12,28 @@ class DocumentRelease(models.Model):
"""
DEFAULT_CACHE_KEY = "%s_recent_release" % settings.CACHE_MIDDLEWARE_KEY_PREFIX
SVN = 'svn'
+ GIT = 'git'
SCM_CHOICES = (
(SVN, 'SVN'),
+ (GIT, 'git'),
)
-
+
lang = models.CharField(max_length=2, choices=settings.LANGUAGES, default='en')
version = models.CharField(max_length=20)
scm = models.CharField(max_length=10, choices=SCM_CHOICES)
- scm_url = models.URLField()
+ scm_url = models.CharField(max_length=200)
+ docs_subdir = models.CharField(max_length=200, blank=True)
is_default = models.BooleanField()
-
+
objects = DocumentReleaseManager()
-
+
def __unicode__(self):
return "%s/%s" % (self.lang, self.version)
-
+
@models.permalink
def get_absolute_url(self):
return ('document-index', [], {'lang': self.lang, 'version': self.version})
-
+
def save(self, *args, **kwargs):
# There can be only one. Default, that is.
if self.is_default:
@@ -41,7 +44,7 @@ def save(self, *args, **kwargs):
settings.CACHE_MIDDLEWARE_SECONDS,
)
super(DocumentRelease, self).save(*args, **kwargs)
-
+
@property
def human_version(self):
"""
Please sign in to comment.
Something went wrong with that request. Please try again.