mirror of
https://git.launchpad.net/ubuntu-dev-tools
synced 2025-03-31 21:01:07 +00:00
pullpkg: add --security param to query ubuntu sec team proposed ppa
This commit is contained in:
parent
87a09640ba
commit
e37e9db7eb
@ -146,13 +146,14 @@ class SourcePackage(object):
|
|||||||
pocket = kwargs.get('pocket')
|
pocket = kwargs.get('pocket')
|
||||||
status = kwargs.get('status')
|
status = kwargs.get('status')
|
||||||
verify_signature = kwargs.get('verify_signature', False)
|
verify_signature = kwargs.get('verify_signature', False)
|
||||||
|
try_binary = kwargs.get('try_binary', True)
|
||||||
|
|
||||||
assert (package is not None or dscfile is not None)
|
assert (package is not None or dscfile is not None)
|
||||||
|
|
||||||
self.source = package
|
self.source = package
|
||||||
self._lp = lp
|
self._lp = lp
|
||||||
self.binary = None
|
self.binary = None
|
||||||
self.try_binary = True
|
self.try_binary = try_binary
|
||||||
self.workdir = workdir
|
self.workdir = workdir
|
||||||
self._series = series
|
self._series = series
|
||||||
self._pocket = pocket
|
self._pocket = pocket
|
||||||
|
@ -105,13 +105,9 @@ class PullPkg(object):
|
|||||||
self._default_pull = kwargs.get('pull')
|
self._default_pull = kwargs.get('pull')
|
||||||
self._default_distro = kwargs.get('distro')
|
self._default_distro = kwargs.get('distro')
|
||||||
self._default_arch = kwargs.get('arch', host_architecture())
|
self._default_arch = kwargs.get('arch', host_architecture())
|
||||||
self._parser = None
|
|
||||||
self._ppa_parser = None
|
|
||||||
|
|
||||||
@property
|
def parse_args(self, args):
|
||||||
def argparser(self):
|
args = args[:]
|
||||||
if self._parser:
|
|
||||||
return self._parser
|
|
||||||
|
|
||||||
help_default_pull = "What to pull: " + ", ".join(VALID_PULLS)
|
help_default_pull = "What to pull: " + ", ".join(VALID_PULLS)
|
||||||
if self._default_pull:
|
if self._default_pull:
|
||||||
@ -122,11 +118,9 @@ class PullPkg(object):
|
|||||||
help_default_arch = ("Get binary packages for arch")
|
help_default_arch = ("Get binary packages for arch")
|
||||||
help_default_arch += ("(default: %s)" % self._default_arch)
|
help_default_arch += ("(default: %s)" % self._default_arch)
|
||||||
|
|
||||||
epilog = ("Note on --status: if a version is provided, all status types "
|
# use add_help=False because we do parse_known_args() below, and if
|
||||||
"will be searched; if no version is provided, by default only "
|
# that sees --help then it exits immediately
|
||||||
"'Pending' and 'Published' status will be searched.")
|
parser = ArgumentParser(add_help=False)
|
||||||
|
|
||||||
parser = ArgumentParser(epilog=epilog)
|
|
||||||
parser.add_argument('-v', '--verbose', action='count', default=0,
|
parser.add_argument('-v', '--verbose', action='count', default=0,
|
||||||
help="Increase verbosity/debug")
|
help="Increase verbosity/debug")
|
||||||
parser.add_argument('-d', '--download-only', action='store_true',
|
parser.add_argument('-d', '--download-only', action='store_true',
|
||||||
@ -145,40 +139,42 @@ class PullPkg(object):
|
|||||||
help=help_default_pull)
|
help=help_default_pull)
|
||||||
parser.add_argument('-D', '--distro', default=self._default_distro,
|
parser.add_argument('-D', '--distro', default=self._default_distro,
|
||||||
help=help_default_distro)
|
help=help_default_distro)
|
||||||
|
|
||||||
|
# add distro-specific params
|
||||||
|
try:
|
||||||
|
distro = self.parse_distro(parser.parse_known_args(args)[0].distro)
|
||||||
|
except InvalidDistroValueError:
|
||||||
|
# don't fail at this point, finish setting up parser help/usage
|
||||||
|
distro = None
|
||||||
|
|
||||||
|
if distro == DISTRO_UBUNTU:
|
||||||
|
parser.add_argument('--security', action='store_true',
|
||||||
|
help='Check the Ubuntu Security Team PPA')
|
||||||
|
if distro == DISTRO_PPA:
|
||||||
parser.add_argument('--ppa', help='PPA to pull from')
|
parser.add_argument('--ppa', help='PPA to pull from')
|
||||||
|
if parser.parse_known_args(args)[0].ppa is None:
|
||||||
|
# check for any param starting with "ppa:"
|
||||||
|
# if found, move it to a --ppa param
|
||||||
|
for param in args:
|
||||||
|
if param.startswith('ppa:'):
|
||||||
|
args.remove(param)
|
||||||
|
args.insert(0, param)
|
||||||
|
args.insert(0, '--ppa')
|
||||||
|
break
|
||||||
|
|
||||||
|
# add the positional params
|
||||||
parser.add_argument('package', help="Package name to pull")
|
parser.add_argument('package', help="Package name to pull")
|
||||||
parser.add_argument('release', nargs='?', help="Release to pull from")
|
parser.add_argument('release', nargs='?', help="Release to pull from")
|
||||||
parser.add_argument('version', nargs='?', help="Package version to pull")
|
parser.add_argument('version', nargs='?', help="Package version to pull")
|
||||||
self._parser = parser
|
|
||||||
return self._parser
|
|
||||||
|
|
||||||
def parse_ppa_args(self, args):
|
epilog = ("Note on --status: if a version is provided, all status types "
|
||||||
"""When pulling from PPA, convert from bare ppa:USER/NAME to --ppa option"""
|
"will be searched; if no version is provided, by default only "
|
||||||
if not args:
|
"'Pending' and 'Published' status will be searched.")
|
||||||
myargs = sys.argv[1:]
|
|
||||||
|
|
||||||
options = vars(self.argparser.parse_known_args(myargs)[0])
|
# since parser has no --help handler, create a new parser that does
|
||||||
# we use these, which all should be always provided by the parser,
|
newparser = ArgumentParser(parents=[parser], epilog=epilog)
|
||||||
# even if their value is None
|
|
||||||
assert 'distro' in options
|
|
||||||
assert 'ppa' in options
|
|
||||||
assert 'release' in options
|
|
||||||
assert 'version' in options
|
|
||||||
|
|
||||||
# if we're not pulling from a PPA, or if we are but --ppa was given,
|
return self.parse_options(vars(newparser.parse_args(args)))
|
||||||
# then no change to the args is needed
|
|
||||||
if options['distro'] != DISTRO_PPA or options['ppa'] is not None:
|
|
||||||
return args
|
|
||||||
|
|
||||||
# check if release or version is a ppa:
|
|
||||||
# if it is, move it to a --ppa param
|
|
||||||
for param in ['release', 'version']:
|
|
||||||
if str(options[param]).startswith('ppa:'):
|
|
||||||
myargs.remove(options[param])
|
|
||||||
myargs.insert(0, options[param])
|
|
||||||
myargs.insert(0, '--ppa')
|
|
||||||
|
|
||||||
return myargs
|
|
||||||
|
|
||||||
def parse_pull(self, pull):
|
def parse_pull(self, pull):
|
||||||
if not pull:
|
if not pull:
|
||||||
@ -276,6 +272,7 @@ class PullPkg(object):
|
|||||||
# they should all be provided, though the optional ones may be None
|
# they should all be provided, though the optional ones may be None
|
||||||
|
|
||||||
# type bool
|
# type bool
|
||||||
|
assert 'verbose' in options
|
||||||
assert 'download_only' in options
|
assert 'download_only' in options
|
||||||
assert 'no_conf' in options
|
assert 'no_conf' in options
|
||||||
assert 'no_verify_signature' in options
|
assert 'no_verify_signature' in options
|
||||||
@ -286,14 +283,23 @@ class PullPkg(object):
|
|||||||
assert 'arch' in options
|
assert 'arch' in options
|
||||||
assert 'package' in options
|
assert 'package' in options
|
||||||
# type string, optional
|
# type string, optional
|
||||||
assert 'ppa' in options
|
|
||||||
assert 'release' in options
|
assert 'release' in options
|
||||||
assert 'version' in options
|
assert 'version' in options
|
||||||
# type list of strings, optional
|
# type list of strings, optional
|
||||||
assert 'mirror' in options
|
assert 'mirror' in options
|
||||||
|
|
||||||
pull = self.parse_pull(options['pull'])
|
options['pull'] = self.parse_pull(options['pull'])
|
||||||
distro = self.parse_distro(options['distro'])
|
options['distro'] = self.parse_distro(options['distro'])
|
||||||
|
|
||||||
|
# ensure these are always included so we can just check for None/False later
|
||||||
|
options['ppa'] = options.get('ppa', None)
|
||||||
|
options['security'] = options.get('security', False)
|
||||||
|
|
||||||
|
return options
|
||||||
|
|
||||||
|
def _get_params(self, options):
|
||||||
|
distro = options['distro']
|
||||||
|
pull = options['pull']
|
||||||
|
|
||||||
params = {}
|
params = {}
|
||||||
params['package'] = options['package']
|
params['package'] = options['package']
|
||||||
@ -309,6 +315,13 @@ class PullPkg(object):
|
|||||||
params['dscfile'] = params['package']
|
params['dscfile'] = params['package']
|
||||||
params.pop('package')
|
params.pop('package')
|
||||||
|
|
||||||
|
if options['security']:
|
||||||
|
if options['ppa']:
|
||||||
|
Logger.warning('Both --security and --ppa specified, ignoring --ppa')
|
||||||
|
Logger.debug('Checking Ubuntu Security PPA')
|
||||||
|
# --security is just a shortcut for --ppa ppa:ubuntu-security-proposed/ppa
|
||||||
|
options['ppa'] = 'ubuntu-security-proposed/ppa'
|
||||||
|
|
||||||
if options['ppa']:
|
if options['ppa']:
|
||||||
if options['ppa'].startswith('ppa:'):
|
if options['ppa'].startswith('ppa:'):
|
||||||
params['ppa'] = options['ppa'][4:]
|
params['ppa'] = options['ppa'][4:]
|
||||||
@ -333,16 +346,12 @@ class PullPkg(object):
|
|||||||
|
|
||||||
params['status'] = STATUSES if 'all' in options['status'] else options['status']
|
params['status'] = STATUSES if 'all' in options['status'] else options['status']
|
||||||
|
|
||||||
return (pull, distro, params)
|
return params
|
||||||
|
|
||||||
def pull(self, args=None):
|
def pull(self, args=sys.argv[1:]):
|
||||||
"""Pull (download) specified package file(s)"""
|
"""Pull (download) specified package file(s)"""
|
||||||
# pull-ppa-* may need conversion from ppa:USER/NAME to --ppa USER/NAME
|
options = self.parse_args(args)
|
||||||
args = self.parse_ppa_args(args)
|
|
||||||
|
|
||||||
options = vars(self.argparser.parse_args(args))
|
|
||||||
|
|
||||||
assert 'verbose' in options
|
|
||||||
if options['verbose']:
|
if options['verbose']:
|
||||||
Logger.setLevel(logging.DEBUG)
|
Logger.setLevel(logging.DEBUG)
|
||||||
if options['verbose'] > 1:
|
if options['verbose'] > 1:
|
||||||
@ -353,7 +362,11 @@ class PullPkg(object):
|
|||||||
# Login anonymously to LP
|
# Login anonymously to LP
|
||||||
Launchpad.login_anonymously()
|
Launchpad.login_anonymously()
|
||||||
|
|
||||||
(pull, distro, params) = self.parse_options(options)
|
pull = options['pull']
|
||||||
|
distro = options['distro']
|
||||||
|
|
||||||
|
params = self._get_params(options)
|
||||||
|
package = params['package']
|
||||||
|
|
||||||
# call implementation, and allow exceptions to flow up to caller
|
# call implementation, and allow exceptions to flow up to caller
|
||||||
srcpkg = DISTRO_PKG_CLASS[distro](**params)
|
srcpkg = DISTRO_PKG_CLASS[distro](**params)
|
||||||
@ -377,11 +390,11 @@ class PullPkg(object):
|
|||||||
srcpkg.unpack()
|
srcpkg.unpack()
|
||||||
else:
|
else:
|
||||||
name = '.*'
|
name = '.*'
|
||||||
if params['package'] != spph.getPackageName():
|
if package != spph.getPackageName():
|
||||||
Logger.info("Pulling only binary package '%s'", params['package'])
|
Logger.info("Pulling only binary package '%s'", package)
|
||||||
Logger.info("Use package name '%s' to pull all binary packages",
|
Logger.info("Use package name '%s' to pull all binary packages",
|
||||||
spph.getPackageName())
|
spph.getPackageName())
|
||||||
name = params['package']
|
name = package
|
||||||
if pull == PULL_DEBS:
|
if pull == PULL_DEBS:
|
||||||
name = r'{}(?<!-di)(?<!-dbgsym)$'.format(name)
|
name = r'{}(?<!-di)(?<!-dbgsym)$'.format(name)
|
||||||
elif pull == PULL_DDEBS:
|
elif pull == PULL_DDEBS:
|
||||||
@ -395,4 +408,4 @@ class PullPkg(object):
|
|||||||
total = srcpkg.pull_binaries(name=name, arch=options['arch'])
|
total = srcpkg.pull_binaries(name=name, arch=options['arch'])
|
||||||
if total < 1:
|
if total < 1:
|
||||||
Logger.error("No %s found for %s %s", pull,
|
Logger.error("No %s found for %s %s", pull,
|
||||||
params['package'], spph.getVersion())
|
package, spph.getVersion())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user