#!/usr/bin/env python3

import argparse

class Formatter(argparse.ArgumentDefaultsHelpFormatter,
                argparse.RawDescriptionHelpFormatter): pass
desc = ('Run a web service in the background, and the html contents can be \n'
        'viewed at\n\n'
        '    localhost:5000\n\n'
        'using a web browser. When running this web service, users can view\n'
        'remotely using ssh to map the port:\n\n'
        '    ssh -L 5000:localhost:5000 server_address\n\n'
        'then access the page using a remote web browser.\n')
parser = argparse.ArgumentParser(description=desc, formatter_class=Formatter)
parser.add_argument('input_dir', help='The directory of html to run.')
parser.add_argument('-p', '--port', default=5000, type=int,
                    help='The localhost port if run flask.')

args = parser.parse_args()


import logging
from flask import Flask, render_template
from pathlib import Path


log = logging.getLogger('werkzeug')
log.setLevel(logging.ERROR)

args.input_dir = Path(args.input_dir).resolve()
image_dir = str(args.input_dir.joinpath('images'))
app = Flask(__name__, static_folder=image_dir,
            template_folder=str(args.input_dir))
@app.route('/')
def render():
    return render_template('index.html')
app.run(port=args.port)
