Ejemplo n.º 1
0
    def mk_workspace(self, working_dir=None,
                     name=None,
                     url='http://localhost',
                     index_prefix=None,
                     auto_destroy=None,
                     author_name='Test Kees',
                     author_email='*****@*****.**'):  # pragma: no cover
        name = name or self.id().lower()
        working_dir = working_dir or self.working_dir
        index_prefix = index_prefix or name
        auto_destroy = auto_destroy or self.destroy
        workspace = EG.workspace(os.path.join(working_dir, name), es={
            'urls': [url],
        }, index_prefix=index_prefix)
        if auto_destroy:
            self.addCleanup(workspace.destroy)

        workspace.setup(author_name, author_email)
        workspace
        while not workspace.index_ready():
            pass

        with open(self.bootstrap_file, 'r') as fp:
            bootstrap_data = yaml.safe_load(fp)
            for model, mapping in bootstrap_data['models'].items():
                workspace.setup_custom_mapping(load_class(model), mapping)

        return workspace
Ejemplo n.º 2
0
 def run(self, config, verbose, clobber, repo_dir, repo_name):
     config_file, config_data = config
     for model_name, mapping in config_data.get('models', {}).items():
         model_class = load_class(model_name)
         self.sync_data(os.path.join(repo_dir, repo_name), model_class,
                        verbose=verbose,
                        clobber=clobber)
Ejemplo n.º 3
0
def load_models(models):
    models_module = load_class(models)
    models = dict([
        (name, value)
        for name, value in models_module.__dict__.items()
        if inspect.isclass(value) and issubclass(value, Model)
    ])
    return models
Ejemplo n.º 4
0
 def run(self, config, verbose, clobber, repo_dir, repo_name):
     config_file, config_data = config
     for model_name, mapping in config_data.get('models', {}).items():
         model_class = load_class(model_name)
         self.sync_data(os.path.join(repo_dir, repo_name),
                        model_class,
                        verbose=verbose,
                        clobber=clobber)
Ejemplo n.º 5
0
 def bootstrap(self, workdir, models=(), clobber=False, verbose=False):
     index_created = self.create_index(workdir,
                                       clobber=clobber,
                                       verbose=verbose)
     for model_name, mapping in models:
         model_class = load_class(model_name)
         if index_created:
             self.create_mapping(workdir, model_class, mapping,
                                 verbose=verbose)
         self.sync_data(workdir, model_class,
                        verbose=verbose, clobber=clobber)
Ejemplo n.º 6
0
    def path_info(self, file_path):
        """
        Analyze a file path and return the object's class and the uuid.

        :param str file_path:
            The path of the object we want a model instance for.
        :returns:
            (model_class, uuid) tuple or ``None`` if not a model file path.
        """
        try:
            module_name, class_name, file_name = file_path.split('/', 3)
            uuid, suffix = file_name.split('.', 2)
            model_class = load_class('%s.%s' % (module_name, class_name))
            if not issubclass(model_class, Model):
                raise RemoteStorageException('%r does not subclass %r' % (
                    model_class, Model))
            return model_class, uuid
        except ValueError, e:
            log.warn('%s does not look like a model file path.' % (
                file_path,), exc_info=True)
Ejemplo n.º 7
0
    def path_info(self, file_path):
        """
        Analyze a file path and return the object's class and the uuid.

        :param str file_path:
            The path of the object we want a model instance for.
        :returns:
            (model_class, uuid) tuple or ``None`` if not a model file path.
        """
        try:
            module_name, class_name, file_name = file_path.split('/', 3)
            uuid, suffix = file_name.split('.', 2)
            model_class = load_class('%s.%s' % (module_name, class_name))
            if not issubclass(model_class, Model):
                raise StorageException('%r does not subclass %r' %
                                       (model_class, Model))
            return model_class, uuid
        except ValueError, e:
            log.warn('%s does not look like a model file path.' %
                     (file_path, ),
                     exc_info=True)
Ejemplo n.º 8
0
def load_models(models):
    models_module = load_class(models)
    models = dict([(name, value)
                   for name, value in models_module.__dict__.items()
                   if inspect.isclass(value) and issubclass(value, Model)])
    return models
Ejemplo n.º 9
0
 def __call__(self, fqcn):
     model_class = load_class(fqcn)
     if not issubclass(model_class, self.class_type):
         raise ToolCommandError('%s does not subclass %s' %
                                (model_class, self.class_type))
     return model_class
Ejemplo n.º 10
0
 def __init__(self, mapping):
     key, _, class_name = mapping.partition('=')
     self.key = key
     self.field_class = load_class(class_name)
Ejemplo n.º 11
0
 def __call__(self, fqcn):
     model_class = load_class(fqcn)
     if not issubclass(model_class, self.class_type):
         raise ToolCommandError('%s does not subclass %s' % (
             model_class, self.class_type))
     return model_class