Example #1
0
    def validate(self, data):
        """See `LaunchpadFormView`."""
        # Make sure that the user is able to create branches for the specified
        # namespace.
        product = self.getProduct(data)
        # 'owner' in data may be None if it failed validation.
        owner = data.get('owner')
        if product is not None and owner is not None:
            namespace = get_branch_namespace(owner, product)
            policy = IBranchNamespacePolicy(namespace)
            if not policy.canCreateBranches(self.user):
                self.setFieldError(
                    'product',
                    "You are not allowed to register imports for %s."
                    % product.displayname)

        rcs_type = data['rcs_type']
        # Make sure fields for unselected revision control systems
        # are blanked out:
        if rcs_type == RevisionControlSystems.CVS:
            self._validateCVS(data.get('cvs_root'), data.get('cvs_module'))
        elif rcs_type == RevisionControlSystems.BZR_SVN:
            self._validateURL(
                data.get('svn_branch_url'), field_name='svn_branch_url')
        elif rcs_type == RevisionControlSystems.GIT:
            self._validateURL(
                data.get('git_repo_url'), field_name='git_repo_url')
        elif rcs_type == RevisionControlSystems.BZR:
            self._validateURL(
                data.get('bzr_branch_url'), field_name='bzr_branch_url')
        else:
            raise AssertionError(
                'Unexpected revision control type %r.' % rcs_type)
Example #2
0
    def makeBranchFromURL(self, url):
        """Make a mirrored branch for `url`.

        The product and owner of the branch are derived from information in
        the launchbag. The name of the branch is derived from the last segment
        of the URL and is guaranteed to be unique for the product.

        :param url: The URL to mirror.
        :return: An `IBranch`.
        """
        # XXX: JonathanLange 2008-12-08 spec=package-branches: This method
        # needs to be rewritten to get the sourcepackage and distroseries out
        # of the launch bag.
        url = unicode(URI(url).ensureNoSlash())
        if getUtility(IBranchLookup).getByUrl(url) is not None:
            raise AlreadyRegisteredError('Already a branch for %r' % url)
        # Make sure the URL is valid.
        IBranch['url'].validate(url)
        product = self.getProduct()
        if product is None:
            raise NoProductError("Could not find product in LaunchBag.")
        owner = self.getPerson()
        name = self.getBranchNameFromURL(url)
        namespace = get_branch_namespace(person=owner, product=product)
        branch = namespace.createBranchWithPrefix(
            BranchType.MIRRORED, name, owner, url=url)
        branch.requestMirror()
        self.request.response.addNotification(
            structured('Registered %s' %
                       BranchFormatterAPI(branch).link(None)))
        return branch
 def test_missing_suffixed_product_branch(self):
     owner = self.factory.makePerson()
     product = self.factory.makeProduct()
     namespace = get_branch_namespace(owner, product=product)
     suffix = self.makeRelativePath()
     branch_name = namespace.getBranchName(self.factory.getUniqueString())
     self.assertMissingPath(NoSuchBranch, branch_name + '/' + suffix)
Example #4
0
 def test_missing_suffixed_personal_branch(self):
     owner = self.factory.makePerson()
     namespace = get_branch_namespace(owner)
     branch_name = namespace.getBranchName(self.factory.getUniqueString())
     suffix = self.makeRelativePath()
     self.assertRaises(NoSuchBranch, self.getByPath,
                       branch_name + '/' + suffix)
 def test_missing_suffixed_personal_branch(self):
     owner = self.factory.makePerson()
     namespace = get_branch_namespace(owner)
     branch_name = namespace.getBranchName(self.factory.getUniqueString())
     suffix = self.makeRelativePath()
     self.assertRaises(
         NoSuchBranch, self.getByPath, branch_name + '/' + suffix)
Example #6
0
    def makeBranchFromURL(self, url):
        """Make a mirrored branch for `url`.

        The product and owner of the branch are derived from information in
        the launchbag. The name of the branch is derived from the last segment
        of the URL and is guaranteed to be unique for the product.

        :param url: The URL to mirror.
        :return: An `IBranch`.
        """
        # XXX: JonathanLange 2008-12-08 spec=package-branches: This method
        # needs to be rewritten to get the sourcepackage and distroseries out
        # of the launch bag.
        url = unicode(URI(url).ensureNoSlash())
        if getUtility(IBranchLookup).getByUrl(url) is not None:
            raise AlreadyRegisteredError('Already a branch for %r' % url)
        # Make sure the URL is valid.
        IBranch['url'].validate(url)
        product = self.getProduct()
        if product is None:
            raise NoProductError("Could not find product in LaunchBag.")
        owner = self.getPerson()
        name = self.getBranchNameFromURL(url)
        namespace = get_branch_namespace(person=owner, product=product)
        branch = namespace.createBranchWithPrefix(BranchType.MIRRORED,
                                                  name,
                                                  owner,
                                                  url=url)
        branch.requestMirror()
        self.request.response.addNotification(
            structured('Registered %s' %
                       BranchFormatterAPI(branch).link(None)))
        return branch
 def getDatabaseBranch(self, personName, productName, branchName):
     """Look up and return the specified branch from the database."""
     owner = Person.byName(personName)
     if productName is None:
         product = None
     else:
         product = Product.selectOneBy(name=productName)
     namespace = get_branch_namespace(owner, product)
     return namespace.getByName(branchName)
 def test_missing_package_branch(self):
     owner = self.factory.makePerson()
     distroseries = self.factory.makeDistroSeries()
     sourcepackagename = self.factory.makeSourcePackageName()
     namespace = get_branch_namespace(
         owner, distroseries=distroseries,
         sourcepackagename=sourcepackagename)
     branch_name = namespace.getBranchName(self.factory.getUniqueString())
     self.assertRaises(NoSuchBranch, self.getByPath, branch_name)
Example #9
0
 def traverse(self, branch_name):
     """Look for a branch in the person/product namespace."""
     namespace = get_branch_namespace(person=self.context.person,
                                      product=self.context.product)
     branch = namespace.getByName(branch_name)
     if branch is None:
         raise NotFoundError
     else:
         return branch
 def test_missing_package_branch(self):
     owner = self.factory.makePerson()
     distroseries = self.factory.makeDistroSeries()
     sourcepackagename = self.factory.makeSourcePackageName()
     namespace = get_branch_namespace(owner,
                                      distroseries=distroseries,
                                      sourcepackagename=sourcepackagename)
     branch_name = namespace.getBranchName(self.factory.getUniqueString())
     self.assertMissingPath(NoSuchBranch, branch_name)
 def getDatabaseBranch(self, personName, productName, branchName):
     """Look up and return the specified branch from the database."""
     owner = Person.byName(personName)
     if productName is None:
         product = None
     else:
         product = Product.selectOneBy(name=productName)
     namespace = get_branch_namespace(owner, product)
     return namespace.getByName(branchName)
 def traverse(self, branch_name):
     """Look for a branch in the person/product namespace."""
     namespace = get_branch_namespace(
         person=self.context.person, product=self.context.product)
     branch = namespace.getByName(branch_name)
     if branch is None:
         raise NotFoundError
     else:
         return branch
Example #13
0
 def test_missing_suffixed_package_branch(self):
     owner = self.factory.makePerson()
     distroseries = self.factory.makeDistroSeries()
     sourcepackagename = self.factory.makeSourcePackageName()
     namespace = get_branch_namespace(owner,
                                      distroseries=distroseries,
                                      sourcepackagename=sourcepackagename)
     suffix = self.makeRelativePath()
     branch_name = namespace.getBranchName(self.factory.getUniqueString())
     self.assertRaises(NoSuchBranch, self.getByPath,
                       branch_name + '/' + suffix)
Example #14
0
    def makeDatabaseBranch(self, owner_name, product_name, branch_name,
                           branch_type=BranchType.HOSTED):
        """Create a new branch in the database."""
        owner = Person.selectOneBy(name=owner_name)
        if product_name == '+junk':
            product = None
        else:
            product = Product.selectOneBy(name=product_name)
        if branch_type == BranchType.MIRRORED:
            url = 'http://example.com'
        else:
            url = None

        namespace = get_branch_namespace(owner, product)
        return namespace.createBranch(
            branch_type=branch_type, name=branch_name, registrant=owner,
            url=url)
Example #15
0
    def register_branch(
        self, branch_url, branch_name, branch_title, branch_description, author_email, product_name, owner_name=""
    ):
        """See IBranchSetAPI."""
        registrant = getUtility(ILaunchBag).user
        assert registrant is not None, "register_branch shouldn't be accessible to unauthenicated" " requests."

        person_set = getUtility(IPersonSet)
        if owner_name:
            owner = person_set.getByName(owner_name)
            if owner is None:
                return faults.NoSuchPersonWithName(owner_name)
            if not registrant.inTeam(owner):
                return faults.NotInTeam(registrant.name, owner_name)
        else:
            owner = registrant

        if product_name:
            product = getUtility(IProductSet).getByName(product_name)
            if product is None:
                return faults.NoSuchProduct(product_name)
        else:
            product = None

        # Branch URLs in Launchpad do not end in a slash, so strip any
        # slashes from the end of the URL.
        branch_url = branch_url.rstrip("/")

        branch_lookup = getUtility(IBranchLookup)
        existing_branch = branch_lookup.getByUrl(branch_url)
        if existing_branch is not None:
            return faults.BranchAlreadyRegistered(branch_url)

        try:
            unicode_branch_url = branch_url.decode("utf-8")
            IBranch["url"].validate(unicode_branch_url)
        except LaunchpadValidationError as exc:
            return faults.InvalidBranchUrl(branch_url, exc)

        # We want it to be None in the database, not ''.
        if not branch_description:
            branch_description = None
        if not branch_title:
            branch_title = None

        if not branch_name:
            branch_name = unicode_branch_url.split("/")[-1]

        try:
            if branch_url:
                branch_type = BranchType.MIRRORED
            else:
                branch_type = BranchType.HOSTED
            namespace = get_branch_namespace(owner, product)
            branch = namespace.createBranch(
                branch_type=branch_type,
                name=branch_name,
                registrant=registrant,
                url=branch_url,
                title=branch_title,
                summary=branch_description,
            )
            if branch_type == BranchType.MIRRORED:
                branch.requestMirror()
        except BranchCreationForbidden:
            return faults.BranchCreationForbidden(product.displayname)
        except BranchCreationException as err:
            return faults.BranchNameInUse(err)
        except LaunchpadValidationError as err:
            return faults.InvalidBranchName(err)

        return canonical_url(branch)
Example #16
0
 def test_missing_product_branch(self):
     owner = self.factory.makePerson()
     product = self.factory.makeProduct()
     namespace = get_branch_namespace(owner, product=product)
     branch_name = namespace.getBranchName(self.factory.getUniqueString())
     self.assertRaises(NoSuchBranch, self.getByPath, branch_name)
 def test_missing_personal_branch(self):
     owner = self.factory.makePerson()
     namespace = get_branch_namespace(owner)
     branch_name = namespace.getBranchName(self.factory.getUniqueString())
     self.assertMissingPath(NoSuchBranch, branch_name)
 def test_missing_product_branch(self):
     owner = self.factory.makePerson()
     product = self.factory.makeProduct()
     namespace = get_branch_namespace(owner, product=product)
     branch_name = namespace.getBranchName(self.factory.getUniqueString())
     self.assertRaises(NoSuchBranch, self.getByPath, branch_name)