X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=notmuch-to-html;h=498921565379514b59e18ce83d532e8dd0d895d6;hb=158211a970cc971fda6f236ce0bcbcce6ba6dad8;hp=6b42affa8cb9d5ab9f8c1aa680da346808bdd1fd;hpb=d4563904220442f95826af4d03620b840f2f0bf7;p=obsolete%2Fnotmuch-to-html
diff --git a/notmuch-to-html b/notmuch-to-html
index 6b42aff..4989215 100755
--- a/notmuch-to-html
+++ b/notmuch-to-html
@@ -45,6 +45,22 @@ import xml.sax.saxutils
_ENCODING = 'UTF-8'
_PAGES = {}
+DEFAULT_CONFIG='''
+{{
+ "meta": {{
+ "title": "Page title",
+ "blurb": "Page description"
+ }},
+
+ "views": [
+ {{
+ "title": "View title",
+ "comment": "View description",
+ "query": [ "{query}" ]
+ }}
+ ]
+}}'''
+
if not hasattr(collections, 'OrderedDict'): # Python 2.6 or earlier
class _OrderedDict (dict):
@@ -188,11 +204,11 @@ class HtmlPage (Page):
stream.write(view['comment'])
stream.write('\n')
for line in [
- 'The view is generated from the following query:',
+ '
This view is generated from the following query:',
'
',
'',
' ',
- view['query-string'],
+ 'notmuch search ' + view['query-string'],
'
',
'
',
]:
@@ -240,17 +256,29 @@ 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')
+group = parser.add_mutually_exclusive_group()
+group.add_argument('--config', help='path to configuration file',
+ metavar='PATH')
+group.add_argument('--query', help='path to configuration file',
+ metavar='PATH')
parser.add_argument('--list-views', help='list views',
action='store_true')
-parser.add_argument('--get-query', help='get query for view',
- metavar='VIEW')
args = parser.parse_args()
-config = read_config(path=args.config)
+if (args.config):
+ config = read_config(path=args.config)
+elif (args.query):
+ config = json.loads(DEFAULT_CONFIG.format(query=args.query))
+else:
+ print ('''To use notmuch-to-html, you need to provide a notmuch query. Try:
+
+ notmuch-to-html --query=tag:inbox
+
+Or 'notmuch-to-html --help' for additional options.''')
+ exit (0)
_PAGES['text'] = Page()
_PAGES['html'] = HtmlPage(
@@ -295,29 +323,25 @@ _PAGES['html'] = HtmlPage(
{title}
-
-Generated: {date}
{blurb}
Views
-'''.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='\n