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
.. _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
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):
'-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,
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)