コード例 #1
0
def parse_prop_and_val_list(PropertyList, ValueList):
    plLogger = PLLogger.GetLogger("methodology")
    attr_dict = {}
    attr_dict["obj_list"] = []
    # Check the length of the PropertyList and ValueList
    # They MUST be the same length.
    if len(PropertyList) != len(ValueList):
        msg = "PropertyList and ValueList must have " + \
              "the same number of elements."
        plLogger.LogError(msg)
        return None, msg

    for prop_id, val in zip(PropertyList, ValueList):
        # Break down the property name
        split_name = prop_id.split(".")
        if len(split_name) < 2:
            msg = "Format of PropertyList item " + str(prop_id) + \
                  " is invalid.  Item should be in the form " + \
                  "Object.Property."
            plLogger.LogError(msg)
            return None, msg
        classname = ".".join(split_name[0:-1])
        prop_name = split_name[-1]
        plLogger.LogDebug("checking class: " + classname + " for prop " +
                          prop_name + " with value " + str(val))

        # Check the class name
        res, classname = dm_utils.validate_classname(classname)
        if res is False:
            return None, "Invalid classname: " + classname + \
                " specified in PropertyList."

        # Check the property and value
        prop_val = (prop_name, val)
        msg, tuple_list = dm_utils.validate_property_tuple(classname,
                                                           [prop_val])
        if msg != "":
            plLogger.LogError(msg)
            return None, msg
        else:
            prop_name = tuple_list[0][0]
            val = tuple_list[0][1]

        attr_dict[classname + "." + prop_name] = val
        if classname not in attr_dict["obj_list"]:
            attr_dict["obj_list"].append(classname)
            attr_dict[classname] = []
        if prop_name not in attr_dict[classname]:
            attr_dict[classname].append(prop_name)
    return attr_dict, ""
コード例 #2
0
def check_obj_and_prop_names(input_obj_name, input_prop_name):
    obj_name = ""
    # Check the object name
    if input_obj_name != "":
        res, obj_name = dm_utils.validate_classname(input_obj_name)
        if res is False:
            err_str = "Invalid object with ObjectName: " + input_obj_name
            return err_str, input_obj_name, input_prop_name

    # Check the property name with start value
    if obj_name != "":
        if input_prop_name != "":
            prop_list = [prop.lower() for prop in CMeta.GetProperties(obj_name)]
            if input_prop_name.lower() not in prop_list:
                err_str = "Object class " + input_obj_name + " does not have a property called " + input_prop_name + "."
                return err_str, input_obj_name, input_prop_name

    # input_prop_name may not exist.  If it does, let validation elsewhere
    # check that it is valid (it will be pulled out of the modifier)
    return "", input_obj_name, input_prop_name
コード例 #3
0
def parse_property_value_list(prop_val_list):
    attr_dict = {}
    attr_dict["obj_list"] = []
    for item in prop_val_list:
        parsed_pattern = re.findall("(.*?)\.(.*?)=(.*)", item)

        # FIXME:
        # Check for three things
        # Use Barry's functions to test obj, param, and val

        obj = parsed_pattern[0][0]
        param = parsed_pattern[0][1]
        val = parsed_pattern[0][2]

        # Check the class name (obj)
        res, classname = dm_utils.validate_classname(obj)
        if res is False:
            return None, "Invalid classname: " + classname + \
                " specified in property value list."
        else:
            obj = classname

        # Check the property and value
        param_val = (param, val)
        msg, tuple_list = dm_utils.validate_property_tuple(obj,
                                                           [param_val])
        if msg != "":
            return None, msg
        else:
            param = tuple_list[0][0]
            val = tuple_list[0][1]

        attr_dict[obj + "." + param] = val
        if obj not in attr_dict["obj_list"]:
            attr_dict["obj_list"].append(obj)
            attr_dict[obj] = []
        if param not in attr_dict[obj]:
            attr_dict[obj].append(param)
    return attr_dict, ""
コード例 #4
0
def test_validate_classname(stc):
    assert (True, "Project") == dm_utils.validate_classname("Project")
    assert (True, "Project") == dm_utils.validate_classname("pROject")
    assert (False, "alaala") == dm_utils.validate_classname("alaala")
コード例 #5
0
def run(ObjectList, TagList, IgnoreEmptyTags, CurrVal,
        Iteration, ClassName, PropertyName):
    plLogger = PLLogger.GetLogger('methodology')
    plLogger.LogInfo("IteratorConfigPropertyValueCommand.run")

    # Validate ClassName
    valid_class, ret_name = dm_utils.validate_classname(ClassName)
    if not valid_class:
        plLogger.LogError("Invalid ClassName: " + str(ClassName))
        return False

    # Validate PropertyName
    prop_list = [p.lower() for p in CMeta.GetProperties(ClassName)]
    if PropertyName.lower() not in prop_list:
        plLogger.LogError("Invalid PropertyName: " + str(PropertyName) +
                          " given for class: " + str(ClassName))
        return False

    if not IgnoreEmptyTags:
        if tag_utils.is_any_empty_tags_given_string_names(TagList, ClassName):
            plLogger.LogError("No tagged objects for TagList: " +
                              str(TagList))
            return False

    # Find the objects
    obj_list = dm_utils.process_inputs_for_objects(ObjectList, TagList,
                                                   ClassName)
    if len(obj_list) == 0:
        plLogger.LogInfo("No objects of type " + ClassName +
                         " to configure.")
        return True

    plLogger.LogDebug("obj_list contains: " + str(len(obj_list)))

    # Set the new value
    prop_meta = CMeta.GetPropertyMeta(ClassName, PropertyName)
    for obj in obj_list:
        plLogger.LogDebug("setting obj " + obj.Get("Name") + "'s " +
                          PropertyName + " to " + CurrVal)
        if prop_meta["isCollection"]:
            plLogger.LogDebug(PropertyName + " is a collection")
            try:
                val_list = ast.literal_eval(CurrVal)
                if isinstance(val_list, list):
                    obj.SetCollection(PropertyName,
                                      [str(val) for val in val_list])
                else:
                    obj.SetCollection(PropertyName, [str(val_list)])
            except ValueError:
                plLogger.LogError("Was not able to to set collection " +
                                  "property: " + PropertyName + " of " +
                                  ClassName + " to " + CurrVal)
                return False
        else:
            # Scalar
            obj.Set(PropertyName, CurrVal)

    # Update the results
    hnd_reg = CHandleRegistry.Instance()
    this_cmd = hnd_reg.Find(__commandHandle__)
    res_name = ClassName + "." + PropertyName
    update_results_with_current_value(res_name, CurrVal, Iteration, this_cmd)
    return True