Exemplo n.º 1
0
    def getByUrl(self, url):
        """See `IBranchLookup`."""
        if url is None:
            return None
        url = url.rstrip('/')
        try:
            uri = URI(url)
        except InvalidURIError:
            return None

        path = self.uriToHostingPath(uri)
        if path is not None:
            branch, trailing = self.getByHostingPath(path)
            if branch is not None:
                return branch

        if uri.scheme == 'lp':
            if not self._uriHostAllowed(uri):
                return None
            try:
                return self.getByLPPath(uri.path.lstrip('/'))[0]
            except (
                CannotHaveLinkedBranch, InvalidNamespace, InvalidProductName,
                NoSuchBranch, NoSuchPerson, NoSuchProduct,
                NoSuchProductSeries, NoSuchDistroSeries,
                NoSuchSourcePackageName, NoLinkedBranch):
                return None

        return Branch.selectOneBy(url=url)
Exemplo n.º 2
0
    def getByUrl(self, url):
        """See `IBranchLookup`."""
        if url is None:
            return None
        url = url.rstrip('/')
        try:
            uri = URI(url)
        except InvalidURIError:
            return None

        path = self.uriToHostingPath(uri)
        if path is not None:
            branch, trailing = self.getByHostingPath(path)
            if branch is not None:
                return branch

        if uri.scheme == 'lp':
            if not self._uriHostAllowed(uri):
                return None
            try:
                return self.getByLPPath(uri.path.lstrip('/'))[0]
            except (CannotHaveLinkedBranch, InvalidNamespace,
                    InvalidProductName, NoSuchBranch, NoSuchPerson,
                    NoSuchProduct, NoSuchProductSeries, NoSuchDistroSeries,
                    NoSuchSourcePackageName, NoLinkedBranch):
                return None

        return Branch.selectOneBy(url=url)
Exemplo n.º 3
0
    def getByUrl(self, url):
        """See `IBranchLookup`."""
        if url is None:
            return None
        url = url.rstrip('/')
        try:
            uri = URI(url)
        except InvalidURIError:
            return None

        path = self.uriToHostingPath(uri)
        if path is not None:
            branch, trailing = self.getByHostingPath(path)
            if branch is not None:
                return branch

        if uri.scheme == 'lp':
            if not self._uriHostAllowed(uri):
                return None
            return self.getByPath(uri.path.lstrip('/'))

        return Branch.selectOneBy(url=url)
Exemplo n.º 4
0
    def createBranch(
        self,
        branch_type,
        name,
        registrant,
        url=None,
        title=None,
        lifecycle_status=BranchLifecycleStatus.DEVELOPMENT,
        summary=None,
        whiteboard=None,
        date_created=None,
        branch_format=None,
        repository_format=None,
        control_format=None,
    ):
        """See `IBranchNamespace`."""

        self.validateRegistrant(registrant)
        self.validateBranchName(name)

        if date_created is None:
            date_created = UTC_NOW

        # Run any necessary data massage on the branch URL.
        if url is not None:
            url = IBranch["url"].normalize(url)

        product = getattr(self, "product", None)
        sourcepackage = getattr(self, "sourcepackage", None)
        if sourcepackage is None:
            distroseries = None
            sourcepackagename = None
        else:
            distroseries = sourcepackage.distroseries
            sourcepackagename = sourcepackage.sourcepackagename

        information_type = self.getDefaultInformationType(registrant)
        if information_type is None:
            raise BranchCreationForbidden()

        branch = Branch(
            registrant=registrant,
            name=name,
            owner=self.owner,
            product=product,
            url=url,
            title=title,
            lifecycle_status=lifecycle_status,
            summary=summary,
            whiteboard=whiteboard,
            information_type=information_type,
            date_created=date_created,
            branch_type=branch_type,
            date_last_modified=date_created,
            branch_format=branch_format,
            repository_format=repository_format,
            control_format=control_format,
            distroseries=distroseries,
            sourcepackagename=sourcepackagename,
        )

        # The registrant of the branch should also be automatically subscribed
        # in order for them to get code review notifications.  The implicit
        # registrant subscription does not cause email to be sent about
        # attribute changes, just merge proposals and code review comments.
        branch.subscribe(
            self.owner,
            BranchSubscriptionNotificationLevel.NOEMAIL,
            BranchSubscriptionDiffSize.NODIFF,
            CodeReviewNotificationLevel.FULL,
            registrant,
        )

        branch._reconcileAccess()

        notify(ObjectCreatedEvent(branch))
        return branch
Exemplo n.º 5
0
    def createBranch(self,
                     branch_type,
                     name,
                     registrant,
                     url=None,
                     title=None,
                     lifecycle_status=BranchLifecycleStatus.DEVELOPMENT,
                     summary=None,
                     whiteboard=None,
                     date_created=None,
                     branch_format=None,
                     repository_format=None,
                     control_format=None):
        """See `IBranchNamespace`."""

        self.validateRegistrant(registrant)
        self.validateBranchName(name)

        if date_created is None:
            date_created = UTC_NOW

        # Run any necessary data massage on the branch URL.
        if url is not None:
            url = IBranch['url'].normalize(url)

        product = getattr(self, 'product', None)
        sourcepackage = getattr(self, 'sourcepackage', None)
        if sourcepackage is None:
            distroseries = None
            sourcepackagename = None
        else:
            distroseries = sourcepackage.distroseries
            sourcepackagename = sourcepackage.sourcepackagename

        information_type = self.getDefaultInformationType(registrant)
        if information_type is None:
            raise BranchCreationForbidden()

        branch = Branch(registrant=registrant,
                        name=name,
                        owner=self.owner,
                        product=product,
                        url=url,
                        title=title,
                        lifecycle_status=lifecycle_status,
                        summary=summary,
                        whiteboard=whiteboard,
                        information_type=information_type,
                        date_created=date_created,
                        branch_type=branch_type,
                        date_last_modified=date_created,
                        branch_format=branch_format,
                        repository_format=repository_format,
                        control_format=control_format,
                        distroseries=distroseries,
                        sourcepackagename=sourcepackagename)

        # The registrant of the branch should also be automatically subscribed
        # in order for them to get code review notifications.  The implicit
        # registrant subscription does not cause email to be sent about
        # attribute changes, just merge proposals and code review comments.
        branch.subscribe(self.owner,
                         BranchSubscriptionNotificationLevel.NOEMAIL,
                         BranchSubscriptionDiffSize.NODIFF,
                         CodeReviewNotificationLevel.FULL, registrant)

        branch._reconcileAccess()

        notify(ObjectCreatedEvent(branch))
        return branch
Exemplo n.º 6
0
 def get(self, branch_id, default=None):
     """See `IBranchLookup`."""
     try:
         return Branch.get(branch_id)
     except SQLObjectNotFound:
         return default
Exemplo n.º 7
0
 def get(self, branch_id, default=None):
     """See `IBranchLookup`."""
     try:
         return Branch.get(branch_id)
     except SQLObjectNotFound:
         return default