Exemple #1
0
    def test_parse(self):
        config_value = 'name:source  |  type:tcp_socket  |  endpoint:host:port  |  enabled:true'
        conn = Connection.parse(config_value)

        self.assertEqual(conn.name, 'source')
        self.assertEqual(conn.type, 'tcp_socket')
        self.assertEqual(conn.endpoint, 'host:port')
        self.assertTrue(conn.enabled)
Exemple #2
0
 def parse(self, key, value):
     if key in ['post_connect_message', 'on_exit_message', 'time_message']:
         self.__setattr__(key, value)
     elif key.startswith('user_command_'):
         self.user_commands.append(Connection.parse(value))
Exemple #3
0
 def parse(self, section, key, value):
     if key in ['user_input_port']:
         self.__setattr__(key, value)
     elif key.startswith('connection_'):
         self.connections.append(Connection.parse(value))
Exemple #4
0
    def start(self):
        self.setup_logging()
        self.load_config()

        for i in self.config.items('CONNECTION'):
            k, v = i
            print('{}: {}'.format(k, v))

    @staticmethod
    def setup_logging():
        try:
            LoggingUtil().setup(log_path=LOG_FILE, log_level=logging.DEBUG)
        except IOError as e:
            print('ERROR: {}'.format(e))
            sys.exit(e.errno)

    def load_config(self):
        try:
            self.config = ConfigParser.ConfigParser()
            with open(CFG_FILE, 'r') as f:
                self.config.readfp(f)
        except IOError as e:
            logging.error(e)
            sys.exit(e.errno)


if __name__ == '__main__':
    EasyConnect().start()
    print(Connection.parse('name:runningball.feeds | type:tcp_socket          | endpoint:feed.rball.com:3371             | enabled:true'))