Example #1
0
 def output(self):
     for server in Server.query.all():
         print server
     print ""
     #This seems like a hack to make sure we don't store any
     #references in memory which get used, modified later on
     database.commit()
Example #2
0
 def delete(self, nick, network_name):
     bot = Bot.query.filter(Bot.nick == nick).filter(Bot.network_name == network_name).first()
     if bot is None:
         return
     db.delete(bot)
     print "Committing deletion of %s, %s" % (nick, network_name)
     database.commit()
Example #3
0
 def delete(self, address):
     server = Server.query.filter(Server.address == address).first()
     if server is None:
         return server
     db.delete(server)
     print "Committing deletion of %s, %s" % (address)
     database.commit()
Example #4
0
 def output(self):
     for channel in Channel.query.all():
         print channel
         for bot in channel.bots:
             print "\t%s" % bot
     print ""
     #This seems like a hack to make sure we don't store any
     #references in memory which get used, modified later on
     database.commit()
Example #5
0
 def addChannel(self, bot_name, channel_name):
     #add/get the channel
     channel = self.channelManager.add(channel_name)
     #get the bot
     bot = Bot.query.filter(Bot.nick == bot_name).first()
     if bot is None:
         return None
     #add channel to bot
     bot.channels.append(channel)
     #commit
     database.commit()
Example #6
0
 def delete(self, name):
     #add/get the channel
     channel = Channel.query.filter(Channel.name == channel_name).first()
     if channel is None:
         print "Unable to find channel: %s" % channel_name
         return
     #get the bots that reference the channel
     if(len(channel.bots) > 0):
         print "Found bots that reference the channel:"
         for bot in channel.bots:
             print bot.nick
     db.delete(channel)
     #commit
     database.commit()
Example #7
0
    def __str__(self):
        #http://www.skymind.com/~ocrow/python_string/
        from cStringIO import StringIO
        ret_str = StringIO()

        for network in Network.query.all():
            ret_str.write(str(network))
            for server in network.servers:
                ret_str.write("\n\t")
                ret_str.write(str(server))
        ret_str.write("\n")
        #This seems like a hack to make sure we don't store any
        #references in memory which get used, modified later on
        database.commit()
        return ret_str.getvalue()
Example #8
0
 def delete(self, network_name, deleteBot = False):
     network = Network.query.filter(Network.name == network_name).first()
     if network is None:
         return
     #If we found the network then there might be bots that use it
     bots = Bot.query.filter(Bot.network_name == network_name).all()
     if(len(bots) > 0):
         if(not deleteBot):
             return
         for bot in bots:
             print "Deleting %s" % bot.nick
             db.delete(bot)
     db.delete(network)
     print "Committing deletion of %s" % network_name
     database.commit()
Example #9
0
    def output(self, name=None):
        if name is not None:
            bots = Bot.query.filter(Bot.nick==name).all()
        else:
            bots = Bot.query.all()

        for bot in bots:
            print bot
            for server in bot.network.servers:
                print "on: \t%s" % server
            for channel in bot.channels:
                print "in: \t%s" % channel
        print ""

        #This seems like a hack to make sure we don't store any
        #references in memory which get used, modified later on
        database.commit()
Example #10
0
 def add(self, name):
     channel = Channel.query.filter(Channel.name == name).first()
     if channel is not None:
         return channel
     channel = Channel(name)
     db.add(channel)
     if not database.commit():
         raise ModelException("Problem committing channel " + name)
     return channel
Example #11
0
 def add(self, network_name):
     network = Network.query.filter(Network.name == network_name).first()
     if network is not None:
         return network
     network = Network(network_name)
     db.add(network)
     if not database.commit():
         raise ModelException("Problem committing network " + network_name)
     return network
Example #12
0
    def add(self, network_name, address, port=None, SSL=False):
        server = Server.query.filter(Server.address == address).first()
        if(server is not None):
            return server

        #Make sure the network exists
        network = self.networkManager.add(network_name)

        if(port is None or len(port.strip()) == 0):
            port = None
        else:
            port = int(port)
        server = Server(network_name, address, port, SSL)
        db.add(server)
        if not database.commit():
            raise ModelException("Problem committing server " + str(server))
        return server
Example #13
0
    def add(self, nick, network_name):
        if network_name is None or len(network_name.strip()) == 0:
            raise ModelException("Network required when adding a bot.")

        network = self.networkManager.add(network_name)

        if(network is None):
            raise ModelException("Unable to get or add network " + network_name)

        bot = Bot.query.filter(Bot.nick == nick).filter(Bot.network == network).first()
        if bot is not None:
            return bot

        bot = Bot(nick, network_name)
        db.add(bot)
        if not database.commit():
            raise ModelException("Error during commit of Bot "+ nick +" for network " + network_name)
        return bot
Example #14
0
 def clean(self):
     servers = Server.query.filter(Server.network == None).all()
     for server in servers:
         db.delete(server)
     database.commit()