hgblog / rename_files.patch

# HG changeset patch
# Parent 04464ddd8808c655110c8203a7cbd712df54ddbc

diff --git a/.hgignore b/.hgignore
--- a/.hgignore
+++ b/.hgignore
@@ -14,3 +14,4 @@
 ^env/
 \.DS_Store$
 ~$
+.*\.swp
diff --git a/README b/README
--- a/README
+++ b/README
@@ -23,7 +23,7 @@ After installing::
 
 Then, direct your browser to ``_build/html/index.html``.
 
-Or read them online at <http://sphinx.pocoo.org/>.
+Or read them online at <http://sphinx.pocoo.org>.
 
 
 Contributing
diff --git a/README.rst b/README.rst
new file mode 120000
--- /dev/null
+++ b/README.rst
@@ -0,0 +1,1 @@
+README
\ No newline at end of file
diff --git a/hgblog/__init__.py b/hgblog/__init__.py
new file mode 100644
--- /dev/null
+++ b/hgblog/__init__.py
@@ -0,0 +1,4 @@
+from server import serve
+
+__version__ = '0.5'
+
diff --git a/hgblog/refresh.py b/hgblog/refresh.py
new file mode 100644
--- /dev/null
+++ b/hgblog/refresh.py
@@ -0,0 +1,26 @@
+from mercurial.match import match
+from mercurial.ui import ui
+from sphinx.cmdline import main as sphinxify
+import os
+
+from hgblog.utils import get_repo
+
+def refresh(repo=None):
+    """Calls on Sphinx to turn our .rst files into pretty HTML"""
+
+    if repo is None:
+        repo = get_repo()
+
+    # find all .rst files that Mercurial is currently tracking
+    m = match(repo.root, repo.getcwd(), ('*.rst',))
+    files_to_consider = repo[None].walk(m)
+
+    # tell Sphinx to HTML-ize the .rst files we found
+    args = [
+        '-bdirhtml',
+        '-d%s' % os.path.join(repo.root, 'build', 'doctrees'),
+        os.path.join(repo.root, 'source'),
+        os.path.join(repo.root, 'build', 'html'),
+    ] + files_to_consider
+    sphinxify(args)
+
diff --git a/hgblog/server.py b/hgblog/server.py
new file mode 100755
--- /dev/null
+++ b/hgblog/server.py
@@ -0,0 +1,35 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+from BaseHTTPServer import HTTPServer
+from SimpleHTTPServer import SimpleHTTPRequestHandler
+from optparse import OptionParser
+import os
+
+from hgblog.utils import get_repo
+
+def serve():
+    """Begins a static HTML web server for an HgBlog"""
+
+    # determine the port on which to listen for traffic
+    parser = OptionParser()
+    parser.add_option('-p', '--port', dest='port', default=8000,
+            help="The port to serve your blog on")
+    options, args = parser.parse_args()
+    port = int(options.port)
+
+    # get the root directory for the HgBlog repo
+    repo = get_repo()
+    html_path = os.path.join(repo.root, 'build', 'html')
+    os.chdir(html_path)
+
+    try:
+        server = HTTPServer(('', port), SimpleHTTPRequestHandler)
+        print 'Serving HTML in %s on port %s...' % (html_path, port)
+        server.serve_forever()
+    except KeyboardInterrupt:
+        server.socket.close()
+
+if __name__ == '__main__':
+    serve()
+
diff --git a/hgblog/utils.py b/hgblog/utils.py
new file mode 100644
--- /dev/null
+++ b/hgblog/utils.py
@@ -0,0 +1,13 @@
+from mercurial.cmdutil import findrepo
+from mercurial import hg
+from mercurial.ui import ui
+import os
+
+def get_repo(path=None):
+    if path is None:
+        path = os.getcwd()
+
+    repo_root = findrepo(path)
+    repo = hg.repository(ui(), path=repo_root)
+    return repo
+
diff --git a/setup.cfg b/setup.cfg
--- a/setup.cfg
+++ b/setup.cfg
@@ -1,6 +1,6 @@
 [egg_info]
-tag_build = dev
-tag_date = true
+tag_build = 
+tag_date = false
 
 [aliases]
 release = egg_info -RDb ''
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -10,6 +10,7 @@ import os
 import sys
 from distutils import log
 
+import hgblog
 import sphinx
 
 long_desc = '''
@@ -159,15 +160,15 @@ else:
 
 
 setup(
-    name='Sphinx',
-    version=sphinx.__version__,
-    url='http://sphinx.pocoo.org/',
-    download_url='http://pypi.python.org/pypi/Sphinx',
+    name='hgblog',
+    version=hgblog.__version__,
+    url='http://bitbucket.org/codekoala/hgblog/',
+    download_url='http://pypi.python.org/pypi/hgblog',
     license='BSD',
-    author='Georg Brandl',
-    author_email='georg@python.org',
-    description='Python documentation generator',
-    long_description=long_desc,
+    author='Josh VanderLinden',
+    author_email='codekoala@gmail.com',
+    description='Sphinx-based blogging engine',
+    long_description=open('README').read(),
     zip_safe=False,
     classifiers=[
         'Development Status :: 5 - Production/Stable',
@@ -187,12 +188,14 @@ setup(
     include_package_data=True,
     entry_points={
         'console_scripts': [
-            'sphinx-build = sphinx:main',
-            'sphinx-quickstart = sphinx.quickstart:main',
-            'sphinx-autogen = sphinx.ext.autosummary.generate:main',
+            'hgblog-build = sphinx:main',
+            'hgblog-quickstart = sphinx.quickstart:main',
+            'hgblog-autogen = sphinx.ext.autosummary.generate:main',
+            'hgblog-serve = hgblog.server:serve',
+            'hgblog-refresh = hgblog.refresh:refresh',
         ],
         'distutils.commands': [
-            'build_sphinx = sphinx.setup_command:BuildDoc',
+            'build_hgblog = sphinx.setup_command:BuildDoc',
         ],
     },
     install_requires=requires,
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.