Exemple #1
0
    def show_all(cls, details):
        """
        Print out information about all the projects in the registry and in OCPI_PROJECT_PATH
        enviroment variable
        """
        reg = AssetFactory.factory("registry", Registry.get_registry_dir())
        json_dict = reg.get_dict(True)

        env_proj_dict = cls.collect_projects_from_path()
        proj_dict = json_dict["projects"]
        proj_dict = ocpiutil.merge_two_dicts(env_proj_dict, proj_dict)
        json_dict["projects"] = proj_dict

        if details == "simple":
            print(" ".join(sorted(json_dict["projects"])))
        elif details == "table":
            rows = [["Project Package-ID", "Path to Project", "Valid/Exists"]]
            for proj in json_dict["projects"]:
                rows.append([
                    proj, json_dict["projects"][proj]["real_path"],
                    json_dict["projects"][proj]["exists"]
                ])
            ocpiutil.print_table(rows, underline="-")
        elif details == "json":
            json.dump(json_dict, sys.stdout)
            print()
Exemple #2
0
 def show_components(self, details, verbose, **kwargs):
     """
     Show all the components in all the projects in the registry
     """
     reg_dict = self._collect_components_dict()
     if details == "simple":
         for proj in reg_dict["projects"]:
             for comp in reg_dict["projects"][proj].get("components", []):
                 print(comp + " ", end="")
             for lib in reg_dict["projects"][proj]["libraries"]:
                 for comp in reg_dict["projects"][proj]["libraries"][lib][
                         "components"]:
                     print(comp + " ", end="")
         print()
     elif details == "table":
         rows = [["Project", "Component Spec Directory", "Component"]]
         for proj in reg_dict["projects"]:
             for comp in reg_dict["projects"][proj].get("components", []):
                 rows.append([
                     proj,
                     reg_dict["projects"][proj]["directory"] + "/specs",
                     comp
                 ])
             for lib in reg_dict["projects"][proj]["libraries"]:
                 for comp in reg_dict["projects"][proj]["libraries"][lib][
                         "components"]:
                     lib_dict = reg_dict["projects"][proj]["libraries"][lib]
                     rows.append(
                         [proj, lib_dict["directory"] + "/specs", comp])
         ocpiutil.print_table(rows, underline="-")
     elif details == "json":
         json.dump(reg_dict, sys.stdout)
         print()
Exemple #3
0
 def _show_libary_workers_table(proj_dict):
     """
     Prints out the table for any workers that are located in a project
     """
     print("Workers:")
     rows = [["Library Directory", "Worker"]]
     lib_dict = proj_dict["project"].get("libraries", [])
     for lib in lib_dict:
         wkr_dict = lib_dict[lib].get("workers", [])
         for wkr in wkr_dict:
             rows.append(
                 [os.path.dirname(ocpiutil.rchop(wkr_dict[wkr], "/")), wkr])
     ocpiutil.print_table(rows, underline="-")
Exemple #4
0
 def _show_libary_comps_table(proj_dict):
     """
     Prints out the table for any components that are located in a project
     """
     print("Components:")
     rows = [["Library Directory", "Component"]]
     lib_dict = proj_dict["project"].get("libraries", [])
     for lib in lib_dict:
         comp_dict = lib_dict[lib].get("components", [])
         for comp in comp_dict:
             rows.append([
                 os.path.dirname(ocpiutil.rchop(comp_dict[comp], "/")), comp
             ])
     ocpiutil.print_table(rows, underline="-")
Exemple #5
0
    def show_all(cls, details):
        """
        shows all of the rcc platforms in the format that is specified using details
        (simple, table, or json)
        """
        plat_dict = cls.get_all_dict()

        if details == "simple":
            for plat in plat_dict:
                print(plat + " ", end='')
            print()
        elif details == "table":
            ocpiutil.print_table(cls.get_all_table(plat_dict), underline="-")
        elif details == "json":
            json.dump(plat_dict, sys.stdout)
            print()
Exemple #6
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 #7
0
    def show(self, details, verbose, **kwargs):
        """
        Print out the ports, properties, and slaves of a given worker in the format that is
        provided by the caller

        Function attribtes:
          details    - the mode to print out the informoton in table or simple are the only valid
                       options
          verbose    - integer for verbosity level 0 is default and lowest and anything above 1
                       shows struct internals and hidden properties
          kwargs     - no extra kwargs arguments expected
        """
        json_dict = self._get_show_dict(verbose)
        # add worker specific stuff to the dictionary
        prop_dict = json_dict["properties"]
        for prop in self.property_list:
            if verbose > 0 or prop.get("hidden", "0") == "0":
                prop_dict[prop["name"]]["isImpl"] = prop.get("isImpl", "0")
                access_dict = prop_dict[prop["name"]]["accessibility"]
                if prop_dict[prop["name"]]["isImpl"] == "0":
                    access_dict["specinitial"] = prop.get("specinitial", "0")
                    access_dict["specparameter"] = prop.get(
                        "specparameter", "0")
                    access_dict["specwritable"] = prop.get("specwritable", "0")
                    access_dict["specreadback"] = prop.get("specreadable", "0")
                    access_dict["specvolitile"] = prop.get("specvolitile", "0")
        slave_dict = {}
        for slave in self.slave_list:
            slave_dict[slave] = {"name": slave}
        json_dict["slaves"] = slave_dict

        if details == "simple" or details == "table":
            print("Component: " + json_dict["name"] + " Package ID: " +
                  json_dict["package_id"])
            print("Directory: " + json_dict["directory"])
            self._show_ports_props(json_dict, details, verbose, True)
            if json_dict.get("slaves"):
                rows = [["Slave Name"]]
                for slave in json_dict["slaves"]:
                    rows.append([json_dict["slaves"][slave]["name"]])
                ocpiutil.print_table(rows, underline="-")
        else:
            json.dump(json_dict, sys.stdout)
            print()
Exemple #8
0
    def show_libraries(self, details, verbose, **kwargs):
        """
        Print out all the libraries that are in this project in the format specified by details
        (simple, table, or json)
        """
        json_dict = {}
        project_dict = {}
        libraries_dict = {}
        for lib_directory in self.get_valid_libraries():
            lib_dict = {}
            lib_package = Library.get_package_id(lib_directory)
            lib_dict["package"] = lib_package
            lib_dict["directory"] = lib_directory
            # in case two or more  libraries have the same package id we update the key to end
            # with a number
            i = 1
            while lib_package in libraries_dict:
                lib_package += ":" + str(i)
                i += 1
            libraries_dict[lib_package] = lib_dict
        project_vars = ocpiutil.set_vars_from_make(
            mk_file=self.directory + "/Makefile",
            mk_arg="projectdeps ShellProjectVars=1",
            verbose=True)
        project_dict["dependencies"] = project_vars['ProjectDependencies']
        project_dict["directory"] = self.directory
        project_dict["libraries"] = libraries_dict
        project_dict["package"] = self.package_id
        json_dict["project"] = project_dict

        if details == "simple":
            lib_dict = json_dict["project"]["libraries"]
            for lib in lib_dict:
                print("Library: " + lib_dict[lib]["directory"])
        elif details == "table":
            rows = [["Library Directories"]]
            lib_dict = json_dict["project"]["libraries"]
            for lib in lib_dict:
                rows.append([lib_dict[lib]["directory"]])
            ocpiutil.print_table(rows, underline="-")
        else:
            json.dump(json_dict, sys.stdout)
            print()
Exemple #9
0
    def show_all(cls, details):
        """
        shows all of the rcc targets in the format that is specified using details
        (simple, table, or json)
        """
        target_dict = cls.get_all_dict()

        if details == "simple":
            for plat in target_dict:
                print(target_dict[plat]["target"] + " ", end='')
            print()
        elif details == "table":
            row_1 = ["Platform", "Target"]
            rows = [row_1]
            for plat in target_dict:
                rows.append([plat, target_dict[plat]["target"]])
            ocpiutil.print_table(rows, underline="-")
        elif details == "json":
            json.dump(target_dict, sys.stdout)
            print()
Exemple #10
0
    def show_all(cls, details):
        """
        shows all of the hdl platforms in the format that is specified using details
        (simple, table, or json)
        """
        plat_dict = cls.get_all_dict()

        if details == "simple":
            for plat in plat_dict:
                print(plat + " ", end='')
            print()
        elif details == "table":
            ocpiutil.print_table(cls.get_all_table(plat_dict), underline="-")
            print(
                "* An asterisk indicates that the platform has not been built yet.\n"
                +
                "  Assemblies and tests cannot be built until the platform is built.\n"
            )
        elif details == "json":
            json.dump(plat_dict, sys.stdout)
            print()
Exemple #11
0
    def _show_non_verbose(self, details, **kwargs):
        """
        show all the information about a project with level 1 of verbocity in the format specified
        by details (simple, table, or json)
        """
        project_vars = ocpiutil.set_vars_from_make(
            mk_file=self.directory + "/Makefile",
            mk_arg="projectdeps ShellProjectVars=1",
            verbose=True)
        #TODO output the project's registry here too
        proj_depends = project_vars['ProjectDependencies']
        if not proj_depends:
            proj_depends.append("None")
        proj_dict = {
            'project': {
                'directory': self.directory,
                'package': self.package_id,
                'dependencies': proj_depends
            }
        }

        if details == "simple":
            print("Project Directory: " + proj_dict["project"]["directory"])
            print("Package-ID: " + proj_dict["project"]["package"])
            print("Project Dependencies: " +
                  ", ".join(proj_dict["project"]["dependencies"]))
        elif details == "table":
            rows = [[
                "Project Directory", "Package-ID", "Project Dependencies"
            ]]
            rows.append([
                proj_dict["project"]["directory"],
                proj_dict["project"]["package"],
                ", ".join(proj_dict["project"]["dependencies"])
            ])
            ocpiutil.print_table(rows, underline="-")
        else:
            json.dump(proj_dict, sys.stdout)
            print()
Exemple #12
0
 def show(self, details, verbose, **kwargs):
     """
     show information about the registry in the format specified by details
     (simple, table, or json)
     """
     reg_dict = self.get_dict(False)
     if details == "simple":
         print(" ".join(sorted(reg_dict["projects"])))
     elif details == "table":
         print("Project registry is located at: " +
               reg_dict["registry_location"])
         # Table header
         row_1 = ["Project Package-ID", "Path to Project", "Valid/Exists"]
         rows = [row_1]
         for proj in reg_dict["projects"]:
             rows.append([
                 proj, reg_dict["projects"][proj]["real_path"],
                 reg_dict["projects"][proj]["exists"]
             ])
         ocpiutil.print_table(rows, underline="-")
     elif details == "json":
         json.dump(reg_dict, sys.stdout)
         print()
Exemple #13
0
 def show_all(cls, details):
     """
     shows all of the hdl targets in the format that is specified using details
     (simple, table, or json)
     """
     target_dict = cls.get_all_dict()
     if details == "simple":
         for vendor in target_dict:
             for target in target_dict[vendor]:
                 print(target + " ", end='')
         print()
     elif details == "table":
         rows = [["Target", "Parts", "Vendor", "Toolset"]]
         for vendor in target_dict:
             for target in target_dict[vendor]:
                 rows.append([
                     target,
                     ", ".join(target_dict[vendor][target]["parts"]),
                     vendor, target_dict[vendor][target]["tool"]
                 ])
         ocpiutil.print_table(rows, underline="-")
     elif details == "json":
         json.dump(target_dict, sys.stdout)
         print()
Exemple #14
0
    def show_all(cls, details):
        """
        shows the list of all rcc and hdl platforms in the format specified from details
        (simple, table, or json)
        """
        if details == "simple":
            print("RCC:")
            RccPlatform.show_all(details)
            print("HDL:")
            HdlPlatform.show_all(details)
        elif details == "table":
            #need to combine rcc and hdl into a single table
            rcc_table = RccPlatform.get_all_table(RccPlatform.get_all_dict())
            rcc_table[0].insert(1, "Type")
            rcc_table[0].append("HDL Part")
            rcc_table[0].append("HDL Vendor")
            for my_list in rcc_table[1:]:
                my_list.append("N/A")
            for my_list in rcc_table[1:]:
                my_list.append("N/A")
            for my_list in rcc_table[1:]:
                my_list.insert(1, "rcc")
            hdl_table = HdlPlatform.get_all_table(HdlPlatform.get_all_dict())
            for my_list in hdl_table[1:]:
                my_list.insert(1, "hdl")
            for my_list in hdl_table[1:]:
                rcc_table.append(my_list)
            ocpiutil.print_table(rcc_table, underline="-")

        elif details == "json":
            rcc_dict = RccPlatform.get_all_dict()
            hdl_dict = HdlPlatform.get_all_dict()

            plat_dict = {"rcc": rcc_dict, "hdl": hdl_dict}
            json.dump(plat_dict, sys.stdout)
            print()
Exemple #15
0
 def show_workers(self, details, verbose, **kwargs):
     """
     Show all the workers in all the projects in the registry
     """
     reg_dict = self._collect_workers_dict()
     if details == "simple":
         for proj in reg_dict["projects"]:
             for lib in reg_dict["projects"][proj]["libraries"]:
                 for wkr in reg_dict["projects"][proj]["libraries"][lib][
                         "workers"]:
                     print(wkr + " ", end="")
         print()
     elif details == "table":
         rows = [["Project", "Library Directory", "Worker"]]
         for proj in reg_dict["projects"]:
             for lib in reg_dict["projects"][proj]["libraries"]:
                 for wkr in reg_dict["projects"][proj]["libraries"][lib][
                         "workers"]:
                     lib_dict = reg_dict["projects"][proj]["libraries"][lib]
                     rows.append([proj, lib_dict["directory"], wkr])
         ocpiutil.print_table(rows, underline="-")
     elif details == "json":
         json.dump(reg_dict, sys.stdout)
         print()
Exemple #16
0
    def _show_verbose(self, details, **kwargs):
        """
        print out information about the project with verbocity level 1 in the format specified by
        details (simple, table, or json)
        """
        proj_dict = self._collect_verbose_dict()

        if details == "simple":
            print("Project Directory: " + proj_dict["project"]["directory"])
            print("Package-ID: " + proj_dict["project"]["package"])
            print("Project Dependencies: " +
                  ", ".join(proj_dict["project"]["dependencies"]))
            comp_dict = proj_dict["project"].get("components", [])
            comps = []
            for comp in comp_dict:
                comps.append(comp)
            if comp_dict:
                print("Top Level Components: " + ", ".join(comps))
            lib_dict = proj_dict["project"].get("libraries", [])
            for lib in lib_dict:
                print("  Library: " + lib_dict[lib])
        elif details == "table":
            print("Overview:")
            rows = [[
                "Project Directory", "Package-ID", "Project Dependencies"
            ]]
            rows.append([
                proj_dict["project"]["directory"],
                proj_dict["project"]["package"],
                ", ".join(proj_dict["project"]["dependencies"])
            ])
            ocpiutil.print_table(rows, underline="-")
            comp_dict = proj_dict["project"].get("components", [])
            if comp_dict:
                print("Top Level Components:")
                rows = [["Component Name"]]
                for comp in comp_dict:
                    rows.append([comp])
                ocpiutil.print_table(rows, underline="-")
            lib_dict = proj_dict["project"].get("libraries", [])
            if lib_dict:
                print("Libraries:")
                rows = [["Library Directories"]]
                for lib in lib_dict:
                    rows.append([lib_dict[lib]])
                ocpiutil.print_table(rows, underline="-")
        else:
            json.dump(proj_dict, sys.stdout)
            print()
Exemple #17
0
 def __show_table_ports_props(self, json_dict, verbose, is_worker):
     if json_dict.get("properties"):
         rows = ([[
             "Property Name", "Spec Property", "Type", "Accessability"
         ]] if is_worker else [["Property Name", "Type", "Accessability"]])
         for prop in json_dict["properties"]:
             access_str = ""
             for access in json_dict["properties"][prop]["accessibility"]:
                 if json_dict["properties"][prop]["accessibility"][
                         access] == "1":
                     access_str += access + " "
             if is_worker:
                 rows.append([
                     prop, json_dict["properties"][prop]["isImpl"] == 1,
                     self.get_type_from_dict(json_dict["properties"][prop]),
                     access_str
                 ])
             else:
                 rows.append([
                     prop,
                     self.get_type_from_dict(json_dict["properties"][prop]),
                     access_str
                 ])
         ocpiutil.print_table(rows, underline="-")
         if verbose > 0:  #output any structs
             for prop in json_dict["properties"]:
                 if json_dict["properties"][prop]["type"] == "Struct":
                     print("Struct for " + prop)
                     rows = [["Member Name", "Type"]]
                     for member in json_dict["properties"][prop]["Struct"]:
                         member_dict = json_dict["properties"][prop][
                             "Struct"][member]
                         rows.append(
                             [member,
                              self.get_type_from_dict(member_dict)])
                     ocpiutil.print_table(rows, underline="-")
     if json_dict.get("ports"):
         rows = [["Port Name", "Protocol", "Producer"]]
         for port in json_dict["ports"]:
             rows.append([
                 port, json_dict["ports"][port]["protocol"],
                 json_dict["ports"][port]["producer"]
             ])
         ocpiutil.print_table(rows, underline="-")
Exemple #18
0
    def _show_very_verbose_table(self, proj_dict, have_any_tests,
                                 have_any_wkrs, have_any_comps):
        """
        Prints out information about a project with verbocity level 2 in table format

        Arguments:
          proj_dict      - dictonary with all the project information
          have_any_tests - boolean flag denoting if this project has any tests
          have_any_wkrs  - boolean flag denoting if this project has any workers
          have_any_comps - boolean flag denoting if this project has any components
        """
        print("Overview:")
        rows = [["Project Directory", "Package-ID", "Project Dependencies"]]
        rows.append([
            proj_dict["project"]["directory"], proj_dict["project"]["package"],
            ", ".join(proj_dict["project"]["dependencies"])
        ])
        ocpiutil.print_table(rows, underline="-")
        comp_dict = proj_dict["project"].get("components", [])
        if comp_dict:
            print("Top Level Components:")
            rows = [["Compenent Name"]]
            for comp in comp_dict:
                rows.append([comp])
        ocpiutil.print_table(rows, underline="-")
        prim_dict = proj_dict["project"].get("primitives", [])
        if prim_dict:
            print("Primitives:")
            rows = [["Primitive Directory", "Primitive"]]
            for prim in prim_dict:
                rows.append([self.directory + "/hdl/primitives", prim])
            ocpiutil.print_table(rows, underline="-")
        assembly_dict = proj_dict["project"].get("assemblies", [])
        if assembly_dict:
            print("Assemblies:")
            rows = [["Assembly Directory", "Assembly"]]
            for assy in assembly_dict:
                rows.append([self.directory + "/hdl/assemblies", assy])
            ocpiutil.print_table(rows, underline="-")
        lib_dict = proj_dict["project"].get("libraries", [])
        if lib_dict:
            print("Libraries:")
            rows = [["Library Directories"]]
            for lib in lib_dict:
                rows.append([lib_dict[lib]["directory"]])
            ocpiutil.print_table(rows, underline="-")
        if have_any_tests:
            print("Tests:")
            rows = [["Library Directory", "Test"]]
            lib_dict = proj_dict["project"].get("libraries", [])
            for lib in lib_dict:
                test_dict = lib_dict[lib].get("tests", [])
                for test in test_dict:
                    rows.append([
                        os.path.dirname(ocpiutil.rchop(test_dict[test], "/")),
                        test
                    ])
            ocpiutil.print_table(rows, underline="-")
        if have_any_wkrs:
            self._show_libary_workers_table(proj_dict)
        if have_any_comps:
            self._show_libary_comps_table(proj_dict)