Commits

John Mulligan committed 1f8aaba

add dump{tags,titles} commands

  • Participants
  • Parent commits 6509d00

Comments (0)

Files changed (2)

File muyhomepage2/app/build.py

         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())

File muyhomepage2/app/cli.py

     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'),
         'opts': [],
         'help': '[SOURCEDIR]',
         },
+    'dumptags': {
+        'target': dumptags,
+        'opts': [
+            ('no-titles', 'T', None, 'only display tags'),
+        ],
+        'help': '[SOURCEDIR]',
+        },
+    'dumptitles': {
+        'target': dumptitles,
+        'opts': [],
+        'help': '[SOURCEDIR]',
+        },
     }