Beispiel #1
0
 def __init__(self, host, port, server_id, login, password):
     self.tsconnection = ServerQuery(host, port)
     self.tsconnection.connect()
     self.tsconnection.command('login', {
         'client_login_name': login,
         'client_login_password': password
     })
     self.tsconnection.command('use', {'sid': server_id})
 def __init__(self, host, port, server_id, login, password):
     self.tsconnection = ServerQuery(host, port)
     self.tsconnection.connect()
     self.tsconnection.command('login', {'client_login_name': login, 'client_login_password': password})
     self.tsconnection.command('use', {'sid': server_id})
Beispiel #3
0
class Ts3Server(object):
    """Quick Ts3 client to control the Teamspeak server from out tests"""
    def __init__(self, host, port, server_id, login, password):
        self.tsconnection = ServerQuery(host, port)
        self.tsconnection.connect()
        self.tsconnection.command('login', {
            'client_login_name': login,
            'client_login_password': password
        })
        self.tsconnection.command('use', {'sid': server_id})
        #self.tsconnection.telnet.set_debuglevel(99)

    def disconnect(self):
        self.tsconnection.disconnect()
        del self.tsconnection

    def get_serverinfo(self):
        return self.tsconnection.command('serverinfo')

    def get_channellist(self):
        return self.tsconnection.command('channellist')

    def get_channel_tree(self):
        channels = self.get_channellist()
        channels_index = {0: {'children': []}}
        for c in channels:
            channels_index[c['cid']] = {'data': c, 'children': []}
        for i, channel in channels_index.iteritems():
            if 'data' in channel:
                parent = channels_index[channel['data']['pid']]
                parent['children'].append(channel)
        return channels_index[0]

    @staticmethod
    def walk_channel_tree(func, channel, level=0):
        func(channel, level)
        for child in sorted(channel['children'],
                            key=lambda x: x['data']['channel_order']):
            Ts3Server.walk_channel_tree(func, child, level + 1)

    def print_channel_tree(self):
        def print_channel(channel, level=0):
            if 'data' in channel:
                print "  " * level + "%s <%s>" % (
                    channel['data']['channel_name'], channel['data']['cid'])

        Ts3Server.walk_channel_tree(print_channel, self.get_channel_tree())

    def del_channel(self, cid):
        try:
            self.tsconnection.command('channeldelete', {
                'cid': cid,
                'force': 1
            })
        except TS3Error, err:
            print err
class Ts3Server(object):
    """Quick Ts3 client to control the Teamspeak server from out tests"""
    def __init__(self, host, port, server_id, login, password):
        self.tsconnection = ServerQuery(host, port)
        self.tsconnection.connect()
        self.tsconnection.command('login', {'client_login_name': login, 'client_login_password': password})
        self.tsconnection.command('use', {'sid': server_id})
        #self.tsconnection.telnet.set_debuglevel(99)

    def disconnect(self):
        self.tsconnection.disconnect()
        del self.tsconnection

    def get_serverinfo(self):
        return self.tsconnection.command('serverinfo')

    def get_channellist(self):
        return self.tsconnection.command('channellist')

    def get_channel_tree(self):
        channels = self.get_channellist()
        channels_index = {0: {'children': []}}
        for c in channels:
            channels_index[c['cid']] = {'data':c, 'children': []}
        for i, channel in channels_index.iteritems():
            if 'data' in channel:
                parent = channels_index[channel['data']['pid']]
                parent['children'].append(channel)
        return channels_index[0]

    @staticmethod
    def walk_channel_tree(func, channel, level=0):
        func(channel, level)
        for child in sorted(channel['children'], key=lambda x: x['data']['channel_order']):
            Ts3Server.walk_channel_tree(func, child, level + 1)

    def print_channel_tree(self):
        def print_channel(channel, level=0):
            if 'data' in channel:
                print "  "*level + "%s <%s>" % (channel['data']['channel_name'], channel['data']['cid'])
        Ts3Server.walk_channel_tree(print_channel, self.get_channel_tree())

    def del_channel(self, cid):
        try:
            self.tsconnection.command('channeldelete', {'cid': cid, 'force': 1})
        except TS3Error, err:
            print err