def _instantiate_dogstreams(cls, logger, config, dogstreams_config): """ Expecting dogstreams config value to look like: <dogstream value>, <dog stream value>, ... Where <dogstream value> looks like: <log path> or <log path>:<module>:<parser function> """ dogstreams = [] # Create a Dogstream object for each <dogstream value> for config_item in dogstreams_config.split(','): try: config_item = config_item.strip() parts = windows_friendly_colon_split(config_item) if len(parts) == 2: logger.warn("Invalid dogstream: %s" % ':'.join(parts)) continue log_path = cls._get_dogstream_log_paths(parts[0]) if len(parts) else [] parser_spec = ':'.join(parts[1:3]) if len(parts) >= 3 else None parser_args = parts[3:] if len(parts) >= 3 else None for path in log_path: dogstreams.append(Dogstream.init( logger, log_path=path, parser_spec=parser_spec, parser_args=parser_args, config=config)) except Exception: logger.exception("Cannot build dogstream") return dogstreams
def load(config_string, default_name=None): split = windows_friendly_colon_split(config_string) if len(split) > 1: module_name, object_name = ":".join(split[:-1]), split[-1] else: module_name, object_name = config_string, default_name module = get_module(module_name) if object_name: return getattr(module, object_name) else: return module
def load(config_string, default_name=None): """Given a module name and an object expected to be contained within, return said object. """ split = windows_friendly_colon_split(config_string) if len(split)> 1: module_name, object_name = ":".join(split[:-1]), split[-1] else: module_name, object_name = config_string, default_name module = get_module(module_name) if object_name: return getattr(module, object_name) else: return module
def testWindowsSplit(self): # Make the function run as if it was on windows func = Platform.is_win32 try: Platform.is_win32 = staticmethod(lambda : True) test_cases = [ ("C:\\Documents\\Users\\script.py:C:\\Documents\\otherscript.py", ["C:\\Documents\\Users\\script.py","C:\\Documents\\otherscript.py"]), ("C:\\Documents\\Users\\script.py:parser.py", ["C:\\Documents\\Users\\script.py","parser.py"]) ] for test_case, expected_result in test_cases: self.assertEqual(windows_friendly_colon_split(test_case), expected_result) finally: # cleanup Platform.is_win32 = staticmethod(func)