Exemplo n.º 1
0
def _build_output_path(output_arg, topology_name):
    """Return the absolute path of the output jar file.

    Default basename:
        TOPOLOGY_DIRECTORY.jar
    """
    if output_arg is not None:
        return expand_path(output_arg)
    else:
        return expand_path(topology_name + ".jar")
Exemplo n.º 2
0
def _build_output_path(output_arg, topology_name):
    """Return the absolute path of the output jar file.

    Default basename:
        TOPOLOGY_DIRECTORY.jar
    """
    if output_arg is not None:
        return expand_path(output_arg)
    else:
        return expand_path(topology_name + ".jar")
Exemplo n.º 3
0
def load_configuration(cmd_line_file):
    """Load configurations from the more generic to the
    more specific configuration file. The latter configurations
    override the previous one.
    If a file is specified from command line, it is considered
    the most specific.

    :return: configuration ``namedtuple``
    """
    config_files_hierarchy = [expand_path(c) for c in CONFIG_FILES_PATH]

    if cmd_line_file is not None:
        _validate_config_file(cmd_line_file)
        config_files_hierarchy.append(cmd_line_file)

    config = ConfigParser.SafeConfigParser()
    config.read(config_files_hierarchy)

    configs = update_configuration(
        DEFAULTS,
        dict(
            (config_name, config_value)
            for section in config.sections()
            for config_name, config_value in config.items(section)
        )
    )
    return configs
Exemplo n.º 4
0
def load_configuration(cmd_line_file):
    """Load configurations from the more generic to the
    more specific configuration file. The latter configurations
    override the previous one.
    If a file is specified from command line, it is considered
    the most specific.

    :return: configuration ``namedtuple``
    """
    config_files_hierarchy = [expand_path(c) for c in CONFIG_FILES_PATH]

    if cmd_line_file is not None:
        _validate_config_file(cmd_line_file)
        config_files_hierarchy.append(cmd_line_file)

    config = configparser.SafeConfigParser()
    config.read(config_files_hierarchy)

    configs = update_configuration(
        DEFAULTS,
        dict(
            (config_name, config_value)
            for section in config.sections()
            for config_name, config_value in config.items(section)
        )
    )
    return configs
Exemplo n.º 5
0
def build_topology_jar(configs):
    """Parse command-line arguments and invoke _create_pyleus_jar()"""
    # Expand paths if necessary
    topology_path = expand_path(configs.topology_path)
    topology_dir = expand_path(os.path.dirname(topology_path))
    base_jar = expand_path(configs.base_jar)

    # Parse the topology
    original_topology_spec = parse_original_topology(topology_path)

    output_jar = _build_output_path(configs.output_jar,
                                    original_topology_spec.name)

    # Extract list of packages to always include from configuration
    include_packages = None
    if configs.include_packages is not None:
        include_packages = configs.include_packages.split(" ")

    # Open the base jar as a zip
    zip_file = _open_jar(base_jar)

    try:
        # Everything will be copied in a tmp directory
        tmp_dir = tempfile.mkdtemp()
        try:
            _create_pyleus_jar(
                original_topology_spec=original_topology_spec,
                topology_dir=topology_dir,
                base_jar=base_jar,
                output_jar=output_jar,
                zip_file=zip_file,
                tmp_dir=tmp_dir,
                include_packages=include_packages,
                system_site_packages=configs.system_site_packages,
                pypi_index_url=configs.pypi_index_url,
                verbose=configs.verbose,
            )
        finally:
            shutil.rmtree(tmp_dir)
    finally:
        zip_file.close()
Exemplo n.º 6
0
def build_topology_jar(configs):
    """Parse command-line arguments and invoke _create_pyleus_jar()"""
    # Expand paths if necessary
    topology_path = expand_path(configs.topology_path)
    topology_dir = expand_path(os.path.dirname(topology_path))
    base_jar = expand_path(configs.base_jar)

    # Parse the topology
    original_topology_spec = parse_original_topology(topology_path)

    output_jar = _build_output_path(configs.output_jar,
                                    original_topology_spec.name)

    # Extract list of packages to always include from configuration
    include_packages = None
    if configs.include_packages is not None:
        include_packages = configs.include_packages.split(" ")

    # Open the base jar as a zip
    zip_file = _open_jar(base_jar)

    try:
        # Everything will be copied in a tmp directory
        tmp_dir = tempfile.mkdtemp()
        try:
            _create_pyleus_jar(
                original_topology_spec=original_topology_spec,
                topology_dir=topology_dir,
                base_jar=base_jar,
                output_jar=output_jar,
                zip_file=zip_file,
                tmp_dir=tmp_dir,
                include_packages=include_packages,
                system_site_packages=configs.system_site_packages,
                pypi_index_url=configs.pypi_index_url,
                verbose=configs.verbose,
            )
        finally:
            shutil.rmtree(tmp_dir)
    finally:
        zip_file.close()
Exemplo n.º 7
0
    def run_subcommand(self, arguments):
        """Load the configuration, update it with the arguments and options
        specified on the command-line and then call the run method implemented
        by each sub-command.
        """
        # Expand path of the command-line specified config file, if any
        if arguments.config_file is not None:
            arguments.config_file = expand_path(arguments.config_file)

        # Load configurations into a Configuration named tuple
        try:
            configs = load_configuration(arguments.config_file)
        except PyleusError as e:
            self.error(e)

        configs = _ensure_storm_path_in_configs(configs)

        # Update configuration with command line values
        configs = update_configuration(configs, vars(arguments))

        try:
            self.run(configs)
        except PyleusError as e:
            self.error(e)
Exemplo n.º 8
0
    def run_subcommand(self, arguments):
        """Load the configuration, update it with the arguments and options
        specified on the command-line and then call the run method implemented
        by each sub-command.
        """
        # Expand path of the command-line specified config file, if any
        if arguments.config_file is not None:
            arguments.config_file = expand_path(arguments.config_file)

        # Load configurations into a Configuration named tuple
        try:
            configs = load_configuration(arguments.config_file)
        except PyleusError as e:
            self.error(e)

        configs = _ensure_storm_path_in_configs(configs)

        # Update configuration with command line values
        configs = update_configuration(configs, vars(arguments))

        try:
            self.run(configs)
        except PyleusError as e:
            self.error(e)
Exemplo n.º 9
0
 def test_expand_path(self, mock_path):
     mock_path.abspath.return_value = "bar"
     expanded = utils.expand_path("foo")
     mock_path.abspath.assert_has_calls([
         mock.call(mock_path.expanduser("foo"))])
     assert expanded == "bar"
Exemplo n.º 10
0
 def test_expand_path(self, mock_path):
     mock_path.abspath.return_value = "bar"
     expanded = utils.expand_path("foo")
     mock_path.abspath.assert_has_calls(
         [mock.call(mock_path.expanduser("foo"))])
     assert expanded == "bar"