Workspace¶
-
class
elasticgit.workspace.
EG
[source]¶ A helper function for things in ElasticGit.
-
classmethod
workspace
(workdir, es={}, index_prefix=None)[source]¶ Create a workspace
Parameters: - workdir (str) – The path to the directory where a git repository can
be found or needs to be created when
Workspace.setup()
is called. - es (dict) – The parameters to pass along to
elasticutils.get_es()
- index_prefix (str) – The index_prefix use when generating index names for Elasticsearch
Returns: - workdir (str) – The path to the directory where a git repository can
be found or needs to be created when
-
classmethod
-
class
elasticgit.workspace.
RemoteWorkspace
(url, es=None, index_prefix=None)[source]¶ A workspace that connects to a unicore.distribute server hosted somewhere on the network.
This is a read only version of the
Workspace
-
class
elasticgit.workspace.
Workspace
(repo, es, index_prefix)[source]¶ The main API exposing a model interface to both a Git repository and an Elasticsearch index.
Parameters: - repo (git.Repo) – A
git.Repo
instance. - es (dit) – A dictionary of values one would pass to elasticutils.get_es to get an Elasticsearch connection
- index_prefix (str) – The prefix to use when generating index names for Elasticsearch
-
S
(model_class)[source]¶ Get a
elasticutils.S
object for the given model class. Under the hood this dynamically generates aelasticutils.MappingType
andelasticutils.Indexable
subclass which maps the Elasticsearch results toelasticgit.models.Model
instances on the UUIDs.Parameters: model_class (elasticgit.models.Model) – The class to provide a search interface for.
-
delete
(model, message, author=None, committer=None)[source]¶ Delete a :py:class`elasticgit.models.Model` instance from Git and the Elasticsearch index.
Parameters: - model (elasticgit.models.Model) – The model instance
- message (str) – The commit message to remove the model from Git with.
- author (tuple) – The author information (name, email address) Defaults repo default if unspecified.
- committer (tuple) – The committer information (name, email address). Defaults to the author if unspecified.
-
destroy
()[source]¶ Removes an ES index and a Git repository completely. Guaranteed to remove things completely, use with caution.
-
exists
()[source]¶ Check if the Git repository or the ES index exists. Returns
True
if either of them exist.Returns: bool
-
get_mapping
(model_class)[source]¶ Get a mapping from Elasticsearch for a model_class :param elasticgit.models.Model model_class: :returns: dict
-
pull
(branch_name='master', remote_name='origin')[source]¶ Fetch & Merge in an upstream’s commits.
Parameters:
-
refresh_index
()[source]¶ Manually refresh the Elasticsearch index. In production this is not necessary but it is useful when running tests.
-
reindex
(model_class, refresh_index=True)[source]¶ Same as
reindex_iter()
but returns a list instead of a generator.
-
reindex_iter
(model_class, refresh_index=True)[source]¶ Reindex everything that Git knows about in an iterator
Parameters: - model_class (elasticgit.models.Model) –
- refresh_index (bool) – Whether or not to refresh the index after everything has
been indexed. Defaults to
True
-
save
(model, message, author=None, committer=None)[source]¶ Save a
elasticgit.models.Model
instance in Git and add it to the Elasticsearch index.Parameters: - model (elasticgit.models.Model) – The model instance
- message (str) – The commit message to write the model to Git with.
- author (tuple) – The author information (name, email address) Defaults repo default if unspecified.
- committer (tuple) – The committer information (name, email address). Defaults to the author if unspecified.
-
setup
(name, email)[source]¶ Setup a Git repository & ES index if they do not yet exist. This is safe to run if already existing.
Parameters:
-
setup_custom_mapping
(model_class, mapping)[source]¶ Add a custom mapping for a model class instead of accepting what the model_class defines.
Parameters: - model_class (elasticgit.models.Model) –
- dict – the Elastisearch mapping definition
Returns: dict, the decoded dictionary from Elasticsearch
-
setup_mapping
(model_class)[source]¶ Add a custom mapping for a model_class
Parameters: model_class (elasticgit.models.Model) – Returns: dict, the decoded dictionary from Elasticsearch
-
sync
(model_class, refresh_index=True)[source]¶ Resync a workspace, it assumes the Git repository is the source of truth and Elasticsearch is made to match. This involves two passes, first to index everything that Git knows about and unindexing everything that’s in Elastisearch that Git does not know about.
Parameters: - model_class (elasticgit.models.Model) – The model to resync
- refresh_index (bool) – Whether or not to refresh the index after indexing everything from Git
- repo (git.Repo) – A