#!/usr/bin/env python
"""
qiprofile

Starts the Quantitaive Imaging Profile web server.
"""

import sys
import os
import subprocess
import argparse

CMD = 'node'
"""The ``Node.js`` executable."""

APP = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'server.js'))
"""The Javascript to run."""


def main(argv=sys.argv):
    # Parse the command line arguments.
    opts = _parse_arguments()

    # Start the server.
    return subprocess.call([CMD, APP])


def _parse_arguments():
    """Parses the command line arguments."""
    parser = argparse.ArgumentParser()

    args = vars(parser.parse_args())
    nonempty_args = dict((k, v) for k, v in args.iteritems() if v != None)

    return nonempty_args


if __name__ == '__main__':
    sys.exit(main())
