~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/soyuz/browser/archive.py

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-06-03 01:24:37 UTC
  • mfrom: (13137.1.11 ppa-api)
  • Revision ID: launchpad@pqm.canonical.com-20110603012437-1hy2195abrbycdtk
[r=allenap][bug=776444,776449] Export PPA dependency APIs

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
    datetime,
34
34
    timedelta,
35
35
    )
36
 
from urlparse import urlparse
37
36
 
38
37
import pytz
39
38
from sqlobject import SQLObjectNotFound
142
141
    IArchiveEditDependenciesForm,
143
142
    IArchiveSet,
144
143
    NoSuchPPA,
 
144
    validate_external_dependencies,
145
145
    )
146
146
from lp.soyuz.interfaces.archivepermission import IArchivePermissionSet
147
147
from lp.soyuz.interfaces.archivesubscriber import IArchiveSubscriberSet
2146
2146
        # Check the external_dependencies field.
2147
2147
        ext_deps = data.get('external_dependencies')
2148
2148
        if ext_deps is not None:
2149
 
            errors = self.validate_external_dependencies(ext_deps)
 
2149
            errors = validate_external_dependencies(ext_deps)
2150
2150
            if len(errors) != 0:
2151
2151
                error_text = "\n".join(errors)
2152
2152
                self.setFieldError('external_dependencies', error_text)
2156
2156
                'commercial',
2157
2157
                'Can only set commericial for private archives.')
2158
2158
 
2159
 
    def validate_external_dependencies(self, ext_deps):
2160
 
        """Validate the external_dependencies field.
2161
 
 
2162
 
        :param ext_deps: The dependencies form field to check.
2163
 
        """
2164
 
        errors = []
2165
 
        # The field can consist of multiple entries separated by
2166
 
        # newlines, so process each in turn.
2167
 
        for dep in ext_deps.splitlines():
2168
 
            try:
2169
 
                deb, url, suite, components = dep.split(" ", 3)
2170
 
            except ValueError:
2171
 
                errors.append(
2172
 
                    "'%s' is not a complete and valid sources.list entry"
2173
 
                        % dep)
2174
 
                continue
2175
 
 
2176
 
            if deb != "deb":
2177
 
                errors.append("%s: Must start with 'deb'" % dep)
2178
 
            url_components = urlparse(url)
2179
 
            if not url_components[0] or not url_components[1]:
2180
 
                errors.append("%s: Invalid URL" % dep)
2181
 
 
2182
 
        return errors
2183
 
 
2184
2159
    @property
2185
2160
    def owner_is_private_team(self):
2186
2161
        """Is the owner a private team?