Beispiel #1
0
def is_valid(mxd_proj_or_desc):
    """Analyse a map document or ArcGIS Pro Project for broken layers and return a boolean indicating if it is in a
    valid state or not.

    :param mxd_proj_or_desc: The map to be validated
    :type mxd_proj_or_desc: arcpy.mapping.MapDocument/arcpy.mapping.ArcGISProject, description, or str
    :returns: Boolean, True if valid, False if there are one or more broken layers

    """
    # get a logger instance
    logger = _get_logger()

    # make sure what we have is a description of the map
    description = mxd_proj_or_desc if isinstance(
        mxd_proj_or_desc, Mapping) else describe(mxd_proj_or_desc)

    broken_items = []

    for m in description["maps"]:
        # iterate layers and tables
        for i in chain(m["layers"], m["tables"]):
            if i["isBroken"]:
                broken_items.append(i)

    if len(broken_items) > 0:
        logger.debug(u"Map '{0}': Broken data sources:".format(
            description["filePath"]))
        for layer in broken_items:
            logger.debug(u" {0}".format(layer["longName"] if "longName" in
                                        layer else layer["name"]))
            logger.debug(u"  datasource: {0}".format(layer["dataSource"]))

        return False

    return True
    def __call__(self, value, loader_context=None):
        if loader_context:
            context = MergeDict(loader_context, self.default_loader_context)
        else:
            context = self.default_loader_context
        wrapped_funcs = [wrap_loader_context(f, context) for f in self.functions]

        results = []

        for func in wrapped_funcs:
            #if value is None and self.stop_on_none:
            #    break
            results.append(func(value))

        return list(itertools.chain(*results))
    def __call__(self, value, loader_context=None):
        if loader_context:
            context = MergeDict(loader_context, self.default_loader_context)
        else:
            context = self.default_loader_context
        wrapped_funcs = [
            wrap_loader_context(f, context) for f in self.functions
        ]

        results = []

        for func in wrapped_funcs:
            #if value is None and self.stop_on_none:
            #    break
            results.append(func(value))

        return list(itertools.chain(*results))
Beispiel #4
0
    def mutations(self, default_value):
        """
        Mutate the primitive by stepping through the fuzz library extended with the "this" library, return False on
        completion.

        Args:
            default_value (str): Default value of element.

        Yields:
            str: Mutations
        """

        for val in itertools.chain(
                self._fuzz_library,
                self._yield_variable_mutations(default_value),
                self._yield_long_strings(self.long_string_seeds),
        ):
            if self.size < 0 or len(val) <= self.size:
                yield val
Beispiel #5
0
    def get_mutations(self):
        """Iterate mutations. Used by boofuzz framework.

        Yields:
            Mutation: Mutations

        """
        try:
            if not self.fuzzable:
                return
            for value in itertools.chain(self.mutations(self.original_value()), self._fuzz_values):
                if self._halt_mutations:
                    self._halt_mutations = False
                    return
                if isinstance(value, Mutation):
                    yield value
                else:
                    yield Mutation(mutations={self.qualified_name: value})
        finally:
            self._halt_mutations = False  # in case stop_mutations is called when mutations were exhausted anyway
Beispiel #6
0
    def get_mutations(self):
        """Iterate mutations. Used by boofuzz framework.

        Yields:
            list of Mutation: Mutations

        """
        try:
            if not self.fuzzable:
                return
            index = 0
            for value in itertools.chain(self.mutations(self.original_value()), self._fuzz_values):
                if self._halt_mutations:
                    self._halt_mutations = False
                    return
                if isinstance(value, list):
                    yield value
                elif isinstance(value, Mutation):
                    yield [value]
                else:
                    yield [Mutation(value=value, qualified_name=self.qualified_name, index=index)]
                    index += 1
        finally:
            self._halt_mutations = False  # in case stop_mutations is called when mutations were exhausted anyway