Coverage for appr/commands/list_package.py: 32%

# Coverage for appr/commands/list_package.py : 32%

## 41 statements 13 run 28 missing 0 excluded

Hot-keys on this page

r m x p toggle line displays

j k next/prev highlighted chunk

0 (zero) top of page

1 (one) first highlighted chunk

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 | from __future__ import absolute_import, division, print_function import os from appr.commands.command_base import CommandBase from appr.display import print_packages class ListPackageCmd(CommandBase): name = 'list' help_message = "list packages" default_media_type = None def __init__(self, options): super(ListPackageCmd, self).__init__(options) self.registry_host = options.registry_host self.user = options.user self.organization = options.organization self.query = options.search self.media_type = options.media_type if options.media_type is None: self.media_type = os.getenv("APPR_DEFAULT_MEDIA_TYPE", None) self.result = None self.ssl_verify = options.cacert or not options.insecure @classmethod def _add_arguments(cls, parser): cls._add_registryhost_arg(parser) cls._add_mediatype_option(parser, default=cls.default_media_type, required=False) parser.add_argument("-u", "--user", default=None, help="list packages owned by USER") parser.add_argument("-o", "--organization", default=None, help="list ORGANIZATION packages") parser.add_argument("-s", "--search", default=None, help="search query") def _call(self): client = self.RegistryClient(self.registry_host, requests_verify=self.ssl_verify) params = {} if self.user: params['username'] = self.user if self.organization: params["namespace"] = self.organization if self.query: params['query'] = self.query if self.media_type: params['media_type'] = self.media_type self.result = client.list_packages(params) def _render_dict(self): return self.result def _render_console(self): return print_packages(self.result, registry_host=self.registry_host)