cheat.sh icon indicating copy to clipboard operation
cheat.sh copied to clipboard

Use pure Python ansi2html

Open abitrolly opened this issue 5 years ago • 2 comments
trafficstars

I noticed that web server runs bash and gawk as a subprocess to present text info as HTML.

Traceback
✗ podman run -it --rm -p 8002 cheat.sh bin/srv.py --debug
Starting server on 0.0.0.0:8002
Traceback (most recent call last):
  File "/usr/lib/python3.8/site-packages/gevent/pywsgi.py", line 968, in handle_one_response
    self.run_application()
  File "/usr/lib/python3.8/site-packages/gevent/pywsgi.py", line 915, in run_application
    self.result = self.application(self.environ, self.start_response)
  File "/usr/lib/python3.8/site-packages/flask/app.py", line 2464, in __call__
    return self.wsgi_app(environ, start_response)
  File "/usr/lib/python3.8/site-packages/flask/app.py", line 2450, in wsgi_app
    response = self.handle_exception(e)
  File "/usr/lib/python3.8/site-packages/flask/app.py", line 1867, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/lib/python3.8/site-packages/flask/_compat.py", line 39, in reraise
    raise value
  File "/usr/lib/python3.8/site-packages/flask/app.py", line 2447, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/lib/python3.8/site-packages/flask/app.py", line 1952, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/lib/python3.8/site-packages/flask/app.py", line 1821, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/lib/python3.8/site-packages/flask/_compat.py", line 39, in reraise
    raise value
  File "/usr/lib/python3.8/site-packages/flask/app.py", line 1950, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/lib/python3.8/site-packages/flask/app.py", line 1936, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "bin/srv.py", line 267, in answer
    result, found = cheat_wrapper(topic, request_options=options, output_format=output_format)
  File "/app/lib/cheat_wrapper.py", line 117, in cheat_wrapper
    return frontend.html.visualize(answer_data, request_options)
  File "/app/lib/frontend/html.py", line 50, in visualize
    return _render_html(query, result, editable, repository_button, topics_list, request_options), found
  File "/app/lib/frontend/html.py", line 89, in _render_html
    result = _html_wrapper(result)
  File "/app/lib/frontend/html.py", line 78, in _html_wrapper
    proc = Popen(
  File "/usr/lib/python3.8/site-packages/gevent/subprocess.py", line 745, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/usr/lib/python3.8/site-packages/gevent/subprocess.py", line 1637, in _execute_child
    raise child_exception
FileNotFoundError: [Errno 2] No such file or directory: 'bash'
2020-07-28T20:07:46Z {'REMOTE_ADDR': '127.0.0.1', 'REMOTE_PORT': '49666', 'HTTP_HOST': 'localhost:8002', (hidden keys: 26)} failed with FileNotFoundError

It should be possible to replace https://github.com/chubin/cheat.sh/blob/master/share/ansi2html.sh with pure Python alternative https://pypi.org/project/ansi2html/

abitrolly avatar Jul 28 '20 22:07 abitrolly

I think it is a good idea, we should test it

chubin avatar Oct 12 '20 12:10 chubin

This can be useful for a comparison https://github.com/theZiz/aha as well as checking out features in newer ansi2html version https://github.com/pixelb/scripts/blob/master/scripts/ansi2html.sh

abitrolly avatar Sep 08 '22 09:09 abitrolly