コード例 #1
0
ファイル: ocpishow.py プロジェクト: luwangg/opencpi
def main():
    (args, noun) = parseCLVars()
    action = "show"
    try:
        cur_dir = args['cur_dir']
        dir_type = ocpiutil.get_dirtype()
        # args['name'] could be None if no name is provided at the command line
        name = args.get("name", None)
        if not name:
            name = ""
        # Now that we have grabbed name, delete it from the args that will be passed into the
        # AssetFactory because name is explicitly passed to AssetFactory as a separate argument
        del args['name']

        check_scope_options(args.get("scope", None), noun)

        if noun in ["registry", "projects"]:
            directory = ocpiregistry.Registry.get_registry_dir()
        elif noun not in ["libraries", "hdlplatforms", "hdltargets", "rccplatforms", "rcctargets", "platforms", "targets"]:
            directory = ocpiutil.get_ocpidev_working_dir(origin_path=cur_dir,
                                                         noun=noun,
                                                         name=name,
                                                         library=args['library'],
                                                         hdl_library=args['hdl_library'],
                                                         hdl_platform=args['hdl_plat_dir'])
        elif noun == "libraries":
            directory = ocpiutil.get_path_to_project_top()
        else:
            directory = ""

        ocpiutil.logging.debug('Choose directory "' + directory + '" to operate in')
        if noun is None:
            noun = dir_type
        #TODO the noun libraries could be an asset or a plural need to add logic to deal with
        #     determining which one it is.  for now we are going to assume that it is always a
        #     plural

        # If name is not set, set it to the current directory's basename
        if name == "." and dir_type in DIR_TYPES:
            name = os.path.basename(os.path.realpath(cur_dir))
        set_init_values(args, noun)
        plural_noun_list = NOUN_PLURALS + ["hdlplatforms", "hdltargets", "rccplatforms",
                                           "rcctargets", "platforms", "targets"]
        if noun in plural_noun_list:
            (noun, action) = get_noun_from_plural(directory, args, noun)
        ocpiutil.logging.debug('Choose noun: "' + str(noun) + '" and action: "' + action +'"')
        if noun not in [None, "hdlplatforms", "hdltargets", "rccplatforms", "rcctargets",
                        "platforms", "targets", "projects"]:
           my_asset = ocpifactory.AssetFactory.factory(noun, directory, "", **args)
           action = ("my_asset." + action + '("' + args["details"] + '", ' +
                    str(args["verbose"]) + ')')

        ocpiutil.logging.debug("running show action: '" + action + "'")
        #not using anything that is user defined so eval is fine
        eval(action)
    except ocpiutil.OCPIException as ex:
        ocpiutil.logging.error(ex)
コード例 #2
0
ファイル: ocpidev_run.py プロジェクト: l3trl-rc/opencpi
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)
コード例 #3
0
def main():
    """
    Function that is called if this module is called as a mian function
    """
    args = parse_cl_vars()
    try:
        cur_dir = args['cur_dir']
        with ocpiutil.cd(cur_dir):
            cur_dir_basename = os.path.basename(os.path.realpath("."))

            name = args['name']
            # Now that we have grabbed name, delete it from the args that will be passed into the
            # AssetFactory because name is explicitly passed to AssetFactory as a separate argument
            del args['name']

            # From the current directory and directory-modifier options, determine
            # the directory to operate from for this ocpidev command
            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'])

            ocpiutil.logging.debug('Choose directory "' + directory +
                                   '" to operate in')

            dir_type = ocpiutil.get_dirtype(directory)

            # Check dir_type for errors:
            # If there is no noun, and the working directory is not a supported type
            if args['noun'] is None and dir_type not in DIR_TYPES:
                raise ocpiutil.OCPIException('Invalid directory type "' +
                                             str(dir_type) +
                                             '" Valid directory types are: ' +
                                             ", ".join(DIR_TYPES))

            # If name is not set, set it to the current directory's basename
            if name == "." and dir_type in DIR_TYPES:
                name = cur_dir_basename

            # Initialize settings to be used by Asset classes
            set_init_values(args, dir_type)

            # Check worker authoring model and strip authoring model for Worker construction
            if args['noun'] == "worker" or (args['noun'] is None
                                            and dir_type == "worker"):
                if not name.endswith(".hdl"):
                    ocpiutil.logging.warning(
                        "Can only show utilization for workers of authoring " +
                        "model 'hdl'.")
                    sys.exit()
                name = name.rsplit('.', 1)[0]

            ocpiutil.logging.debug(
                "Creating asset object with the following \nname: " +
                str(name) + "\n" + "directory: " + str(directory) +
                "\nargs: " + str(args))

            my_asset = ocpifactory.AssetFactory.factory(
                dir_type, directory, name, **args)

            my_asset.show_utilization()

    except ocpiutil.OCPIException as ex:
        ocpiutil.logging.error(ex)
        # Construct error message and exit
        if args['noun'] is not None:
            my_noun = '' if args['noun'] is None else ' "' + args['noun'] + '"'
            my_name = '' if name == "." else ' named "' + name + '"'
            my_dir = ' in directory "' + args['cur_dir'] + '"'
            ocpiutil.logging.error("Unable to show utilization for " +
                                   my_noun + my_name + my_dir +
                                   " due to previous errors")
        else:
            ocpiutil.logging.error(
                "Unable to show utilization due to previous errors.")
        sys.exit(1)