mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-22 19:01:33 +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:
|
||||
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):
|
||||
if not self._repo_is_initialized():
|
||||
self._run(('git', 'init'))
|
||||
@ -68,13 +90,6 @@ class SnapshotProvider:
|
||||
commit = self._get_commit_from_timestamp(date)
|
||||
self._checkout(commit)
|
||||
|
||||
def _checkout(self, what):
|
||||
self._run((
|
||||
'git', 'checkout',
|
||||
what
|
||||
))
|
||||
self._update_last_valid_branch()
|
||||
|
||||
def _get_commit_from_timestamp(self, date):
|
||||
return self._get_stdout((
|
||||
'git', 'rev-list',
|
||||
@ -84,16 +99,21 @@ class SnapshotProvider:
|
||||
self._last_valid_branch
|
||||
))
|
||||
|
||||
def _get_stdout(self, *args, **kwargs):
|
||||
kwargs['capture_output'] = True
|
||||
stdout_bytes = self._run(*args, **kwargs).stdout
|
||||
return stdout_bytes.decode().rstrip('\n')
|
||||
@property
|
||||
def _last_valid_branch(self):
|
||||
self._update_last_valid_branch()
|
||||
return self.__last_valid_branch
|
||||
|
||||
def _run(self, *args, **kwargs):
|
||||
kwargs['check'] = True
|
||||
if 'env' not in kwargs:
|
||||
kwargs['env'] = self.gitenv
|
||||
return run(*args, **kwargs)
|
||||
def _update_last_valid_branch(self):
|
||||
if not self._head_detached:
|
||||
self.__last_valid_branch = self._branch
|
||||
|
||||
def _checkout(self, what):
|
||||
self._run((
|
||||
'git', 'checkout',
|
||||
what
|
||||
))
|
||||
self._update_last_valid_branch()
|
||||
|
||||
@property
|
||||
def all_timelines(self):
|
||||
@ -109,26 +129,6 @@ class SnapshotProvider:
|
||||
def timeline(self):
|
||||
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
|
||||
def timeline(self, value):
|
||||
self._checkout(value)
|
||||
|
Loading…
Reference in New Issue
Block a user