Example #1
0
def align_data_maps(*args):
    """
    Aligns the skip fields in the supplied datamaps.
    If a single skip is set for an entrie, all other entries in the other
    datamaps will be set.
    
    Raises a DataMapError if the datamaps are of different size and
    alignment is not possible.
    """
    if len(args) < 2:
        raise DataMapError(
            "At least two datamaps are needed to perform align.")

    if not validate_data_maps(*args):
        raise DataMapError("Validation of data maps failed in align_data_map"
                           " Supplied datamaps: {0}".format(repr(args)))

    # for all the input maps get the entries in a single tuple
    for entries in zip(*args):
        skip = False
        # For each entrie perform an or of the skip fields
        for entrie in entries:
            skip = skip or entrie.skip
        # Assign the resulting skip field to all the entries
        for entrie in entries:
            entrie.skip = skip
Example #2
0
    def append(self, data, dtype=MultiDataProduct):
        """
        Append an item to the end of the internal storage, allows appending
        of DataProduct or tuple. Default skip=True
        """
        try:
            if isinstance(data, dtype):
                self._data.append(data)

            # tuple or argument input
            elif isinstance(data, tuple):
                # use the DataProduct validation to assure correct types
                item = None
                if len(data) < 2:
                    raise TypeError(
                        "MultiDataMap: Incorrect tuple size (< 2): {0}".format(
                            repr(tuple)))
                elif len(data) == 2:
                    item = MultiDataProduct(data[0], data[1])
                elif len(data) == 3:
                    item = MultiDataProduct(data[0], data[1], data[2])
                elif len(data) == 4:
                    item = MultiDataProduct(data[0], data[1], data[2], data[3])
                else:
                    raise TypeError(
                        "MultiDataMap: Incorrect tuple size (> 4): {0}".format(
                            repr(tuple)))

                self._data.append(item)
            else:
                raise TypeError
        except TypeError:
            raise DataMapError("Failed to append item: %s" % repr(data))
Example #3
0
    def append(self, data, dtype=DataProduct):
        """
        Append an item to the end of the internal storage, allows appending
        of DataProduct or tuple. Default skip=False when only (host, file) is
        supplied
        """
        try:
            if isinstance(data, dtype):
                self._data.append(data)

            # tuple
            elif isinstance(data, tuple):
                item = None
                if len(data) == 3:
                    # use the DataProduct validation to assure correct types
                    item = DataProduct(data[0], data[1], data[2])
                elif len(data) == 2:
                    item = DataProduct(data[0], data[1], False)
                else:
                    raise TypeError(
                        "DataMap, Suplied tuple is not valid: {0}".format(
                            repr(tuple)))
                self._data.append(item)
            else:
                raise TypeError
        except TypeError:
            raise DataMapError("Failed to append item: %s" % repr(data))
Example #4
0
 def _set_data(self, data, dtype=DataProduct):
     try:
         if all(isinstance(item, dtype) for item in data):
             self._data = data
         elif all(isinstance(item, dict) for item in data):
             self._data = [dtype(**item) for item in data]
         elif all(isinstance(item, tuple) for item in data):
             self._data = [dtype(*item) for item in data]
         else:
             raise TypeError
     except TypeError:
         raise DataMapError("Failed to validate data map: %s" % repr(data))