Exemplo n.º 1
0
    def process(self, ctx, m):

        if (parsebool(ctx.interpolate(self.condition, m))):
            yield m
        else:
            if (self.message):
                logger.info(ctx.interpolate(self.message, m))
            elif (ctx.debug2):
                logger.debug("Filtering out message")
            return
Exemplo n.º 2
0
    def process(self, ctx, m):

        self.count = self.count + 1

        dolog = True
        if (self.condition):
            dolog = parsebool(ctx.interpolate(m, self.condition))

        if dolog and (not self.once or self.count == 1):
            logger.log(self.level, ctx.interpolate(m, self.message))

        yield m
Exemplo n.º 3
0
    def process(self, ctx, m):

        self.count = self.count + 1

        dolog = True
        if (self.condition):
            dolog = parsebool(ctx.interpolate(self.condition, m))

        if dolog and (not self.once or self.count == 1):
            logger.log(self.level, ctx.interpolate(self.message, m))

        yield m
Exemplo n.º 4
0
    def process(self, ctx, m):

        if (self.condition == None):
            raise Exception("Filter node with no condition.")

        if (parsebool(ctx.interpolate(m, self.condition))):
            yield m
        else:
            if (self.message):
                logger.info(ctx.interpolate(m, self.message))
            elif (ctx.debug2):
                logger.debug("Filtering out message")
            return
Exemplo n.º 5
0
    def process(self, ctx, m):

        if (self.condition == None):
            raise Exception("Filter node with no condition.")

        if (parsebool(ctx.interpolate(m, self.condition))):
            yield m
        else:
            if (self.message):
                logger.info(ctx.interpolate(m, self.message))
            elif (ctx.debug2):
                logger.debug("Filtering out message")
            return
Exemplo n.º 6
0
    def initialize(self, ctx):

        super(SQLTable, self).initialize(ctx)

        if self._lookup_changed_fields == None:
            self._lookup_changed_fields = []

        ctx.comp.initialize(self.connection)

        logger.debug("Loading table %s on %s" % (self.name, self))

        self.sa_metadata = MetaData()
        self.sa_table = Table(self.name, self.sa_metadata)

        self._selects = 0
        self._inserts = 0
        self._updates = 0
        self._unicode_errors = 0

        # Drop?

        columns_ex = []
        for column in self.columns:

            logger.debug("Adding column to %s: %s" % (self, column))

            # Check for duplicate names
            if (column["name"] in columns_ex):
                logger.warn("Duplicate column name '%s' in %s" %
                            (column["name"], self))

            columns_ex.append(column["name"])

            # Configure column
            column["pk"] = False if (not "pk" in column) else parsebool(
                column["pk"])
            if (not "type" in column): column["type"] = "String"
            #if (not "value" in column): column["value"] = None
            self.sa_table.append_column(
                Column(column["name"],
                       self._get_sa_type(column),
                       primary_key=column["pk"],
                       autoincrement=(True if column["type"] == "AutoIncrement"
                                      else False)))

        # Check schema

        # Create if doesn't exist
        if (not self.connection.engine().has_table(self.name)):
            logger.info("Creating table %s" % self.name)
            self.sa_table.create(self.connection.connection())
Exemplo n.º 7
0
    def pk(self, ctx):
        #Returns the primary key mapping.

        pk_mappings = []
        for mapping in self._mappings(ctx):
            if ("pk" in mapping):
                if parsebool(mapping["pk"]):
                    pk_mappings.append(mapping)

        if (len(pk_mappings) > 1):
            raise Exception("%s has multiple primary keys mapped: %s" % (self, pk_mappings))
        elif (len(pk_mappings) == 1):
            return pk_mappings[0]
        else:
            return None
Exemplo n.º 8
0
    def _ensure_mappings(self, ctx, mappings):

        for mapping in mappings:
            mapping["pk"] = (False if (not "pk" in mapping) else parsebool(mapping["pk"]))
            if (not "column" in mapping): mapping["column"] = mapping["name"]
            if (not "value" in mapping): mapping["value"] = None

            if (mapping["pk"] and not "type" in mapping):
                if (not "value" in mapping or mapping["value"] == None):
                    mapping["type"] = "AutoIncrement"

            if (not "column" in mapping): mapping["column"] = mapping["name"]
            if (not "type" in mapping): mapping["type"] = "String"

        return mappings
Exemplo n.º 9
0
    def pk(self, ctx):
        #Returns the primary key mapping.

        pk_mappings = []
        for mapping in self._mappings(ctx):
            if ("pk" in mapping):
                if parsebool(mapping["pk"]):
                    pk_mappings.append(mapping)

        if (len(pk_mappings) > 1):
            raise Exception("%s has multiple primary keys mapped: %s" %
                            (self, pk_mappings))
        elif (len(pk_mappings) == 1):
            return pk_mappings[0]
        else:
            return None
Exemplo n.º 10
0
    def _ensure_mappings(self, ctx, mappings):

        for mapping in mappings:
            mapping["pk"] = (False if (not "pk" in mapping) else parsebool(
                mapping["pk"]))
            if (not "column" in mapping): mapping["column"] = mapping["name"]
            if (not "value" in mapping): mapping["value"] = None

            if (mapping["pk"] and not "type" in mapping):
                if (not "value" in mapping or mapping["value"] == None):
                    mapping["type"] = "AutoIncrement"

            if (not "column" in mapping): mapping["column"] = mapping["name"]
            if (not "type" in mapping): mapping["type"] = "String"

        return mappings
Exemplo n.º 11
0
    def initialize(self, ctx):

        super(SQLTable, self).initialize(ctx)

        if self._lookup_changed_fields == None:
            self._lookup_changed_fields = []

        ctx.comp.initialize(self.connection)

        logger.debug("Loading table %s on %s" % (self.name, self))


        self.sa_metadata = MetaData()
        self.sa_table = Table(self.name, self.sa_metadata)

        # Drop?

        columns_ex = []
        for column in self.columns:

            logger.debug("Adding column to %s: %s" % (self, column))

            # Check for duplicate names
            if (column["name"] in columns_ex):
                raise Exception("Duplicate column name '%s' in %s" % (column["name"], self))
            columns_ex.append(column["name"])

            # Configure column
            column["pk"] = False if (not "pk" in column) else parsebool(column["pk"])
            if (not "type" in column): column["type"] = "String"
            #if (not "value" in column): column["value"] = None
            self.sa_table.append_column( Column(column["name"],
                                                self._get_sa_type(column),
                                                primary_key = column["pk"],
                                                autoincrement = (True if column["type"] == "AutoIncrement" else False) ))

        # Check schema

        # Create if doesn't exist
        if (not self.connection.engine().has_table(self.name)):
            logger.info("Creating table %s" % self.name)
            self.sa_table.create(self.connection.connection())
Exemplo n.º 12
0
    def pk(self, ctx):
        """
        Returns the primary key column definitToClauion, or None if none defined.
        """

        if (self._pk == False):
            pk_cols = []
            for col in self.columns:
                if ("pk" in col):
                    if parsebool(col["pk"]):
                        pk_cols.append(col)

            if (len(pk_cols) > 1):
                raise Exception("Table %s has multiple primary keys: %s" % (self.name, pk_cols))
            elif (len(pk_cols) == 1):
                self._pk = pk_cols[0]
            else:
                self._pk = None

        return self._pk
Exemplo n.º 13
0
    def pk(self, ctx):
        """
        Returns the primary key column definitToClauion, or None if none defined.
        """

        if (self._pk == False):
            pk_cols = []
            for col in self.columns:
                if ("pk" in col):
                    if parsebool(col["pk"]):
                        pk_cols.append(col)

            if (len(pk_cols) > 1):
                raise Exception("Table %s has multiple primary keys: %s" %
                                (self.name, pk_cols))
            elif (len(pk_cols) == 1):
                self._pk = pk_cols[0]
            else:
                self._pk = None

        return self._pk
Exemplo n.º 14
0
    def process(self, ctx, m):

        cond = True
        if self.condition:
            cond = parsebool(ctx.interpolate(self.condition, m))

        if cond:
            if (not self.fork):
                result_msgs = self._process(self.steps, ctx, m)
                for m in result_msgs:
                    yield m
            else:
                logger.debug("Forking flow (copying message).")
                m2 = ctx.copy_message(m)
                result_msgs = self._process(self.steps, ctx, m2)
                count = 0
                for mdis in result_msgs:
                    count = count + 1

                logger.debug("Forked flow end - discarded %d messages" % count)
                yield m
        else:
            yield m
Exemplo n.º 15
0
 def initialize(self, ctx):
     super(Transaction, self).initialize(ctx)
     ctx.comp.initialize(self.connection)
     self.enabled = parsebool(self.enabled)
Exemplo n.º 16
0
 def initialize(self, ctx):
     super(Transaction, self).initialize(ctx)
     ctx.comp.initialize(self.connection)
     self.enabled = parsebool(self.enabled)