Storage Manager¶
-
class
elasticgit.storage.
StorageManager
(repo)[source]¶ An interface to
elasticgit.models.Model
instances stored in Git.Parameters: repo (git.Repo) – The repository to operate on. -
create_storage
(bare=False)[source]¶ Creates a new
git.Repo
Parameters: bare (bool) – Whether or not to create a bare repository. Defaults to False
.
-
delete
(model, message, author=None, committer=None)[source]¶ Delete a model instance from Git.
Parameters: - model (elasticgit.models.Model) – The model instance
- message (str) – The commit message.
- 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.
Returns: The commit.
-
delete_data
(repo_path, message, author=None, committer=None)[source]¶ Delete a file that’s not necessarily a model file.
Parameters: Returns: The commit
-
get
(model_class, uuid)[source]¶ Get a model instance by loading the data from git and constructing the model_class
Parameters: - model_class (elasticgit.models.Model) – The model class of which an instance to return
- uuid (str) – The uuid for the object to retrieve
Returns: :py:class:elasticgit.models.Model
-
get_data
(repo_path)[source]¶ Get the data for a file stored in git
Parameters: repo_path (str) – The path to the file in the Git repository Returns: str
-
git_name
(model)[source]¶ Return the file path to where the data for a
elasticgit.models.Model
lives.Parameters: model (elasticgit.models.Model) – The model instance Returns: str >>> from git import Repo >>> from elasticgit.tests.base import TestPerson >>> from elasticgit.storage import StorageManager >>> person = TestPerson({'age': 1, 'name': 'Foo', 'uuid': 'the-uuid'}) >>> sm = StorageManager(Repo('.')) >>> sm.git_name(person) 'elasticgit.tests.base/TestPerson/the-uuid.json' >>>
-
git_path
(model_class, *args)[source]¶ Return the path of a model_class when layed out in the git repository.
Parameters: - model_class (class) – The class to map to a path
- args (tuple) – Optional bits to join together after the path.
Returns: str
>>> from git import Repo >>> from elasticgit.tests.base import TestPerson >>> from elasticgit.storage import StorageManager >>> sm = StorageManager(Repo('.')) >>> sm.git_path(TestPerson) 'elasticgit.tests.base/TestPerson' >>> sm.git_path(TestPerson, 'some-uuid.json') 'elasticgit.tests.base/TestPerson/some-uuid.json' >>>
-
iterate
(model_class)[source]¶ This loads all known instances of this model from Git because we need to know how to re-populate Elasticsearch.
Parameters: model_class (elasticgit.models.Model) – The class to look for instances of. Returns: generator
-
load
(file_path)[source]¶ Load a file from the repository and return it as a Model instance.
Parameters: file_path (str) – The path of the object we want a model instance for. Returns: elasticgit.models.Model
-
path_info
(file_path)[source]¶ Analyze a file path and return the object’s class and the uuid.
Parameters: file_path (str) – The path of the object we want a model instance for. Returns: (model_class, uuid) tuple or None
if not a model file path.
-
pull
(branch_name='master', remote_name=None)[source]¶ Fetch & Merge in an upstream’s commits.
Parameters:
-
read_config
(section)[source]¶ Read a config block for a git repository.
Parameters: section (str) – The section to read. Returns: dict
-
storage_exists
()[source]¶ Check if the storage exists. Returns
True
if the directory exists, it does not check if it is an actualgit.Repo
.Returns: bool
-
store
(model, message, author=None, committer=None)[source]¶ Store an instance’s data in Git.
Parameters: - model (elasticgit.models.Model) – The model instance
- message (str) – The commit message.
- 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.
Returns: The commit.
-
store_data
(repo_path, data, message, author=None, committer=None)[source]¶ Store some data in a file
Parameters: - repo_path (str) – Where to store the file.
- data (obj) – The data to write in the file.
- message (str) – The commit message.
- 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.
Returns: The commit
-