コード例 #1
0
ファイル: database.py プロジェクト: pombredanne/mint
    def createProduct(self, product):
        self.auth.requireProductCreationRights()
        if not product.name:
            raise errors.InvalidItem("Product name must be specified")
        if self.cfg.rBuilderOnline or not product.domainname:
            product.domainname = self.cfg.projectDomainName.split(':')[0]
        projects._validateShortname(product.shortname, product.domainname, 
                                    reservedHosts)
        projects._validateHostname(product.hostname, product.domainname, 
                                   reservedHosts)
        if product.namespace:
            projects._validateNamespace(product.namespace)
        else:
            #If none was set use the default namespace set in config
            product.namespace = self.cfg.namespace
        # validate the label, which will be added later.  This is done
        # here so the project is not created before this error occurs
        if product.version is None:
            product.version = '1'
        projects._validateProductVersion(product.version)
        label = '%s.%s@%s:%s-%s-devel' % (product.hostname, product.domainname,
                                          product.namespace, product.hostname,
                                          product.version)
        if projects.validLabel.match(label) == None:
            raise mint_error.InvalidLabel(label)

        prodtype = product.prodtype
        if not prodtype:
            prodtype = 'Appliance'
        elif prodtype not in ('Appliance', 'Component', 'Platform', 'Repository', 'PlatformFoundation'):
            raise mint_error.InvalidProdType

        fqdn = ".".join((product.hostname, product.domainname))
        projecturl = product.projecturl
        if (projecturl and not (projecturl.startswith('https://') 
            or projecturl.startswith('http://'))):
            product.projecturl = "http://" + projecturl
        for attr in ('projecturl', 'description', 'commitEmail'):
            if getattr(product, attr) is None:
                setattr(product, attr, '')

        if self.cfg.hideNewProjects:
            product.hidden = True
        elif product.hidden is None:
            product.hidden = False

        productId = self.productMgr.createProduct(product.name, 
                                      product.description, product.hostname,
                                      product.domainname, product.namespace,
                                      product.projecturl,
                                      product.shortname, product.prodtype,
                                      product.version,
                                      product.commitEmail, 
                                      isPrivate=product.hidden)
        product.productId = productId
        return product
コード例 #2
0
ファイル: models.py プロジェクト: pombredanne/mint
    def save(self, *args, **kwargs):
        # FIXME: move code into mgr.addProject

        if self._rbmgr is not None:
            cfg = self._rbmgr.cfg
        else:
            cfg = None
        if self.domain_name is None and cfg:
            self.domain_name = cfg.projectDomainName
        if self.namespace is None and cfg:
            self.namespace = cfg.namespace
        if not self.hostname:
            self.hostname = self.short_name

        self.validateNamespace(self.namespace)
        mintprojects._validateShortname(self.short_name, self.domain_name,
            self.RESERVED_HOSTS)
        mintprojects._validateHostname(self.hostname, self.domain_name,
            self.RESERVED_HOSTS)

        # Default project type to Appliance
        if self.project_type is None:
            self.project_type = "Appliance"
        if not self.project_url:
            self.project_url = ''

        self.setIsAppliance()

        if not self.repository_hostname and self.hostname and self.domain_name:
            self.repository_hostname = '%s.%s' % (self.hostname, self.domain_name)

        labels = self.labels.all()
        if labels:
            label = labels[0]
            if self.database:
                # Internal projects and mirror projects have no use for these
                # fields so make sure they are nulled out.
                label.url = None
                label.auth_type = 'none'
                label.user_name = None
                label.password = None
                label.entitlement = None
            else:
                assert self.external
                label.url = str(self.upstream_url)
                label.auth_type = str(self.auth_type)
                label.user_name = str(self.user_name)
                label.password = str(self.password)
                label.entitlement = str(self.entitlement)
            # This field doesn't mean anything but some old code might still
            # use it.
            label.label = self.repository_hostname + '@dummy:label'
            label.save()
        return modellib.XObjIdModel.save(self, *args, **kwargs)