From: W. Trevor King Date: Sun, 13 Jan 2013 14:45:23 +0000 (-0500) Subject: script-publish.py: Use -o/--output instead of -t/--target X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=a8fa608ce0ac27370892cdf17f48356dc9c7f980;p=blog.git script-publish.py: Use -o/--output instead of -t/--target This seems to be more conventional. As a side benefit, we can now use -t as the short form of --term. --- diff --git a/posts/script/script-publish.py b/posts/script/script-publish.py index bd64c81..d1c74ba 100755 --- a/posts/script/script-publish.py +++ b/posts/script/script-publish.py @@ -680,10 +680,10 @@ class ScriptParser (object): body.text = body.tail = '\n' return tree - def process(self, source, target=None): + def process(self, source, output=None): typescript = self._read_file(filename=source) # byte stream rendered = self.render(typescript) - self._write_etree(tree=rendered, filename=target) + self._write_etree(tree=rendered, filename=output) def _read_file(self, filename=None): # byte stream @@ -727,10 +727,10 @@ class ScriptServerApp (ScriptParser): .. _PEP 333: http://www.python.org/dev/peps/pep-0333/ """ - def __init__(self, source=None, target=None, delay=2, **kwargs): + def __init__(self, source=None, output=None, delay=2, **kwargs): super(ScriptServerApp, self).__init__(**kwargs) self._source = source - self._target = target + self._output = output self._delay = delay self._next_render = 0 self._content = None @@ -738,7 +738,7 @@ class ScriptServerApp (ScriptParser): def process(self): if _time.time() > self._next_render: super(ScriptServerApp, self).process( - source=self._source, target=self._target) + source=self._source, output=self._output) self._next_render += self._delay def _write_etree(self, tree, **kwargs): @@ -800,13 +800,14 @@ if __name__ == '__main__': '-s', '--source', metavar='SOURCE', help='source script file (defaults to stdin)') parser.add_argument( - '-t', '--target', metavar='TARGET', - help='target HTML file (defaults to stdout)') + '-o', '--output', metavar='OUTPUT', + help='output HTML file (defaults to stdout)') parser.add_argument( '-e', '--encoding', metavar='ENCODING', default='utf-8', help='file content encoding (defaults to utf-8)') parser.add_argument( - '--term', metavar='TERM', default=_os.environ.get('TERM', 'ansi'), + '-t', '--term', metavar='TERM', + default=_os.environ.get('TERM', 'ansi'), help='terminal to emulate (defaults to $TERM)') parser.add_argument( '-p', '--poll', metavar='SECONDS', type=float, @@ -823,12 +824,12 @@ if __name__ == '__main__': sp = ScriptParser(encoding=args.encoding, term=args.term) if args.serve: server = ScriptServerApp( - source=args.source, target=args.target, delay=args.poll or 2, + source=args.source, output=args.output, delay=args.poll or 2, encoding=args.encoding, term=args.term) server.run(port=args.serve) elif args.poll: while True: - sp.process(source=args.source, target=args.target) + sp.process(source=args.source, output=args.output) _time.sleep(args.poll) else: # single shot - sp.process(source=args.source, target=args.target) + sp.process(source=args.source, output=args.output)