Coverage for appr/commands/inspect.py: 29%

# Coverage for appr/commands/inspect.py : 29%

## 41 statements 12 run 29 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 53 | from __future__ import absolute_import, division, print_function import os from appr.commands.command_base import CommandBase from appr.pack import ApprPackage class InspectCmd(CommandBase): name = 'inspect' help_message = "Browse package files" def __init__(self, options): super(InspectCmd, self).__init__(options) self.package = options.package self.registry_host = options.registry_host self.version = options.version self.version_parts = options.version_parts self.file = options.file self.tree = options.tree self.media_type = options.media_type if options.media_type is self.default_media_type: self.media_type = os.getenv("APPR_DEFAULT_MEDIA_TYPE", self.default_media_type) self.result = None self.format = options.media_type self.ssl_verify = options.cacert or not options.insecure @classmethod def _add_arguments(cls, parser): cls._add_registryhost_option(parser) cls._add_mediatype_option(parser, required=True) cls._add_packagename_option(parser) cls._add_packageversion_option(parser) parser.add_argument('--tree', help="List files inside the package", action='store_true', default=True) parser.add_argument('-f', '--file', help="Display a file", default=None) def _call(self): client = self.RegistryClient(self.registry_host, requests_verify=self.ssl_verify) result = client.pull(self.package, version_parts=self.version_parts, media_type=self.media_type) package = ApprPackage(result, b64_encoded=False) if self.file: self.result = package.file(self.file) elif self.tree: self.result = "\n".join(package.tree()) else: self.result = package.manifest def _render_dict(self): return {"inspect": self.package, "output": self.result} def _render_console(self): return self.result