#!python

import argparse
import asyncio
import sys
from mt.base import path


async def main(args):
    try:
        res = path.exists_timeout(args.path, timeout=args.timeout)
        return int(not res)
    except asyncio.TimeoutError:
        return 2

if __name__ == '__main__':
    parser = argparse.ArgumentParser(description="Checks if a path exists, with timeout.")
    parser.add_argument('-t', '--timeout', default=3.0, type=float,
                        help="Timeout in seconds to check.")
    parser.add_argument('path', type=str,
                        help="Path to check for existence.")
    args = parser.parse_args()

    res = asyncio.run(main(args))
    sys.exit(res)
