Beispiel #1
0
def do_tests(options):
    if options.scope != "local":
        raise ocpiutil.OCPIException(
            "ocpidev show tests is only valid in \"--local\" scope.  " +
            "Other scope options are under construction.")
    if not ocpiutil.get_path_to_project_top():
        raise ocpiutil.OCPIException(
            "When using the \"--local\" scope you must run the command " +
            "in a valid OpenCPI project. " + os.path.realpath(".") +
            " is not a valid project.  Use the \"-d\" option or change " +
            "directories")
    #TODO this may not be the right way to do this long term
    my_asset = ocpiassets.AssetFactory.factory(
        "project", ocpiutil.get_path_to_project_top(), init_libs=True)
    my_asset.show(tests=True, details=options.details, verbose=options.verbose)
Beispiel #2
0
def do_worker_or_comp(options, worker):
    #TODO this is not be the right way to do this long term
    if worker:
        cap_asset = "Worker"
        xml_asset = "worker"
    else:
        cap_asset = "Component"
        xml_asset = "spec"
    mdFileList = ocpiutil.get_all_projects()
    assetList = ""
    if options.details == "table":
        # Table header
        row_1 = ["Project Directory", cap_asset]
        row_2 = ["------------------", "------------------------------------"]
        rows = [row_1, row_2]

    for proj_dir in mdFileList:
        proj_dir = rchop(proj_dir, '/')
        proj_dir = rchop(proj_dir, 'exports')
        if os.access('proj_dir', os.W_OK):
            subprocess.check_output([
                os.environ['OCPI_CDK_DIR'] + "/scripts/genProjMetaData.py",
                mdFile
            ])
        mdFile = proj_dir + "/project.xml"
        if os.path.isfile(mdFile):
            assetList = get_tags(mdFile, xml_asset)
            if options.details == "simple":
                print("Project: " + proj_dir)
                for asset in assetList.split():
                    print("    " + cap_asset + ": " + asset)
            elif options.details == "table":
                # Generate rows of the table. Only add the registered column if only_registry is False
                for asset in assetList.split():
                    row_n = [os.path.realpath(proj_dir), asset]
                    rows.append(row_n)
            else:
                raise ocpiutil.OCPIException(
                    "ocpidev show components/worker --json is not " +
                    "valid, this option is under construction.")
    if options.details == "table":
        ocpiutil.print_table(rows)
Beispiel #3
0
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
    """
    if args['noun'] == "library":
        args['init_tests'] = True
    if args['noun'] == "project":
        args['init_libs'] = True
        args['init_tests'] = True
        args['init_apps'] = True
    if args['noun'] == "tests":
        args['init_libs'] = True
        args['init_tests'] = True
        #TODO add libraries here and libraries collection to allow call in a libraries directory
        if dir_type in ["library", "project"]:
            args['noun'] = dir_type
        else:
            raise ocpiutil.OCPIException("Use of tests noun in an invalid directory type: \"" +
                                         dir_type + "\". Valid types are library and project")
Beispiel #4
0
def main():
    ocpiutil.configure_logging()
    args = parse_cl_vars()
    try:
        with ocpiutil.cd(args['cur_dir']):
            dir_type = ocpiutil.get_dirtype()
            # args['name'] could be None if no name is provided at the command line
            name = args['name']
            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"]))
            set_init_values(args, dir_type)
            lib = args.get("lib", "")
            if args['noun'] in ["test", "library"]:
                if dir_type == "library":
                    lib = ""
                if (lib != "components") and ('/' not in lib) and (dir_type == "project"):
                    lib = "components/" + lib
                # pylint:disable=bad-continuation
                if (dir_type == "libraries" and
                    os.path.basename(os.path.realpath('.')) == "components"):
                    #set lib to a blank string
                    lib = ""
                # pylint:enable=bad-continuation
            directory = get_directory(args, name, lib)
            ocpiutil.logging.debug("creating asset as the following \nname: " + str(name) + "\n" +
                                   "directory: " + str(directory) + "\nargs: " + str(args))
            my_asset = ocpiassets.AssetFactory.factory(args['noun'], directory, name, **args)
            #TODO make sure return value is working right always returning zero ?

            sys.exit(my_asset.run())
    except ocpiutil.OCPIException as ex:
        ocpiutil.logging.error(str(ex))
        sys.exit(1)
Beispiel #5
0
    def setUpClass(cls):
        logging.info("Setting up test projects...")
        logging.info("...")
        # Set the registry, (export the variable in bash), register core in the new location
        os.environ['OCPI_PROJECT_REGISTRY_DIR'] = os.path.realpath(
            './project-registry')
        ocpidev_command = "set -e; set -o pipefail && rm -r -f project-registry; " + SET_X
        ocpidev_command += OCPIDEV_CMD + " create registry project-registry; "
        ocpidev_command += "export OCPI_PROJECT_REGISTRY_DIR=" + \
                           os.path.realpath('./project-registry') + " ; "
        # Create PROJECT0 and fill it with assets of many types
        ocpidev_command += "ln -s " + OCPI_CDK_DIR + \
                           "/../project-registry/ocpi.core project-registry/ocpi.core; "
        ocpidev_command += OCPIDEV_CMD + " --register create project " + PROJECT0 + "; "
        ocpidev_command += OCPIDEV_CMD + " -d " + PROJECT0 + " create library mylibrary; "
        ocpidev_command += OCPIDEV_CMD + " -d " + PROJECT0 + " create -l mylibrary spec myspec; "
        ocpidev_command += OCPIDEV_CMD + " -d " + PROJECT0 + " create -l mylibrary test myspec; "
        ocpidev_command += OCPIDEV_CMD + " -d " + PROJECT0 + \
                           " create -l mylibrary worker myworker0.rcc -S myspec-spec.xml; "
        ocpidev_command += OCPIDEV_CMD + " -d " + PROJECT0 + \
                           " create -l mylibrary worker myworker1.hdl -S myspec-spec.xml; "
        ocpidev_command += OCPIDEV_CMD + " -d " + PROJECT0 + " create hdl primitive core mycore; "
        ocpidev_command += OCPIDEV_CMD + " -d " + PROJECT0 + " create hdl primitive library mylib; "
        ocpidev_command += OCPIDEV_CMD + " -d " + PROJECT0 + " create hdl platform myplat; "
        ocpidev_command += OCPIDEV_CMD + " -d " + PROJECT0 + " create hdl assembly myassemb; "
        ocpidev_command += OCPIDEV_CMD + " -d " + PROJECT0 + " create application myapp; "
        # Create a handful of proje " + OCPIDEV_VERBOSE + "cts with different names and packages
        ocpidev_command += OCPIDEV_CMD + " --register -K pkg0               create project mypj0; "
        ocpidev_command += OCPIDEV_CMD + " --register -K pkg1   -N whocares create project mypj1; "
        ocpidev_command += OCPIDEV_CMD + " --register -F pref0              create project mypj2; "
        ocpidev_command += OCPIDEV_CMD + " --register -F pref1  -N myname0  create project mypj3; "
        ocpidev_command += OCPIDEV_CMD + " --register -F pref2. -N myname1  create project mypj4; "
        ocpidev_command += OCPIDEV_CMD + " --register           -N myname2  create project mypj5; "
        ocpidev_command += OCPIDEV_CMD + " --register -K pkg2   -N wc -F wc create project mypj6; "
        ocpidev_command += OCPIDEV_CMD + " --register                       create project mypj7; "
        ocpidev_command += OCPIDEV_CMD + "            -F prefexports -N nm8 create project mypj8; "
        # Create a components library in each
        ocpidev_command += OCPIDEV_CMD + " -d mypj0 create library components; "
        ocpidev_command += OCPIDEV_CMD + " -d mypj1 create library components; "
        ocpidev_command += OCPIDEV_CMD + " -d mypj2 create library components; "
        ocpidev_command += OCPIDEV_CMD + " -d mypj3 create library components; "
        ocpidev_command += OCPIDEV_CMD + " -d mypj4 create library components; "
        ocpidev_command += OCPIDEV_CMD + " -d mypj5 create library components; "
        ocpidev_command += OCPIDEV_CMD + " -d mypj6 create library components; "
        ocpidev_command += OCPIDEV_CMD + " -d mypj7 create library components; "
        ocpidev_command += OCPIDEV_CMD + " -d mypj8 create library components; "
        # Export mypj8
        ocpidev_command += "make exports -C mypj8;"
        # Copy the exported pj8 to a new dir, but omit the imports
        ocpidev_command += "mkdir mypj8_exported;"
        ocpidev_command += "rm mypj8/exports/imports; "
        # Note use -R, not -r, for POSIX/BSD portability
        ocpidev_command += "cp -RfL mypj8/exports/* mypj8_exported 2>/dev/null; "
        # Rebuild pj8's imports
        ocpidev_command += "make imports -C mypj8; "
        # Get imports by setting registry for the new exported non-source project
        ocpidev_command += OCPIDEV_CMD + " -d mypj8_exported set registry; "
        # Register the exported project
        ocpidev_command += OCPIDEV_CMD + " register project mypj8_exported; "

        logging.debug("OCPIDEV CMD: '" + ocpidev_command.replace('; ', ';\n') +
                      "';")
        process = subprocess.Popen(ocpidev_command,
                                   shell=True,
                                   executable='/bin/bash')
        results = process.communicate()
        if results[1] or process.returncode != 0:
            raise ocpiutil.OCPIException(
                "'ocpidev create project' failed in ocpiutil test\n" +
                "process.returncode: " + str(process.returncode))
Beispiel #6
0
def do_workers(options):
    if options.scope != "global":
        raise ocpiutil.OCPIException(
            "ocpidev show workers is only valid in \"--global-scope\"." +
            "  Other scope options are under construction.")
    do_worker_or_comp(options, True)