Example #1
0
class Factoid(Base):
    __table__ = Table('factoids',
                      Base.metadata,
                      Column('id', Integer, primary_key=True),
                      Column('time', DateTime, nullable=False),
                      Column('factpack',
                             Integer,
                             ForeignKey('factpacks.id'),
                             index=True),
                      useexisting=True)

    names = relation(FactoidName, cascade='all,delete', backref='factoid')
    values = relation(FactoidValue, cascade='all,delete', backref='factoid')

    class FactoidSchema(VersionedSchema):
        def upgrade_1_to_2(self):
            self.add_column(
                Column('factpack', Integer, ForeignKey('factpacks.id')))

        def upgrade_2_to_3(self):
            self.add_index(self.table.c.factpack)

    __table__.versioned_schema = FactoidSchema(__table__, 3)

    def __init__(self, factpack=None):
        self.time = datetime.utcnow()
        self.factpack = factpack

    def __repr__(self):
        return u"<Factoid %s = %s>" % (', '.join([
            name.name for name in self.names
        ]), ', '.join([value.value for value in self.values]))
Example #2
0
File: seen.py Project: rsnyman/ibid
class Sighting(Base):
    __table__ = Table('seen',
                      Base.metadata,
                      Column('id', Integer, primary_key=True),
                      Column('identity_id',
                             Integer,
                             ForeignKey('identities.id'),
                             nullable=False,
                             index=True),
                      Column('type',
                             IbidUnicode(8),
                             nullable=False,
                             index=True),
                      Column('channel', IbidUnicode(32)),
                      Column('value', IbidUnicodeText),
                      Column('time', DateTime, nullable=False),
                      Column('count', Integer, nullable=False),
                      UniqueConstraint('identity_id', 'type'),
                      useexisting=True)

    class SightingSchema(VersionedSchema):
        def upgrade_1_to_2(self):
            self.add_index(self.table.c.identity_id)
            self.add_index(self.table.c.type)

        def upgrade_2_to_3(self):
            self.drop_index(self.table.c.type)
            self.alter_column(Column('type',
                                     IbidUnicode(8),
                                     nullable=False,
                                     index=True),
                              force_rebuild=True)
            self.alter_column(Column('channel', IbidUnicode(32)),
                              force_rebuild=True)
            self.alter_column(Column('value', IbidUnicodeText),
                              force_rebuild=True)
            self.add_index(self.table.c.type)

    __table__.versioned_schema = SightingSchema(__table__, 3)

    identity = relation('Identity')

    def __init__(self,
                 identity_id=None,
                 type='message',
                 channel=None,
                 value=None):
        self.identity_id = identity_id
        self.type = type
        self.channel = channel
        self.value = value
        self.time = datetime.utcnow()
        self.count = 0

    def __repr__(self):
        return u'<Sighting %s %s in %s at %s: %s>' % (
            self.type, self.identity_id, self.channel, self.time, self.value)
Example #3
0
File: fun.py Project: vhata/ibid
class Item(Base):
    __table__ = Table('bucket_items',
                      Base.metadata,
                      Column('id', Integer, primary_key=True),
                      Column('description',
                             IbidUnicodeText(case_insensitive=True),
                             nullable=False,
                             index=True),
                      Column('determiner',
                             IbidUnicodeText(case_insensitive=True),
                             index=True),
                      Column('carried', Boolean, nullable=False, index=True),
                      Column('giver_id',
                             Integer,
                             ForeignKey('identities.id'),
                             nullable=False),
                      useexisting=True)

    __table__.versioned_schema = VersionedSchema(__table__, 1)

    giver = relation(Identity)

    def __init__(self, description, determiner, giver):
        self.description = description
        self.determiner = determiner
        self.carried = True
        self.giver_id = giver

    @classmethod
    def carried_items(cls, session):
        return session.query(cls).filter_by(carried=True)

    @classmethod
    def take_item(cls, session):
        items = cls.carried_items(session)
        num = items.count()
        if num:
            item = items[randrange(0, num)]
        else:
            raise EmptyBucketException

        item.carried = False
        session.save_or_update(item)

        return item

    def __unicode__(self):
        if self.determiner:
            return self.determiner + u' ' + self.description
        else:
            return self.description
Example #4
0
File: memo.py Project: shoosen/ibid
            self.add_index(self.table.c.delivered)
        def upgrade_2_to_3(self):
            self.alter_column(Column('memo', IbidUnicodeText, nullable=False),
                              force_rebuild=True)

    __table__.versioned_schema = MemoSchema(__table__, 3)

    def __init__(self, from_id, to_id, memo, private=False):
        self.from_id = from_id
        self.to_id = to_id
        self.memo = memo
        self.private = private
        self.delivered = False
        self.time = datetime.utcnow()

Identity.memos_sent = relation(Memo, primaryjoin=Identity.id==Memo.from_id,
                               backref='sender')
Identity.memos_recvd = relation(Memo, primaryjoin=Identity.id==Memo.to_id,
                                backref='recipient')

class Tell(Processor):
    usage = u"""(tell|pm|privmsg|msg|ask) <person> [on <source>] <message>
    forget my (first|last|<n>th) message for <person> [on <source>]"""
    feature = ('memo',)

    permission = u'sendmemo'
    permissions = (u'recvmemo',)

    @match(r'^\s*(?:please\s+)?(tell|pm|privmsg|msg|ask)'
           r'\s+(\S+)\s+(.+?)\s*$', version='deaddressed')
    @authorise(fallthrough=False)
    def tell(self, event, how, who, memo):
Example #5
0
            self.add_index(self.table.c.delivered)
        def upgrade_2_to_3(self):
            self.alter_column(Column('memo', IbidUnicodeText, nullable=False),
                              force_rebuild=True)

    __table__.versioned_schema = MemoSchema(__table__, 3)

    def __init__(self, from_id, to_id, memo, private=False):
        self.from_id = from_id
        self.to_id = to_id
        self.memo = memo
        self.private = private
        self.delivered = False
        self.time = datetime.utcnow()

Identity.memos_sent = relation(Memo, primaryjoin=Identity.id==Memo.from_id,
                               backref='sender')
Identity.memos_recvd = relation(Memo, primaryjoin=Identity.id==Memo.to_id,
                                backref='recipient')

class Tell(Processor):
    usage = u"""(tell|pm|privmsg|msg|ask) <person> [on <source>] <message>
    forget my (first|last|<n>th) message for <person> [on <source>]"""
    features = ('memo',)

    permission = u'sendmemo'
    permissions = (u'recvmemo',)

    @match(r'^\s*(?:please\s+)?(tell|pm|privmsg|msg|ask)'
           r'\s+(\S+)\s+(.+?)\s*$', version='deaddressed')
    @authorise(fallthrough=False)
    def tell(self, event, how, who, memo):