示例#1
0
文件: depends.py 项目: wdobbels/CAAPR
# -----------------------------------------------------------------

# If no script name is given, execute the "list_dependencies.py" script to list all dependencies of PTS and the
# PTS modules that use them
if arguments.script is None:
    dependencies = introspection.get_all_dependencies()

else:

    scripts = introspection.get_scripts()
    tables = introspection.get_arguments_tables()

    # Find matching 'do' commands (actuall scripts or tabulated commands)
    matches = introspection.find_matches_scripts(arguments.script, scripts)
    table_matches = introspection.find_matches_tables(arguments.script, tables)

    # List the dependencies of the matching script
    dependencies = defaultdict(set)

    # No match
    if len(matches) + len(table_matches) == 0:
        introspection.show_all_available(scripts, tables)
        exit()

    # More mathces
    elif len(matches) + len(table_matches) > 1:
        introspection.show_possible_matches(matches, table_matches, tables)
        exit()

    # Exactly one match from existing do script
示例#2
0
# Get the name of the script to execute
script_name = sys.argv[1] if len(sys.argv) > 1 else None

# Find matches in existing do scripts
scripts = introspection.get_scripts()
tables = introspection.get_arguments_tables()

if script_name is None:

    print("Welcome to PTS")
    introspection.show_all_available(scripts, tables)
    exit()

matches = introspection.find_matches_scripts(script_name, scripts)
table_matches = introspection.find_matches_tables(script_name, tables)

# No match
if len(matches) + len(table_matches) == 0: introspection.show_all_available(scripts, tables)

# If there is a unique match in an existing script, return it
elif len(matches) == 1 and len(table_matches) == 0:

    match = matches[0]

    # Execute the matching script, after adjusting the command line arguments so that it appears that the script was executed directly
    target = fs.join(introspection.pts_do_dir, match[0], match[1])
    sys.argv[0] = target
    del sys.argv[1]
    print "Executing: " + match[0] + "/" + match[1] + " " + " ".join(sys.argv[1:])
    exec open(target)
示例#3
0
    def get_dependencies(self):
        """
        This function ...
        :return:
        """

        # If no script name is given, list all dependencies of PTS and the
        # PTS modules that use them
        if self.config.script is None:

            if self.config.subprojects:

                self.dependencies = defaultdict(set)

                directories_for_subproject = defaultdict(list)

                # Loop over the subdirectories of the 'do' directory
                for path, name in fs.directories_in_path(
                        introspection.pts_do_dir, returns=["path", "name"]):
                    subproject = name
                    directories_for_subproject[subproject].append(path)

                # Loop over the other directories in 'pts' (other than 'do' and 'doc')
                for path, name in fs.directories_in_path(
                        introspection.pts_package_dir,
                        returns=["path", "name"],
                        exact_not_name=["do", "doc"]):
                    subproject = name
                    directories_for_subproject[subproject].append(path)

                encountered_internal_modules = set()

                for subproject in directories_for_subproject:

                    # print(subproject, directories_for_subproject[subproject])

                    # List the dependencies of the matching script
                    dependencies_for_this = defaultdict(set)

                    for dir_path in directories_for_subproject[subproject]:

                        for file_path in fs.files_in_path(dir_path,
                                                          extension="py",
                                                          recursive=True):
                            # if subproject == "dustpedia": print(file_path)

                            introspection.add_dependencies(
                                dependencies_for_this, file_path,
                                encountered_internal_modules)

                    self.dependencies_for_subproject[
                        subproject] = dependencies_for_this.keys()

                    for dependency in dependencies_for_this:
                        for name in dependencies_for_this[dependency]:
                            self.dependencies[dependency].add(name)

            # No subprojects are specified, list all PTS dependencies
            else:
                self.dependencies = introspection.get_all_dependencies()

        # If a script name is given
        else:

            scripts = introspection.get_scripts()
            tables = introspection.get_arguments_tables()

            # Find matching 'do' commands (actual scripts or tabulated commands)
            matches = introspection.find_matches_scripts(
                self.config.script, scripts)
            table_matches = introspection.find_matches_tables(
                self.config.script, tables)

            # List the dependencies of the matching script
            self.dependencies = defaultdict(set)

            # No match
            if len(matches) + len(table_matches) == 0:
                show_all_available(scripts, tables)
                exit()

            # More matches
            elif len(matches) + len(table_matches) > 1:
                show_possible_matches(matches, table_matches, tables)
                exit()

            # Exactly one match from existing do script
            elif len(matches) == 1 and len(table_matches) == 0:

                # Determine the full path to the matching script
                script_path = fs.join(introspection.pts_do_dir, matches[0][0],
                                      matches[0][1])

                introspection.add_dependencies(self.dependencies, script_path,
                                               set())

            # Exactly one match from tabulated command
            elif len(table_matches) == 1 and len(matches) == 0:

                # from pts.core.tools import logging
                # configuration

                # Path to class module

                table_match = table_matches[0]
                subproject = table_match[0]
                index = table_match[1]

                relative_class_module_path = tables[subproject]["Path"][
                    index].replace(".", "/").rsplit("/", 1)[0] + ".py"

                class_module_path = fs.join(
                    introspection.pts_subproject_dir(subproject),
                    relative_class_module_path)

                logging_path = fs.join(introspection.pts_package_dir, "core",
                                       "tools", "logging.py")

                command_name = tables[subproject]["Command"][index]
                configuration_name = tables[subproject]["Configuration"][index]
                if configuration_name == "--":
                    configuration_name = command_name
                configuration_module_path = fs.join(
                    introspection.pts_root_dir, "pts/" + subproject +
                    "/config/" + configuration_name + ".py")

                # Add dependencies
                encountered = set()
                introspection.add_dependencies(self.dependencies, logging_path,
                                               encountered)
                introspection.add_dependencies(self.dependencies,
                                               configuration_module_path,
                                               encountered)
                introspection.add_dependencies(self.dependencies,
                                               class_module_path, encountered)
示例#4
0
# Get the name of the script to execute
script_name = sys.argv[1] if len(sys.argv) > 1 else None

# Find matches in existing do scripts
scripts = introspection.get_scripts()
tables = introspection.get_arguments_tables()

if script_name is None:

    print("Welcome to PTS")
    introspection.show_all_available(scripts, tables)
    exit()

matches = introspection.find_matches_scripts(script_name, scripts)
table_matches = introspection.find_matches_tables(script_name, tables)

# No match
if len(matches) + len(table_matches) == 0:
    introspection.show_all_available(scripts, tables)

    # If there is a unique match in an existing script, return it
elif len(matches) == 1 and len(table_matches) == 0:

    match = matches[0]

    # Execute the matching script, after adjusting the command line arguments so that it appears that the script was executed directly
    target = fs.join(introspection.pts_do_dir, match[0], match[1])
    sys.argv[0] = target
    del sys.argv[1]
    print "Executing: " + match[0] + "/" + match[1] + " " + " ".join(
示例#5
0
arguments = parser.parse_args()

# -----------------------------------------------------------------

# If no script name is given, execute the "list_dependencies.py" script to list all dependencies of PTS and the
# PTS modules that use them
if arguments.script is None: dependencies = introspection.get_all_dependencies()

else:

    scripts = introspection.get_scripts()
    tables = introspection.get_arguments_tables()

    # Find matching 'do' commands (actuall scripts or tabulated commands)
    matches = introspection.find_matches_scripts(arguments.script, scripts)
    table_matches = introspection.find_matches_tables(arguments.script, tables)

    # List the dependencies of the matching script
    dependencies = defaultdict(set)

    # No match
    if len(matches) + len(table_matches) == 0:
        introspection.show_all_available(scripts, tables)
        exit()

    # More mathces
    elif len(matches) + len(table_matches) > 1:
        introspection.show_possible_matches(matches, table_matches, tables)
        exit()

    # Exactly one match from existing do script
示例#6
0
文件: dependencies.py 项目: SKIRT/PTS
    def get_dependencies(self):

        """
        This function ...
        :return:
        """

        # If no script name is given, list all dependencies of PTS and the
        # PTS modules that use them
        if self.config.script is None:

            if self.config.subprojects:

                self.dependencies = defaultdict(set)

                directories_for_subproject = defaultdict(list)

                # Loop over the subdirectories of the 'do' directory
                for path, name in fs.directories_in_path(introspection.pts_do_dir, returns=["path", "name"]):
                    subproject = name
                    directories_for_subproject[subproject].append(path)

                # Loop over the other directories in 'pts' (other than 'do' and 'doc')
                for path, name in fs.directories_in_path(introspection.pts_package_dir, returns=["path", "name"],
                                                         exact_not_name=["do", "doc"]):
                    subproject = name
                    directories_for_subproject[subproject].append(path)

                encountered_internal_modules = set()

                for subproject in directories_for_subproject:

                    # print(subproject, directories_for_subproject[subproject])

                    # List the dependencies of the matching script
                    dependencies_for_this = defaultdict(set)

                    for dir_path in directories_for_subproject[subproject]:

                        for file_path in fs.files_in_path(dir_path, extension="py", recursive=True):
                            # if subproject == "dustpedia": print(file_path)

                            introspection.add_dependencies(dependencies_for_this, file_path,
                                                           encountered_internal_modules)

                    self.dependencies_for_subproject[subproject] = dependencies_for_this.keys()

                    for dependency in dependencies_for_this:
                        for name in dependencies_for_this[dependency]:
                            self.dependencies[dependency].add(name)

            # No subprojects are specified, list all PTS dependencies
            else: self.dependencies = introspection.get_all_dependencies()

        # If a script name is given
        else:

            scripts = introspection.get_scripts()
            tables = introspection.get_arguments_tables()

            # Find matching 'do' commands (actual scripts or tabulated commands)
            matches = introspection.find_matches_scripts(self.config.script, scripts)
            table_matches = introspection.find_matches_tables(self.config.script, tables)

            # List the dependencies of the matching script
            self.dependencies = defaultdict(set)

            # No match
            if len(matches) + len(table_matches) == 0:
                show_all_available(scripts, tables)
                exit()

            # More matches
            elif len(matches) + len(table_matches) > 1:
                show_possible_matches(matches, table_matches, tables)
                exit()

            # Exactly one match from existing do script
            elif len(matches) == 1 and len(table_matches) == 0:

                # Determine the full path to the matching script
                script_path = fs.join(introspection.pts_do_dir, matches[0][0], matches[0][1])

                introspection.add_dependencies(self.dependencies, script_path, set())

            # Exactly one match from tabulated command
            elif len(table_matches) == 1 and len(matches) == 0:

                # from pts.core.tools import logging
                # configuration

                # Path to class module

                table_match = table_matches[0]
                subproject = table_match[0]
                index = table_match[1]

                relative_class_module_path = tables[subproject]["Path"][index].replace(".", "/").rsplit("/", 1)[0] + ".py"
                class_module_path = fs.join(introspection.pts_subproject_dir(subproject), relative_class_module_path)
                logging_path = fs.join(introspection.pts_package_dir, "core", "basics", "log.py")

                command_name = tables[subproject]["Command"][index]
                configuration_name = tables[subproject]["Configuration"][index]
                if configuration_name == "--": configuration_name = command_name
                configuration_module_path = fs.join(introspection.pts_root_dir,
                                                    "pts/" + subproject + "/config/" + configuration_name + ".py")

                # Add dependencies
                encountered = set()
                introspection.add_dependencies(self.dependencies, logging_path, encountered)
                introspection.add_dependencies(self.dependencies, configuration_module_path, encountered)
                introspection.add_dependencies(self.dependencies, class_module_path, encountered)