Commits

David Chambers committed 7ed8477

Added an update script. It must be passed one argument, the URL at which the
Mango site is mounted (`./update.py http://example.com/blog/`, for example).

Comments (0)

Files changed (3)

+#!/usr/bin/env python
+
+import os
+import sys
+
+try:
+    url = sys.argv[1]
+except IndexError:
+    sys.stderr.write('You must provide the URL at which your Mango site is mounted.\n')
+    sys.exit(1)
+
+try:
+    from mercurial import commands, hg, ui
+except ImportError:
+    sys.stderr.write('The mercurial module is missing. Run `pip install mercurial`.\n')
+
+head, tail = os.path.split(os.path.abspath(__file__))
+while tail:
+    if tail == 'mango':
+        sys.path.append(head)
+        break
+    head, tail = os.path.split(head)
+else:
+    sys.stderr.write('Failed to locate Mango.\n')
+    sys.exit(1)
+
+from mango.settings import PROJECT_PATH
+head, tail = os.path.split(PROJECT_PATH)
+sys.path.append(head)
+os.environ['DJANGO_SETTINGS_MODULE'] = '%s.settings' % tail
+
+import mango
+from mango.main import Index
+from mango.settings import MANGO_PATH, REPO_URL
+
+repo = hg.repository(ui=ui.ui(), path=MANGO_PATH)
+old_tip = repo['tip']
+commands.pull(ui=ui.ui(), repo=repo, source=REPO_URL, update=True)
+new_tip = repo['tip']
+
+if new_tip == old_tip:
+    sys.stdout.write('You are already running the latest version of Mango.\n')
+    sys.exit()
+
+# clear documents from the cache
+Index().uncache(uncache_documents=True)
+
+# hard-code the base URL
+mango.decorators.baseurl = lambda: url
+
+# create and cache documents
+Index()
+
+sys.stdout.write('Successfully updated to Mango %s (%s).\n' % (mango.VERSION, new_tip))
+sys.exit()
 from django.utils.safestring import mark_safe
 
 import mango
-from mango import utf8
+from mango import decorators, utf8
 from mango.settings import (AUTHORS, COMMENTS_REQUIRE_APPROVAL, DISQUS,
         DOCUMENTS_PATH, FORUM, INDEX_CACHE_SECONDS, KILOBYTE_SIZE,
         MARKDOWN_DATE_FORMAT, MARKDOWN_EXTENSIONS, MARKDOWN_TIME_FORMAT,
         POST_CACHE_SECONDS, PROJECT_PATH, SHORT_URL_BASE, TIME_ZONES)
-from mango.decorators import baseurl
 from mango.templatetags.mango_extras import _convert, convert_html_chars
 from mango.utils import canonicalize, logger, replace
 
         canon_path = (u'%s%s/' % (mount_point, '/'.join(canon_fragments))).replace(*repl).lower()
         short_path = (u'%s%s/' % (mount_point, '/'.join(short_fragments))).replace(*repl).lower()
         self.urls = {
-            'canon': {'rel': canon_path, 'abs': u'%s%s' % (baseurl(), canon_path[1:])},
-            'short': {'rel': short_path, 'abs': u'%s%s' % (SHORT_URL_BASE or baseurl(), short_path[1:])},
+            'canon': {'rel': canon_path, 'abs': u'%s%s' % (decorators.baseurl(), canon_path[1:])},
+            'short': {'rel': short_path, 'abs': u'%s%s' % (SHORT_URL_BASE or decorators.baseurl(), short_path[1:])},
         }
 
         aliases = [u'']
 class Index(Category):
     @staticmethod
     def cache_key():
-        return 'mango:toplevel:%s' % baseurl()
+        return 'mango:toplevel:%s' % decorators.baseurl()
 
     def __new__(cls):
         def create_index():
 if not os.path.isabs(DOCUMENTS_PATH):
     DOCUMENTS_PATH = os.path.join(PROJECT_PATH, *DOCUMENTS_PATH.split(u'/'))
 
+REPO_URL = u'https://bitbucket.org/davidchambers/mango'
+
 def _unix_documents_path():
     fragments = []
     head, tail = os.path.split(DOCUMENTS_PATH)