This file is indexed.

/usr/lib/python2.7/dist-packages/phabletutils/arguments.py is in phablet-tools 1.2+16.04.20160317-0ubuntu1.

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

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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
# Copyright (C) 2013 Canonical Ltd.
# Author: Sergio Schvezov <sergio.schvezov@canonical.com>

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 3 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import argparse
import logging
import tempfile
import urllib
import urlparse

from phabletutils import cdimage
from phabletutils import environment
from phabletutils import resources
from phabletutils import settings

log = logging.getLogger()


class PathAction(argparse.Action):
    def __call__(self, parser, namespace, values, option_string=None):
        log.debug('PathAction: %r %r %r' %
                  (namespace, values, option_string))
        uri = urlparse.urlparse(values)
        if not uri.scheme or uri.scheme == 'file':
            if '%' in uri.path:
                zip_file_path = urllib.unquote(
                    urlparse.urlparse(uri.path))
            else:
                zip_file_path = uri.path
            zip_file_uri = None
            check = False
        elif uri.scheme == 'http' or uri.scheme == 'https':
            zip_file_path = tempfile.mktemp()
            zip_file_uri = values
            check = True
        log.debug('Download from %s, path on disk %s' %
                  (zip_file_uri, zip_file_path))
        artifact = resources.File(file_path=zip_file_path,
                                  file_uri=zip_file_uri,
                                  check=check)
        setattr(namespace, self.dest, artifact)


class RevisionListAction(argparse.Action):
    def __call__(self, parser, namespace, values, option_string=None):
        log.debug('RevisionListAction: %r %r %r' %
                  (namespace, values, option_string))
        project = 'ubuntu-touch-preview'
        uri = '%s/%s' % (settings.cdimage_uri_base, project)
        setattr(namespace, 'func', environment.list_revisions)
        setattr(namespace, 'uri', uri)


class DeprecatedBackup(argparse.Action):
    def __call__(self, parser, namespace, values, option_string=None):
        log.warn('--no-backup is deprecated, use --bootstrap instead')
        setattr(namespace, 'bootstrap', True)


class RevisionAction(argparse.Action):
    def __call__(self, parser, namespace, values, option_string=None):
        log.debug('RevisionAction: %r %r %r' %
                  (namespace, values, option_string))
        project = 'ubuntu-touch-preview'
        base_uri = '%s/%s' % (settings.cdimage_uri_base, project)
        if values:
            revision_split = values.split('/')
            if len(revision_split) != 2:
                raise EnvironmentError(
                    'Improper use of revision, needs to be formatted like'
                    '[series]/[revision]. Use --list-revisions to find'
                    'the available revisions on cdimage')
            series = revision_split[0]
            build = revision_split[1]
        else:
            series, build = cdimage.get_latest_revision(base_uri)
        uri = '%s/%s/%s' % (base_uri, series, build)
        setattr(namespace, self.dest, True)
        setattr(namespace, 'series', series)
        setattr(namespace, 'build', build)
        setattr(namespace, 'uri', uri)


def cdimage_touch(parent_parser, parents):
    parser = parent_parser.add_parser(
        'cdimage-touch', parents=parents,
        help='Provisions the device with a CDimage build of Ubuntu Touch.')
    parser.set_defaults(func=environment.setup_cdimage_touch,
                        project='ubuntu-touch',
                        series=settings.default_series,
                        build=None,
                        uri=None)
    parser.add_argument('-b',
                        '--bootstrap',
                        help='''Bootstrap the target device, this only
                                works on Nexus devices or devices that
                                use fastboot and are unlocked. All user
                                data is destroyed''',
                        action='store_true')
    group = parser.add_mutually_exclusive_group()
    group.add_argument('--pending',
                       action='store_true',
                       required=False,
                       help='Get pending link from cdimage')
    group.add_argument('-p',
                       '--base-path',
                       required=False,
                       default=None,
                       help='''Installs from base path, you must have
                               the same directory structure as if you
                               downloaded for real.
                               This option is completely offline.''')
    return parser


def ubuntu_system(parent_parser, parents):
    parser = parent_parser.add_parser(
        'ubuntu-system', parents=parents,
        help='Provisions the device with an Ubuntu Image Based Upgrade image.')
    parser.set_defaults(func=environment.setup_ubuntu_system,
                        revision=0,
                        series=settings.default_series,
                        project='imageupdates')
    parser.add_argument('--channel',
                        default='stable',
                        help='''Use an alternate system-image channel,
                                e.g. devel-proposed; defaults to stable.''')
    parser.add_argument('--revision',
                        type=int,
                        help='''Download a relative revision from current
                                (-1, -2, ...) or a specific version.''')
    parser.add_argument('--system-image-ready',
                        action='store_true',
                        help='''Explicitly state that the image already on
                                the device is a system image''')
    parser.add_argument('--alternate-server',
                        default=settings.system_image_uri,
                        help='''Use an alternate system server, the default
                                server is %(default)s''')
    group = parser.add_mutually_exclusive_group()
    group.add_argument('--no-backup',
                       action=DeprecatedBackup,
                       nargs=0,
                       help='''(Deprecated) Disables backup procedure of
                               current the Ubuntu install.''')
    group.add_argument('-b',
                       '--bootstrap',
                       action='store_true',
                       help='''Bootstraps the system into Ubuntu
                               wiping all data while doing so.''')
    return parser


def legacy(parent_parser, parents):
    parser = parent_parser.add_parser(
        'cdimage-legacy', parents=parents,
        help='Provisions the device with legacy unflipped images.')
    parser.set_defaults(func=environment.setup_cdimage_legacy,
                        project='ubuntu-touch-preview',
                        series=settings.cdimage_legacy_series,
                        build=None,
                        uri=None)
    parser.add_argument('-b',
                        '--bootstrap',
                        help='''Bootstrap the target device, this only
                                works on Nexus devices or devices that
                                use fastboot and are unlocked. All user
                                data is destroyed''',
                        action='store_true')
    group = parser.add_mutually_exclusive_group()
    group.add_argument('--list-revisions',
                       action=RevisionListAction,
                       nargs=0,
                       help='List available revisions on cdimage and exits')
    group.add_argument('-r',
                       '--revision',
                       action=RevisionAction,
                       help='''Choose a specific release to install
                               from cdimage, the format is
                               [series]/[rev].''')
    group.add_argument('-l',
                       '--latest-revision',
                       action=RevisionAction,
                       nargs=0,
                       help='''Pulls the latest tagged revision.''')
    group.add_argument('-p',
                       '--base-path',
                       required=False,
                       default=None,
                       help='''Installs from base path, you must have
                               the same directory structure as if you
                               downloaded for real.
                               This option is completely offline.''')
    return parser


def community(parent_parser, parents):
    parser = parent_parser.add_parser(
        'community', parents=parents,
        help='Provisions the device with a community supported build.')
    parser.add_argument('-d', '--device', required=True,
                        help='''Specify device to flash.
                                Find out more about flashable devices at
                                https://wiki.ubuntu.com/Touch/Devices''')
    parser.set_defaults(func=environment.setup_community,
                        series=settings.default_series)
    return parser


def common_non_system():
    parser = argparse.ArgumentParser(add_help=False)
    parser.add_argument('--device-path',
                        action=PathAction,
                        help='''uri to device zip to flash,
                                e.g.; file:///..., http://.''',)
    parser.add_argument('--ubuntu-path',
                        action=PathAction,
                        help='''uri to ubuntu zip to flash,
                                e.g.; file:///..., http://.''',)
    parser.add_argument('--wipe',
                        action='store_true',
                        help='''Wipes device data.''')
    return parser


def common_supported():
    parser = argparse.ArgumentParser(add_help=False)
    parser.add_argument('-d',
                        '--device',
                        help='''Target device to deploy.''',
                        required=False,
                        choices=settings.supported_devices)
    return parser


def common():
    parser = argparse.ArgumentParser(add_help=False)
    parser.add_argument('--debug',
                        action='store_true',
                        help='''Enable debug messages.''')
    parser.add_argument('-s',
                        '--serial',
                        help='''Device serial. Use when more than
                                one device is connected.''')
    parser.add_argument('-D',
                        '--download-only',
                        action='store_true',
                        help='Download image only, but do not flash device.')
    return parser


def get_parser():
    """
    Returns a Namespace of the parsed arguments from the command line.
    """
    parser = argparse.ArgumentParser(

        description='''phablet-flash is used to provision devices.
                       It does a best effort to deploy in different ways.''',
        epilog='''Use -h or --help after each command to learn about
                  their provisioning options.''')
    # Parsers
    common_parser = common()
    common_supported_parser = common_supported()
    common_non_system_parser = common_non_system()
    sub = parser.add_subparsers(title='Commands', metavar='')
    cdimage_touch(sub, [common_parser, common_supported_parser,
                        common_non_system_parser])
    legacy(sub, [common_parser, common_supported_parser,
                 common_non_system_parser])
    ubuntu_system(sub, [common_parser, common_supported_parser, ])
    community(sub, [common_parser, common_non_system_parser, ])
    return parser