This file is indexed.

/usr/bin/ubuntu-upload-permission is in ubuntu-dev-tools 0.155.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/usr/bin/python
#
# Copyright (C) 2011, Stefano Rivera <stefanor@ubuntu.com>
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

import optparse
import sys

from ubuntutools.lp.lpapicache import (Launchpad, Distribution, PersonTeam,
                                       Packageset, PackageNotFoundException,
                                       SeriesNotFoundException)
from ubuntutools.logger import Logger
from ubuntutools.misc import split_release_pocket


def parse_arguments():
    '''Parse arguments and return (options, package)'''
    parser = optparse.OptionParser('%prog [options] package')
    parser.add_option('-r', '--release', default=None, metavar='RELEASE',
                      help='Use RELEASE, rather than the current development '
                           'release')
    parser.add_option('-a', '--list-uploaders',
                      default=False, action='store_true',
                      help='List all the people/teams with upload rights')
    parser.add_option('-t', '--list-team-members',
                      default=False, action='store_true',
                      help='List all team members of teams with upload rights '
                           '(implies --list-uploaders)')
    options, args = parser.parse_args()

    if len(args) != 1:
        parser.error("One (and only one) package must be specified")
    package = args[0]

    if options.list_team_members:
        options.list_uploaders = True

    return (options, package)


def main():
    '''Query upload permissions'''
    options, package = parse_arguments()
    # Need to be logged in to see uploaders:
    Launchpad.login()

    ubuntu = Distribution('ubuntu')
    archive = ubuntu.getArchive()
    if options.release is None:
        options.release = ubuntu.getDevelopmentSeries().name
    try:
        release, pocket = split_release_pocket(options.release)
        series = ubuntu.getSeries(release)
    except SeriesNotFoundException, e:
        Logger.error(str(e))
        sys.exit(2)

    try:
        spph = archive.getSourcePackage(package)
    except PackageNotFoundException, e:
        Logger.error(str(e))
        sys.exit(2)
    component = spph.getComponent()
    if (options.list_uploaders and (pocket != 'Release' or series.status in
            ('Experimental', 'Active Development', 'Pre-release Freeze'))):

        component_uploader = archive.getUploadersForComponent(
                component_name=component)[0]
        print "All upload permissions for %s:" % package
        print
        print "Component (%s)" % component
        print "============" + ("=" * len(component))
        print_uploaders([component_uploader], options.list_team_members)

        packagesets = sorted(Packageset.setsIncludingSource(
                distroseries=series,
                sourcepackagename=package))
        if packagesets:
            print
            print "Packagesets"
            print "==========="
            for packageset in packagesets:
                print
                print "%s:" % packageset.name
                print_uploaders(archive.getUploadersForPackageset(
                    packageset=packageset), options.list_team_members)

        ppu_uploaders = archive.getUploadersForPackage(
                source_package_name=package)
        if ppu_uploaders:
            print
            print "Per-Package-Uploaders"
            print "====================="
            print
            print_uploaders(ppu_uploaders, options.list_team_members)
        print

    if PersonTeam.me.canUploadPackage(archive, series, package, component,
                                      pocket):
        print "You can upload %s to %s." % (package, options.release)
    else:
        print ("You can not upload %s to %s, yourself."
               % (package, options.release))
        if (series.status in ('Current Stable Release', 'Supported', 'Obsolete')
                and pocket == 'Release'):
            print ("%s is in the '%s' state. "
                   "You may want to query the %s-proposed pocket."
                   % (release, series.status, release))
        else:
            print ("But you can still contribute to it via the sponsorship "
                   "process: https://wiki.ubuntu.com/SponsorshipProcess")
            if not options.list_uploaders:
                print ("To see who has the necessary upload rights, "
                       "use the --list-uploaders option.")
        sys.exit(1)


def print_uploaders(uploaders, expand_teams=False, prefix=''):
    """Given a list of uploaders, pretty-print them all
    Each line is prefixed with prefix.
    If expand_teams is set, recurse, adding more spaces to prefix on each
    recursion.
    """
    for uploader in sorted(uploaders, key=lambda p: p.display_name):
        print ("%s* %s (%s)%s"
               % (prefix, uploader.display_name, uploader.name,
                  ' [team]' if uploader.is_team else ''))
        if expand_teams and uploader.is_team:
            print_uploaders(uploader.participants, True, prefix=prefix + '  ')


if __name__ == '__main__':
    main()