Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added support for updating docs from git.

  • Loading branch information...
commit 02f01dc9f5d6f2c85b4de21053ee08b0b2850853 1 parent b2dda8b
Jacob Kaplan-Moss authored May 04, 2012
24  django_website/docs/management/commands/update_docs.py
@@ -4,6 +4,7 @@
4 4
 """
5 5
 from __future__ import absolute_import
6 6
 
  7
+import os
7 8
 import json
8 9
 import haystack
9 10
 import optparse
@@ -53,6 +54,11 @@ def handle_noargs(self, **kwargs):
53 54
             #
54 55
             # Use Sphinx to build the release docs into JSON and HTML documents.
55 56
             #
  57
+            if release.docs_subdir:
  58
+                source_dir = destdir.child(*release.docs_subdir.split('/'))
  59
+            else:
  60
+                source_dir = destdir
  61
+
56 62
             for builder in ('json', 'html'):
57 63
                 # Make the directory for the built files - sphinx-build doesn't
58 64
                 # do it for us, apparently.
@@ -66,7 +72,7 @@ def handle_noargs(self, **kwargs):
66 72
                 sphinx.cmdline.main(['sphinx-build',
67 73
                     '-b', builder,
68 74
                     '-q',              # Be vewy qwiet
69  
-                    destdir,           # Source file directory
  75
+                    source_dir,        # Source file directory
70 76
                     build_dir,         # Destination directory
71 77
                 ])
72 78
 
@@ -150,3 +156,19 @@ def zipfile_inclusion_filter(f):
150 156
 
151 157
     def update_svn(self, url, destdir):
152 158
         subprocess.call(['svn', 'checkout', '-q', url, destdir])
  159
+
  160
+    def update_git(self, url, destdir):
  161
+        if '@' in url:
  162
+            repo, branch = url.rsplit('@', 1)
  163
+        else:
  164
+            repo, branch = url, 'master'
  165
+        if destdir.exists():
  166
+            try:
  167
+                cwd = os.getcwdu()
  168
+                os.chdir(destdir)
  169
+                subprocess.call(['git', 'fetch'])
  170
+                subprocess.call(['git', 'reset', '--hard', branch])
  171
+            finally:
  172
+                os.chdir(cwd)
  173
+        else:
  174
+            subprocess.call(['git', 'clone', '-q', '--branch', branch, repo, destdir])
47  django_website/docs/migrations/0004_add_git_support.py
... ...
@@ -0,0 +1,47 @@
  1
+# encoding: utf-8
  2
+import datetime
  3
+from south.db import db
  4
+from south.v2 import SchemaMigration
  5
+from django.db import models
  6
+
  7
+class Migration(SchemaMigration):
  8
+
  9
+    def forwards(self, orm):
  10
+        
  11
+        # Adding field 'DocumentRelease.docs_subdir'
  12
+        db.add_column('docs_documentrelease', 'docs_subdir', self.gf('django.db.models.fields.CharField')(default='', max_length=200, blank=True), keep_default=False)
  13
+
  14
+        # Changing field 'DocumentRelease.scm_url'
  15
+        db.alter_column('docs_documentrelease', 'scm_url', self.gf('django.db.models.fields.CharField')(max_length=200))
  16
+
  17
+
  18
+    def backwards(self, orm):
  19
+        
  20
+        # Deleting field 'DocumentRelease.docs_subdir'
  21
+        db.delete_column('docs_documentrelease', 'docs_subdir')
  22
+
  23
+        # Changing field 'DocumentRelease.scm_url'
  24
+        db.alter_column('docs_documentrelease', 'scm_url', self.gf('django.db.models.fields.URLField')(max_length=200))
  25
+
  26
+
  27
+    models = {
  28
+        'docs.document': {
  29
+            'Meta': {'object_name': 'Document'},
  30
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
  31
+            'path': ('django.db.models.fields.CharField', [], {'max_length': '500'}),
  32
+            'release': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'documents'", 'to': "orm['docs.DocumentRelease']"}),
  33
+            'title': ('django.db.models.fields.CharField', [], {'max_length': '500'})
  34
+        },
  35
+        'docs.documentrelease': {
  36
+            'Meta': {'object_name': 'DocumentRelease'},
  37
+            'docs_subdir': ('django.db.models.fields.CharField', [], {'max_length': '200', 'blank': 'True'}),
  38
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
  39
+            'is_default': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
  40
+            'lang': ('django.db.models.fields.CharField', [], {'default': "'en'", 'max_length': '2'}),
  41
+            'scm': ('django.db.models.fields.CharField', [], {'max_length': '10'}),
  42
+            'scm_url': ('django.db.models.fields.CharField', [], {'max_length': '200'}),
  43
+            'version': ('django.db.models.fields.CharField', [], {'max_length': '20'})
  44
+        }
  45
+    }
  46
+
  47
+    complete_apps = ['docs']
17  django_website/docs/models.py
@@ -12,25 +12,28 @@ class DocumentRelease(models.Model):
12 12
     """
13 13
     DEFAULT_CACHE_KEY = "%s_recent_release" % settings.CACHE_MIDDLEWARE_KEY_PREFIX
14 14
     SVN = 'svn'
  15
+    GIT = 'git'
15 16
     SCM_CHOICES = (
16 17
         (SVN, 'SVN'),
  18
+        (GIT, 'git'),
17 19
     )
18  
-    
  20
+
19 21
     lang = models.CharField(max_length=2, choices=settings.LANGUAGES, default='en')
20 22
     version = models.CharField(max_length=20)
21 23
     scm = models.CharField(max_length=10, choices=SCM_CHOICES)
22  
-    scm_url = models.URLField()
  24
+    scm_url = models.CharField(max_length=200)
  25
+    docs_subdir = models.CharField(max_length=200, blank=True)
23 26
     is_default = models.BooleanField()
24  
-    
  27
+
25 28
     objects = DocumentReleaseManager()
26  
-    
  29
+
27 30
     def __unicode__(self):
28 31
         return "%s/%s" % (self.lang, self.version)
29  
-    
  32
+
30 33
     @models.permalink
31 34
     def get_absolute_url(self):
32 35
         return ('document-index', [], {'lang': self.lang, 'version': self.version})
33  
-            
  36
+
34 37
     def save(self, *args, **kwargs):
35 38
         # There can be only one. Default, that is.
36 39
         if self.is_default:
@@ -41,7 +44,7 @@ def save(self, *args, **kwargs):
41 44
                 settings.CACHE_MIDDLEWARE_SECONDS,
42 45
             )
43 46
         super(DocumentRelease, self).save(*args, **kwargs)
44  
-    
  47
+
45 48
     @property
46 49
     def human_version(self):
47 50
         """

0 notes on commit 02f01dc

Please sign in to comment.
Something went wrong with that request. Please try again.