]> git.cworth.org Git - obsolete/notmuch-to-html/blobdiff - notmuch-to-html
Move the generated date from the top of the page to the footer.
[obsolete/notmuch-to-html] / notmuch-to-html
index c3de6969f2cfbd0674f8efa81f587a00cdb7bd2d..edf5c974294d5fe80bfdd604e5fb0a5fb77fd73a 100755 (executable)
@@ -1,10 +1,26 @@
 #!/usr/bin/python
 #
+# Generate an HTML page with the result of one or more notmuch
+# searches, (with links to gmane views of each email if available).
+#
 # Copyright (c) 2011-2012 David Bremner <david@tethera.net>
-# License: Same as notmuch
+#
 # dependencies
 #       - python 2.6 for json
 #       - argparse; either python 2.7, or install separately
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see http://www.gnu.org/licenses/ .
 
 from __future__ import print_function
 from __future__ import unicode_literals
@@ -49,27 +65,11 @@ if not hasattr(collections, 'OrderedDict'):  # Python 2.6 or earlier
     collections.OrderedDict = _OrderedDict
 
 
-def read_config(path=None, encoding=None):
+def read_config(path, encoding=None):
     "Read config from json file"
     if not encoding:
         encoding = _ENCODING
-    if path:
-        fp = open(path)
-    else:
-        nmbhome = os.getenv('NMBGIT', os.path.expanduser('~/.nmbug'))
-
-        # read only the first line from the pipe
-        sha1_bytes = subprocess.Popen(
-            ['git', '--git-dir', nmbhome, 'show-ref', '-s', 'config'],
-            stdout=subprocess.PIPE).stdout.readline()
-        sha1 = sha1_bytes.decode(encoding).rstrip()
-
-        fp_byte_stream = subprocess.Popen(
-            ['git', '--git-dir', nmbhome, 'cat-file', 'blob',
-             sha1+':status-config.json'],
-            stdout=subprocess.PIPE).stdout
-        fp = codecs.getreader(encoding=encoding)(stream=fp_byte_stream)
-
+    fp = open(path)
     return json.load(fp)
 
 
@@ -188,11 +188,11 @@ class HtmlPage (Page):
             stream.write(view['comment'])
             stream.write('\n')
         for line in [
-                'The view is generated from the following query:',
+                '<p>This view is generated from the following query:',
                 '</p>',
                 '<p>',
                 '  <code>',
-                view['query-string'],
+                'notmuch search ' + view['query-string'],
                 '  </code>',
                 '</p>',
                 ]:
@@ -240,10 +240,9 @@ class HtmlPage (Page):
         return self._slug_regexp.sub('-', string)
 
 parser = argparse.ArgumentParser()
+parser.add_argument('config', help='path to configuration file', metavar='CONFIG_FILE')
 parser.add_argument('--text', help='output plain text format',
                     action='store_true')
-parser.add_argument('--config', help='load config from given file',
-                    metavar='PATH')
 parser.add_argument('--list-views', help='list views',
                     action='store_true')
 parser.add_argument('--get-query', help='get query for view',
@@ -296,18 +295,15 @@ _PAGES['html'] = HtmlPage(
 </head>
 <body>
 <h2>{title}</h2>
-<p>
-Generated: {date}<br />
 {blurb}
 </p>
 <h3>Views</h3>
-'''.format(date=datetime.datetime.utcnow().date(),
-           title=config['meta']['title'],
+'''.format(title=config['meta']['title'],
            blurb=config['meta']['blurb'],
            encoding=_ENCODING,
            inter_message_padding='0.25em',
            border_radius='0.5em'),
-    footer='</body>\n</html>\n',
+    footer='<hr><p>Generated: {date}</body>\n</html>\n'.format(date=datetime.datetime.utcnow().date())
     )
 
 if args.list_views: