def make_branch_from_config(branch_name): di = DirectoryInfo() branch_path = di.get_branch_path(branch_name) path = os.path.join(branch_path, 'branch.ini') branch = Branch(branch_name) branch.get_data_from_config(path) return branch
def load_config(self): di = DirectoryInfo() config_path = os.path.join(di.get_branch_path(self.name), 'branch.ini') config = configparser.ConfigParser() config.read(config_path) config.optionxform = str self.config = config self.get_data_from_config(config_path)
def init_config(self): di = DirectoryInfo() path = os.path.join(di.get_branch_path(self.name), 'branch.ini') config = configparser.ConfigParser() config['info'] = {} config['info']['name'] = self.name config['info']['current_commit_number'] = '' with open(path, 'w') as cfg_file: config.write(cfg_file)
class DirectoryInfoTest(unittest.TestCase): def setUp(self) -> None: self.info = DirectoryInfo() self.info.init(os.getcwd()) def test_init_should_initialize_working_path(self): result = self.info.working_path self.assertIsNotNone(result) def test_init_should_initialize_cvs_path(self): result = self.info.cvs_path self.assertTrue(result.endswith('CVS')) def test_init_should_initialize_index_path(self): result = self.info.index_path self.assertTrue(result.endswith('INDEX')) def test_add_branch_path_should_add_path_to_branch(self): self.info.add_branch_path("master") count = len(self.info.branches_paths) self.assertGreater(count, 0) def test_add_branch_path_should_add_path_to_commits(self): self.info.add_branch_path("master") count = len(self.info.branches_commits_paths) self.assertGreater(count, 0) def test_get_branch_path_should_get_path_to_branch(self): self.info.add_branch_path("master") path = self.info.get_branch_path("master") self.assertTrue(path.endswith("master")) def test_get_commits_path_should_get_commits_path(self): self.info.add_branch_path("master") path = self.info.get_commits_path("master") self.assertTrue(path.endswith("COMMITS"))
def save_config(self): di = DirectoryInfo() config_path = os.path.join(di.get_branch_path(self.name), 'branch.ini') with open(config_path, 'w') as f: self.config.write(f)