X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=notmuch-to-html;h=5aba2a5fe67e6f13782a37590ff55411e7daf295;hb=f55ff7e7dcea67f544050c4a9508b3d1764d7c69;hp=f0146f8ea0c6137d15458609603be10635805fba;hpb=fb9f586a19b5872d1436d0dbe3e898ec463f72d6;p=obsolete%2Fnotmuch-to-html diff --git a/notmuch-to-html b/notmuch-to-html index f0146f8..5aba2a5 100755 --- a/notmuch-to-html +++ b/notmuch-to-html @@ -1,5 +1,8 @@ #!/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 # # dependencies @@ -62,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) @@ -201,11 +188,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'], ' ', '

', ]: @@ -253,14 +240,11 @@ 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', - metavar='VIEW') args = parser.parse_args() @@ -309,29 +293,21 @@ _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\n', + footer='

Generated: {date}\n\n'.format(date=datetime.datetime.utcnow().date()) ) if args.list_views: for view in config['views']: print(view['title']) sys.exit(0) -elif args.get_query != None: - for view in config['views']: - if args.get_query == view['title']: - print(' and '.join(view['query'])) - sys.exit(0) else: # only import notmuch if needed import notmuch