Commits

John Mulligan  committed 5ba1358

add software page handling

  • Participants
  • Parent commits 347da89

Comments (0)

Files changed (3)

File muyhomepage2/app/configuration.py

 from muyhomepage2.pagehandlers.standard import StandardHandler
 from muyhomepage2.pagehandlers.tagsummary import TagSummaryHandler
 from muyhomepage2.pagehandlers.tagglobal import TagGlobalHandler
+from muyhomepage2.pagehandlers.software import SoftwareHandler
 
 
 DEFAULT_HANDLERS = {
     'blog': StandardHandler,
     'tagsummary': TagSummaryHandler,
     'tagglobal': TagGlobalHandler,
-    'software': StandardHandler,
+    'software': SoftwareHandler,
     'atom': StandardHandler,
     'rss2': StandardHandler,
     }

File muyhomepage2/pagehandlers/software.py

+
+import re
+from muyhomepage2.pagehandlers import handler
+from muyhomepage2.text import wikirst
+
+class SoftwareHandler(handler.PageHandler):
+    def content(self):
+        return wikirst.format(self.page.body)
+
+    @property
+    def software(self):
+        return SoftwareInfo(self.page)
+
+    def template(self):
+        return 'softwarepage.html'
+
+    def extension(self, website, config):
+        return None
+
+
+class SoftwareInfo(object):
+    def __init__(self, page):
+        self.page = page
+
+    @property
+    def version(self):
+        ver = self.page.headers.get('software-version')
+        if not ver:
+            ver = self.page.headers.get('x-software-version')
+        if not ver:
+            ver = ''
+        return ver
+
+    @property
+    def language(self):
+        lang = self.page.headers.get('software-lang')
+        if not lang:
+            lang = self.page.headers.get('x-software-lang')
+        if not lang:
+            lang = ''
+        return lang
+
+    @property
+    def downloads(self):
+        dl = (self.page.headers.get('downloads') or '').strip()
+        if not dl:
+            return []
+        return list(parse_reflist(dl))
+
+    @property
+    def dependencies(self):
+        dp = (self.page.headers.get('dependencies') or '').strip()
+        if not dp:
+            return []
+        return list(parse_reflist(dp))
+
+    @property
+    def sources(self):
+    # Software-RCS: Hg
+    # Software-RCS-Url: http://hg.asynchrono.us/scrob-ws
+        rcs = self.page.headers.get('software-rcs')
+        if not rcs:
+            return []
+        if rcs in ('Hg', 'Mercurial'):
+            return self._hgsources()
+        raise ValueError('unexpected rcs name: %r' % rcs)
+
+    def _hgsources(self):
+        url = self.page.headers.get('software-rcs-url')
+        if not url:
+            return []
+        return [
+            ('Type <tt class="literal">hg clone %s</tt> at the command'
+             ' prompt to get a copy of the development source code.') % url,
+            '<a href="%s">Source Code Web View</a>' % url,
+            ]
+
+
+def parse_reflist(txt):
+    for part in (d.strip() for d in txt.split(';')):
+        if not part:
+            continue
+        tmatch = re.search(r'(.+) <(.+)>', part.replace('\n', ' '))
+        if not tmatch:
+            raise ValueError('invalid section: %r' % part)
+        label = tmatch.group(1).strip()
+        url = tmatch.group(2).strip()
+        yield (url, label)

File skins/default/softwarepage.html

+{% extends "base.html" %}
+
+{% block main %}
+<div id="page-content">
+  <h2>{{current.page.title}}</h2>
+  <div></div>
+  <div class="written-text">
+    {{current.content()}}
+  </div>
+  <div></div>
+
+  <div class="post-text">
+    <h3>Details</h3>
+    <a name="software-details"></a>
+    <dl>
+        {% if current.software.version %}
+        <dt>Current Version</dt>
+        <dd>{{current.software.version}}</dd>
+        {% endif %}
+
+        {% if current.software.language %}
+        <dt>Language</dt>
+        <dd>{{current.software.language}}</dd>
+        {% endif %}
+
+        {% if current.software.dependencies %}
+        <dt>Dependencies</dt>
+        {% for link, text in current.software.dependencies %}
+          <dd><a href="{{link}}">{{text}}</a></dd>
+        {% endfor %}
+        {% endif %}
+
+        {% if current.software.downloads %}
+        <dt>Downloads</dt>
+        {% for link, text in current.software.downloads %}
+          <dd><a href="{{link}}">{{text}}</a></dd>
+        {% endfor %}
+        {% endif %}
+
+        {% if current.software.sources %}
+        <dt>Downloads</dt>
+        {% for html in current.software.sources %}
+          <dd>{{html}}</dd>
+        {% endfor %}
+        {% endif %}
+    </dl>
+
+  <ul class="tidbits">
+    <li>
+        <a href="mailto:phglogistonjohn+web@gmail.com?={{current.page.title}}">
+            Comment on {{current.page.title}}
+        </a>
+    </li>
+    <li>
+        <!-- repeat tidbits -->
+    </li>
+  </ul>
+</div>
+{% endblock %}