#!/usr/bin/env python3
# PYTHON_ARGCOMPLETE_OK
# This file is part of Tryton.  The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
import os
import sys

try:
    import argcomplete
except ImportError:
    argcomplete = None

DIR = os.path.abspath(os.path.normpath(os.path.join(__file__,
    '..', '..', 'trytond')))
if os.path.isdir(DIR):
    sys.path.insert(0, os.path.dirname(DIR))

import trytond.commandline as commandline
from trytond.config import config

parser = commandline.get_parser_cron()
if argcomplete:
    argcomplete.autocomplete(parser)
options = parser.parse_args()
config.update_etc(options.configfile)
commandline.config_log(options)

import trytond.cron as cron
# Import after application is configured
from trytond.pool import Pool

with commandline.pidfile(options):
    Pool.start()
    cron.run(options)
