def _pull(self, path, remote_id, branch_id): """ Pull the specified branch. :param path: The absolute path to the local repository. :type path: str :param remote_id: The remote ID. :type remote_id: str :param branch_id: The branch to pull. :type branch_id: str :raises PulpCodedException: """ def report_progress(report): data = dict( b=branch_id, f=report.fetched, r=report.requested, p=report.percent ) self.progress_details = 'branch: %(b)s fetching %(f)d/%(r)d %(p)d%%' % data self.report_progress(force=True) try: repository = lib.Repository(path) repository.pull(remote_id, [branch_id], report_progress) except lib.LibError, le: pe = PulpCodedException(errors.OST0002, branch=branch_id, reason=str(le)) raise pe
def _pull(self, path, remote_id, refs, depth): """ Pull the specified branch. :param path: The absolute path to the local repository. :type path: str :param remote_id: The remote ID. :type remote_id: str :param refs: The refs to pull. :type refs: list :param depth: The tree traversal depth. :type depth: int :raises PulpCodedException: """ def report_progress(report): data = dict(f=report.fetched, r=report.requested, p=report.percent) self.progress_details = 'fetching %(f)d/%(r)d %(p)d%%' % data self.report_progress(force=True) try: repository = lib.Repository(path) repository.pull(remote_id, refs, report_progress, depth) except lib.LibError, le: pe = PulpCodedException(errors.OST0002, reason=str(le)) raise pe
def process_main(self, item=None): """ Find all branch (heads) in the local repository and create content units for each branch and commit in the history. """ lib_repository = lib.Repository(self.parent.storage_dir) for ref in lib_repository.list_refs(): # the branches listed here can have an undesired prefix ending with a ":" branch = ref.path.split(':')[-1] if self.parent.branches is not ALL: if branch not in self.parent.branches: # not listed log.debug( 'skipping non-selected branch: {0}'.format(branch)) continue for commit in reversed(lib_repository.history(ref.commit)): unit = model.Branch(remote_id=self.parent.remote_id, branch=branch, commit=commit.id, metadata=commit.metadata) try: unit.save() except NotUniqueError: unit = model.Branch.objects.get(**unit.unit_key) associate_single_unit(self.get_repo().repo_obj, unit)
def process_main(self, item=None): """ Add/update the remote summary information in the repository scratchpad. """ try: lib_repository = lib.Repository(self.parent.storage_dir) remote = lib.Remote(self.parent.repo_id, lib_repository) refs = [r.dict() for r in remote.list_refs()] except lib.LibError, le: pe = PulpCodedException(errors.OST0005, reason=str(le)) raise pe
def process_main(self, item=None): """ Clean up after import: - Delete the remote used for the pull. """ path = self.parent.storage_dir remote_id = self.parent.repo_id try: repository = lib.Repository(path) remote = lib.Remote(remote_id, repository) remote.delete() except lib.LibError, le: pe = PulpCodedException(errors.OST0003, id=remote_id, reason=str(le)) raise pe
def process_main(self): """ Find all branch (heads) in the local repository and create content units for them. """ conduit = self.get_conduit() repository = lib.Repository(self.parent.storage_path) for ref in repository.list_refs(): if ref.path not in self.parent.branches: # not listed continue commit = model.Commit(ref.commit, ref.metadata) unit = model.Unit(self.parent.remote_id, ref.path, commit) self.link(unit) _unit = Unit(constants.OSTREE_TYPE_ID, unit.key, unit.metadata, unit.storage_path) conduit.save_unit(_unit)
def process_main(self, item=None): """ Add/update the remote summary information in the repository scratchpad. """ repository = self.get_repo().repo_obj lib_repository = lib.Repository(self.parent.storage_dir) remote = lib.Remote(self.parent.repo_id, lib_repository) refs = [r.dict() for r in remote.list_refs()] map(self.convert_metadata_dict, refs) repository.scratchpad.update({ constants.REMOTE: { constants.SUMMARY: refs } }) repository.save()
def process_main(self, item=None): """ Publish the repository. Create an empty repository. Then, for each unit, perform a (local) pull which links objects in this repository to objects in the *backing* repository at the storage path. This starts with the branch HEAD commit and then includes all referenced objects. """ path = self.parent.publish_dir repository = lib.Repository(path) repository.create() for unit in self._get_units(): repository.pull_local(unit.storage_path, [unit.commit]) MainStep._add_ref(path, unit.branch, unit.commit) summary = lib.Summary(repository) summary.generate()
def process_main(self): """ Publish the repository. Create an empty repository. Then, for each unit, perform a (local) pull which links objects in this repository to objects in the *backing* repository at the storage path. This starts with the branch HEAD commit and then includes all referenced objects. """ repo = self.get_repo() path = os.path.join(self.get_working_dir(), repo.id) ostree_repo = lib.Repository(path) ostree_repo.create() for unit in self._get_units(): branch = unit.unit_key['branch'] commit = unit.unit_key['commit'] ostree_repo.pull_local(unit.storage_path, [commit]) MainStep._add_ref(path, branch, commit)
def process_main(self, item=None): """ Add/update the remote summary information in the repository scratchpad. """ try: lib_repository = lib.Repository(self.parent.storage_dir) remote = lib.Remote(self.parent.repo_id, lib_repository) refs = [r.dict() for r in remote.list_refs()] except lib.LibError as le: pe = PulpCodedException(errors.OST0005, reason=str(le)) raise pe repository = self.get_repo().repo_obj map(self.clean_metadata, refs) repository.scratchpad.update( {constants.REMOTE: { constants.SUMMARY: refs }}) repository.save()
def process_main(self, item=None): """ Ensure the local ostree repository has been created and the configured. Also creates and configures a temporary remote used for the subsequent pulls. :raises PulpCodedException: """ path = self.parent.storage_dir try: repository = lib.Repository(path) try: repository.open() except lib.LibError: repository.create() remote = Remote(self, repository) remote.add() except lib.LibError, le: pe = PulpCodedException(errors.OST0001, path=path, reason=str(le)) raise pe
def process_main(self, item=None): """ Repair corrupted local repository. The only option to repair a corrupted repository is to re-create it. Separate step because: - shutil.rmtree() is very slow and should be reflected in progress reporting. - anticipating better tools provided by libostree for doing the repair in the future. :raises PulpCodedException: """ path = self.parent.storage_dir shutil.rmtree(path, ignore_errors=True) try: repository = lib.Repository(path) repository.create() except lib.LibError as le: pe = PulpCodedException(errors.OST0007, path=path, reason=str(le)) raise pe
def process_main(self, item=None): """ Publish the repository. Create an empty repository. Then, for each unit, perform a (local) pull which links objects in this repository to objects in the *backing* repository at the storage path. This starts with the branch HEAD commit and then includes all referenced objects. :raise PulpCodedException: on error. """ path = self.parent.publish_dir repository = lib.Repository(path) repository.create() for unit in self._get_units(): try: repository.pull_local(unit.storage_path, [unit.commit], self.depth) MainStep._add_ref(path, unit.branch, unit.commit) except lib.LibError as le: pe = PulpCodedException(errors.OST0006, reason=str(le)) raise pe summary = lib.Summary(repository) summary.generate()
def _init_repository(path, remote_id, url): """ Ensure the local ostree repository has been created and the configured. :param path: The absolute path to the local repository. :type path: str :param remote_id: The remote ID. :type remote_id: str :param url: The URL to the remote repository. :type url: str :raises PulpCodedException: """ try: repository = lib.Repository(path) try: repository.open() except lib.LibError: repository.create() repository.add_remote(remote_id, url) except lib.LibError, le: pe = PulpCodedException(errors.OST0001, path=path, reason=str(le)) raise pe