Exemple #1
0
    def get_registry_dir(cls, directory="."):
        """
        Determine the project registry directory. If in a project, check for the imports link.
        Otherwise, get the default registry from the environment setup:
            OCPI_PROJECT_REGISTRY_DIR, OCPI_CDK_DIR/../project-registry or
            /opt/opencpi/project-registry

        Determine whether the resulting path exists.

        Return the exists boolean and the path to the project registry directory.
        """
        if (ocpiutil.is_path_in_project(directory) and os.path.isdir(
                ocpiutil.get_path_to_project_top(directory) + "/imports")):
            # allow imports to be a link OR a dir (needed for deep copies of exported projects)
            project_registry_dir = os.path.realpath(
                ocpiutil.get_path_to_project_top(directory) + "/imports")
        else:
            project_registry_dir = cls.get_default_registry_dir()

        exists = os.path.exists(project_registry_dir)
        if not exists:
            raise ocpiutil.OCPIException(
                "The project registry directory '" + project_registry_dir +
                "' does not exist.\nCorrect " +
                "'OCPI_PROJECT_REGISTRY_DIR' or run: " +
                "'ocpidev create registry " + project_registry_dir + "'")
        elif not os.path.isdir(project_registry_dir):
            raise ocpiutil.OCPIException(
                "The current project registry '" + project_registry_dir +
                "' exists but is not a directory.\nCorrect " +
                "'OCPI_PROJECT_REGISTRY_DIR'")
        return project_registry_dir
Exemple #2
0
    def factory(cls, asset_type, directory, name=None, **kwargs):
        """
        Class method that is the intended wrapper to create all instances of any Asset subclass.
        Returns a constructed object of the type specified by asset_type. Throws an exception for
        an invalid type.

        Every asset must have a directory, and may provide a name and other args.
        Some assets will be created via the corresponding subclass constructor.
        Others will use an auxiliary function to first check if a matching instance
        already exists.
        """
        if not directory:
            raise ocpiutil.OCPIException(
                "directory passed to  AssetFactory is None.  Pass a " +
                "valid directory to the factory")
        # actions maps asset_type string to the function that creates objects of that type
        # Some types will use plain constructors,
        # and some will use __get_or_create with asset_cls set accordingly
        import _opencpi.assets.application
        import _opencpi.assets.test
        import _opencpi.assets.worker
        import _opencpi.assets.platform
        import _opencpi.assets.assembly
        import _opencpi.assets.library
        import _opencpi.assets.project
        import _opencpi.assets.registry
        actions = {
            "worker":
            cls.__worker_with_model,
            "hdl-assemblies":
            _opencpi.assets.assembly.HdlAssembliesCollection,
            "hdl-assembly":
            _opencpi.assets.assembly.HdlApplicationAssembly,
            "hdl-platforms":
            _opencpi.assets.platform.HdlPlatformsCollection,
            "hdl-platform":
            _opencpi.assets.platform.HdlPlatformWorker,
            "hdl-container":
            _opencpi.assets.assembly.HdlContainer,
            "test":
            _opencpi.assets.test.Test,
            "application":
            _opencpi.assets.application.Application,
            "applications":
            _opencpi.assets.application.ApplicationsCollection,
            "library":
            _opencpi.assets.library.Library,
            #"libraries":    LibrariesCollection, # TODO implement this class
            "project":
            partial(cls.__get_or_create, _opencpi.assets.project.Project),
            "registry":
            partial(cls.__get_or_create, _opencpi.assets.registry.Registry)
        }

        if asset_type not in actions.keys():
            raise ocpiutil.OCPIException("Bad asset creation, \"" +
                                         asset_type + "\" not supported")

        # Call the action for this type and hand it the arguments provided
        return actions[asset_type](directory, name, **kwargs)
Exemple #3
0
    def collect_report_items(self,
                             files,
                             target=None,
                             platform=None,
                             mode="synth"):
        """
        For a given list of files and a target OR platform, iterate through this
        tool's ReportableItems and apply them to each file to collect a dictionary
        mapping element keys to the values where each value was determined
        by applying a ReportableItem to a file.
        """
        ocpiutil.logging.debug("Reporting on files: " + str(files))
        if files is None or files == []:
            ocpiutil.logging.info("No files to report on")
            return {}
        if mode != "synth" and mode != "impl":
            raise ocpiutil.OCPIException(
                "Valid modes for reporting utilization are \"synth\" " +
                "and \"impl\". Mode specified was \"" + mode + "\".")

        # pylint:disable=bad-continuation
        target_plat_not_none = target is not None and platform is not None
        if ((mode == "synth" and target is None)
                or (mode == "impl" and platform is None)
                or target_plat_not_none):
            raise ocpiutil.OCPIException(
                "Synthesis reporting operates only on HDL targets.\n" +
                "Implementation reporting operates only on HDL platforms.")
        # pylint:enable=bad-continuation

        elem_dict = {}
        if mode == "impl":
            elem_dict["OCPI Platform"] = platform.name
            elem_dict["OCPI Target"] = platform.target.name
        else:
            elem_dict["OCPI Target"] = target.name
        elem_dict["Tool"] = self.title

        # If not a single value is found for this tool's ReportableItems,
        # this data-point is empty
        non_empty = False
        # Iterate through this tool's ReportableItems and match each item (regex) with on the files
        # provided. Each value found is added to this data_point or filled in with None
        for item in self.reportable_items:
            elem = None
            for fil in files:
                if mode == "synth":
                    elem = item.match_and_transform_synth(fil)
                else:
                    elem = item.match_and_transform_impl(fil)
                if elem:
                    elem_dict[item.key] = elem
                    # An element's value has been found, so this item is non-empty
                    non_empty = True
                    break
            if elem is None:
                # No value was found/matched in the provided files for this item
                # Fill in None
                elem_dict[item.key] = None
        return elem_dict if non_empty else {}
Exemple #4
0
    def contains(self, package_id=None, directory=None):
        """
        Given a project's package-ID or directory, determine if the project is present
        in this registry.
        """
        # If neither package_id nor directory are provided, exception
        if package_id is None:
            if directory is None:
                raise ocpiutil.OCPIException(
                    "Could determine whether project exists because " +
                    "the package_id and directory provided were both " +
                    "None.\nProvide one or both of these arguments.")
            # Project's package-ID is determined from its directory if not provided
            package_id = ocpiutil.get_project_package(directory)
            if package_id is None:
                raise ocpiutil.OCPIException(
                    "Could not determine package-ID of project located " +
                    "at \"" + directory + "\".\nDouble check this " +
                    "configurations.")

        # If the project is registered here by package-ID, return True.
        # If not, or if a different project is registered here with that pacakge-ID, return False
        if package_id in self.__projects:
            # pylint:disable=bad-continuation
            if (directory is not None and os.path.realpath(directory) !=
                    self.__projects[package_id].directory):
                logging.warning("Registry at \"" + self.directory +
                                "\" contains a project with " +
                                "package-ID \"" + package_id +
                                "\", but it is not the same " +
                                "project as \"" + directory + "\".")
                return False
            # pylint:enable=bad-continuation
            return True
        return False
Exemple #5
0
    def remove(self, package_id=None, directory=None):
        """
        Given a project's package-ID or directory, determine if the project is present
        in this registry. If so, remove it from this registry's __projects dictionary
        and remove the registered symlink.
        """
        logging.debug("package_id=" + str(package_id) + " directory=" +
                      str(directory))
        if package_id is None:
            package_id = ocpiutil.get_project_package(directory)
            if package_id is None:
                raise ocpiutil.OCPIException(
                    "Could not unregister project located at \"" + directory +
                    "\" because the project's package-ID " +
                    "could not be determined.\nIs it really a project?")

        if package_id not in self.__projects:
            link_path = self.directory + "/" + package_id
            if os.path.exists(link_path) and not os.path.exists(
                    os.readlink(link_path)):
                logging.debug(
                    "Removing the following broken link from the registry:\n" +
                    link_path + " -> " + os.readlink(link_path))
                self.remove_link(package_id)
                print("Successfully unregistered the " + package_id +
                      " project: " + os.path.realpath(directory) +
                      "\nFrom the registry: " +
                      os.path.realpath(self.directory) + "\n")
                return
            raise ocpiutil.OCPIException(
                "Could not unregister project with package-ID \"" +
                package_id + "\" because the project is not in the " +
                "registry.\n Run 'ocpidev show registry --table' for " +
                "information about the currently registered projects.\n")

        # if a project is deleted from disk underneath our feet this could be None (AV-4483)
        if self.__projects[package_id] is not None:
            project_link = self.__projects[package_id].directory
            if directory is not None and os.path.realpath(
                    directory) != project_link:
                raise ocpiutil.OCPIException(
                    "Failure to unregister project with package '" +
                    package_id + "'.\nThe registered project with link '" +
                    package_id + " --> " + project_link + "' does not " +
                    "point to the specified project '" +
                    os.path.realpath(directory) + "'." + "\nThis " +
                    "project does not appear to be registered.")

        if directory is None:
            directory = str(self.__projects[package_id].directory)
        # Remove the symlink registry/package-ID --> project
        self.remove_link(package_id)
        # Remove the project from this registry's dict
        self.__projects.pop(package_id)
        print("Successfully unregistered the " + package_id + " project: " +
              os.path.realpath(directory) + "\nFrom the registry: " +
              os.path.realpath(self.directory) + "\n")
Exemple #6
0
 def setUpClass(cls):
     """
     Need to make sure registry is set to current system default before proceeding
     """
     if subprocess.call("mkdir -p " + UTIL_PROJ, shell=True) != 0:
        raise ocpiutil.OCPIException("mkdir failed to create the utilization test project directory")
     with ocpiutil.cd(UTIL_PROJ):
         if subprocess.call("tar xf ../" + UTIL_PROJ + ".tgz", shell=True) != 0:
             raise ocpiutil.OCPIException("could not unpack tar file for utilization test project")
         process = subprocess.Popen([OCPIDEV_PATH, "set", "registry"])
         results = process.communicate()
         if results[1] or process.returncode != 0:
             raise ocpiutil.OCPIException("'ocpidev set registry' failed in utilization test\n" +
                                          "process.returncode: " +  str(process.returncode))
Exemple #7
0
    def construct_report_item(self,
                              directory,
                              target=None,
                              platform=None,
                              mode="synth",
                              init_report=None):
        """
        For a single directory and single target OR platform, construct (or add to) a Report with
        a new data-point for the directory and target/platform provided. The data-point will
        contain a key/value pair for each ReportableItem of this toolset.
        """
        if mode != "synth" and mode != "impl":
            raise ocpiutil.OCPIException(
                "Valid modes for reporting utilization are \"synth\" " +
                "and \"impl\". Mode specified was \"" + mode + "\".")

        # pylint:disable=bad-continuation
        target_plat_not_none = target is not None and platform is not None
        if ((mode == "synth" and target is None)
                or (mode == "impl" and platform is None)
                or target_plat_not_none):
            raise ocpiutil.OCPIException(
                "Synthesis reporting operates only on HDL targets.\n" +
                "Implementation reporting operates only on HDL platforms.")
        # pylint:enable=bad-continuation

        # Initialize a report object with the default ordered headers for this mode
        if init_report is None:
            init_report = ocpiutil.Report(
                ordered_headers=self.get_ordered_items(mode))

        # Determine the toolset to collect these report items
        if mode == "synth":
            toolset = target.toolset
        elif mode == "impl":
            toolset = platform.target.toolset

        # For the tool in question, get the files for reporting on this directory/mode
        files = toolset.get_files(directory, mode)
        # Collect the actual report items dict of itemkey=>value and add as a data-point to the
        # report for returning
        new_report = toolset.collect_report_items(files,
                                                  target=target,
                                                  platform=platform,
                                                  mode=mode)
        # If the new_report is non-empty, add it to the initial one
        if new_report:
            init_report.append(new_report)
        return init_report
Exemple #8
0
    def create_link(self, project):
        """
        Create a link to the provided project in this registry
        """
        # Try to make the path relative. This helps with environments involving mounted directories
        # Find the path that is common to the project and registry
        common_prefix = os.path.commonprefix(
            [project.directory, self.directory])
        # If the two paths contain no common directory except root,
        #     use the path as-is
        # Otherwise, use the relative path from the registry to the project
        if common_prefix == '/' or common_prefix == '':
            project_to_reg = os.path.normpath(project.directory)
        else:
            project_to_reg = os.path.relpath(
                os.path.normpath(project.directory), self.directory)

        project_link = self.directory + "/" + project.package_id
        try:
            os.symlink(project_to_reg, project_link)
        except OSError:
            raise ocpiutil.OCPIException(
                "Failure to register project link: " + project_link + " --> " +
                project_to_reg + "\nCommand attempted: " + "'ln -s " +
                project_to_reg + " " + project_link +
                "'.\nTo (un)register projects in " +
                "/opt/opencpi/project-registry, you need to be a " +
                "member of the opencpi group.")
Exemple #9
0
    def __init_package_id(self):
        """
        Get the Package Name of the project containing 'self.directory'.
        """
        # From the project top, probe the Makefile for the projectpackage
        # which is printed in cdk/include/project.mk in the projectpackage rule
        # if ShellProjectVars is defined
        project_package = None
        # If the project-package-id file exists, set package-id to its contents
        if os.path.isfile(self.directory + "/project-package-id"):
            with open(self.directory + "/project-package-id",
                      "r") as package_id_file:
                self.__is_exported = True
                project_package = package_id_file.read().strip()
                logging.debug("Read Project-ID '" + project_package +
                              "' from file: " + self.directory +
                              "/project-package-id")

        # Otherwise, ask Makefile at the project top for the ProjectPackage
        if project_package is None or project_package == "":
            project_vars = ocpiutil.set_vars_from_make(
                mk_file=self.directory + "/Makefile",
                mk_arg="projectpackage ShellProjectVars=1",
                verbose=True)
            if (not project_vars is None and 'ProjectPackage' in project_vars
                    and len(project_vars['ProjectPackage']) > 0):
                # There is only one value associated with ProjectPackage, so get element 0
                project_package = project_vars['ProjectPackage'][0]
            else:
                raise ocpiutil.OCPIException(
                    "Could not determine Package-ID of project \"" +
                    self.directory + "\".")
        self.package_id = project_package
def set_init_values(args, dir_type):
    """
    Determine which contents of library and project objects need to be initialized and set the
    corresponding kwargs values
    """
    my_noun = dir_type if args['noun'] is None else args['noun']
    container_nouns = ["library", "libraries", "project"]
    if (my_noun in ["workers", "library", "libraries", "project"]
            or dir_type in container_nouns):
        args['init_workers'] = True
    if my_noun in ["hdl-assemblies", "project"
                   ] or dir_type in ["hdl-assemblies", "project"]:
        args['init_hdlassembs'] = True
    if my_noun in ["workers", "libraries", "project"
                   ] or dir_type in ["libraries", "project"]:
        args['init_libs'] = True
    if my_noun in ["hdl-platforms", "project"
                   ] or dir_type in ["hdl-platforms", "project"]:
        args['init_hdlplats'] = True
    if my_noun == "library" and dir_type == "libraries":
        args['init_libs_col'] = True
    if my_noun == "workers":
        if dir_type not in ["library", "libraries", "project"]:
            raise ocpiutil.OCPIException(
                'Use of workers noun in an invalid directory type: "' +
                dir_type + '". Valid types are library and project')
    # This driver defaults hdl_plats to all
    if not args['hdl_plats'] and not args['hdl_tgts']:
        args['hdl_plats'] = ["all"]
Exemple #11
0
 def get_or_create_all(cls, asset_type):
     """
     Create all assets of the provided type (target platform or tool)
     """
     if cls.__tgt_dict == {}:
         cls.__parse_hdltargets_from_make()
     asset_list = []
     if asset_type == "hdltarget":
         # iterate through all target names, construct, and add to return list for tgt in cls.__tgt_dict:
         for tgt in cls.__tgt_dict:
             import _opencpi.assets.platform as ocpiplat
             asset_list.append(cls.__get_or_create(ocpiplat.HdlTarget, tgt))
         return asset_list
     if asset_type == "hdlplatform":
         # iterate through all platform names, construct, and add to return list
         for plat in cls.__plat_dict:
             import _opencpi.assets.platform as ocpiplat
             asset_list.append(
                 cls.__get_or_create(ocpiplat.HdlPlatform, plat))
         return asset_list
     if asset_type == "hdltoolset":
         # iterate through all tool names, construct, and add to return list
         for tool in cls.__tool_dict:
             asset_list.append(cls.__get_or_create(HdlToolSet, tool))
         return asset_list
     raise ocpiutil.OCPIException("Bad asset creation, \"" + asset_type +
                                  "\" not supported")
Exemple #12
0
    def factory(cls, asset_type, name=None):
        """
        Class method that is the intended wrapper to create all instances of any Asset subclass.
        Returns a constructed object of the type specified by asset_type. Throws an exception for
        an invalid type.

        Every asset must have a directory, and may provide a name and other args.
        Some assets will be created via the corresponding subclass constructor.
        Others will use an auxiliary function to first check if a matching instance
        already exists.
        """
        # actions maps asset_type string to the function that creates objects of that type
        # Some types will use plain constructors,
        # and some will use __get_or_create with asset_cls set accordingly
        import _opencpi.assets.platform as ocpiplat
        actions = {
            "hdltoolset": partial(cls.__get_or_create, HdlToolSet),
            "hdltarget": partial(cls.__get_or_create, ocpiplat.HdlTarget),
            "hdlplatform": partial(cls.__get_or_create, ocpiplat.HdlPlatform)
        }

        if asset_type not in actions.keys():
            raise ocpiutil.OCPIException("Bad asset creation, \"" +
                                         asset_type + "\" not supported")

        # Call the action for this type and hand it the arguments provided
        return actions[asset_type](name)
Exemple #13
0
def check_scope_options(scope, noun):
    """
    Verify that the scope options passed in are valid given the noun
    """
    if noun in NOUN_NON_PLURALS:
        scope = "local"

    valid_scope_dict = {
        "registry": ["global"],
        "projects": ["global"],
        "workers": ["global"],
        "components": ["global"],
        "component": ["local"],
        "worker": ["local"],
        "tests": ["local"],
        "libraries": ["local"],
        "project": ["local"],
        "platforms": ["global"],
        "targets": ["global"],
        "rccplatforms": ["global"],
        "rcctargets": ["global"],
        "hdlplatforms": ["global"],
        "hdltargets": ["global"],
    }

    if scope not in valid_scope_dict[noun]:
        raise ocpiutil.OCPIException("Invalid scope option '" + scope +
                                     "' for " + noun +
                                     ".  Valid options are: " +
                                     " ,".join(valid_scope_dict[noun]))
Exemple #14
0
 def remove(cls, directory=None, instance=None):
     """
     Removes an instance from the static class variable __assets by dierectory or the instance
     itself.  Throws an exception if neither optional argument is provided.
     """
     if directory is not None:
         real_dir = os.path.realpath(directory)
         import _opencpi.assets.project
         import _opencpi.assets.registry
         dirtype_dict = {
             "project": _opencpi.assets.project.Project,
             "registry": _opencpi.assets.registry.Registry
         }
         dirtype = ocpiutil.get_dirtype(real_dir)
         cls.__assets[dirtype_dict[dirtype]].pop(real_dir, None)
     elif instance is not None:
         cls.__assets[instance.__class__] = {
             k: v
             for k, v in cls.__assets[instance.__class__].items()
             if v is not instance
         }
     else:
         raise ocpiutil.OCPIException(
             "Invalid use of AssetFactory.remove() both directory " +
             "and instance are None.")
Exemple #15
0
    def check_dirtype(dirtype, directory):
        """
        checks that the directory passed in is of the type passed in and if not an exception is
        thrown
        """
        if not os.path.isdir(directory):
            raise ocpiutil.OCPIException("Expected directory of type \"" +
                                         dirtype + "\" for a " +
                                         "directory that does not exist \"" +
                                         directory + "\"")

        if ocpiutil.get_dirtype(directory) != dirtype:
            raise ocpiutil.OCPIException("Expected directory of type \"" +
                                         dirtype + "\", but " +
                                         "found type \"" +
                                         str(ocpiutil.get_dirtype(directory)) +
                                         "\" for directory \"" + directory +
                                         "\"")
Exemple #16
0
 def get_project(self, package_id):
     """
     Return the project with the specified package-id that is registered in this registry
     """
     if package_id not in self.__projects:
         raise ocpiutil.OCPIException("\"" + package_id +
                                      "\" is not a valid package-id or " +
                                      "project directory")
     return self.__projects[package_id]
Exemple #17
0
def main():
    """
    Function that is called if this module is called as a mian function
    """
    args = parse_cl_vars()
    directory = None
    name = None
    try:
        cur_dir = args['cur_dir']
        with ocpiutil.cd(cur_dir):
            dir_type = ocpiutil.get_dirtype()
            # args['name'] could be None if no name is provided at the command line
            name = args['name']
            directory = ocpiutil.get_ocpidev_working_dir(
                origin_path=".",
                noun=args.get("noun", ""),
                name=name,
                library=args['library'],
                hdl_library=args['hdl_library'],
                hdl_platform=args['hdl_plat_dir'])
            if (name is None) and (dir_type
                                   in [n for n in NOUNS if n != "tests"]):
                name = os.path.basename(os.path.realpath('.'))
            del args['name']
            if args['noun'] is None:
                if dir_type in [n for n in NOUNS if n != "tests"]:
                    args['noun'] = dir_type
                else:
                    raise ocpiutil.OCPIException(
                        "Invalid directory type \"" + str(dir_type) +
                        "\" Valid directory types are: " +
                        ", ".join([n for n in NOUNS if n != "tests"]))
            if ocpiutil.get_dirtype(
                    directory) == "libraries" and args['noun'] == "library":
                args['noun'] = "libraries"
            set_init_values(args, dir_type)
            ocpiutil.logging.debug("creating asset as the following \nnoun: " +
                                   args['noun'] + "\nname: " + str(name) +
                                   "\n" + "directory: " + str(directory) +
                                   "\nargs: " + str(args))
            my_asset = ocpifactory.AssetFactory.factory(
                args['noun'], directory, name, **args)
            sys.exit(my_asset.run())
    except ocpiutil.OCPIException as ex:
        ocpiutil.logging.error(ex)
        if args['noun'] is not None:
            my_noun = '' if args[
                'noun'] is None else " \"" + args['noun'] + "\""
            my_name = '' if name is None else " named \"" + name + "\""
            my_dir = '' if directory is None else " in directory \"" + directory + "\""
            run_dbg = "Unable to run" + my_noun + my_name + my_dir + " due to previous errors"
        else:
            run_dbg = "Unable to run due to previous errors"
        ocpiutil.logging.error(run_dbg)
        sys.exit(1)
Exemple #18
0
 def get_ordered_items(cls, mode="synth"):
     """
     Return the default ordering for the given mode
     """
     if mode == "synth":
         return cls.__default_synth_items + cls.__default_common_items + cls.__ordered_items
     if mode == "impl":
         return cls.__default_impl_items + cls.__default_common_items + cls.__ordered_items
     raise ocpiutil.OCPIException(
         "Valid modes for reporting utilization are \"synth\" " +
         "and \"impl\". Mode specified was \"" + mode + "\".")
Exemple #19
0
 def get_sort_priority(cls, mode="synth"):
     """
     Return the default sort priority for the given mode
     """
     if mode == "synth":
         return cls.__default_synth_sort_priority
     elif mode == "impl":
         return cls.__default_impl_sort_priority
     else:
         raise ocpiutil.OCPIException(
             "Valid modes for reporting utilization are \"synth\" " +
             "and \"impl\". Mode specified was \"" + mode + "\".")
Exemple #20
0
    def init_configs(self, **kwargs):
        """
        Parse this worker's build XML and populate its "configs" dictionary
        with mappings of <config-index> -> <config-instance>
        """
        # Determine if the build XML is named .build or -build.xml
        if os.path.exists(self.directory + "/" + os.path.basename(self.name) +
                          "-build.xml"):
            build_xml = self.directory + "/" + self.name + "-build.xml"
        elif os.path.exists(self.directory + "/" + self.name + ".build"):
            build_xml = self.directory + "/" + self.name + ".build"
        else:
            # If neither is found, there is no build XML and so we assume there is only one config
            # and assign it index 0
            self.configs[0] = HdlLibraryWorkerConfig(directory=self.directory,
                                                     name=self.name,
                                                     config_index=0,
                                                     **kwargs)
            return

        # Begin parsing the build XML
        root = ET.parse(build_xml).getroot()
        #TODO confirm root.tag is build?

        # Find each build configuration, get the ID, get all parameters (place in dict),
        # construct the HdlLibraryWorkerConfig instance, and add it to the "configs" dict
        for config in root.findall("configuration"):
            config_id = config.get("id")
            # Confirm the ID is an integer
            if config_id is not None:
                if not ocpiutil.isint(config_id):
                    raise ocpiutil.OCPIException(
                        "Invalid configuration ID in build XML \"" +
                        build_xml + "\".")
            # Find elements with type "parameter", and load them into the param_dict
            # as name -> value
            param_dict = {}
            for param in config.findall("parameter") + config.findall(
                    "Parameter"):
                pname = param.get("name")
                value = param.get("value")
                param_dict[pname] = value

            # Initialize the config instance with this worker's dir and name, and the
            # configuration's ID and parameter dictionary
            if config_id:
                self.configs[int(config_id)] = HdlLibraryWorkerConfig(
                    directory=self.directory,
                    name=self.name,
                    config_index=int(config_id),
                    config_params=param_dict,
                    **kwargs)
Exemple #21
0
 def __init__(self, directory, name, **kwargs):
     """
     Initializes HdlPlatformWorkerConfig member data and calls the super class __init__.
     valid kwargs handled at this level are:
         platform (HdlPlatform) - The HdlPlatform object that is bound to this configuration.
     """
     super().__init__(directory, name, **kwargs)
     self.platform = kwargs.get("platform", None)
     if self.platform is None:
         raise ocpiutil.OCPIException(
             "HdlPlatformWorkerConfig cannot be constructed without " +
             "being provided a platform")
     self.subdir_prefix = directory + "/target-" + self.platform.target.name
Exemple #22
0
    def show_utilization(self):
        """
        Show the utilization Report for this asset and print/record the results.

        This default behavior is likely sufficient, but subclasses that are collections of OpenCPI
        assets may override this function to instead iterate over children assets and call their
        show_utilization functions.
        """
        # Get the directory type to add in the header/caption for the utilization info
        dirtype = ocpiutil.get_dirtype(self.directory)
        if dirtype is None:
            dirtype = "asset"
        caption = "Resource Utilization Table for " + dirtype + " \"" + self.name + "\""

        # Get the utilization using this class' hopefully overridden get_utilization() function
        util_report = self.get_utilization()
        if not util_report:
            if dirtype == "hdl-platform":
                plat_obj = hdltargets.HdlToolFactory.factory(
                    "hdlplatform", self.name)
                if not plat_obj.get_toolset().is_simtool:
                    logging.warning("Skipping " + caption +
                                    " because the report is empty")
            else:
                logging.warning("Skipping " + caption +
                                " because the report is empty")
            return

        if self.output_format not in self.valid_formats:
            raise ocpiutil.OCPIException(
                "Valid formats for showing utilization are \"" +
                ", ".join(self.valid_formats) + "\", but \"" +
                self.output_format + "\" was chosen.")
        if self.output_format == "table":
            print(caption)
            # Maybe Report.print_table() should accept caption as well?
            # print the Report as a table
            util_report.print_table()
        if self.output_format == "latex":
            logging.info("Generating " + caption)
            # Record the utilization in LaTeX in a utilization.inc file for this asset
            util_file_path = self.directory + "/utilization.inc"
            with open(util_file_path, 'w') as util_file:
                # Get the LaTeX table string, and write it to the utilization file
                latex_table = util_report.get_latex_table(caption=caption)
                # Only write to the file if the latex table is non-empty
                if latex_table != "":
                    util_file.write(latex_table)
                    logging.info("  LaTeX Utilization Table was written to: " +
                                 util_file_path + "\n")
Exemple #23
0
 def registry(self):
     """
     This function will return the registry object for this Project instance.
     If the registry is None, it will try to find/construct it first
     """
     if self.__registry is None:
         import _opencpi.assets.registry
         self.__registry = AssetFactory.factory(
             "registry", Registry.get_registry_dir(self.directory))
         if self.__registry is None:
             raise ocpiutil.OCPIException(
                 "The registry for the current project ('" +
                 self.directory + "') could not be determined.")
     return self.__registry
Exemple #24
0
    def unset_registry(self):
        """
        Unset the project registry link for this project.
        I.e. remove the 'imports' link at the top-level of the project.
        """
        # If the 'imports' link exists at the project-top, and it is a link, remove it.
        # If it is not a link, let the user remove it manually.
        reg = self.registry()
        # If we are about to unset the, but this project is registered in the current one,
        # raise an exception; user needs to unregister the project first.
        if reg.contains(directory=self.directory):
            raise ocpiutil.OCPIException(
                "Before (un)setting the registry for the project at \"" +
                self.directory + "\", you must unregister the project.\n" +
                "This can be done by running 'ocpidev unregister project" +
                " -d " + self.directory)

        imports_link = self.directory + "/imports"
        if os.path.islink(imports_link):
            os.unlink(imports_link)
            # Set this project's registry reference to the default
            self.__registry = None
        else:
            if os.path.exists(imports_link):
                raise ocpiutil.OCPIException(
                    "The 'imports' for the current project ('" + imports_link +
                    "') is not a symbolic link.\nThe " +
                    "file will need to be removed manually.")
            else:
                logging.debug(
                    "Unset project registry has succeeded, but nothing was done.\n"
                    +
                    "Registry was not set in the first place for this project."
                )
        print("Succesfully unset the registry of the project " +
              os.path.realpath(self.directory) + "\nFrom the registry: " +
              os.path.realpath(reg.directory) + "to the default registry")
Exemple #25
0
 def remove_link(self, package_id):
     """
     Remove link with name=package-ID from this registry
     """
     link_path = self.directory + "/" + package_id
     try:
         os.unlink(link_path)
     except OSError:
         raise ocpiutil.OCPIException(
             "Failure to unregister link to project: " + package_id +
             " --> " + os.readlink(link_path) + "\nCommand " +
             "attempted: 'unlink " + link_path + "'\nTo " +
             "(un)register projects in " +
             "/opt/opencpi/project-registry, you need to be a " +
             "member of the opencpi group.")
Exemple #26
0
 def run(self):
     """
     Runs the Library with the settings specified in the object.  Throws an exception if the
     tests were not initialized by using the init_tests variable at initialization.  Running a
     Library will run all the component unit tests that are contained in the Library
     """
     ret_val = 0
     if self.test_list is None:
         raise ocpiutil.OCPIException(
             "For a Library to be run \"init_tests\" must be set to " +
             "True when the object is constructed")
     for test in self.test_list:
         run_val = test.run()
         ret_val = ret_val + run_val
     return ret_val
Exemple #27
0
 def __worker_with_model(cls, directory, name=None, **kwargs):
     """
     Construct Worker subclass based on authoring model of worker
     (e.g. RccWorker or HdlLibraryWorker)
     """
     import _opencpi.assets.worker
     if os.path.basename(directory).endswith(".hdl"):
         return _opencpi.assets.worker.HdlLibraryWorker(
             directory, name, **kwargs)
     elif os.path.basename(directory).endswith(".rcc"):
         return _opencpi.assets.worker.RccWorker(directory, name, **kwargs)
     else:
         raise ocpiutil.OCPIException(
             "Unsupported authoring model for worker located at '" +
             directory + "'")
Exemple #28
0
    def show_tests(self, details, verbose, **kwargs):
        """
        Print out all the tests ina project in the format given by details
        (simple, verbose, or json)

        JSON format:
        {project:{
          name: proj_name
          directory: proj_directory
          libraries:{
            lib_name:{
              name: lib_name
              directory:lib_directory
              tests:{
                test_name : test_directory
                ...
              }
            }
          }
        }
        """
        if self.lib_list is None:
            raise ocpiutil.OCPIException(
                "For a Project to show tests \"init_libs\" "
                "must be set to True when the object is constructed")
        json_dict = self.get_show_test_dict()
        if details == "simple":
            for lib in json_dict["project"]["libraries"]:
                print("Library: " +
                      json_dict["project"]["libraries"][lib]["directory"])
                tests_dict = json_dict["project"]["libraries"][lib]["tests"]
                for test in tests_dict:
                    print("    Test: " + tests_dict[test])
        elif details == "table":
            rows = [["Library Directory", "Test"]]
            for lib in json_dict["project"]["libraries"]:
                tests_dict = json_dict["project"]["libraries"][lib]["tests"]
                for test in tests_dict:
                    rows.append([
                        json_dict["project"]["libraries"][lib]["directory"],
                        test
                    ])
            ocpiutil.print_table(rows, underline="-")
        else:
            json.dump(json_dict, sys.stdout)
            print()
Exemple #29
0
    def get_all_dict(cls):
        """
        returns a dictionary with all available rcc targets from the RccAllPlatforms make variable
        """
        rcc_dict = ocpiutil.get_make_vars_rcc_targets()
        try:
            rcc_plats = rcc_dict["RccAllPlatforms"]

        except TypeError:
            raise ocpiutil.OCPIException(
                "No RCC platforms found. Make sure the core project is " +
                "registered or in the OCPI_PROJECT_PATH.")
        target_dict = {}
        for plat in rcc_plats:
            target_dict[plat] = {}
            target_dict[plat]["target"] = rcc_dict["RccTarget_" + plat][0]
        return target_dict
Exemple #30
0
 def __init__(self,
              name,
              title=None,
              is_simtool=False,
              synth_files=[],
              impl_files=[],
              reportable_items=[]):
     super().__init__(name, title, is_simtool)
     self.files = {}
     self.files["synth"] = synth_files
     self.files["impl"] = impl_files
     self.reportable_items = reportable_items
     for item in reportable_items:
         if item.key not in HdlReportableToolSet.get_ordered_items():
             raise ocpiutil.OCPIException(
                 "Item \"" + item.key + "\" is not recognized." +
                 "Be sure to use " +
                 "HdlReportableToolSet.set_ordered_items([<items>])" +
                 "to set the list of acceptable report items.")