Exemplo n.º 1
0
    def batch_update(self, trace=False):
        '''   Batch update ph5 file from kef file   '''
        err = False
        self.rewind()
        p, kv = self.next()
        while p:
            if trace is True:
                kys = kv.keys()
                print("=-" * 30)
                print("{0}".format(p))
                for k in kys:
                    print("\t{0} = {1}".format(k, kv[k]))

            DELETE = False
            # Update or Append or Delete
            mo = deleteRE.match(p)
            if mo:
                DELETE = True
            else:
                mo = updateRE.match(p)

            key = []
            if mo:
                p, k = mo.groups()
                key.append(k)

            # columns.TABLES keeps a dictionary of key = table name, value =
            # reference to table
            if p not in columns.TABLES:
                LOGGER.warning("No table reference for key: {0}".format(p))
                LOGGER.info("Possibly ph5 file is not open or initialized?")
                p, kv = self.next()
                continue

            # Get handle
            ref = columns.TABLES[p]
            # key needs to be list for columns.validate
            if trace is True:
                LOGGER.info("Validating...")

            errs_keys, errs_required = columns.validate(ref, kv, key)
            for e in errs_keys + errs_required:
                err = True
                LOGGER.error(e)

            if trace is True:
                LOGGER.info("Done")

            if len(key) == 0:
                key = None
            else:
                key = key.pop(0)

            if DELETE:
                if trace is True:
                    LOGGER.info("Deleting...")
                else:
                    columns.delete(ref, kv[key], key)
            else:
                if trace is True:
                    LOGGER.info("Updating...")
                else:
                    columns.populate(ref, kv, key)

            if trace is True:
                LOGGER.info("Skipped")

            p, kv = self.next()

        return err
Exemplo n.º 2
0
    def batch_update(self, trace=False):
        '''   Batch update ph5 file from kef file   '''
        err = False
        self.rewind()
        p, kv = self.next()
        while p:
            if trace == True:
                kys = kv.keys()
                sys.stderr.write('=-' * 30)
                sys.stderr.write("\n%s\n" % p)
                for k in kys:
                    sys.stderr.write("\t%s = %s\n" % (k, kv[k]))

            DELETE = False
            #   Update or Append or Delete
            mo = deleteRE.match(p)
            if mo:
                DELETE = True
            else:
                mo = updateRE.match(p)

            key = []
            if mo:
                p, k = mo.groups()
                key.append(k)

            #if receiverRE.match (p) :
            ##   We are trying to update something in a Receivers_g
            #sys.stderr.write ("Warning: Attempting to modify something under /Experiment_g/Receivers_g.\n")

            #   columns.TABLES keeps a dictionary of key = table name, value = reference to table
            if not columns.TABLES.has_key(p):
                sys.stderr.write("Warning: No table reference for key: %s\n" %
                                 p)
                sys.stderr.write(
                    "Possibly ph5 file is not open or initialized?\n")
                p, kv = self.next()
                continue

            #   Get handle
            ref = columns.TABLES[p]
            #   key needs to be list for columns.validate
            if trace == True:
                sys.stderr.write("Validating...\n")

            errs_keys, errs_required = columns.validate(ref, kv, key)
            for e in errs_keys + errs_required:
                err = True
                sys.stderr.write(e + '\n')

            if trace == True:
                sys.stderr.write("Done\n")

            if len(key) == 0:
                key = None
            else:
                key = key.pop(0)

            if DELETE:
                if trace == True:
                    sys.stderr.write("Deleting...")
                else:
                    columns.delete(ref, kv[key], key)
            else:
                if trace == True:
                    sys.stderr.write("Updating...")
                else:
                    columns.populate(ref, kv, key)

            if trace == True:
                sys.stderr.write("Skipped\n")

            p, kv = self.next()

        return err