def create_new_repo(self, git_repo_url, layout, git_branch='master', local_base_path='/etc/ansible-townhall/repos/'): repo_data = self.collection.find_one({"gitRepoUrl": git_repo_url}) if repo_data is not None: return { "created": False, "message": "Repository exists", "name": repo_data['name'] } new_repo = AnsibleRepo() new_repo.load_from_git(git_repo_url, layout, git_branch, local_base_path) new_repo.generate_metadata() self.add_repo(new_repo) self.save_to_db(new_repo) new_repo_data = self.collection.find_one({"gitRepoUrl": git_repo_url}) new_repo_data.pop('_id') new_repo_data.update({ "created": True, "message": "Repository created" }) return new_repo_data
def rebuild_from_db(self): for repo_data in self.collection.find(): repo = AnsibleRepo() repo.load_from_json(repo_data) repo.generate_metadata() self.add_repo(repo)