mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-22 18:21:31 +00:00
Implement properties to get info from SnapshotProvider instance
This commit is contained in:
parent
e80782aa6c
commit
d306d0e484
@ -4,6 +4,7 @@
|
||||
from subprocess import run
|
||||
from getpass import getuser
|
||||
from os.path import isdir
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
class SnapshotProvider:
|
||||
@ -15,7 +16,8 @@ class SnapshotProvider:
|
||||
'GIT_AUTHOR_NAME': author,
|
||||
'GIT_AUTHOR_EMAIL': '',
|
||||
'GIT_COMMITTER_NAME': author,
|
||||
'GIT_COMMITTER_EMAIL': ''
|
||||
'GIT_COMMITTER_EMAIL': '',
|
||||
'GIT_PAGER': 'cat'
|
||||
}
|
||||
|
||||
self._check_environment()
|
||||
@ -58,7 +60,7 @@ class SnapshotProvider:
|
||||
|
||||
def restore_snapshot(self, date):
|
||||
commit = self._get_commit_from_timestamp(date)
|
||||
self._checkout_commit(commit)
|
||||
self._checkout(commit)
|
||||
self._head_detached = True
|
||||
|
||||
def _get_commit_from_timestamp(self, date):
|
||||
@ -70,10 +72,10 @@ class SnapshotProvider:
|
||||
self._branch
|
||||
))
|
||||
|
||||
def _checkout_commit(self, commit):
|
||||
def _checkout(self, what):
|
||||
self._run((
|
||||
'git', 'checkout',
|
||||
commit
|
||||
what
|
||||
))
|
||||
|
||||
def _get_stdout(self, *args, **kwargs):
|
||||
@ -85,3 +87,35 @@ class SnapshotProvider:
|
||||
if 'env' not in kwargs:
|
||||
kwargs['env'] = self.gitenv
|
||||
return run(*args, **kwargs)
|
||||
|
||||
@property
|
||||
def all_timelines(self):
|
||||
return self._branches
|
||||
|
||||
@property
|
||||
def timeline(self):
|
||||
return self._branch
|
||||
|
||||
@timeline.setter
|
||||
def timeline(self, value):
|
||||
self._checkout(value)
|
||||
|
||||
@property
|
||||
def snapshots(self):
|
||||
return self._pretty_log_branch()
|
||||
|
||||
def _pretty_log_branch(self):
|
||||
git_log_output = self._get_stdout((
|
||||
'git', 'log',
|
||||
'--pretty=%H@%aI'
|
||||
))
|
||||
|
||||
commits = []
|
||||
for line in git_log_output.splitlines():
|
||||
commit_hash, timestamp = line.split('@')
|
||||
commits.append({
|
||||
'hash': commit_hash,
|
||||
'timestamp': datetime.fromisoformat(timestamp)
|
||||
})
|
||||
|
||||
return commits
|
||||
|
Loading…
Reference in New Issue
Block a user