Ejemplo n.º 1
0
def initEvent(sFile:str, oLog:logging=None, isSilent:bool=False) -> None:
    msg = "({0}) Initialisation".format(getFileName(sFile))
    if oLog:
        oLog.debug(msg, outConsole=True)
    elif not isSilent:
        print(msg)
    return
Ejemplo n.º 2
0
def download_file(file_url: str, file_name: str, log: logging) -> str:
    """
     Download file_url and move it to file_name, do nothing if file_name already exists.

    :param log: log to be use.
    :param file_url: file url to be download
    :param file_name: file name where the data will be downloaded
    :return: name of the file if the file can be download.
    """
    if os.path.isfile(file_name):
        return file_name

    if log is not None:
        log = logging

    remaining_download_tries = REMAINING_DOWNLOAD_TRIES
    downloaded_file = None
    while remaining_download_tries > 0:
        try:
            downloaded_file, error_code = request.urlretrieve(
                file_url, file_name)
            log.debug("File downloaded -- " + downloaded_file)
            if downloaded_file.endswith('.gz'):
                extracted_file = downloaded_file.replace('.gz', '')
                with open(extracted_file, 'w') as outfile:
                    outfile.write(
                        gzip.decompress(open(downloaded_file,
                                             'rb').read()).decode('utf-8'))
                    os.remove(downloaded_file)
                    downloaded_file = extracted_file
                    log.debug("File extracted-- " + downloaded_file)
            break
        except (
                HTTPError,
                URLError,
                ContentTooShortError,
        ) as error:
            logging.error(
                "Error downloading -- Incorrect URL or file not found: " +
                file_url + " on trial no: " +
                str(REMAINING_DOWNLOAD_TRIES - remaining_download_tries))
            log.error("Error code: " + str(error))
            remaining_download_tries = remaining_download_tries - 1
            downloaded_file = None
            continue
        except Exception as error:
            remaining_download_tries = remaining_download_tries - 1
            log.error("Error code: " + str(error))
            downloaded_file = None

    return downloaded_file
Ejemplo n.º 3
0
    def dump(self, logger:logging = None, header:str = None, footer:str = None, indent:int = 0):
        """
        :param logger: open file object, to which the dump is written
        :param header: text to write before the dump
        :param footer: text to write after the dump
        :param indent: number of leading spaces (for recursive calls)
        """
        if not logger:
            # Not in debug mode
            return

        if hasattr(self, "__slots__"):
            attr_list = sorted((attr, getattr(self, attr)) for attr in self.__slots__)
        else:
            attr_list = sorted(self.__dict__.items())

        pad = " " * indent

        if header:
            logger.debug(header)

        for attr, value in attr_list:
            if getattr(value, 'dump', None) and attr != 'book':
                obj_name = value.__class__.__name__
                value.dump(logger, header=f"{pad}{attr} ({obj_name} object):", indent=indent + 4)

            elif attr not in self._repr_these and (isinstance(value, list) or isinstance(value, dict)):
                logger.debug(f"{pad}{attr}: {type(value)}, len = {len(value)}")

            else:
                logger.debug(f"{pad}{attr}: {value}")

        if footer:
            logger.debug(footer)
Ejemplo n.º 4
0
 def _reader_func(stream: PIPE, queue: Queue, logger: logging):
     try:
         while True:
             line = stream.readline()
             if len(line) > 0:
                 queue.put(line)
                 if logger is not None:
                     logger.debug(
                         "LiveRNAfold, _reader_func ({}) [{}]".format(
                             queue.qsize(), line))
             else:
                 break
     except Exception as e:
         self.logger.debug(
             "LiveRNAfold, _reader_func THREAD DEAD [{}]".format(e))
         queue.put(END_SEQUENCE)
Ejemplo n.º 5
0
def download_file(file_url: str, file_name: str, log: logging) -> str:
    """
     Download file_url and move it to file_name, do nothing if file_name already exists.

    :param log: log to be use.
    :param file_url: file url to be download
    :param file_name: file name where the data will be downloaded
    :return: name of the file if the file can be download.
    """
    if os.path.isfile(file_name):
        return file_name

    if log is not None:
        log = logging

    remaining_download_tries = REMAINING_DOWNLOAD_TRIES
    downloaded_file = None
    while remaining_download_tries > 0:
        try:
            downloaded_file, error_code = request.urlretrieve(
                file_url, file_name)
            log.debug("File downloaded -- " + downloaded_file)
            break
        except (HTTPError, URLError, ContentTooShortError) as error:
            logging.error(
                "Error downloading -- Incorrect URL or file not found: " +
                file_url + " on trial no: " +
                str(REMAINING_DOWNLOAD_TRIES - remaining_download_tries))
            log.error("Error code: " + str(error))
            remaining_download_tries = remaining_download_tries - 1
            downloaded_file = None
            continue
        except Exception as error:
            remaining_download_tries = remaining_download_tries - 1
            log.error("Error code: " + str(error))
            downloaded_file = None

    return downloaded_file
Ejemplo n.º 6
0
 def trace(self, logger: logging):
     logger.debug('\t\t\t\tname: ' + self.name)
     s = '['
     for c in self.community_cards:
         s += c
         s += ', '
     s += ']'
     logger.debug('\t\t\t\tcommunity_cards: ' + s)
     s = '['
     for c in self.cards:
         s += c
         s += ', '
     s += ']'
     logger.debug('\t\t\t\tcards: ' + s)
     s = '['
     for c in self.discards:
         s += c
         s += ', '
     s += ']'
     logger.debug('\t\t\t\tdiscards: ' + s)
     logger.debug('\t\t\t\tactions:')
     for action in self.actions:
         action.trace(logger)
Ejemplo n.º 7
0
 def trace(self, logger: logging):
     logger.debug('\t\tname: ' + self.name)
     logger.debug('\t\t\tante: ' + str(self.ante))
     logger.debug('\t\t\tseat: ' + str(self.seat))
     logger.debug('\t\t\tposition: ' + str(self.position))
     logger.debug('\t\t\tblindAmount: ' + str(self.blind_amount))
     logger.debug('\t\t\tsmallBlind: ' + str(self.small_blind))
     logger.debug('\t\t\tbigBlind: ' + str(self.big_blind))
     logger.debug('\t\t\tbothBlinds: ' + str(self.both_blinds))
     logger.debug('\t\t\treturnedAmount: ' + str(self.returned_amount))
     logger.debug('\t\t\tcollectedAmount: ' + str(self.collected_amount))
     logger.debug('\t\t\tnet: ' + str(self.net))
     logger.debug('\t\t\tnetBigBets: ' + str(self.net_big_bets))
     logger.debug('\t\t\tnetBigBlinds: ' + str(self.net_big_blinds))
     logger.debug('\t\t\tsawShowdown: ' + str(self.saw_showdown))
     logger.debug('\t\t\tposition: ' + str(self.position))
     s = '['
     for c in self.final_hand:
         s += c
         s += ', '
     s += ']'
     logger.debug('\t\t\tfinalHand: ' + s)
     logger.debug('\t\t\tstreets:')
     for street in self.streets:
         street.trace(logger)
Ejemplo n.º 8
0
def show_message_log_console(message: str, logger: logging = None) -> None:
    if logger is not None:
        logger.debug(message)
    else:
        print(message)
Ejemplo n.º 9
0
def verify(p_parameter_type: tuple, p_logger: logging, p_param_value=None):

    p_param_value_sent_type = type(p_param_value)

    param_key_name: str = p_parameter_type[0]
    param_val_expected_type: str = p_parameter_type[1]
    param_val_expected_list_of_values: [] = []

    if ',' in param_val_expected_type:
        # parameter has distinct values
        param_val_expected_list_of_values = param_val_expected_type.split(
            ',')[1].split('|')
        param_val_expected_type = param_val_expected_type.split(',')[0]
        print()

    if ('LIST[STR]' in param_val_expected_type.strip().upper()
            and 'LIST[STR]' in param_val_expected_type.strip()):
        # parameter value must be a list and exists and value can't be []
        print()

    elif ('LIST[str]' in param_val_expected_type.strip().upper()
          and 'LIST[str]' in param_val_expected_type.strip()):
        # parameter value must be a list and exists and can be []
        print()

    elif 'list[STR]' in param_val_expected_type.strip().upper():
        # parameter must be a list if exists and value can't be []
        print()

    elif 'list[str]' in param_val_expected_type.strip().upper():
        # parameter must be a list if exists and value can be []
        print()

    elif param_val_expected_type.replace(' ', '').strip().upper() == 'ANY':
        # parameter value must exists
        print()

    elif param_val_expected_type.strip() == 'any':
        # parameter value may exists
        print()

    elif (param_val_expected_type.replace(' ', str()).strip().upper() == 'STR'
          and param_val_expected_type.strip() == 'STR'):
        p_logger.debug(
            "Verify parameter ({param_key_name}) is a string and its value {p_param_value} exists"
        )

    elif param_val_expected_type.strip().upper() == 'STR':
        # parameter value must be a string if it exists
        print()

    elif (param_val_expected_type.strip().upper() == 'INT'
          and param_val_expected_type.strip() == 'INT'):
        # parameter value must be a int and exists
        print()

    elif param_val_expected_type.strip().upper() == 'INT':
        # parameter value must be a int if it exists
        print()

    elif (param_val_expected_type.strip().upper() == 'FLOAT'
          and param_val_expected_type.strip() == 'FLOAT'):
        # parameter value must be a int and exists
        print()

    elif param_val_expected_type.strip().upper() == 'FLOAT':
        # parameter value must be a int if it exists
        print()
Ejemplo n.º 10
0
    def trace(self, logger: logging):
        logger.debug('handId: ' + str(self.hand_id))
        logger.debug('\ttimeStamp: ' + self.time_stamp)
        logger.debug('\tsessionStartTime: ' + self.session_start_time)
        logger.debug('\tsessionEndTime: ' + self.session_end_time)
        logger.debug('\ttable: ' + self.table_name)
        logger.debug('\tmix: ' + self.mix)
        logger.debug('\tgame: ' + self.game)
        logger.debug('\tgameSize: ' + str(self.game_size))
        logger.debug('\tstakes: $' + str(self.small_bet) + '/$' + str(self.big_bet))
        logger.debug('\tsmallBlind: ' + str(self.small_blind))
        logger.debug('\tbigBlind: ' + str(self.big_blind))
        logger.debug('\tante: ' + str(self.ante))
        logger.debug('\tcurrency: ' + self.currency)
        logger.debug('\tbuttonSeat: ' + str(self.button_seat))
        logger.debug('\tpot: ' + str(self.pot))
        logger.debug('\trake: ' + str(self.rake))
        s = '['
        for c in self.flop:
            s += c
            s += ', '
        s += ']'
        logger.debug('\tflop: ' + s)
        s = '['
        for c in self.turn:
            s += c
            s += ', '
        s += ']'
        logger.debug('\tturn: ' + s)
        s = '['
        for c in self.river:
            s += c
            s += ', '
        s += ']'
        logger.debug('\triver: ' + s)

        logger.debug('\tplayers:')
        for p in self.players:
            p.trace(logger)
Ejemplo n.º 11
0
 def trace(self, logger: logging):
     logger.debug('\t\t\t\t\tindex: ' + str(self.index))
     logger.debug('\t\t\t\t\taction: ' + self.action)
     logger.debug('\t\t\t\t\tamount: ' + str(self.amount))
     logger.debug('\t\t\t\t\tto_amount: ' + str(self.to_amount))