#!/usr/bin/env python

# Copyright 2015 Earth Sciences Department, BSC-CNS

# This file is part of Autosubmit.

# Autosubmit is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# Autosubmit is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with Autosubmit.  If not, see <http://www.gnu.org/licenses/>.

"""Script for handling experiment monitoring"""
import os
import sys

script_dir = os.path.abspath(os.path.dirname(sys.argv[0]))
sys.path.append(script_dir)
sys.path.append(os.path.normpath(os.path.join(script_dir, os.pardir)))
# noinspection PyUnresolvedReferences
from log.log import Log, AutosubmitCritical, AutosubmitError
from autosubmit import delete_lock_file, exit_from_error
from autosubmit.autosubmit import Autosubmit


# noinspection PyProtectedMember
def main():
    try:
        return_value = Autosubmit.parse_args()
        delete_lock_file()
        return_value = return_value if type(return_value) is int else 0
        os._exit(return_value)
    except BaseException as e:
        exit_from_error(e)


if __name__ == "__main__":
    main()
