Пример #1
0
    def test_create_log_directory_as_needed(self):
        log_dir_as_file = 'test_log_path.txt'
        log_path = 'test_log_path.txt/test_log_path.txt'

        with open(log_dir_as_file, 'w') as f:
            f.write('dummy log file by unittest')

        with self.assertRaises(IOError):
            LoggingUtil.setup(log_path=log_path)
 def __init__(self):
     LoggingUtil.setup()
     t = Terminal()
     t.ssh(user=self.USER, server=self.SERVER)
     t.cp(options='-R', source=self.COPY_FILE_FROM, dest=self.TMP_SERVER_DIR)
     t.chown(options='-R', owner_group=self.OWNER_GROUP, target=self.TMP_SERVER_DIR)
     t.mkdir(options='-p', path=self.COPY_FILE_TO)
     src = '{}@{}:{}'.format(self.USER, self.SERVER, os.path.join(self.TMP_SERVER_DIR, os.path.basename(self.COPY_FILE_FROM)))
     t.scp(options='-r', source=src, dest=self.COPY_FILE_TO)
     time.sleep(5)
     t.close()
Пример #3
0
    def test_setup(self):
        log_path = 'test_log_path.txt'

        self.assertFalse(os.path.exists(log_path))

        LoggingUtil.setup(log_path=log_path, log_level=logging.DEBUG)
        self.assertTrue(os.path.exists(log_path))

        orig_file_size = os.path.getsize(log_path)
        logging.debug("debug log test from unittest")
        new_file_size = os.path.getsize(log_path)
        self.assertNotEqual(orig_file_size, new_file_size)
Пример #4
0
    def __init__(self):
        LoggingUtil.setup(log_path='rb_server.log')
        console = Console()
        console.start_input_reader(on_command_method=self.on_command)
        self.stop = False
        #self.ctr = 0
        self.registered = False
        #self.clients = 0
        self.message_ctr = -1
        self.clients = []
        self.messages = []
        self.events = set()
        self.regex_match_id = re.compile(self.MATCH_ID_PATTERN.replace('?<', '?P<'))

        for time in ['17_45', '17_46', '17_47', '17_48', '17_49']:
            print('Opening {}...'.format(time))

            with open(self.MESSAGES_PATH.format(time), 'r') as f:
                for line in f.readlines():
                    self.messages.append(line)
            with open(self.EVENTS_PATH.format(time), 'r') as f:
                for line in f.readlines():
                    self.events.add(line)

        self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        self.sock.bind((self.HOST, self.PORT))
        self.sock.listen(10)
        logging.info('Server is now listening to port {}...'.format(self.PORT))

        while not self.stop:
            conn, addr = self.sock.accept()
            self.clients.append([conn, addr])
            logging.info('Received connection at {}.'.format(addr))

            kp_alv_timer = Timer(5, self.keep_alive_task, args=(conn, addr))
            receive_thread = Thread(target=self.receive_task, args=(conn, addr))
            #talk_thread = Thread(target=self.talk, args=(conn, addr))

            #self.clients += 1

            kp_alv_timer.daemon = True
            receive_thread.daemon = True
            #talk_thread.daemon = True

            kp_alv_timer.start()
            receive_thread.start()
            #talk_thread.start()

        self.sock.close()
        logging.info('ENDED.')
Пример #5
0
 def __init__(self):
     LoggingUtil.setup()
     text_aggregator = TextAggregator(self.MATCH_DIR)
     text_aggregator.run()
Пример #6
0
 def __init__(self):
     LoggingUtil.setup()
Пример #7
0
    def __init__(self):
        LoggingUtil.setup(log_path='{}.log'.format(os.path.splitext(os.path.split(__file__)[1])[0]))

        text_reader = TextReader()
        text_reader.start()
Пример #8
0
 def __init__(self):
     log_file = '{}.log'.format(os.path.splitext(os.path.split(__file__)[1])[0])
     LoggingUtil.setup(log_path=log_file, log_level=logging.INFO)
     text_reader = TextReader2()
     text_reader.start()
Пример #9
0
            time.sleep(0.1)

    def _process_user_input(self):
        while not self.stopped:
            user_input = self._get_user_input()
            commands = user_input.split(' ')
            if commands[0] in ['bookmatch', 'book', 'bm'] and len(commands) > 1:
                self.rb_server.book_match(commands[1])
            elif commands[0] in ['register', 'subscribe', 'reg', 'sub'] and len(commands) > 1:
                self.rb_server.register(commands[1])
            elif commands[0] in ['resend']:
                self.rb_server.resend_events(commands[1])
            else:
                self.rb_server.send('{}{}'.format(user_input, os.linesep))

    def _process_server_response(self):
        while not self.stopped:
            response = self.rb_server.recv()
            if 'loginok' in response:
                self.logged_in = True

    @staticmethod
    def _get_user_input():
        return raw_input()


if __name__ == '__main__':
    LoggingUtil.setup('runningball_server.log')
    Main().start()
    #<match_list_request timestamp="1184145289891" date_from="1448180950418" date_to="1468180950418" />
Пример #10
0
 def __init__(self):
     log_file = '{}.log'.format(os.path.splitext(os.path.basename(__file__))[0])
     LoggingUtil.setup(log_file, logging.INFO)
     demo = Demo()