示例#1
0
 def connect(self):
     '''Connect to server.'''
     self.disconnect()
     self.connection = PyMyServerControl(self.host, self.port,
                                         self.username, self.password)
示例#2
0
 def connect(self):
     '''Connect to server.'''
     self.disconnect()
     self.connection = PyMyServerControl(self.host, self.port,
                                         self.username, self.password)
示例#3
0
class BasicController():
    def __init__(self, host, port, username, password):
        self.connection = None
        self.host = host
        self.port = int(port)
        self.username = username
        self.password = password

    def __check_return_code(self):
        return_code = self.connection.response_code
        if error_codes.get(return_code, '') != 'CONTROL_OK':
            raise ServerError('MyServer returned {0}: {1}'.format(
                return_code, error_codes.get(return_code, '')))

    def connect(self):
        '''Connect to server.'''
        self.disconnect()
        self.connection = PyMyServerControl(self.host, self.port,
                                            self.username, self.password)

    def disconnect(self):
        '''Disconnect from server.'''
        if self.connection is not None:
            self.connection.close()
            self.connection = None

    def reboot(self):
        '''Reboot server.'''
        if self.connection:
            self.connection.send_header('REBOOT', 0)
            self.connection.read_header()
            self.__check_return_code()

    def version(self):
        '''Get version string.'''
        if self.connection:
            self.connection.send_header('VERSION', 0)
            self.connection.read_header()
            self.__check_return_code()
            return self.connection.read()

    def enable_reboot(self):
        '''Enable server auto-reboot.'''
        if self.connection:
            self.connection.send_header('ENABLEREBOOT', 0)
            self.connection.read_header()
            self.__check_return_code()

    def disable_reboot(self):
        '''Disable server auto-reboot.'''
        if self.connection:
            self.connection.send_header('DISABLEREBOOT', 0)
            self.connection.read_header()
            self.__check_return_code()

    def show_connections(self):
        '''List active server connections.'''
        if self.connection:
            self.connection.send_header('SHOWCONNECTIONS', 0)
            self.connection.read_header()
            self.__check_return_code()
            return self.connection.read()

    def kill_connection(self, num):
        '''Kill connection to server.'''
        if self.connection:
            self.connection.send_header('KILLCONNECTION', 0, str(num))
            self.connection.read_header()
            self.__check_return_code()

    def show_language_files(self):
        '''List available language files.'''
        if self.connection:
            self.connection.send_header('SHOWLANGUAGEFILES', 0)
            self.connection.read_header()
            self.__check_return_code()
            return self.connection.read()

    def get_file(self, path):
        '''Get file from server.'''
        if self.connection:
            self.connection.send_header('GETFILE', 0, path)
            self.connection.read_header()
            self.__check_return_code()
            return self.connection.read()

    def put_file(self, text, path):
        '''Put file to server.'''
        if self.connection:
            self.connection.send_header('PUTFILE', len(text), path)
            self.connection.send(text)
            self.connection.read_header()
            self.__check_return_code()
示例#4
0
class BasicController():
    def __init__(self, host, port, username, password):
        self.connection = None
        self.host = host
        self.port = int(port)
        self.username = username
        self.password = password

    def __check_return_code(self):
        return_code = self.connection.response_code
        if error_codes.get(return_code, '') != 'CONTROL_OK':
            raise ServerError('MyServer returned {0}: {1}'.format(
                    return_code, error_codes.get(return_code, '')))

    def connect(self):
        '''Connect to server.'''
        self.disconnect()
        self.connection = PyMyServerControl(self.host, self.port,
                                            self.username, self.password)

    def disconnect(self):
        '''Disconnect from server.'''
        if self.connection is not None:
            self.connection.close()
            self.connection = None

    def reboot(self):
        '''Reboot server.'''
        if self.connection:
            self.connection.send_header('REBOOT', 0)
            self.connection.read_header()
            self.__check_return_code()

    def version(self):
        '''Get version string.'''
        if self.connection:
            self.connection.send_header('VERSION', 0)
            self.connection.read_header()
            self.__check_return_code()
            return self.connection.read()

    def enable_reboot(self):
        '''Enable server auto-reboot.'''
        if self.connection:
            self.connection.send_header('ENABLEREBOOT', 0)
            self.connection.read_header()
            self.__check_return_code()

    def disable_reboot(self):
        '''Disable server auto-reboot.'''
        if self.connection:
            self.connection.send_header('DISABLEREBOOT', 0)
            self.connection.read_header()
            self.__check_return_code()

    def show_connections(self):
        '''List active server connections.'''
        if self.connection:
            self.connection.send_header('SHOWCONNECTIONS', 0)
            self.connection.read_header()
            self.__check_return_code()
            return self.connection.read()

    def kill_connection(self, num):
        '''Kill connection to server.'''
        if self.connection:
            self.connection.send_header('KILLCONNECTION', 0, str(num))
            self.connection.read_header()
            self.__check_return_code()

    def show_language_files(self):
        '''List available language files.'''
        if self.connection:
            self.connection.send_header('SHOWLANGUAGEFILES', 0)
            self.connection.read_header()
            self.__check_return_code()
            return self.connection.read()

    def get_file(self, path):
        '''Get file from server.'''
        if self.connection:
            self.connection.send_header('GETFILE', 0, path)
            self.connection.read_header()
            self.__check_return_code()
            return self.connection.read()

    def put_file(self, text, path):
        '''Put file to server.'''
        if self.connection:
            self.connection.send_header('PUTFILE', len(text), path)
            self.connection.send(text)
            self.connection.read_header()
            self.__check_return_code()