#!/usr/bin/env python
# -*- coding: utf-8

import os.path
import sys
import subprocess


def run(args, env=None):
    proc = subprocess.Popen(args, env=env)
    proc.wait()
    code = proc.returncode
    sys.exit(code)


def main():
    try:
        cmd = sys.argv[1]
    except IndexError:
        sys.exit('manage takes at least one argument')
    if cmd == 'test':
        run(['nosetests', '-c', '.noserc'] + sys.argv[2:])
    else:
        pythonpath = 'PYTHONPATH=' + os.path.dirname(__file__)
        run(['sudo', pythonpath, 'bin/pywebstack'] + sys.argv[1:])


if __name__ == '__main__':
    main()
