mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-22 22:51:32 +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 subprocess import run
|
||||||
from getpass import getuser
|
from getpass import getuser
|
||||||
from os.path import isdir
|
from os.path import isdir
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
|
||||||
class SnapshotProvider:
|
class SnapshotProvider:
|
||||||
@ -15,7 +16,8 @@ class SnapshotProvider:
|
|||||||
'GIT_AUTHOR_NAME': author,
|
'GIT_AUTHOR_NAME': author,
|
||||||
'GIT_AUTHOR_EMAIL': '',
|
'GIT_AUTHOR_EMAIL': '',
|
||||||
'GIT_COMMITTER_NAME': author,
|
'GIT_COMMITTER_NAME': author,
|
||||||
'GIT_COMMITTER_EMAIL': ''
|
'GIT_COMMITTER_EMAIL': '',
|
||||||
|
'GIT_PAGER': 'cat'
|
||||||
}
|
}
|
||||||
|
|
||||||
self._check_environment()
|
self._check_environment()
|
||||||
@ -58,7 +60,7 @@ class SnapshotProvider:
|
|||||||
|
|
||||||
def restore_snapshot(self, date):
|
def restore_snapshot(self, date):
|
||||||
commit = self._get_commit_from_timestamp(date)
|
commit = self._get_commit_from_timestamp(date)
|
||||||
self._checkout_commit(commit)
|
self._checkout(commit)
|
||||||
self._head_detached = True
|
self._head_detached = True
|
||||||
|
|
||||||
def _get_commit_from_timestamp(self, date):
|
def _get_commit_from_timestamp(self, date):
|
||||||
@ -70,10 +72,10 @@ class SnapshotProvider:
|
|||||||
self._branch
|
self._branch
|
||||||
))
|
))
|
||||||
|
|
||||||
def _checkout_commit(self, commit):
|
def _checkout(self, what):
|
||||||
self._run((
|
self._run((
|
||||||
'git', 'checkout',
|
'git', 'checkout',
|
||||||
commit
|
what
|
||||||
))
|
))
|
||||||
|
|
||||||
def _get_stdout(self, *args, **kwargs):
|
def _get_stdout(self, *args, **kwargs):
|
||||||
@ -85,3 +87,35 @@ class SnapshotProvider:
|
|||||||
if 'env' not in kwargs:
|
if 'env' not in kwargs:
|
||||||
kwargs['env'] = self.gitenv
|
kwargs['env'] = self.gitenv
|
||||||
return run(*args, **kwargs)
|
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