API/launchpadlib/code_snippets

Not logged in - Log In / Register

Revision 4 as of 2009-03-16 18:02:30

Clear message

code snippets

(Under construction)

This page lists some useful pieces of code

Bugs

Does a bug have a release target?

    >>> def has_target(bug, series):
    ...     series_url = str(series)
    ...     for task in bug.bug_tasks:
    ...         if str(task).startswith(series_url):
    ...             return True
    ...     return False
    ...
    >>> b = launchpad.bugs[324614]
    >>> ubuntu = launchpad.distributions["ubuntu"]
    >>> jaunty = ubuntu.getSeries(name_or_version="jaunty")
    >>> has_target(b, jaunty)
    True

Packages

listing the current package versions in a particular distroseries

    >>> ubuntu = launchpad.distributions["ubuntu"]
    >>> archive = ubuntu.main_archive
    >>> series = ubuntu.current_series
    >>> archive.getPublishedSources(exact_match=True, source_name="apport", distro_series=series)[0].source_package_version
    u'0.123'

get dsc-files for sources in an archive

    import re
    import urlparse
                
    def create_webroot_url_from_self_link(self_link):
        scheme, netloc, _, _, _ = urlparse.urlsplit(self_link)
        netloc = netloc.lstrip("api.")
        return u"%s://%s/" %(scheme, netloc)
    
    def get_dsc(archive):
        re_version = re.compile(r"^\d+\:")
        x = archive.getPublishedSources()
        webroot = create_webroot_url_from_self_link(archive.self_link)
        for i in x:
            version = i.source_package_version
            version = re_version.sub("", version, 1)
            yield "%s~%s/+archive/+files/%s_%s.dsc" \
                %(webroot, archive.owner.name, i.source_package_name, version)