Source

hgblog / hooks.patch

# HG changeset patch
# Parent 8300548579e43167adf173c74eac06dce69c67ab

diff -r 8300548579e4 hgblog/generate_html.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hgblog/generate_html.py	Fri Sep 30 01:32:49 2011 -0400
@@ -0,0 +1,7 @@
+from hgblog.refresh import refresh
+
+def htmlize_articles(ui, repo, **kwargs):
+    """Calls on Sphinx to turn our .rst files into pretty HTML"""
+
+    refresh(repo)
+
diff -r 8300548579e4 hgblog/refresh.py
--- a/hgblog/refresh.py	Fri Sep 30 00:59:01 2011 -0400
+++ b/hgblog/refresh.py	Fri Sep 30 01:32:49 2011 -0400
@@ -1,19 +1,15 @@
-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"""
 
+    from sphinx.cmdline import main as sphinxify
+    from hgblog.utils import get_repo, get_tracked_rst_files
+
     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)
+    files_to_consider = get_tracked_rst_files(repo)
 
     # tell Sphinx to HTML-ize the .rst files we found
     args = [
diff -r 8300548579e4 hgblog/utils.py
--- a/hgblog/utils.py	Fri Sep 30 00:59:01 2011 -0400
+++ b/hgblog/utils.py	Fri Sep 30 01:32:49 2011 -0400
@@ -1,9 +1,49 @@
-from mercurial.cmdutil import findrepo
-from mercurial import hg
-from mercurial.ui import ui
 import os
 
+def get_tracked_rst_files(repo=None):
+    """Returns a list of .rst files that are under version control"""
+
+    from mercurial.match import match
+
+    if repo is None:
+        repo = get_repo()
+
+    m = match(repo, '.', ('*.rst',), {}, default='relglob')
+    tracked = filter(lambda f: f in repo.dirstate, repo[None].walk(m))
+    return [os.path.join(repo.root, f) for f in tracked]
+
+def get_untracked_rst_files(repo=None):
+    """
+    Returns a list of all .rst files that are not currently tracked by
+    Mercurial
+    """
+
+    if repo is None:
+        repo = get_repo()
+
+    tracked = get_tracked_rst_files(repo)
+    all_files = []
+
+    for path, dirs, files in os.walk(repo.root):
+        for d in dirs:
+            if d.startswith('.'):
+                dirs.remove(d)
+
+        rst_files = filter(lambda s: s.endswith('.rst'), files)
+
+        for f in rst_files:
+            full_path = os.path.join(path, f)
+            all_files.append(full_path)
+
+    untracked = filter(lambda f: f not in tracked, all_files)
+    source = os.path.join(repo.root, 'source')
+    return [f.replace(source, '').strip('/') for f in untracked]
+
 def get_repo(path=None):
+    from mercurial.cmdutil import findrepo
+    from mercurial import hg
+    from mercurial.ui import ui
+
     if path is None:
         path = os.getcwd()
 
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.