#!/usr/bin/env python
import os
import sys

lib_path = os.path.relpath('etmQt/')
sys.path.append(lib_path)

if __name__ == "__main__":
    etmdir = ''
    etm = sys.argv[0]
    if (len(sys.argv) > 1 and os.path.isdir(sys.argv[1])):
        etmdir = sys.argv.pop(1)
    if len(sys.argv) > 1:
        if (sys.argv[1] not in ['a', 'c', 'l', 'm', 'n', 's', 'v', '?'] or
                (sys.argv[1] == '?' and len(sys.argv) == 2)):
            print("""\
Usage:

    etm_qt [path] [acmnsv?l]

With no arguments, etm will use settings from the configuration file
~/.etm/etm.cfg and open the GUI.

If the first argument is the path to a directory which contains a file named
etm.cfg, then settings from that file will be used instead.

If the first argument, other than the optional path, is one of the commands
listed below, then it will be executed by etm without opening the GUI.

    a ARGS  display an action report using the remaining arguments as the
            report specification.
    c ARGS  display a custom report using the remaining arguments as the
            report specification.
    m INT   display a report using the remaining argument, which must be a
            positive integer, to display a report using the corresponding
            entry from the file given by report_specifications in etm.cfg.
            Use ? m to display the numbered list of entries from this file.
    n ARGS  Create a new item using the remaining arguments
            as the item specification.
    s       display the next few days from the day view combined with any
            items in the now and next views.
    v       display information about etm and the operating system.

    ? ARGS  display (this) command line help information if ARGS = '' or,
            if ARGS = X, then display details about command X.
    l       (lower case L) begin an interactive shell loop in which the
            above commands are available and can be adjusted and run again
            without reloading the data files. Enter ? in the shell loop for
            a listing of additional commands available there.\
    """)
        else:
            import etmQt.etmData as etmData
            etmData.main(etmdir, sys.argv)
    else:
        import etmQt.etmView as etmView
        etmView.main(etmdir)
