mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-22 18:41:32 +00:00
Reorder SnapshotProvider methods in accordance with Uncle Bob
This commit is contained in:
parent
c6d3b8ad21
commit
d8ac0dc311
@ -31,6 +31,28 @@ class SnapshotProvider:
|
|||||||
if self._head_detached:
|
if self._head_detached:
|
||||||
raise EnvironmentError(f'{self.__class__.__name__} cannot init from detached HEAD state!')
|
raise EnvironmentError(f'{self.__class__.__name__} cannot init from detached HEAD state!')
|
||||||
|
|
||||||
|
@property
|
||||||
|
def _head_detached(self):
|
||||||
|
return self._branch == 'HEAD'
|
||||||
|
|
||||||
|
@property
|
||||||
|
def _branch(self):
|
||||||
|
return self._get_stdout((
|
||||||
|
'git', 'rev-parse',
|
||||||
|
'--abbrev-ref', 'HEAD'
|
||||||
|
))
|
||||||
|
|
||||||
|
def _get_stdout(self, *args, **kwargs):
|
||||||
|
kwargs['capture_output'] = True
|
||||||
|
stdout_bytes = self._run(*args, **kwargs).stdout
|
||||||
|
return stdout_bytes.decode().rstrip('\n')
|
||||||
|
|
||||||
|
def _run(self, *args, **kwargs):
|
||||||
|
kwargs['check'] = True
|
||||||
|
if 'env' not in kwargs:
|
||||||
|
kwargs['env'] = self.gitenv
|
||||||
|
return run(*args, **kwargs)
|
||||||
|
|
||||||
def _init_repo_if_needed(self):
|
def _init_repo_if_needed(self):
|
||||||
if not self._repo_is_initialized():
|
if not self._repo_is_initialized():
|
||||||
self._run(('git', 'init'))
|
self._run(('git', 'init'))
|
||||||
@ -68,13 +90,6 @@ class SnapshotProvider:
|
|||||||
commit = self._get_commit_from_timestamp(date)
|
commit = self._get_commit_from_timestamp(date)
|
||||||
self._checkout(commit)
|
self._checkout(commit)
|
||||||
|
|
||||||
def _checkout(self, what):
|
|
||||||
self._run((
|
|
||||||
'git', 'checkout',
|
|
||||||
what
|
|
||||||
))
|
|
||||||
self._update_last_valid_branch()
|
|
||||||
|
|
||||||
def _get_commit_from_timestamp(self, date):
|
def _get_commit_from_timestamp(self, date):
|
||||||
return self._get_stdout((
|
return self._get_stdout((
|
||||||
'git', 'rev-list',
|
'git', 'rev-list',
|
||||||
@ -84,16 +99,21 @@ class SnapshotProvider:
|
|||||||
self._last_valid_branch
|
self._last_valid_branch
|
||||||
))
|
))
|
||||||
|
|
||||||
def _get_stdout(self, *args, **kwargs):
|
@property
|
||||||
kwargs['capture_output'] = True
|
def _last_valid_branch(self):
|
||||||
stdout_bytes = self._run(*args, **kwargs).stdout
|
self._update_last_valid_branch()
|
||||||
return stdout_bytes.decode().rstrip('\n')
|
return self.__last_valid_branch
|
||||||
|
|
||||||
def _run(self, *args, **kwargs):
|
def _update_last_valid_branch(self):
|
||||||
kwargs['check'] = True
|
if not self._head_detached:
|
||||||
if 'env' not in kwargs:
|
self.__last_valid_branch = self._branch
|
||||||
kwargs['env'] = self.gitenv
|
|
||||||
return run(*args, **kwargs)
|
def _checkout(self, what):
|
||||||
|
self._run((
|
||||||
|
'git', 'checkout',
|
||||||
|
what
|
||||||
|
))
|
||||||
|
self._update_last_valid_branch()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def all_timelines(self):
|
def all_timelines(self):
|
||||||
@ -109,26 +129,6 @@ class SnapshotProvider:
|
|||||||
def timeline(self):
|
def timeline(self):
|
||||||
return self._branch
|
return self._branch
|
||||||
|
|
||||||
@property
|
|
||||||
def _branch(self):
|
|
||||||
return self._get_stdout((
|
|
||||||
'git', 'rev-parse',
|
|
||||||
'--abbrev-ref', 'HEAD'
|
|
||||||
))
|
|
||||||
|
|
||||||
@property
|
|
||||||
def _last_valid_branch(self):
|
|
||||||
self._update_last_valid_branch()
|
|
||||||
return self.__last_valid_branch
|
|
||||||
|
|
||||||
def _update_last_valid_branch(self):
|
|
||||||
if not self._head_detached:
|
|
||||||
self.__last_valid_branch = self._branch
|
|
||||||
|
|
||||||
@property
|
|
||||||
def _head_detached(self):
|
|
||||||
return self._branch == 'HEAD'
|
|
||||||
|
|
||||||
@timeline.setter
|
@timeline.setter
|
||||||
def timeline(self, value):
|
def timeline(self, value):
|
||||||
self._checkout(value)
|
self._checkout(value)
|
||||||
|
Loading…
Reference in New Issue
Block a user