def _get_or_create_repo(self): """ A repo model object may exist for this binary, if it exists, then return it otherwise create it and then return it. """ # try to find one that matches our needs first repo = Repo.query.filter_by(ref=self.ref, sha1=self.sha1, flavor=self.flavor, distro=self.distro, distro_version=self.distro_version, project=self.project).first() # create one otherwise if not repo: repo = Repo( self.project, self.ref, self.distro, self.distro_version, sha1=self.sha1, flavor=self.flavor, type=self._get_repo_type(), ) # only needs_update when binary is not generic and automatic repos # are configured for this project repo.needs_update = not self.is_generic and util.repository_is_automatic( self.project.name) return repo
def _get_or_create_repo(self): """ A repo model object may exist for this binary, if it exists, then return it otherwise create it and then return it. """ # try to find one that matches our needs first repo = Repo.query.filter_by( ref=self.ref, sha1=self.sha1, flavor=self.flavor, distro=self.distro, distro_version=self.distro_version, project=self.project).first() # create one otherwise if not repo: repo = Repo( self.project, self.ref, self.distro, self.distro_version, sha1=self.sha1, flavor=self.flavor, type=self._get_repo_type(), ) # only needs_update when binary is not generic and automatic repos # are configured for this project repo.needs_update = not self.is_generic and util.repository_is_automatic(self.project.name) return repo
def mark_related_repos(self): related_projects = util.get_related_projects(self.project.name) repos = [] projects = [] for project_name, refs in related_projects.items(): p = models.projects.get_or_create(name=project_name) projects.append(p) repo_query = [] if refs == ['all']: # we need all the repos available repo_query = models.Repo.filter_by(project=p).all() else: for ref in refs: repo_query = models.Repo.filter_by(project=p, ref=ref).all() if repo_query: for r in repo_query: repos.append(r) if not repos: # there are no repositories associated with this project, so go ahead # and create one so that it can be queried by the celery task later for project in projects: repo = models.Repo( project, self.ref, self.distro, self.distro_version, sha1=self.sha1, ) repo.needs_update = repository_is_automatic(project.name) repo.type = self.binary._get_repo_type() else: for repo in repos: repo.needs_update = repository_is_automatic(repo.project.name) if repo.type is None: repo.type = self.binary._get_repo_type()
def mark_related_repos(self): related_projects = util.get_related_projects(self.project.name) repos = [] projects = [] for project_name, refs in related_projects.items(): p = models.projects.get_or_create(name=project_name) projects.append(p) repo_query = [] if refs == ['all']: # we need all the repos available repo_query = models.Repo.filter_by(project=p).all() else: for ref in refs: repo_query = models.Repo.filter_by(project=p, ref=ref).all() if repo_query: for r in repo_query: repos.append(r) if not repos: # there are no repositories associated with this project, so go ahead # and create one so that it can be queried by the celery task later for project in projects: repo = models.Repo( project, self.ref, self.distro, self.distro_version, sha1=self.sha1, ) repo.needs_update = repository_is_automatic(project.name) repo.type = self.binary._get_repo_type() else: for repo in repos: repo.needs_update = repository_is_automatic(repo.project.name) if repo.type is None: repo.type = self.binary._get_repo_type()
def update_repo(mapper, connection, target): try: if target.repo.is_generic: return except (AttributeError, InvalidRequestError): # SQLA might not have finished flushing the object # so it really doesn't know if it is a generic one or not # so do not update anything return try: if util.repository_is_automatic(target.project.name): target.repo.needs_update = True except AttributeError: # target may be None in certain cases, and we don't care which one # triggered it because there is nothing we need to do pass
def update_repo(mapper, connection, target): try: if target.repo.is_generic: return except (AttributeError, InvalidRequestError): # SQLA might not have finished flushing the object # so it really doesn't know if it is a generic one or not # so do not update anything return try: if util.repository_is_automatic(target.project.name): target.repo.needs_update = True except AttributeError: # target may be None in certain cases, and we don't care which one # triggered it because there is nothing we need to do pass