Exemplo n.º 1
0
def get_service_service3_app_modules_shop_services_test3():
    module_instance = Importer.import_module("app.modules.shop.services.test3")
    instance = getattr(module_instance, "test3class")
    instance = instance(**{'some': 'object'})
    instance.testmethod('test param', 'test param2')
    instance.testmethod('test param3', 'test param4')
    instance.set_alchemy(get_service_sqlalchemy_sqlalchemy())
    return instance
Exemplo n.º 2
0
 def get_service_instance(cls, name):
     service_info = get_config('services', dict()).get(name)
     service_getter = 'get_service_' + name.replace(
         '.', '_') + '_' + service_info.get('module').replace('.', '_')
     service_module = Importer.import_module(
         os.environ.get('APPLICATION_NAME') + '.cache.bootstrap')
     service = getattr(service_module, service_getter)
     return service
Exemplo n.º 3
0
def get_service_cool_service_app_modules_shop_services_test():
    module_instance = Importer.import_module("app.modules.shop.services.test")
    instance = getattr(module_instance, "test")

    return instance(
        **{
            'name': "Dmitri Mes'hin",
            'value':
            get_service_another_service_app_modules_shop_services_test2()
        })
Exemplo n.º 4
0
    def get_import_file_path(cls, import_file_path, base_dir=''):
        import_file_path_regexp = re.compile('^(@[a-zA-Z0-9._]+:)', re.IGNORECASE)
        import_file_module_list = import_file_path_regexp.findall(import_file_path)

        if len(import_file_module_list):
            import_file_module = import_file_module_list[0]
            import_file_path = import_file_path.replace(import_file_module, '')
            import_file_module = import_file_module.replace('@', '').replace(':', '')
            import_file_module = Importer.import_module(import_file_module)
            import_file_path = os.path.dirname(import_file_module.__file__).rstrip(os.sep) + os.sep + import_file_path.strip(os.sep)
        else:
            import_file_path = (base_dir + os.sep if base_dir else '') + (import_file_path.strip(os.sep) if base_dir else import_file_path.rstrip(os.sep))
        return import_file_path
Exemplo n.º 5
0
    def get_import_file_path(cls, import_file_path, base_dir=''):
        import_file_path_regexp = re.compile('^(@[a-zA-Z0-9._]+:)',
                                             re.IGNORECASE)
        import_file_module_list = import_file_path_regexp.findall(
            import_file_path)

        if len(import_file_module_list):
            import_file_module = import_file_module_list[0]
            import_file_path = import_file_path.replace(import_file_module, '')
            import_file_module = import_file_module.replace('@', '').replace(
                ':', '')
            import_file_module = Importer.import_module(import_file_module)
            import_file_path = os.path.dirname(
                import_file_module.__file__).rstrip(
                    os.sep) + os.sep + import_file_path.strip(os.sep)
        else:
            import_file_path = (base_dir + os.sep if base_dir else '') + (
                import_file_path.strip(os.sep)
                if base_dir else import_file_path.rstrip(os.sep))
        return import_file_path
Exemplo n.º 6
0
def get_service_sqlalchemy_sqlalchemy():
    module_instance = Importer.import_module("sqlalchemy")
    instance = getattr(module_instance, "create_engine")

    return instance
Exemplo n.º 7
0
def get_service_another_service_app_modules_shop_services_test2():
    module_instance = Importer.import_module("app.modules.shop.services.test2")
    instance = getattr(module_instance, "test2")

    return instance(get_config("locale"),
                    get_service_service3_app_modules_shop_services_test3())
Exemplo n.º 8
0
    def compile(cls, config, output_file_path):
        output_file = open(output_file_path, 'wb')

        output_file.write('# _*_ coding: utf-8 _*_\n')
        output_file.write("# DDN'T CHANGE THIS FILE!\n")
        output_file.write('from __future__ import unicode_literals\n')
        output_file.write('from entrodec.component.di.importer import Importer\n')
        output_file.write('from entrodec.component.config import get_config\n\n')

        for service_name, service_config in config.get('services', dict()).iteritems():
            module_path = service_config.get('module')
            module_object = service_config.get('class')
            module_arguments = service_config.get('arguments')
            class_calls = service_config.get('calls', [])
            allow_constructor = service_config.get('constructor', True)
            is_variable = False
            is_class = True
            is_function = False

            if not module_object:
                module_object = service_config.get('function')
                is_function = True
                is_class = False
                is_variable = False

            if not module_object:
                module_object = service_config.get('variable')
                is_variable = True
                is_function = False
                is_class = False

            class_calls_string = []
            if is_class and class_calls:
                for class_call in class_calls:
                    class_call_method = class_call[0]
                    class_call_params = class_call[1:]
                    class_calls_string.append('    instance.%s(%s)' % (class_call_method, cls.get_module_arguments_string(config=config, module_arguments=class_call_params)))

            class_calls_string = '\n'.join(class_calls_string)

            if module_path and module_object:
                module_instance = Importer.import_module(module_path)
                instance = getattr(module_instance, module_object)

                if not instance:
                    raise Exception('Can not instantiate service: `%s`. Expected function or class.' % (service_name))

                module_arguments_string = cls.get_module_arguments_string(config=config, module_arguments=module_arguments)

                return_instance = '    return instance'
                if is_function:
                    if allow_constructor:
                        return_instance = '    return instance(%s)' % (module_arguments_string if len(module_arguments_string) else '')
                    else:
                        return_instance = '    return instance'
                elif is_class:
                    class_calls_string = '    instance = instance(%s)\n' % (module_arguments_string if len(module_arguments_string) else '') + class_calls_string

                service_getter = [
                    '\ndef get_service_%s_%s():' % (service_name.replace('.', '_'), module_path.replace('.', '_')),
                    '    module_instance = Importer.import_module("%s")' % (module_path),
                    '    instance = getattr(module_instance, "%s")' % (module_object),
                    class_calls_string,
                     return_instance,
                    '\n'
                ]

                output_file.write('\n'.join(service_getter))

        output_file.flush()
        output_file.close()
Exemplo n.º 9
0
    def compile(cls, config, output_file_path):
        output_file = open(output_file_path, 'wb')

        output_file.write('# _*_ coding: utf-8 _*_\n')
        output_file.write("# DDN'T CHANGE THIS FILE!\n")
        output_file.write('from __future__ import unicode_literals\n')
        output_file.write(
            'from entrodec.component.di.importer import Importer\n')
        output_file.write(
            'from entrodec.component.config import get_config\n\n')

        for service_name, service_config in config.get('services',
                                                       dict()).iteritems():
            module_path = service_config.get('module')
            module_object = service_config.get('class')
            module_arguments = service_config.get('arguments')
            class_calls = service_config.get('calls', [])
            allow_constructor = service_config.get('constructor', True)
            is_variable = False
            is_class = True
            is_function = False

            if not module_object:
                module_object = service_config.get('function')
                is_function = True
                is_class = False
                is_variable = False

            if not module_object:
                module_object = service_config.get('variable')
                is_variable = True
                is_function = False
                is_class = False

            class_calls_string = []
            if is_class and class_calls:
                for class_call in class_calls:
                    class_call_method = class_call[0]
                    class_call_params = class_call[1:]
                    class_calls_string.append(
                        '    instance.%s(%s)' %
                        (class_call_method,
                         cls.get_module_arguments_string(
                             config=config,
                             module_arguments=class_call_params)))

            class_calls_string = '\n'.join(class_calls_string)

            if module_path and module_object:
                module_instance = Importer.import_module(module_path)
                instance = getattr(module_instance, module_object)

                if not instance:
                    raise Exception(
                        'Can not instantiate service: `%s`. Expected function or class.'
                        % (service_name))

                module_arguments_string = cls.get_module_arguments_string(
                    config=config, module_arguments=module_arguments)

                return_instance = '    return instance'
                if is_function:
                    if allow_constructor:
                        return_instance = '    return instance(%s)' % (
                            module_arguments_string
                            if len(module_arguments_string) else '')
                    else:
                        return_instance = '    return instance'
                elif is_class:
                    class_calls_string = '    instance = instance(%s)\n' % (
                        module_arguments_string if len(module_arguments_string)
                        else '') + class_calls_string

                service_getter = [
                    '\ndef get_service_%s_%s():' % (service_name.replace(
                        '.', '_'), module_path.replace('.', '_')),
                    '    module_instance = Importer.import_module("%s")' %
                    (module_path),
                    '    instance = getattr(module_instance, "%s")' %
                    (module_object), class_calls_string, return_instance, '\n'
                ]

                output_file.write('\n'.join(service_getter))

        output_file.flush()
        output_file.close()