def all_committers_set() -> List[CommittersSet]: lines = read_lines(Path(join(CONFIGURATION_DIRECTORY, constants.COMMITTERS_SET))) committers_sets = [] for line in lines: *initials, set_time, path_as_str = line.split(',') committers_sets.append(CommittersSet(initials, set_time, Path(path_as_str))) return committers_sets
def _get_file_content(path_to_hook, create: bool): try: _content = read_lines(path_to_hook) except FileNotFoundError: if create: if not which('python3'): _content = PYTHON_GUET_HOOK else: _content = PYTHON3_GUET_HOOK else: raise return _content
def __init__(self, repository_path: Path): super().__init__() if not repository_path.is_dir(): raise NoGitPresentError() default = _load_hooks( HookLoader(repository_path.joinpath('hooks'), BaseFileNameStrategy(), DontCreateStrategy())) alongside = _load_hooks( HookLoader(repository_path.joinpath('hooks'), AlongsideFileNameStrategy(), DontCreateStrategy())) self.hooks = default + alongside self.path_to_git_folder = repository_path self._commit_msg = _load_commit_msg(repository_path) self._config_lines = read_lines(repository_path.joinpath('config')) self._author: Author = load_author(self._config_lines) self._hooks_destination = None
def test_returns_lines_from_file(self, mock_Path): path: Path = Mock() expected = ['Line1', 'Line2'] path.read_text.return_value = 'Line1\nLine2' result = read_lines(path) self.assertEqual(expected, result)
def test_removes_last_empty_line(self, mock_Path): path: Path = Mock() path.read_text.return_value = 'Line1\nLine2\n' result = read_lines(path) self.assertEqual(['Line1', 'Line2'], result)
def test_strips_newlines_from_the_end_of_lines(self, mock_Path): path: Path = Mock() path.read_text.return_value = 'Line1\nLine2\n' result = read_lines(path) self.assertEqual(['Line1', 'Line2'], result)
def _load_commit_msg(path_to_repository: Path) -> List[str]: try: return read_lines(path_to_repository.joinpath('COMMIT_EDITMSG')) except FileNotFoundError: return []
def get_settings() -> Settings: lines = read_lines(Path(join(CONFIGURATION_DIRECTORY, constants.CONFIG))) settings = Settings() settings.load(lines) return settings
def _read_all_committers_from_file(path: Path) -> List[str]: try: return read_lines(path) except FileNotFoundError: return []
def read(self) -> List[str]: try: self._content = read_lines(self._absolute_path) except FileNotFoundError: self._content = [] return self._content