add dump{tags,titles} commands
2 files changed, 65 insertions(+), 0 deletions(-)

M muyhomepage2/app/build.py
M muyhomepage2/app/cli.py
M muyhomepage2/app/build.py +24 -0
@@ 34,6 34,30 @@ class TemplateConfig(configuration.Confi
         return None
 
 
+def dumpbytags(config):
+    website = site.Site()
+    website.pages = site.read_site_pages(config.page_cache())
+    site.update_site_tags(website, config.tag_cache())
+    cached = [p.filename for p in website.pages]
+    for pagefile in page.walkpages(config.root()):
+        if pagefile not in cached:
+            website.pages.add(page.parse(pagefile))
+    for tag, pgs in website.tagmap.iteritems():
+        for pg in pgs:
+            yield (tag, pg)
+
+
+def dumppages(config):
+    website = site.Site()
+    website.pages = site.read_site_pages(config.page_cache())
+    site.update_site_tags(website, config.tag_cache())
+    cached = [p.filename for p in website.pages]
+    for pagefile in page.walkpages(config.root()):
+        if pagefile not in cached:
+            website.pages.add(page.parse(pagefile))
+    return iter(website.pages)
+
+
 def build(config):
     website = site.Site()
     website.pages = site.read_site_pages(config.page_cache())

          
M muyhomepage2/app/cli.py +41 -0
@@ 54,6 54,35 @@ def flushcache(sourcedir='.', **opts):
     zap(config.tag_cache(), opts.get('verbose'))
 
 
+def dumptags(sourcedir='.', no_titles=False, **opts):
+    os.chdir(sourcedir)
+    config = _newconfig(opts)
+    stags = sorted(muyhomepage2.app.build.dumpbytags(config))
+    if no_titles:
+        shown = []
+        for tag, _ in stags:
+            if tag not in shown:
+                print tag
+                shown.append(tag)
+    else:
+        for tag, page in stags:
+            print '%s: %s' % (tag, page.title)
+    return
+
+
+def dumptitles(sourcedir='.', **opts):
+    os.chdir(sourcedir)
+    config = _newconfig(opts)
+    pages = muyhomepage2.app.build.dumppages(config)
+    for title in sorted(p.title for p in pages):
+        print title
+
+
+
+def edit(title, **opts):
+    pass
+
+
 OPTS = [
     ('config', 'C', '', 'path to configuration file'),
     ('verbose', 'v', None, 'be verbose'),

          
@@ 71,4 100,16 @@ CMDS = {
         'opts': [],
         'help': '[SOURCEDIR]',
         },
+    'dumptags': {
+        'target': dumptags,
+        'opts': [
+            ('no-titles', 'T', None, 'only display tags'),
+        ],
+        'help': '[SOURCEDIR]',
+        },
+    'dumptitles': {
+        'target': dumptitles,
+        'opts': [],
+        'help': '[SOURCEDIR]',
+        },
     }