Exemple #1
0
 def parse_oob_xml(self, oob: ET.Element):
     if oob is not None and oob.text is not None:
         self._location = oob.text
         return True
     else:
         YLogger.error(self, "Unvalid geomap oob command - missing location text!")
         return False
Exemple #2
0
    def poll_and_answer(self):

        running = True
        try:
            (last_direct_message_id, last_status_id) = self._get_last_message_ids()

            self._poll(last_direct_message_id, last_status_id)

        except KeyboardInterrupt:
            running = False

        except RateLimitError:

            if self._configuration.client_configuration.rate_limit_sleep != -1:
                rate_limit_sleep = self._configuration.client_configuration.rate_limit_sleep
            else:
                rate_limit_sleep = self.FIFTEEN_MINUTES

            YLogger.error(self, "Rate limit exceeded, sleeping for %d seconds", rate_limit_sleep)

            self.sleep(rate_limit_sleep)

        except Exception as excep:
            YLogger.exception(self, "Poll and answer error", excep)

        return running
Exemple #3
0
 def save_conversation(self, clientid):
     if self._conversation_storage is not None:
         if clientid in self._conversations:
             conversation = self._conversations[clientid]
             self._conversation_storage.save_conversation(conversation, clientid)
         else:
             YLogger.error(self, "Unknown conversation id type [%s] unable tonot persist!", clientid)
Exemple #4
0
    def create_viber_bot(self, viber_token):

        if viber_token is None:
            YLogger.error(self, "'viber_token' missing")
            return None

        name = self.configuration.client_configuration.name
        if name is None:
            YLogger.error(self, "'name' missing from Viber configuration")
            return None

        avatar = self.configuration.client_configuration.avatar
        if avatar is None:
            YLogger.error(self, "'avatar' missing from Viber configuration")
            return None

        webhook = self.configuration.client_configuration.webhook
        if webhook is None:
            YLogger.error(self, "'webhook' missing from Viber configuration")
            return None

        configuration = BotConfiguration(
            name=name,
            avatar=avatar,
            auth_token=viber_token
        )

        bot = self.create_viber_api(configuration)
        if bot is not None:
            YLogger.error(self, "'Failed to create Viber api")

        bot.set_webhook(webhook)
        return bot
Exemple #5
0
 def parse_oob_xml(self, oob: ET.Element):
     if oob is not None and oob.text is not None:
         self._search = oob.text
         return True
     else:
         YLogger.error(self, "Unvalid search oob command - missing search query!")
         return False
Exemple #6
0
    def receive_message(self, request):

        api_key_response = self.check_api_key(request)
        if api_key_response is not None:
            return api_key_response

        question = self.get_question(request)
        if question is None:
            YLogger.error(self, "'question' missing from request")
            abort(400)

        userid = self.get_userid(request)

        userid_expire_date = self.get_userid_cookie_expirary_date(self.configuration.client_configuration.cookie_expires)

        client_context = self.create_client_context(userid)
        try:
            answer = self.get_answer(client_context, question)
            rendered = self._renderer.render(client_context, answer)
            response_data = self.create_success_response_data(question, rendered)

        except Exception as excep:
            YLogger.exception(self, "Failed receving message", excep)
            response_data = self.create_error_response_data(client_context, question, str(excep))

        return self.create_response(response_data, userid, userid_expire_date)
Exemple #7
0
    def handle_message(self, message):

        try:
            if self.configuration.client_configuration.debug is True:
                self.dump_request(message)
            self.renderer.print_payload("Incoming", message)

            # Facebook Messenger ID for user so we know where to send response back to
            recipient_id = self.get_recipitent_id(message)
            if recipient_id:
                client_context = self.create_client_context(recipient_id)

                message_text = self.get_message_text(message)

                # We have been send a text message, we can respond
                if message_text is not None:
                    response_text = self.handle_text_message(client_context, message_text)

                # else if user sends us a GIF, photo,video, or any other non-text item
                elif self.has_attachements(message):
                    response_text = self.handle_attachement(client_context, message)

                # otherwise its a general error
                else:
                    YLogger.error(client_context, "Facebook general error handling message")
                    response_text = "Sorry, I do not understand you!"

                YLogger.debug(client_context, "Facebook message response: [%s]", response_text)
                self.render_response(client_context, response_text)

        except Exception as e:
            YLogger.exception(None, "Error handling facebook message", e)
Exemple #8
0
    def equals(self, client_context, words, word_no):
        word = words.word(word_no)

        if self.userid != '*':
            if self.userid != client_context.userid:
                return EqualsMatch(False, word_no)

        if self._pattern_template is not None:
            template = client_context.brain.regex_templates[self._pattern_template]
            if template is not None:
                result = template.match(word)
                if result is not None:
                    YLogger.debug(client_context, "Match word [%s] regex", word)
                    return EqualsMatch(True, word_no, word)
                else:
                    YLogger.error(client_context, "No word [%s] matched regex", word)
                    return EqualsMatch(False, word_no)
            else:
                return EqualsMatch(False, word_no)
        else:
            result = self.pattern.match(word)
            if result is not None:
                YLogger.debug(client_context, "Match word [%s] regex", word)
                return EqualsMatch(True, word_no, word)
            else:
                YLogger.error(client_context, "No word [%s] matched regex", word)
                return EqualsMatch(False, word_no)
Exemple #9
0
 def parse_oob_xml(self, oob: ET.Element):
     if oob is not None and oob.text is not None:
         self._url = oob.text
         return True
     else:
         YLogger.error(self, "Unvalid url oob command - missing url!")
         return False
Exemple #10
0
 def parse_oob_xml(self, oob):
     if oob is not None and oob.text is not None:
         self._command = oob.text
         return True
     else:
         YLogger.error(self, "Unvalid clear oob command - missing command")
         return False
Exemple #11
0
    def get_property_value(client_context, local, name):

        if local is True:

            value = None
            #TODO Why would you need this test, when is get_conversation(clientid) == None ?
            if client_context.bot.get_conversation(client_context) is not None:
                if client_context.bot.get_conversation(client_context).has_current_question():
                    value = client_context.bot.get_conversation(client_context).current_question().property(name)

        else:

            if name is not None and client_context.brain.dynamics.is_dynamic_var(name) is True:
                value = client_context.brain.dynamics.dynamic_var(client_context, name)
            else:
                value = client_context.bot.get_conversation(client_context).property(name)
                #if value is None:
                #    value = bot.brain.properties.property(name)

        if value is None:
            YLogger.error(client_context, "No property for [%s]", name)

            value = TemplateGetNode.get_default_value(client_context.bot)

        return value
Exemple #12
0
 def load_license_key_file(self, license_key_filename):
     try:
         YLogger.info(self, "Loading license key file: [%s]", license_key_filename)
         with open(license_key_filename, "r", encoding="utf-8") as license_file:
             for line in license_file:
                 self._process_license_key_line(line)
     except Exception:
         YLogger.error(self, "Invalid license key file [%s]", license_key_filename)
Exemple #13
0
 def load_config_section(self, configuration_file, configuration, bot_root):
     dynamic_config = configuration_file.get_section("dynamic", configuration)
     if dynamic_config is not None:
         self.load_dynamic_sets(configuration_file, dynamic_config)
         self.load_dynamic_maps(configuration_file, dynamic_config)
         self.load_dynamic_vars(configuration_file, dynamic_config)
     else:
         YLogger.error(self, "Config section [dynamic] missing from Brain, using defaults")
Exemple #14
0
    def get_headlines(self, source, max_articles=0, sort=False, reverse=False):

        if source in self.function_mapping:
            function = self.function_mapping[source]
            return function(self.api_key, max_articles, sort, reverse)
        else:
            YLogger.error(self, "No source available for %s", source)
            return []
Exemple #15
0
    def scheduled_event(name, userid, clientid, action, text):
        YLogger.debug(None, "Received Scheduled Event [%s] [%s] [%s] [%s] [%s]", name, userid, clientid, action, text)

        if name in ProgramyScheduler.schedulers:
            scheduler = ProgramyScheduler.schedulers[name]
            scheduler.scheduled(userid, clientid, action, text)
        else:
            YLogger.error(None, "Unknown scheduler [%s]", name)
Exemple #16
0
    def execute(self, context, data):

        source, max_num, sort, reverse = self.parse_data(context, data)

        if source is None:
            YLogger.error(context, "NewsAPIExtension no source passed in as data parameter!")
            return ""

        return self.get_news(context, source, max_num, sort, reverse)
Exemple #17
0
 def map_value(self, client_context, input_value):
     try:
         int_value = int(input_value)
         str_value = str(int_value + 1)
         YLogger.debug(client_context, "SuccessorMap converted %s to %s", input_value, str_value)
         return str_value
     except Exception:
         YLogger.error(client_context, "SuccessorMap could not convert %s to integer string", input_value)
         return ""
Exemple #18
0
    def unknown(self, telegram_bot, update):
        try:
            unknown_response = self.get_unknown_command(update.message.chat_id)
            if unknown_response:
                telegram_bot.send_message(chat_id=update.message.chat_id, text=unknown_response)
                YLogger.error(self, "No response to return in unknown()")

        except Exception as e:
            YLogger.exception(self, "Failed to handle unknown", e)
Exemple #19
0
 def resolve_to_string(self, client_context):
     sentence = client_context.bot.get_conversation(client_context).current_question().current_sentence()
     star = sentence.matched_context.star(1)
     if star is not None:
         resolved = client_context.bot.ask_question(client_context, star, srai=True)
     else:
         YLogger.error(client_context, "Sr node has no stars available")
         resolved = ""
     YLogger.debug(client_context, "[%s] resolved to [%s]", self.to_string(), resolved)
     return resolved
Exemple #20
0
 def load_file_contents(self, id, filename, userid="*"):
     YLogger.debug(self, "Loading map [%s]", filename)
     the_map = {}
     try:
         with open(filename, 'r', encoding='utf8') as my_file:
             for line in my_file:
                 self.process_line(line, the_map)
     except Exception as excep:
         YLogger.error(self, "Failed to load map [%s] - %s", filename, excep)
     return the_map
Exemple #21
0
    def start(self, telegram_bot, update):
        try:
            initial_question = self.get_initial_question(update)
            if initial_question:
                telegram_bot.send_message(chat_id=update.message.chat_id, text=initial_question)
            else:
                YLogger.error(self, "Not initial question to return in start()")

        except Exception as e:
            YLogger.exception(self, "Failed to start", e)
Exemple #22
0
    def listener_event(event):
        try:
            message = ProgramyScheduler.get_event_str(event)
            if message is not None:
                YLogger.debug(None, message)
            else:
                YLogger.error(None, "Unknown APSchedulerEvent! %s", str(event))

        except Exception as e:
            YLogger.exception(None, "APScheduler Listener Error", e)
Exemple #23
0
    def message(self, telegram_bot, update):
        try:
            response = self.ask_question(update.message.chat_id, update.message.text)
            if response:
                telegram_bot.send_message(chat_id=update.message.chat_id, text=response)
            else:
                YLogger.error(self, "Not response to return in message()")

        except Exception as e:
            YLogger.exception(self, "Failed to handle message", e)
    def test_check_log_not_output(self):
        logging.getLogger().setLevel(level=logging.NOTSET)
        YLogger.set_default_level()

        YLogger.critical(None, "Critical Log")
        YLogger.fatal(None, "Fatal Log")
        YLogger.error(None, "Error Log")
        YLogger.exception(None, "Exception Log", Exception("test"))
        YLogger.warning(None, "Warning Log")
        YLogger.info(None, "Info Log")
        YLogger.debug(None, "Debug Log")
Exemple #25
0
 def load_file_contents(self, id, filename, userid="*"):
     YLogger.debug(self, "Loading set [%s]", filename)
     the_set = {}
     try:
         with open(filename, 'r', encoding='utf8') as my_file:
             for line in my_file:
                 self.process_line(line, the_set)
     except Exception as excep:
         YLogger.error(self, "Failed to load set [%s] - %s", filename,
                       excep)
     return self.sort_sets(the_set)
Exemple #26
0
    def shutdown_ping_service(self):

        self.unregister_with_healthchecker()

        try:
            url = "http://%s:%d%s" % (self.config.host, self.config.port,
                                      self.config.shutdown)
            requests.get(url)

        except Exception:
            YLogger.error(None, "Failed to shutdown ping service")
Exemple #27
0
 def load_config_section(self, configuration_file, configuration, bot_root):
     dynamic_config = configuration_file.get_section(
         "dynamic", configuration)
     if dynamic_config is not None:
         self.load_dynamic_sets(configuration_file, dynamic_config)
         self.load_dynamic_maps(configuration_file, dynamic_config)
         self.load_dynamic_vars(configuration_file, dynamic_config)
     else:
         YLogger.error(
             self,
             "Config section [dynamic] missing from Brain, using defaults")
Exemple #28
0
    def get_default_value(bot):
        value = bot.brain.properties.property("default-get")
        if value is None:
            YLogger.error(None, "No property defined for default-get, checking defaults")

            value = bot.brain.configuration.defaults.default_get
            if value is None:
                YLogger.error(None, "No value defined for default default-get, returning 'unknown'")
                value = "unknown"

        return value
Exemple #29
0
 def load_services(self, client):
     YLogger.debug(self, "Loading services")
     self._client = client
     if client.storage_factory.entity_storage_engine_available(
             StorageFactory.SERVICES) is True:
         storage_engine = client.storage_factory.entity_storage_engine(
             StorageFactory.SERVICES)
         services_store = storage_engine.services_store()
         services_store.load_all(self)
     else:
         YLogger.error(None, "No storage engine available for services!")
Exemple #30
0
    def scheduled_event(name, userid, clientid, action, text):
        YLogger.debug(None,
                      "Received Scheduled Event [%s] [%s] [%s] [%s] [%s]",
                      name, userid, clientid, action, text)

        if name in ProgramyScheduler.schedulers:
            scheduler = ProgramyScheduler.schedulers[name]
            scheduler.scheduled(userid, clientid, action, text)

        else:
            YLogger.error(None, "Unknown scheduler [%s]", name)
Exemple #31
0
    def verify_fb_token(self, token_sent, request):
        # take token sent by facebook and verify it matches the verify token you sent
        # if they match, allow the request, else return an error
        if token_sent is None:
            YLogger.error(self, "Verify Token is None!")

        if token_sent == self._verify_token:
            return self.get_hub_challenge(request)

        YLogger.error(self, "Facebook verify token failed received [%s]", token_sent)
        return 'Invalid verification token'
Exemple #32
0
    def load_single_file_contents(self, filename):
        just_filename = self.get_just_filename_from_filepath(filename)

        collection = {}
        try:
            collection[just_filename] = self.load_file_contents(filename)
        except Exception as excep:
            YLogger.exception(self, excep)
            YLogger.error(self, "Failed to load file contents for file [%s]", filename)

        return collection
Exemple #33
0
    def load_from_filename(self, filename, id=None):
        count = 0
        try:
            with open(filename, "r", encoding="utf-8") as data_file:
                for line in data_file:
                    if self.process_line(line, id):
                        count += 1
        except FileNotFoundError:
            YLogger.error(self, "File not found [%s]", filename)

        return count
Exemple #34
0
 def split_line_by_pattern(self, line):
     line = line.strip()
     if line is not None and line:
         pattern = self.get_split_pattern()
         match = pattern.search(line)
         if match is not None:
             lhs = match.group(1)
             rhs = match.group(2)
             return [lhs, rhs]
         YLogger.error(self, "Pattern is bad [%s]", line)
     return None
Exemple #35
0
    def load_from_filename(self, filename):
        count = 0
        try:
            with open(filename, "r", encoding="utf-8") as data_file:
                for line in data_file:
                    if self.process_line(line):
                        count += 1
        except FileNotFoundError:
            YLogger.error(self, "File not found [%s]", filename)

        return count
Exemple #36
0
 def load_file_contents(self, filename):
     YLogger.debug(self, "Loading map [%s]", filename)
     the_map = {}
     try:
         with open(filename, 'r', encoding='utf8') as my_file:
             for line in my_file:
                 self.process_line(line, the_map)
     except Exception as excep:
         YLogger.error(self, "Failed to load map [%s] - %s", filename,
                       excep)
     return the_map
Exemple #37
0
 def split_line_by_pattern(self, line):
     line = line.strip()
     if line is not None and line:
         pattern = self.get_split_pattern()
         match = pattern.search(line)
         if match is not None:
             lhs = match.group(1)
             rhs = match.group(2)
             return [lhs, rhs]
         YLogger.error(self, "Pattern is bad [%s]", line)
     return None
Exemple #38
0
    def test_ylogger_error(self):
        client_context = ClientContext(TestClient(), "testid")
        YLogger.reset_snapshot()

        YLogger.error(client_context, "Test Message")
        snapshot = YLogger.snapshot()
        self.assertIsNotNone(snapshot)
        self.assertEqual(
            str(snapshot),
            "Critical(0) Fatal(0) Error(1) Exception(0) Warning(0) Info(0), Debug(0)"
        )
Exemple #39
0
    def verify_fb_token(self, token_sent, request):
        # take token sent by facebook and verify it matches the verify token you sent
        # if they match, allow the request, else return an error
        if token_sent is None:
            YLogger.error(self, "Verify Token is None!")

        if token_sent == self._verify_token:
            return self.get_hub_challenge(request)

        YLogger.error(self, "Facebook verify token failed received [%s]", token_sent)
        return 'Invalid verification token'
Exemple #40
0
    def execute(self, context, data):

        source, max_num, sort, reverse = self.parse_data(context, data)

        if source is None:
            YLogger.error(
                context,
                "NewsAPIExtension no source passed in as data parameter!")
            return ""

        return self.get_news(context, source, max_num, sort, reverse)
Exemple #41
0
    def scheduled(self, userid, clientid, action, text):
        YLogger.debug(None, "Processing Scheduled Event [%s] [%s] [%s] [%s] [%s]", self.name, userid, clientid, action, text)

        client_context = self._client.create_client_context(userid)
        if action == 'TEXT':
            self._client.render_response(client_context, text)
        elif action == 'SRAI':
            response = client_context.bot.ask_question(client_context, text)
            self._client.render_response(client_context, response)
        else:
            YLogger.error(client_context, "Unknown scheduler command [%s]", action)
Exemple #42
0
    def get_time(self, rest_request):
        time_param = self.get_parameter(rest_request, 'time')
        if time_param != 'None':
            try:
                iso8601.parse_date(time_param)
            except Exception:
                errMsg = "<time> datetime parser error: [%s]" % time_param
                YLogger.error(self, errMsg)
                self.server_abort(400, errMsg)

        return time_param
Exemple #43
0
 def save_conversation(self, clientid):
     if self._conversation_storage is not None:
         if clientid in self._conversations:
             conversation = self._conversations[clientid]
             self._conversation_storage.save_conversation(
                 conversation, clientid)
         else:
             YLogger.error(
                 self,
                 "Unknown conversation id type [%s] unable tonot persist!",
                 clientid)
Exemple #44
0
    def resolve_to_string(self, client_context):
        resolved = self.resolve_children_to_string(client_context)
        YLogger.debug(client_context, "[%s] resolved to [%s]", self.to_string(), resolved)

        if self._service is not None:
            bot_service = ServiceFactory.get_service(self._service)
            response = bot_service.ask_question(client_context, resolved)
            YLogger.debug(client_context, "SRAIX service [%s] return [%s]", self._service, response)
            return response
        else:
            YLogger.error(client_context, "Sorry SRAIX does not currently have an implementation for [%s]", self._service)
            return ""
Exemple #45
0
 def load_config_section(self,
                         configuration_file,
                         configuration,
                         bot_root,
                         subs: Substitutions = None):
     storage = configuration_file.get_section(self._section_name,
                                              configuration)
     if storage is not None:
         self._conversation_logger = configuration_file.get_option(
             storage, "conversation_logger", subs=subs)
     else:
         YLogger.error(None, "'config' section missing from storage config")
Exemple #46
0
 def load_config_section(self, configuration_file, configuration, bot_root, subs: Substitutions = None):
     storage = configuration_file.get_section(self._section_name, configuration)
     if storage is not None:
         self._host = configuration_file.get_option(storage, "host")
         self._port = configuration_file.get_option(storage, "port")
         self._password = configuration_file.get_option(storage, "password")
         self._db = configuration_file.get_option(storage, "db")
         self._prefix = configuration_file.get_option(storage, "prefix")
         self._drop_all_first = configuration_file.get_option(storage, "drop_all_first")
         self._expiretime = configuration_file.get_option(storage, "expiretime")
     else:
         YLogger.error(None, "'config' section missing from storage config")
Exemple #47
0
    def equals(self, client_context, words, word_no):
        word = words.word(word_no)
        if word is not None:
            word = word.upper()
            for set_word in self._words:
                if word == set_word:
                    YLogger.debug(client_context, "Found word [%s] in iset",
                                  word)
                    return EqualsMatch(True, word_no, word)

        YLogger.error(client_context, "No word [%s] found in iset", word)
        return EqualsMatch(False, word_no)
Exemple #48
0
    def resolve_to_string(self, client_context):
        resolved = self.resolve_children_to_string(client_context)
        YLogger.debug(client_context, "[%s] resolved to [%s]", self.to_string(), resolved)

        if self._service is not None:
            bot_service = ServiceFactory.get_service(self._service)
            response = bot_service.ask_question(client_context, resolved)
            YLogger.debug(client_context, "SRAIX service [%s] return [%s]", self._service, response)
            return response
        else:
            YLogger.error(client_context, "Sorry SRAIX does not currently have an implementation for [%s]", self._service)
            return ""
Exemple #49
0
    def check_api_key(self, request):
        if self.configuration.client_configuration.use_api_keys is True:
            api_key = self.api_keys.get_api_key(request)
            if api_key is None:
                YLogger.error(self, "Unauthorised access - api required but missing")
                return self.unauthorised_access_response()

            if self.api_keys.is_apikey_valid(api_key) is False:
                YLogger.error(self, "'Unauthorised access - invalid api key")
                return self.unauthorised_access_response()

        return None
Exemple #50
0
    def start(self, telegram_bot, update):
        try:
            initial_question = self.get_initial_question(update)
            if initial_question:
                telegram_bot.send_message(chat_id=update.message.chat_id,
                                          text=initial_question)
            else:
                YLogger.error(self,
                              "Not initial question to return in start()")

        except Exception as e:
            YLogger.exception(self, "Failed to start", e)
Exemple #51
0
    def message(self, telegram_bot, update):
        try:
            response = self.ask_question(update.message.chat_id,
                                         update.message.text)
            if response:
                telegram_bot.send_message(chat_id=update.message.chat_id,
                                          text=response)
            else:
                YLogger.error(self, "Not response to return in message()")

        except Exception as e:
            YLogger.exception(self, "Failed to handle message", e)
Exemple #52
0
    def load_trigger_manager(config: TriggerConfiguration):
        if config.manager is not None:
            try:
                return ClassLoader.instantiate_class(config.manager)(config)
            except Exception as e:
                YLogger.exception(None, "Failed to load trigger manager [%s]",
                                  e, config.manager)

        else:
            YLogger.error(None, "No Trigger Manager defined in configuration")

        return None
Exemple #53
0
    def check_api_key(self, request):
        if self.configuration.client_configuration.use_api_keys is True:
            api_key = self.get_api_key(request)
            if api_key is None:
                YLogger.error(self, "Unauthorised access - api required but missing")
                return self.unauthorised_access_response()

            if self.is_apikey_valid(api_key) is False:
                YLogger.error(self, "'Unauthorised access - invalid api key")
                return self.unauthorised_access_response()

        return None
Exemple #54
0
    def __init__(self, argument_parser=None):
        self._viber_bot = None
        self._viber_token = None
        FlaskRestBotClient.__init__(self, "viber", argument_parser)

        YLogger.debug(self, "Viber Client is running....")

        if self._viber_token is not None:
            self._viber_bot = self.create_viber_bot(self._viber_token)

        else:
            YLogger.error(self, "Viber token missing, unable to create client")
Exemple #55
0
    def load_oob_processors(self, storage_factory):
        if storage_factory.entity_storage_engine_available(
                StorageFactory.OOBS) is True:
            storage_engine = storage_factory.entity_storage_engine(
                StorageFactory.OOBS)
            oobs_store = storage_engine.oobs_store()
            oobs_store.load(self)
        else:
            YLogger.error(None, "No storage engine available for oobs!")

        if self._oobs.get('default', None) is None:
            self._oobs['default'] = DefaultOutOfBandProcessor()
Exemple #56
0
    def authenticate(self, client_context):
        try:
            if client_context.userid in self.authorised:
                return True
            else:
                if self._auth_clientid(client_context) is True:
                    return True

                return False
        except Exception as excep:
            YLogger.error(client_context, str(excep))
            return False
Exemple #57
0
    def _load_file_contents(self, collection, filename):
        YLogger.debug(self, "Loading nodes from file [%s]", filename)
        count = 0
        try:
            with open(filename, "r", encoding="utf-8") as file:
                for line in file:
                    line = line.strip()
                    if line:
                        self.process_config_line(collection, line, filename)
        except FileNotFoundError:
            YLogger.error(self, "File not found [%s]", filename)

        return count
Exemple #58
0
 def map_value(self, client_context, input_value):
     try:
         int_value = int(input_value)
         str_value = str(int_value - 1)
         YLogger.debug(client_context, "PredecessorMap converted %s to %s",
                       input_value, str_value)
         return str_value
     except Exception:
         YLogger.error(
             client_context,
             "PredecessorMap could not convert %s to integer string",
             input_value)
         return ""
Exemple #59
0
    def load_substitutions(self, substitutions):
        if substitutions is not None:
            try:
                with open(substitutions, "r") as subsfile:
                    for line in subsfile:
                        namevalue = line.strip().split(":")

                        if len(namevalue) > 1:
                            self.add_substitute(namevalue[0],
                                                ":".join(namevalue[1:]))

            except Exception as e:
                YLogger.error(None, "Failed to load substitutions file")