Beispiel #1
0
def execute(cwd=None, force_exit=True):
    """
    The main entry point of the application, should parse
    the provided command line arguments and then start the
    execution of the colony plugin system.

    An optional force exit flag controls if the exit function
    should always be used in exit.

    :type cwd: String
    :param cwd: The "original" current working directory to
    be used for situations where the "cwd" has been changed
    so that files generated are put on the colony path. This
    is created as a legacy operation.
    :type force_exit: bool
    :param force_exit: If in case the return code is a valid
    one, the exit function should "still" be used to return
    the control flow immediately to the caller process.
    """

    # verifies if the cwd value is defined an in case it's not
    # retrieves the real cwd values as to be used for operations
    cwd = cwd or os.getcwd()

    try:
        # defines the options retrieval schema/template and runs it
        # retrieves the various options and the remaining arguments
        # that have not been parsed by the processor
        options, args = getopt.getopt(
            sys.argv[1:], "hnv:l:r:c:o:f:d:m:g:i:t:p:", [
                "help"
                "noloop", "level="
                "layout_mode=", "run_mode=", "container=", "daemon_pid=",
                "config_file=", "daemon_file=", "manager_dir=", "logger_dir=",
                "library_dir=", "meta_dir=", "plugin_dir="
            ])
    except getopt.GetoptError as error:
        # prints the error description so that the user is able
        # to react to the error, then prints the possible usage
        # for the command and exists in error
        print(str(error))
        usage()
        sys.exit(2)

    # retrieves the execution mode for colony as the first non parsed
    # value from the command line (as expected)
    if args: mode = args[0]
    else: mode = None

    # retrieves the complete set of arguments that are going to be
    # provided for the mode execution, these arguments are considered
    # to be (mode) context specific and valuable only inside context
    margs = args[1:]

    # retrieves the file system encoding
    file_system_encoding = sys.getfilesystemencoding()

    # starts the options values
    loop = True
    level = None
    threads = True
    signals = True
    layout_mode = None
    run_mode = None
    container = "default"
    daemon_pid = None
    config_file_path = DEFAULT_CONFIG_FILE_PATH
    daemon_file_path = None
    manager_path = colony.resolve_manager(RELATIVE_MANAGER_PATH)
    logger_path = DEFAULT_LOGGER_PATH
    library_path = None
    meta_path = None
    plugin_path = None

    # iterates over all the options to be able to parse its value
    # starting it from the command line
    for option, value in options:
        if option in ("-h", "--help"):
            usage()
            sys.exit()
        elif option in ("-n", "--noloop"):
            loop = False
        elif option in ("-v", "--level"):
            level = value
        elif option in ("-l", "--layout_mode"):
            layout_mode = value
        elif option in ("-r", "--run_mode"):
            run_mode = value
        elif option in ("-c", "--container"):
            container = value
        elif option in ("-o", "--daemon_pid"):
            daemon_pid = int(value)
        elif option in ("-f", "--config_file"):
            config_file_path = value.decode(file_system_encoding)
        elif option in ("-d", "--daemon_file"):
            daemon_file_path = value.decode(file_system_encoding)
        elif option in ("-m", "--manager_dir"):
            manager_path = value.decode(file_system_encoding)
        elif option in ("-g", "--logger_dir"):
            logger_path = value.decode(file_system_encoding)
        elif option in ("-i", "--library_dir"):
            library_path = value.decode(file_system_encoding)
        elif option in ("-t", "--meta_dir"):
            meta_path = value.decode(file_system_encoding)
        elif option in ("-p", "--plugin_dir"):
            plugin_path = value.decode(file_system_encoding)
        else:
            assert False, "unhandled option"

    # parses the configuration options, retrieving the various values that
    # control the execution of the plugin system
    mode, level, layout_mode, run_mode, stop_on_cycle_error,\
    prefix_paths, daemon_file_path, logger_path, library_path, meta_path,\
    plugin_path = parse_configuration(
        cwd,
        mode,
        config_file_path,
        level,
        layout_mode,
        run_mode,
        daemon_file_path,
        logger_path,
        library_path,
        meta_path,
        plugin_path,
        manager_path
    )

    # configures the system using the layout mode, the run mode
    # and the  manager path
    configure_system(layout_mode, run_mode, manager_path)

    # in case the daemon file path is valid and not an absolute path
    # must the (complete) daemon file path prepending the manager path
    if daemon_file_path and not os.path.isabs(daemon_file_path):
        daemon_file_path = manager_path + "/" + daemon_file_path

    # in case the logger path is not an absolute path, must create
    # the (complete) logger path prepending the manager path
    if not os.path.isabs(logger_path):
        logger_path = manager_path + "/" + logger_path

    # strips the various component location paths around the
    # semi-colon character so that it's possible to send them
    library_path_striped = library_path.strip(";")
    meta_path_striped = meta_path.strip(";")
    plugin_path_striped = plugin_path.strip(";")

    # starts the running process, this should launch the manager
    # and then start the main loop of execution returning the
    # return code (result of execution) to the caller process
    return_code = run(manager_path,
                      logger_path,
                      library_path_striped,
                      meta_path_striped,
                      plugin_path_striped,
                      mode=mode,
                      margs=margs,
                      level=level,
                      layout_mode=layout_mode,
                      run_mode=run_mode,
                      stop_on_cycle_error=stop_on_cycle_error,
                      loop=loop,
                      threads=threads,
                      signals=signals,
                      container=container,
                      prefix_paths=prefix_paths,
                      daemon_pid=daemon_pid,
                      daemon_file_path=daemon_file_path)

    # in case the return code is not success or the force
    # exit flag is set then calls the exit function
    if not return_code == 0 or force_exit: exit(return_code)
Beispiel #2
0
def resolve_manager(path, ensure=True):
    manager_path = colony.resolve_manager(path)
    if ensure: colony.ensure_tree(manager_path)
    return manager_path
Beispiel #3
0
def execute(cwd = None):
    """
    The main entry point of the application, should parse
    the provided command line arguments and then start the
    execution of the colony plugin system.

    @type cwd: String
    @param cwd: The "original" current working directory to
    be used for situations where the "cwd" has been changed
    so that files generated are put on the colony path. This
    is created as a legacy operation.
    """

    # verifies if the cwd value is defined an in case it's not
    # retrieves the real cwd values as to be used for operations
    cwd = cwd or os.getcwd()

    try:
        # defines the options retrieval schema/template and runs it
        # retrieves the various options and the remaining arguments
        # that have not been parsed by the processor
        options, args = getopt.getopt(
            sys.argv[1:],
            "hnv:l:r:c:o:f:d:m:g:i:t:p:",
            [
                 "help"
                 "noloop",
                 "level="
                 "layout_mode=",
                 "run_mode=",
                 "container=",
                 "daemon_pid=",
                 "config_file=",
                 "daemon_file=",
                 "manager_dir=",
                 "logger_dir=",
                 "library_dir=",
                 "meta_dir=",
                 "plugin_dir="
            ]
        )
    except getopt.GetoptError as error:
        # prints the error description so that the user is able
        # to react to the error, then prints the possible usage
        # for the command and exists in error
        print(str(error))
        usage()
        sys.exit(2)

    # retrieves the execution mode for colony as the first non parsed
    # value from the command line (as expected)
    if args: mode = args[0]
    else: mode = None

    # retrieves the complete set of arguments that are going to be
    # provided for the mode execution, these arguments are considered
    # to be (mode) context specific and valuable only inside context
    margs = args[1:]

    # retrieves the file system encoding
    file_system_encoding = sys.getfilesystemencoding()

    # starts the options values
    loop = True
    level = None
    threads = True
    signals = True
    layout_mode = None
    run_mode = None
    container = "default"
    daemon_pid = None
    config_file_path = DEFAULT_CONFIG_FILE_PATH
    daemon_file_path = None
    manager_path = colony.resolve_manager(RELATIVE_MANAGER_PATH)
    logger_path = DEFAULT_LOGGER_PATH
    library_path = None
    meta_path = None
    plugin_path = None

    # iterates over all the options to be able to parse its value
    # starting it from the command line
    for option, value in options:
        if option in ("-h", "--help"):
            usage()
            sys.exit()
        elif option in ("-n", "--noloop"):
            loop = False
        elif option in ("-v", "--level"):
            level = value
        elif option in ("-l", "--layout_mode"):
            layout_mode = value
        elif option in ("-r", "--run_mode"):
            run_mode = value
        elif option in ("-c", "--container"):
            container = value
        elif option in ("-o", "--daemon_pid"):
            daemon_pid = int(value)
        elif option in ("-f", "--config_file"):
            config_file_path = value.decode(file_system_encoding)
        elif option in ("-d", "--daemon_file"):
            daemon_file_path = value.decode(file_system_encoding)
        elif option in ("-m", "--manager_dir"):
            manager_path = value.decode(file_system_encoding)
        elif option in ("-g", "--logger_dir"):
            logger_path = value.decode(file_system_encoding)
        elif option in ("-i", "--library_dir"):
            library_path = value.decode(file_system_encoding)
        elif option in ("-t", "--meta_dir"):
            meta_path = value.decode(file_system_encoding)
        elif option in ("-p", "--plugin_dir"):
            plugin_path = value.decode(file_system_encoding)
        else:
            assert False, "unhandled option"

    # parses the configuration options, retrieving the various values that
    # control the execution of the plugin system
    mode, level, layout_mode, run_mode, stop_on_cycle_error,\
    prefix_paths, daemon_file_path, logger_path, library_path, meta_path,\
    plugin_path = parse_configuration(
        cwd,
        mode,
        config_file_path,
        level,
        layout_mode,
        run_mode,
        daemon_file_path,
        logger_path,
        library_path,
        meta_path,
        plugin_path,
        manager_path
    )

    # configures the system using the layout mode, the run mode
    # and the  manager path
    configure_system(layout_mode, run_mode, manager_path)

    # in case the daemon file path is valid and not an absolute path
    # must the (complete) daemon file path prepending the manager path
    if daemon_file_path and not os.path.isabs(daemon_file_path):
        daemon_file_path = manager_path + "/" + daemon_file_path

    # in case the logger path is not an absolute path, must create
    # the (complete) logger path prepending the manager path
    if not os.path.isabs(logger_path): logger_path = manager_path + "/" + logger_path

    # strips the various component location paths around the
    # semi-colon character so that it's possible to send them
    library_path_striped = library_path.strip(";")
    meta_path_striped = meta_path.strip(";")
    plugin_path_striped = plugin_path.strip(";")

    # starts the running process, this should lunch the manager
    # and then start the main loop of execution returning the
    # return code (result of execution) to the caller process
    return_code = run(
        manager_path,
        logger_path,
        library_path_striped,
        meta_path_striped,
        plugin_path_striped,
        mode = mode,
        margs = margs,
        level = level,
        layout_mode = layout_mode,
        run_mode = run_mode,
        stop_on_cycle_error = stop_on_cycle_error,
        loop = loop,
        threads = threads,
        signals = signals,
        container = container,
        prefix_paths = prefix_paths,
        daemon_pid = daemon_pid,
        daemon_file_path = daemon_file_path
    )
    exit(return_code)
Beispiel #4
0
""" The sequence that contains the names that are considered
excluded from the auto parsing of parameters """

# retrieves the base path for the current file and uses
# it to insert it in the current system path in case it's
# not already present (required for module importing)
base_path = os.path.dirname(__file__)
if not base_path in sys.path: sys.path.insert(0, base_path)

import colony

# runs the resolution process in order to be able to retrieve
# the "real" a "best" match for the manager path, this method
# should decide between the personal and the master versions
# then ensures that the proper directory tree is created
manager_path = colony.resolve_manager(base_path)
colony.ensure_tree(manager_path)

# registers the ignore flag in the deprecation warnings so that
# no message with this kind of warning is printed (clean console)
warnings.filterwarnings("ignore", category=DeprecationWarning)

# retrieves the layout mode that is going to be used for the
# resolution of resources in the colony infra-structure
layout_mode = colony.conf("LAYOUT_MODE", "default")

# tries to retrieve the run mode from the currently set
# environment variables, in case of failure defaults to
# the default value (as expected by the specification)
run_mode = colony.conf("RUN_MODE", "development")
Beispiel #5
0
""" The sequence that contains the names that are considered
excluded from the auto parsing of parameters """

# retrieves the base path for the current file and uses
# it to insert it in the current system path in case it's
# not already present (required for module importing)
base_path = os.path.dirname(__file__)
if not base_path in sys.path: sys.path.insert(0, base_path)

import colony

# runs the resolution process in order to be able to retrieve
# the "real" a "best" match for the manager path, this method
# should decide between the personal and the master versions
# then ensures that the proper directory tree is created
manager_path = colony.resolve_manager(base_path)
colony.ensure_tree(manager_path)

# registers the ignore flag in the deprecation warnings so that
# no message with this kind of warning is printed (clean console)
warnings.filterwarnings("ignore", category = DeprecationWarning)

# retrieves the layout mode that is going to be used for the
# resolution of resources in the colony infra-structure
layout_mode = colony.conf("LAYOUT_MODE", "default")

# tries to retrieve the run mode from the currently set
# environment variables, in case of failure defaults to
# the default value (as expected by the specification)
run_mode = colony.conf("RUN_MODE", "development")