#!/usr/bin/env python
# coding: utf-8
# /*##########################################################################
#
# Copyright (c) 2017 European Synchrotron Radiation Facility
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
# ###########################################################################*/
"""This module describe tomwer applications which are available  through
the silx launcher.

Your environment should provide a command `tomwer`. You can reach help with
`tomwer --help`, and check the version with `tomwer --version`.
"""

__authors__ = ["V. Valls", "P. Knobel", "H. Payno"]
__license__ = "MIT"
__date__ = "04/01/2018"


import logging
logging.basicConfig()

import sys
from silx.utils.launcher import Launcher
import tomwer.version


def main():
    """Main function of the launcher

    This function is referenced in the setup.py file, to create a
    launcher script generated by setuptools.

    :rtype: int
    :returns: The execution status
    """
    _version = tomwer.version.version
    launcher = Launcher(prog="tomwer", version=_version)
    launcher.add_command("canvas",
                         module_name="tomwer.app.canvas",
                         description="open the orange-canvas")
    launcher.add_command("axis",
                         module_name="tomwer.app.axis",
                         description="Compute center of rotation of a scan or "
                                     "between two projections")
    launcher.add_command("rsync",
                         module_name="tomwer.app.rsync",
                         description="Tool for synchronization between "
                                     "acquisition contained in a folder and "
                                     "a target folder")
    launcher.add_command("darkref",
                         module_name="tomwer.app.darkref",
                         description="Compute mean / median darks and flat "
                                     "fields")
    launcher.add_command("ftseries",
                         module_name="tomwer.app.ftseries",
                         description="Interface for pyhst reconstruction")
    launcher.add_command("liveslice",
                         module_name="tomwer.app.liveslice",
                         description="Run liveslice application")
    launcher.add_command("samplemoved",
                         module_name="tomwer.app.samplemoved",
                         description="Interface to check if a sample have "
                                     "moved during acquisition ")
    launcher.add_command("sinogram-viewer",
                         module_name="tomwer.app.sinogramviewer",
                         description="Allows to compute on the fly sinogram "
                                     "and display them")
    launcher.add_command("slicestack",
                         module_name="tomwer.app.slicestack",
                         description="Display each reconstruction contained "
                                     "in the ROOT_DIR or sub-folders")
    launcher.add_command("radiostack",
                         module_name="tomwer.app.radiostack",
                         description="Display each radio contained in the "
                                     "ROOT_DIR or sub-folders")
    launcher.add_command("lamino",
                         module_name="tomwer.app.lamino",
                         description="Run laminography reconstruction using tofu")
    launcher.add_command("nabu",
                         module_name="tomwer.app.nabu",
                         description="Use nabu to reconstruct a given scan")
    launcher.add_command("test",
                         module_name="tomwer.app.test_",
                         description="Launch tomwer unittest")
    status = launcher.execute(sys.argv)
    return status


if __name__ == "__main__":
    # executed when using python -m PROJECT_NAME
    status = main()
    sys.exit(status)
