Esempio n. 1
0
def cls_to_pypath(cls):
    """when a class is defined within the module that is being executed as
    main, the module name will be specified as '__main__' even though the
    module actually had its own real name.  This ends up being very confusing
    to Configman as it tries to refer to a class by its proper module name.
    This function will convert a class into its properly qualified actual
    pathname."""
    if cls.__module__ == '__main__':
        module_path = (
            sys.modules['__main__']
            .__file__[:-3]
        )
        module_name = ''
        for a_python_path in sys.path:
            tentative_pathname = module_path.replace(a_python_path, '')
            if tentative_pathname != module_path:
                module_name = (
                    tentative_pathname.replace('/', '.').strip('.')
                )
                break
        if module_name == '':
            return py_obj_to_str(cls)
    else:
        module_name = cls.__module__
    return "%s.%s" % (module_name, cls.__name__)
Esempio n. 2
0
def klass_to_pypath(klass):
    """when a class is defined within the module that is being executed as
    main, the module name will be specified as '__main__' even though the
    module actually had its own real name.  This ends up being very confusing
    to Configman as it tries to refer to a class by its proper module name.
    This function will convert a class into its properly qualified actual
    pathname.  This method is used when a Socorro app is actually invoked
    directly through the file in which the App class is defined.  This allows
    configman to reimport the class under its proper name and treat it as if
    it had been run through the SocorroWelcomeApp.  In turn, this allows
    the application defaults to be fetched from the properly imported class
    in time for configman use that information as value source."""
    if klass.__module__ == '__main__':
        module_path = (
            sys.modules['__main__']
            .__file__[:-3]
        )
        module_name = ''
        for a_python_path in sys.path:
            tentative_pathname = module_path.replace(a_python_path, '')
            if tentative_pathname != module_path:
                module_name = (
                    tentative_pathname.replace('/', '.').strip('.')
                )
                break
        if module_name == '':
            return py_obj_to_str(klass)
    else:
        module_name = klass.__module__
    return "%s.%s" % (module_name, klass.__name__)
def klass_to_pypath(klass):
    """when a class is defined within the module that is being executed as
    main, the module name will be specified as '__main__' even though the
    module actually had its own real name.  This ends up being very confusing
    to Configman as it tries to refer to a class by its proper module name.
    This function will convert a class into its properly qualified actual
    pathname.  This method is used when a Socorro app is actually invoked
    directly through the file in which the App class is defined.  This allows
    configman to reimport the class under its proper name and treat it as if
    it had been run through the SocorroWelcomeApp.  In turn, this allows
    the application defaults to be fetched from the properly imported class
    in time for configman use that information as value source."""
    if klass.__module__ == '__main__':
        module_path = (sys.modules['__main__'].__file__[:-3])
        module_name = ''
        for a_python_path in sys.path:
            tentative_pathname = module_path.replace(a_python_path, '')
            if tentative_pathname != module_path:
                module_name = (tentative_pathname.replace('/', '.').strip('.'))
                break
        if module_name == '':
            return py_obj_to_str(klass)
    else:
        module_name = klass.__module__
    return "%s.%s" % (module_name, klass.__name__)
Esempio n. 4
0
    def __init__(self, config, quit_check_callback=None):
        super(BotoS3CrashStorage, self).__init__(config, quit_check_callback)

        self._bucket_name = config.bucket_name

        self.transaction = config.transaction_executor_class(
            config, self, quit_check_callback  # we are our own connection
        )
        if config.transaction_executor_class_for_get.is_infinite:
            self.config.logger.error(
                "the class %s identifies itself as an infinite iterator. "
                "As a TransactionExecutor for reads from Boto, this may "
                "result in infinite loops that will consume threads forever."
                % py_obj_to_str(config.transaction_executor_class_for_get)
            )

        self.transaction_for_get = config.transaction_executor_class_for_get(
            config, self, quit_check_callback  # we are our own connection
        )

        # short cuts to external resources - makes testing/mocking easier
        self._connect_to_endpoint = boto.connect_s3
        self._calling_format = config.calling_format
        self._CreateError = boto.exception.S3CreateError
        self._S3ResponseError = boto.exception.S3ResponseError
        self._open = open
Esempio n. 5
0
    def __init__(self, config, quit_check_callback=None):
        super(BotoCrashStorage, self).__init__(
            config,
            quit_check_callback
        )

        self.connection_source = config.resource_class(config)
        self.transaction = config.transaction_executor_class(
            config,
            self.connection_source,
            quit_check_callback
        )
        if config.transaction_executor_class_for_get.is_infinite:
            self.config.logger.error(
                'the class %s identifies itself as an infinite iterator. '
                'As a TransactionExecutor for reads from Boto, this may '
                'result in infinite loops that will consume threads forever.'
                % py_obj_to_str(config.transaction_executor_class_for_get)
            )

        self.transaction_for_get = config.transaction_executor_class_for_get(
            config,
            self.connection_source,
            quit_check_callback
        )
Esempio n. 6
0
    def __init__(self, config, quit_check_callback=None):
        super(BotoCrashStorage, self).__init__(
            config,
            quit_check_callback
        )

        self.connection_source = config.resource_class(config)
        self.transaction = config.transaction_executor_class(
            config,
            self.connection_source,
            quit_check_callback
        )
        if config.transaction_executor_class_for_get.is_infinite:
            self.config.logger.error(
                'the class %s identifies itself as an infinite iterator. '
                'As a TransactionExecutor for reads from Boto, this may '
                'result in infinite loops that will consume threads forever.'
                % py_obj_to_str(config.transaction_executor_class_for_get)
            )

        self.transaction_for_get = config.transaction_executor_class_for_get(
            config,
            self.connection_source,
            quit_check_callback
        )
Esempio n. 7
0
    def __init__(self, config, quit_check_callback=None):
        super(BotoS3CrashStorage, self).__init__(config, quit_check_callback)

        self._bucket_name = config.bucket_name

        self.transaction = config.transaction_executor_class(
            config,
            self,  # we are our own connection
            quit_check_callback)
        if config.transaction_executor_class_for_get.is_infinite:
            self.config.logger.error(
                'the class %s identifies itself as an infinite iterator. '
                'As a TransactionExecutor for reads from Boto, this may '
                'result in infinite loops that will consume threads forever.' %
                py_obj_to_str(config.transaction_executor_class_for_get))

        self.transaction_for_get = config.transaction_executor_class_for_get(
            config,
            self,  # we are our own connection
            quit_check_callback)

        # short cuts to external resources - makes testing/mocking easier
        self._connect_to_endpoint = boto.connect_s3
        self._calling_format = config.calling_format
        self._CreateError = boto.exception.S3CreateError
        self._S3ResponseError = boto.exception.S3ResponseError
        self._open = open
Esempio n. 8
0
 def to_str(cls):
     """this method takes this inner class object and turns it back
     into the original string of classnames.  This is used
     primarily as for the output of the 'help' option"""
     return ', '.join(
         py_obj_to_str(v[name_of_class_option].value)
         for v in cls.get_required_config().values()
         if isinstance(v, Namespace))
Esempio n. 9
0
 def to_str(cls):
     """this method takes this inner class object and turns it back
     into the original string of classnames.  This is used
     primarily as for the output of the 'help' option"""
     return ', '.join(
         py_obj_to_str(v[name_of_class_option].value)
         for v in cls.get_required_config().values()
         if isinstance(v, Namespace)
     )
Esempio n. 10
0
 def test_classes_in_namespaces_converter_1(self):
     converter_fn = converters.classes_in_namespaces_converter("HH%d")
     class_list_str = "configman.tests.test_converters.Foo," "configman.tests.test_converters.Bar"
     result = converter_fn(class_list_str)
     self.assertTrue(hasattr(result, "required_config"))
     req = result.required_config
     self.assertEqual(len(req), 2)
     self.assertTrue("HH0" in req)
     self.assertEqual(len(req.HH0), 1)
     self.assertTrue("cls" in req.HH0)
     self.assertTrue("HH1" in req)
     self.assertEqual(len(req.HH1), 1)
     self.assertTrue("cls" in req.HH1)
     self.assertEqual(
         sorted([x.strip() for x in class_list_str.split(",")]),
         sorted([x.strip() for x in converters.py_obj_to_str(result).split(",")]),
     )
Esempio n. 11
0
 def test_classes_in_namespaces_converter_1(self):
     converter_fn = converters.classes_in_namespaces_converter('HH%d')
     class_list_str = ('configman.tests.test_converters.Foo,'
                       'configman.tests.test_converters.Bar')
     result = converter_fn(class_list_str)
     self.assertTrue(hasattr(result, 'required_config'))
     req = result.required_config
     self.assertEqual(len(req), 2)
     self.assertTrue('HH0' in req)
     self.assertEqual(len(req.HH0), 1)
     self.assertTrue('cls' in req.HH0)
     self.assertTrue('HH1' in req)
     self.assertEqual(len(req.HH1), 1)
     self.assertTrue('cls' in req.HH1)
     self.assertEqual(
             sorted([x.strip() for x in class_list_str.split(',')]),
             sorted([x.strip() for x in
                          converters.py_obj_to_str(result).split(',')]))
Esempio n. 12
0
 def test_classes_in_namespaces_converter_1(self):
     converter_fn = converters.classes_in_namespaces_converter('HH%d')
     class_list_str = ('configman.tests.test_converters.Foo,'
                       'configman.tests.test_converters.Bar')
     result = converter_fn(class_list_str)
     self.assertTrue(hasattr(result, 'required_config'))
     req = result.required_config
     self.assertEqual(len(req), 2)
     self.assertTrue('HH0' in req)
     self.assertEqual(len(req.HH0), 1)
     self.assertTrue('cls' in req.HH0)
     self.assertTrue('HH1' in req)
     self.assertEqual(len(req.HH1), 1)
     self.assertTrue('cls' in req.HH1)
     self.assertEqual(
             sorted([x.strip() for x in class_list_str.split(',')]),
             sorted([x.strip() for x in
                          converters.py_obj_to_str(result).split(',')]))
Esempio n. 13
0
 def __init__(self, config):
     print(self.__class__)
     self.class_as_string = conv.py_obj_to_str(self.__class__)
     log('starting %s' % self.class_as_string)
     self.config = config
     self.datasource = config.source.database_type(config)
Esempio n. 14
0
 def __init__(self, config):
     self.class_as_string = conv.py_obj_to_str(self.__class__)
     log('starting %s' % self.class_as_string)
     self.config = config
     self.data_sink = config.destination.database_type(config)
Esempio n. 15
0
 def __init__(self, config):
     print(self.__class__)
     self.class_as_string = conv.py_obj_to_str(self.__class__)
     log('starting %s' % self.class_as_string)
     self.config = config
     self.datasource = config.source.database_type(config)
Esempio n. 16
0
 def __init__(self, config):
     super(Database, self).__init__()
     self.config = config
     self.class_as_string = conv.py_obj_to_str(self.__class__)
     self.connection = (0, 0)
Esempio n. 17
0
 def __init__(self, config):
     super(HBase, self).__init__()
     self.class_as_string = conv.py_obj_to_str(self.__class__)
     self.config = config
     log('connecting to Fake HBase with %s' % self.class_as_string)
     self.connection = (100, 90, -1)
Esempio n. 18
0
 def __init__(self, config):
     super(HBase, self).__init__()
     self.class_as_string = conv.py_obj_to_str(self.__class__)
     self.config = config
     log('connecting to Fake HBase with %s' % self.class_as_string)
     self.connection = (100, 90, -1)
Esempio n. 19
0
 def __init__(self, config):
     super(Database, self).__init__()
     self.config = config
     self.class_as_string = conv.py_obj_to_str(self.__class__)
     self.connection = (0, 0)
Esempio n. 20
0
 def __init__(self, config):
     self.class_as_string = conv.py_obj_to_str(self.__class__)
     log('starting %s' % self.class_as_string)
     self.config = config
     self.data_sink = config.destination.database_type(config)