Exemplo n.º 1
0
    def ensurePersonForSelf(
        self, display_name, email, rationale, creation_comment):
        """Return a Person that is linked to this bug tracker."""
        # If we have an email address to work with we can use
        # ensurePerson() to get the Person we need.
        if email is not None:
            return getUtility(IPersonSet).ensurePerson(
                email, display_name, rationale, creation_comment)

        # First, see if there's already a BugTrackerPerson for this
        # display_name on this bugtracker. If there is, return it.
        bugtracker_person = self.getLinkedPersonByName(display_name)

        if bugtracker_person is not None:
            return bugtracker_person.person

        # Generate a valid Launchpad name for the Person.
        base_canonical_name = (
            "%s-%s" % (sanitize_name(display_name.lower()), self.name))
        canonical_name = base_canonical_name

        person_set = getUtility(IPersonSet)
        index = 0
        while person_set.getByName(canonical_name) is not None:
            index += 1
            canonical_name = "%s-%s" % (base_canonical_name, index)

        person = person_set.createPersonWithoutEmail(
            canonical_name, rationale, creation_comment,
            displayname=display_name)

        # Link the Person to the bugtracker for future reference.
        bugtracker_person = self.linkPersonToSelf(display_name, person)

        return person
Exemplo n.º 2
0
def make_bugtracker_name(uri):
    """Return a name string for a bug tracker based on a URI.

    :param uri: The base URI to be used to identify the bug tracker,
        e.g. http://bugs.example.com or mailto:[email protected]
    """
    base_uri = URI(uri)
    if base_uri.scheme == 'mailto':
        if valid_email(base_uri.path):
            base_name = base_uri.path.split('@', 1)[0]
        else:
            raise AssertionError(
                'Not a valid email address: %s' % base_uri.path)
    elif base_uri.host == 'github.com' and base_uri.path.endswith('/issues'):
        repository_id = base_uri.path[:-len('/issues')].lstrip('/')
        base_name = 'github-' + repository_id.replace('/', '-').lower()
    elif (('gitlab' in base_uri.host or
           base_uri.host == 'salsa.debian.org') and
          base_uri.path.endswith('/issues')):
        repository_id = base_uri.path[:-len('/issues')].lstrip('/')
        base_name = '%s-%s' % (
            base_uri.host, repository_id.replace('/', '-').lower())
    else:
        base_name = base_uri.host

    return 'auto-%s' % sanitize_name(base_name)
Exemplo n.º 3
0
    def _getNameToken(self, text):
        """Return the search text as a Launchpad name.

        Launchpad names may contain ^[a-z0-9][a-z0-9\+\.\-]+$.
        See `valid_name_pattern`.
        """
        hypen_pattern = re.compile(r'[ _]')
        name = hypen_pattern.sub('-', text.strip().lower())
        return sanitize_name(name)
Exemplo n.º 4
0
    def _getNameToken(self, text):
        """Return the search text as a Launchpad name.

        Launchpad names may contain ^[a-z0-9][a-z0-9\+\.\-]+$.
        See `valid_name_pattern`.
        """
        hypen_pattern = re.compile(r'[ _]')
        name = hypen_pattern.sub('-', text.strip().lower())
        return sanitize_name(name)
Exemplo n.º 5
0
def make_bugtracker_name(uri):
    """Return a name string for a bug tracker based on a URI.

    :param uri: The base URI to be used to identify the bug tracker,
        e.g. http://bugs.example.com or mailto:[email protected]
    """
    base_uri = URI(uri)
    if base_uri.scheme == 'mailto':
        if valid_email(base_uri.path):
            base_name = base_uri.path.split('@', 1)[0]
        else:
            raise AssertionError('Not a valid email address: %s' %
                                 base_uri.path)
    else:
        base_name = base_uri.host

    return 'auto-%s' % sanitize_name(base_name)
Exemplo n.º 6
0
def make_name(domain):
    """Make a template name from a translation domain."""
    return sanitize_name(domain.replace('_', '-').lower())