Exemplo n.º 1
0
def main():
    parser = argparse.ArgumentParser()

    # application language: by default the system language
    parser.add_argument("-l",
                        "--lang",
                        action="store",
                        default=params.getp("LANG"),
                        help=i18n.le2mtrans(u"Language of the application"))

    # automatic mode: with GUI and random decisions
    parser.add_argument(
        "-a",
        "--automatique",
        action="store_true",
        default=False,
        help=i18n.le2mtrans(u"Run the application in the automatic mode."))

    # simulation mode: random decisions without GUI
    parser.add_argument(
        "-s",
        "--simulation",
        action="store_true",
        default=False,
        help=i18n.le2mtrans(u"Run the application in the simulation mode"))

    # server ip
    parser.add_argument("-i",
                        "--ip",
                        action="store",
                        default=params.getp("SERVIP"),
                        help=i18n.le2mtrans(u"IP adress of the server"))

    # server port
    parser.add_argument("-p",
                        "--port",
                        action="store",
                        type=int,
                        default=params.getp("SERVPORT"),
                        help=i18n.le2mtrans(u"Server port"))

    # check the options ========================================================
    args = parser.parse_args()
    options = vars(args)
    params.setp("LANG", args.lang)
    i18n.install()
    params.setp("SERVIP", args.ip)
    params.setp("SERVPORT", args.port)

    # LOGGER  ------------------------------------------------------------------
    logger = logging.getLogger("le2m")
    logger.setLevel(logging.DEBUG)
    formatter = logging.Formatter(
        params.getp("LOGGING_FORMATTER"),
        datefmt=params.getp("LOGGING_FORMATTER_DATE"))
    # file handler
    fichier_log = logging.FileHandler(
        os.path.join(params.getp("REMOTELOGDIR"), 'le2m.log'))
    fichier_log.setLevel(logging.INFO)
    fichier_log.setFormatter(formatter)
    logger.addHandler(fichier_log)
    # console handler
    console_log = logging.StreamHandler()
    console_log.setLevel(logging.DEBUG)
    console_log.setFormatter(formatter)
    logger.addHandler(console_log)

    # first log
    logger.info(30 * "~")
    logger.info(u"Logger LE2M created")
    logger.info("Command ligne options: {}".format(options))

    # start remote -------------------------------------------------------------
    from client import clt  # after appdir and le2mtrans

    client = clt.Client(args.automatique, args.simulation)
    client.start()
Exemplo n.º 2
0
def main():
    parser = argparse.ArgumentParser()

    # application language: by default the system language
    parser.add_argument(
        "-l", "--lang", action="store", default=params.getp("LANG"), help=i18n.le2mtrans(u"Language of the application")
    )

    # automatic mode: with GUI and random decisions
    parser.add_argument(
        "-a",
        "--automatique",
        action="store_true",
        default=False,
        help=i18n.le2mtrans(u"Run the application in the automatic mode."),
    )

    # simulation mode: random decisions without GUI
    parser.add_argument(
        "-s",
        "--simulation",
        action="store_true",
        default=False,
        help=i18n.le2mtrans(u"Run the application in the simulation mode"),
    )

    # server ip
    parser.add_argument(
        "-i", "--ip", action="store", default=params.getp("SERVIP"), help=i18n.le2mtrans(u"IP adress of the server")
    )

    # server port
    parser.add_argument(
        "-p", "--port", action="store", type=int, default=params.getp("SERVPORT"), help=i18n.le2mtrans(u"Server port")
    )

    # check the options ========================================================
    args = parser.parse_args()
    options = vars(args)
    params.setp("LANG", args.lang)
    i18n.install()
    params.setp("SERVIP", args.ip)
    params.setp("SERVPORT", args.port)

    # LOGGER  ------------------------------------------------------------------
    logger = logging.getLogger("le2m")
    logger.setLevel(logging.DEBUG)
    formatter = logging.Formatter(params.getp("LOGGING_FORMATTER"), datefmt=params.getp("LOGGING_FORMATTER_DATE"))
    # file handler
    fichier_log = logging.FileHandler(os.path.join(params.getp("REMOTELOGDIR"), "le2m.log"))
    fichier_log.setLevel(logging.INFO)
    fichier_log.setFormatter(formatter)
    logger.addHandler(fichier_log)
    # console handler
    console_log = logging.StreamHandler()
    console_log.setLevel(logging.DEBUG)
    console_log.setFormatter(formatter)
    logger.addHandler(console_log)

    # first log
    logger.info(30 * "~")
    logger.info(u"Logger LE2M created")
    logger.info("Command ligne options: {}".format(options))

    # start remote -------------------------------------------------------------
    from client import clt  # after appdir and le2mtrans

    client = clt.Client(args.automatique, args.simulation)
    client.start()
Exemplo n.º 3
0
def main():
    parser = argparse.ArgumentParser()

    # application language
    parser.add_argument("-l", "--lang", action="store",
                        default=params.getp("LANG"),
                        help=i18n.le2mtrans(u"Language of the application"))

    # directory for the database
    parser.add_argument("-db", "--dirbase", action="store",
                        default=None,
                        help=i18n.le2mtrans(
                            u"Directory in which to store the database. "
                            u"This argument is not an option if several "
                            u"parts are started with arg -e"))

    # database name
    parser.add_argument("-nb", "--namebase", action="store",
                        default="data.sqlite",
                        help=i18n.le2mtrans(u"Name of the sqlite file, if not data"))

    # server port
    parser.add_argument("-p", "--port", action="store", type=int,
                        default=params.getp("SERVPORT"))

    # names of parts to load directly
    parser.add_argument("-e", "--parts", nargs='+', default=[],
                        dest="parts",
                        help=i18n.le2mtrans(u"The name(s) of the part(s) to load)."))

    # whether it is a test session or not
    test_parser = parser.add_mutually_exclusive_group(required=False)
    test_parser.add_argument('--test', dest='test', action='store_true',
                             help=i18n.le2mtrans(u"The session is launched in "
                                                 u"test mode"))
    test_parser.add_argument('--no-test', dest='test', action='store_false',
                             help=i18n.le2mtrans(u"The session is launched for "
                                                 u"real (not test mode)"))
    parser.set_defaults(test=True)
    # parser.add_argument("-nt", "--notest", action="store_false", default=True,
    #                     help=i18n.le2mtrans(
    #                         u"With this option the experiment is launched for "
    #                         u"real"))

    # check the options ========================================================
    args = parser.parse_args()
    params.setp("LANG", args.lang)
    i18n.install()

    if args.parts:
        for e in args.parts:
            if e not in os.listdir(params.getp("PARTSDIR")):
                parser.error(i18n.le2mtrans(u"Part {p} does not exist").format(p=e))
    # check database if several parts
    if len(args.parts) > 1 and not args.dirbase:
        parser.error(i18n.le2mtrans(
            u"The directory in which store the database has to be provided "
            u"with arg -db"))

    params.setp("SERVPORT", args.port)
    options = vars(args)  # we put the args in a dict

    # creation logger ==========================================================
    logger = logging.getLogger("le2m")
    logger.setLevel(logging.DEBUG)
    formatter = logging.Formatter(
        params.getp("LOGGING_FORMATTER"),
        datefmt=params.getp("LOGGING_FORMATTER_DATE"))
    fichier_log = logging.FileHandler(
        os.path.join(params.getp("LOGDIR"), 'le2m.log'))
    fichier_log.setLevel(logging.INFO)
    fichier_log.setFormatter(formatter)
    logger.addHandler(fichier_log)
    console_log = logging.StreamHandler()
    console_log.setLevel(logging.DEBUG)
    console_log.setFormatter(formatter)
    logger.addHandler(console_log)
    logger.info(30 * "=")
    logger.info("Logger LE2M created")
    logger.info("APPDIR: {}".format(params.getp("APPDIR")))
    logger.info("PARTSDIR: {}".format(params.getp("PARTSDIR")))
    logger.info("Command ligne options: {}".format(options))

    # start server -------------------------------------------------------------
    from server.serv import Serveur

    serveur = Serveur(**options)
    serveur.start()
Exemplo n.º 4
0
def main():
    parser = argparse.ArgumentParser()

    # application language
    parser.add_argument("-l",
                        "--lang",
                        action="store",
                        default=params.getp("LANG"),
                        help=i18n.le2mtrans(u"Language of the application"))

    # directory for the database
    parser.add_argument("-db",
                        "--dirbase",
                        action="store",
                        default=None,
                        help=i18n.le2mtrans(
                            u"Directory in which to store the database. "
                            u"This argument is not an option if several "
                            u"parts are started with arg -e"))

    # database name
    parser.add_argument(
        "-nb",
        "--namebase",
        action="store",
        default="data.sqlite",
        help=i18n.le2mtrans(u"Name of the sqlite file, if not data"))

    # server port
    parser.add_argument("-p",
                        "--port",
                        action="store",
                        type=int,
                        default=params.getp("SERVPORT"))

    # names of parts to load directly
    parser.add_argument(
        "-e",
        "--parts",
        nargs='+',
        default=[],
        dest="parts",
        help=i18n.le2mtrans(u"The name(s) of the part(s) to load)."))

    # whether it is a test session or not
    test_parser = parser.add_mutually_exclusive_group(required=False)
    test_parser.add_argument('--test',
                             dest='test',
                             action='store_true',
                             help=i18n.le2mtrans(u"The session is launched in "
                                                 u"test mode"))
    test_parser.add_argument('--no-test',
                             dest='test',
                             action='store_false',
                             help=i18n.le2mtrans(
                                 u"The session is launched for "
                                 u"real (not test mode)"))
    parser.set_defaults(test=True)

    # check the options ========================================================
    args = parser.parse_args()
    params.setp("LANG", args.lang)
    i18n.install()

    if args.parts:
        for e in args.parts:
            if e not in os.listdir(params.getp("PARTSDIR")):
                parser.error(
                    i18n.le2mtrans(u"Part {} does not exist").format(e))
    # check database if several parts
    if len(args.parts) > 1 and not args.dirbase:
        parser.error(
            i18n.le2mtrans(
                u"The directory in which store the database has to be provided "
                u"with arg -db"))

    params.setp("SERVPORT", args.port)
    options = vars(args)  # we put the args in a dict

    # creation logger ==========================================================
    logger = logging.getLogger("le2m")
    logger.setLevel(logging.DEBUG)
    formatter = logging.Formatter(
        params.getp("LOGGING_FORMATTER"),
        datefmt=params.getp("LOGGING_FORMATTER_DATE"))
    fichier_log = logging.FileHandler(
        os.path.join(params.getp("LOGDIR"), 'le2m.log'))
    fichier_log.setLevel(logging.INFO)
    fichier_log.setFormatter(formatter)
    logger.addHandler(fichier_log)
    console_log = logging.StreamHandler()
    console_log.setLevel(logging.DEBUG)
    console_log.setFormatter(formatter)
    logger.addHandler(console_log)
    logger.info(60 * "=")
    logger.info("Logger LE2M created")
    logger.info("APPDIR: {}".format(params.getp("APPDIR")))
    logger.info("PARTSDIR: {}".format(params.getp("PARTSDIR")))
    logger.info("Command line options: {}".format(options))

    # start server -------------------------------------------------------------
    from server.serv import Serveur

    serveur = Serveur(**options)
    serveur.start()