src/client.py
author Bart Smaalders <Bart.Smaalders@Sun.COM>
Fri, 10 Oct 2008 22:15:14 -0700
changeset 584 22bc748edce6
parent 583 fc856572d86e
child 594 b072bc027c54
permissions -rwxr-xr-x
577 need service action for smf(5) manifests 578 need restart action or equivalent to poke smf(5) services
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
409
713e20963dc2 2314 shebang lines should use minimum python version
Shawn Walker <swalker@opensolaris.org>
parents: 393
diff changeset
     1
#!/usr/bin/python2.4
1
3f1f244aa967 begin adding design/implementation documents
sch@rosseau
parents: 0
diff changeset
     2
#
3f1f244aa967 begin adding design/implementation documents
sch@rosseau
parents: 0
diff changeset
     3
# CDDL HEADER START
3f1f244aa967 begin adding design/implementation documents
sch@rosseau
parents: 0
diff changeset
     4
#
3f1f244aa967 begin adding design/implementation documents
sch@rosseau
parents: 0
diff changeset
     5
# The contents of this file are subject to the terms of the
3f1f244aa967 begin adding design/implementation documents
sch@rosseau
parents: 0
diff changeset
     6
# Common Development and Distribution License (the "License").
3f1f244aa967 begin adding design/implementation documents
sch@rosseau
parents: 0
diff changeset
     7
# You may not use this file except in compliance with the License.
3f1f244aa967 begin adding design/implementation documents
sch@rosseau
parents: 0
diff changeset
     8
#
3f1f244aa967 begin adding design/implementation documents
sch@rosseau
parents: 0
diff changeset
     9
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
3f1f244aa967 begin adding design/implementation documents
sch@rosseau
parents: 0
diff changeset
    10
# or http://www.opensolaris.org/os/licensing.
3f1f244aa967 begin adding design/implementation documents
sch@rosseau
parents: 0
diff changeset
    11
# See the License for the specific language governing permissions
3f1f244aa967 begin adding design/implementation documents
sch@rosseau
parents: 0
diff changeset
    12
# and limitations under the License.
3f1f244aa967 begin adding design/implementation documents
sch@rosseau
parents: 0
diff changeset
    13
#
3f1f244aa967 begin adding design/implementation documents
sch@rosseau
parents: 0
diff changeset
    14
# When distributing Covered Code, include this CDDL HEADER in each
3f1f244aa967 begin adding design/implementation documents
sch@rosseau
parents: 0
diff changeset
    15
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
3f1f244aa967 begin adding design/implementation documents
sch@rosseau
parents: 0
diff changeset
    16
# If applicable, add the following below this CDDL HEADER, with the
3f1f244aa967 begin adding design/implementation documents
sch@rosseau
parents: 0
diff changeset
    17
# fields enclosed by brackets "[]" replaced with your own identifying
3f1f244aa967 begin adding design/implementation documents
sch@rosseau
parents: 0
diff changeset
    18
# information: Portions Copyright [yyyy] [name of copyright owner]
3f1f244aa967 begin adding design/implementation documents
sch@rosseau
parents: 0
diff changeset
    19
#
3f1f244aa967 begin adding design/implementation documents
sch@rosseau
parents: 0
diff changeset
    20
# CDDL HEADER END
3f1f244aa967 begin adding design/implementation documents
sch@rosseau
parents: 0
diff changeset
    21
#
221
e1dbb27a23b5 52 catalog can leave inventory behind, making pkg(1) blind
Stephen Hahn <sch@Sun.COM>
parents: 219
diff changeset
    22
# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
1
3f1f244aa967 begin adding design/implementation documents
sch@rosseau
parents: 0
diff changeset
    23
# Use is subject to license terms.
3f1f244aa967 begin adding design/implementation documents
sch@rosseau
parents: 0
diff changeset
    24
#
22
379f0f6809ff pkgsend open, pkgsend add file, pkgsend close; Transaction object
"Stephen Hahn <sch@sun.com>"
parents: 14
diff changeset
    25
# pkg - package system client utility
379f0f6809ff pkgsend open, pkgsend add file, pkgsend close; Transaction object
"Stephen Hahn <sch@sun.com>"
parents: 14
diff changeset
    26
#
0
f08899079fb4 implemented open, add (file case), close for transactions
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    27
# We use urllib2 for GET and POST operations, but httplib for PUT and DELETE
f08899079fb4 implemented open, add (file case), close for transactions
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    28
# operations.
221
e1dbb27a23b5 52 catalog can leave inventory behind, making pkg(1) blind
Stephen Hahn <sch@Sun.COM>
parents: 219
diff changeset
    29
#
539
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
    30
# The client is going to maintain an on-disk cache of its state, so that
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
    31
# startup assembly of the graph is reduced.
221
e1dbb27a23b5 52 catalog can leave inventory behind, making pkg(1) blind
Stephen Hahn <sch@Sun.COM>
parents: 219
diff changeset
    32
#
14
969c85e852af start pkg graph management, annotate pkgsend with server states
"Stephen Hahn <sch@sun.com>"
parents: 3
diff changeset
    33
# Client graph is of the entire local catalog.  As operations progress, package
969c85e852af start pkg graph management, annotate pkgsend with server states
"Stephen Hahn <sch@sun.com>"
parents: 3
diff changeset
    34
# states will change.
221
e1dbb27a23b5 52 catalog can leave inventory behind, making pkg(1) blind
Stephen Hahn <sch@Sun.COM>
parents: 219
diff changeset
    35
#
14
969c85e852af start pkg graph management, annotate pkgsend with server states
"Stephen Hahn <sch@sun.com>"
parents: 3
diff changeset
    36
# Deduction operation allows the compilation of the local component of the
969c85e852af start pkg graph management, annotate pkgsend with server states
"Stephen Hahn <sch@sun.com>"
parents: 3
diff changeset
    37
# catalog, only if an authoritative repository can identify critical files.
22
379f0f6809ff pkgsend open, pkgsend add file, pkgsend close; Transaction object
"Stephen Hahn <sch@sun.com>"
parents: 14
diff changeset
    38
#
379f0f6809ff pkgsend open, pkgsend add file, pkgsend close; Transaction object
"Stephen Hahn <sch@sun.com>"
parents: 14
diff changeset
    39
# Environment variables
379f0f6809ff pkgsend open, pkgsend add file, pkgsend close; Transaction object
"Stephen Hahn <sch@sun.com>"
parents: 14
diff changeset
    40
#
379f0f6809ff pkgsend open, pkgsend add file, pkgsend close; Transaction object
"Stephen Hahn <sch@sun.com>"
parents: 14
diff changeset
    41
# PKG_IMAGE - root path of target image
379f0f6809ff pkgsend open, pkgsend add file, pkgsend close; Transaction object
"Stephen Hahn <sch@sun.com>"
parents: 14
diff changeset
    42
# PKG_IMAGE_TYPE [entire, partial, user] - type of image
379f0f6809ff pkgsend open, pkgsend add file, pkgsend close; Transaction object
"Stephen Hahn <sch@sun.com>"
parents: 14
diff changeset
    43
#       XXX or is this in the Image configuration?
14
969c85e852af start pkg graph management, annotate pkgsend with server states
"Stephen Hahn <sch@sun.com>"
parents: 3
diff changeset
    44
0
f08899079fb4 implemented open, add (file case), close for transactions
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    45
import getopt
116
9c9942a52984 (image flag day) remove pkg catalog, improve pkg status, localize pkg(1), use
Stephen Hahn <sch@Sun.COM>
parents: 111
diff changeset
    46
import gettext
204
8f650d596aec 72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents: 201
diff changeset
    47
import itertools
0
f08899079fb4 implemented open, add (file case), close for transactions
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    48
import os
391
23ec5f7ee0d3 2245 client - pylint cleanup needed
Shawn Walker <swalker@opensolaris.org>
parents: 388
diff changeset
    49
import socket
0
f08899079fb4 implemented open, add (file case), close for transactions
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    50
import sys
192
0c6f1066777b 58 getopt handling needs cleanup
Dan Price <dp@eng.sun.com>
parents: 177
diff changeset
    51
import traceback
0
f08899079fb4 implemented open, add (file case), close for transactions
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    52
import urllib2
f08899079fb4 implemented open, add (file case), close for transactions
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    53
import urlparse
479
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 461
diff changeset
    54
import datetime
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 461
diff changeset
    55
import time
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 461
diff changeset
    56
import calendar
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 461
diff changeset
    57
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 461
diff changeset
    58
import OpenSSL.crypto
0
f08899079fb4 implemented open, add (file case), close for transactions
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    59
576
6ee6de304041 3777 PKG_TIMEOUT_MAX is a placebo setting
Dan Price <dp@eng.sun.com>
parents: 575
diff changeset
    60
from pkg.client import global_settings
583
fc856572d86e 388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents: 582
diff changeset
    61
import pkg.client.bootenv as bootenv
26
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
    62
import pkg.client.image as image
119
537d69114be4 Implement bundled file downloads using filelist
johansen <johansen@sun.com>
parents: 116
diff changeset
    63
import pkg.client.filelist as filelist
235
61994d15c39b 373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents: 227
diff changeset
    64
import pkg.client.progress as progress
539
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
    65
import pkg.client.history as history
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
    66
import pkg.client.api as api
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
    67
import pkg.client.api_errors as api_errors
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 427
diff changeset
    68
import pkg.search_errors as search_errors
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
    69
import pkg.fmri as fmri
327
6c6bd07efe8d 1031 authority prefix needs validation
johansen <johansen@sun.com>
parents: 326
diff changeset
    70
import pkg.misc as misc
391
23ec5f7ee0d3 2245 client - pylint cleanup needed
Shawn Walker <swalker@opensolaris.org>
parents: 388
diff changeset
    71
from pkg.misc import msg, emsg, PipeError
361
5aca6ca29a5d 1612 pkg contents doesn't give me the manifest I asked for
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 344
diff changeset
    72
import pkg.version
551
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 542
diff changeset
    73
import pkg.Uuid25
362
d974bb176266 1341 pkg(1) - pkg contents example#3 doesn't work and "pkg verify" synopsis does not match subcommand description
Danek Duvall <danek.duvall@sun.com>
parents: 361
diff changeset
    74
import pkg
584
22bc748edce6 577 need service action for smf(5) manifests
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 583
diff changeset
    75
from pkg.client.debugvalues import DebugValues
26
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
    76
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
    77
from pkg.client.history import RESULT_FAILED_UNKNOWN
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
    78
from pkg.client.history import RESULT_CANCELED
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
    79
from pkg.client.history import RESULT_FAILED_TRANSPORT
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
    80
from pkg.client.history import RESULT_SUCCEEDED
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
    81
from pkg.client.history import RESULT_FAILED_SEARCH
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
    82
from pkg.client.history import RESULT_FAILED_STORAGE
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
    83
from pkg.client.retrieve import ManifestRetrievalError
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
    84
from pkg.client.retrieve import DatastreamRetrievalError
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
    85
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
    86
CLIENT_API_VERSION = 0
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
    87
PKG_CLIENT_NAME = "pkg"
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
    88
391
23ec5f7ee0d3 2245 client - pylint cleanup needed
Shawn Walker <swalker@opensolaris.org>
parents: 388
diff changeset
    89
def error(text):
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 427
diff changeset
    90
        """Emit an error message prefixed by the command name """
384
9d4746e5dd3e 115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents: 362
diff changeset
    91
526
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 523
diff changeset
    92
        # If we get passed something like an Exception, we can convert it
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 523
diff changeset
    93
        # down to a string.
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 523
diff changeset
    94
        text = str(text)
497
534694fcd5b7 2678 Toplevel traceback handler should emit pkg version id
Danek Duvall <danek.duvall@sun.com>
parents: 496
diff changeset
    95
        # If the message starts with whitespace, assume that it should come
534694fcd5b7 2678 Toplevel traceback handler should emit pkg version id
Danek Duvall <danek.duvall@sun.com>
parents: 496
diff changeset
    96
        # *before* the command-name prefix.
534694fcd5b7 2678 Toplevel traceback handler should emit pkg version id
Danek Duvall <danek.duvall@sun.com>
parents: 496
diff changeset
    97
        text_nows = text.lstrip()
534694fcd5b7 2678 Toplevel traceback handler should emit pkg version id
Danek Duvall <danek.duvall@sun.com>
parents: 496
diff changeset
    98
        ws = text[:len(text) - len(text_nows)]
534694fcd5b7 2678 Toplevel traceback handler should emit pkg version id
Danek Duvall <danek.duvall@sun.com>
parents: 496
diff changeset
    99
384
9d4746e5dd3e 115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents: 362
diff changeset
   100
        # This has to be a constant value as we can't reliably get our actual
9d4746e5dd3e 115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents: 362
diff changeset
   101
        # program name on all platforms.
497
534694fcd5b7 2678 Toplevel traceback handler should emit pkg version id
Danek Duvall <danek.duvall@sun.com>
parents: 496
diff changeset
   102
        emsg(ws + "pkg: " + text_nows)
384
9d4746e5dd3e 115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents: 362
diff changeset
   103
301
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
   104
def usage(usage_error = None):
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 427
diff changeset
   105
        """Emit a usage message and optionally prefix it with a more
301
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
   106
            specific error message.  Causes program to exit. """
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
   107
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
   108
        if usage_error:
384
9d4746e5dd3e 115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents: 362
diff changeset
   109
                error(usage_error)
301
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
   110
384
9d4746e5dd3e 115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents: 362
diff changeset
   111
        emsg(_("""\
0
f08899079fb4 implemented open, add (file case), close for transactions
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
   112
Usage:
f08899079fb4 implemented open, add (file case), close for transactions
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
   113
        pkg [options] command [cmd_options] [operands]
f08899079fb4 implemented open, add (file case), close for transactions
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
   114
301
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
   115
Basic subcommands:
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
   116
        pkg install [-nvq] package...
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
   117
        pkg uninstall [-nrvq] package...
575
09bfbff29dc0 1929 pkg list should give an option to display only current latest package
Brock Pytlik <bpytlik@sun.com>
parents: 569
diff changeset
   118
        pkg list [-aHsuvf] [package...]
301
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
   119
        pkg image-update [-nvq]
215
c10719939c6d 245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents: 205
diff changeset
   120
        pkg refresh [--full]
362
d974bb176266 1341 pkg(1) - pkg contents example#3 doesn't work and "pkg verify" synopsis does not match subcommand description
Danek Duvall <danek.duvall@sun.com>
parents: 361
diff changeset
   121
        pkg version
d974bb176266 1341 pkg(1) - pkg contents example#3 doesn't work and "pkg verify" synopsis does not match subcommand description
Danek Duvall <danek.duvall@sun.com>
parents: 361
diff changeset
   122
        pkg help
162
275856fd67a7 Implement simple 'info' and 'list' subcommands.
Danek Duvall <danek.duvall@sun.com>
parents: 161
diff changeset
   123
301
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
   124
Advanced subcommands:
342
5e1f4d8429bf 669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
   125
        pkg info [-lr] [--license] [pkg_fmri_pattern ...]
499
ff214b0daeb1 2672 Search should allow for case insensitive search.
Brock Pytlik <bpytlik@sun.com>
parents: 497
diff changeset
   126
        pkg search [-lrI] [-s server] token
235
61994d15c39b 373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents: 227
diff changeset
   127
        pkg verify [-fHqv] [pkg_fmri_pattern ...]
583
fc856572d86e 388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents: 582
diff changeset
   128
        pkg fix [pkg_fmri_pattern ...]
342
5e1f4d8429bf 669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
   129
        pkg contents [-Hmr] [-o attribute ...] [-s sort_key] [-t action_type ... ]
301
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
   130
            pkg_fmri_pattern [...]
582
303fa3b78f93 3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents: 576
diff changeset
   131
        pkg image-create [-fFPUz] [--force] [--full|--partial|--user] [--zone]
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
   132
            [-k ssl_key] [-c ssl_cert] -a <prefix>=<url> dir
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
   133
551
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 542
diff changeset
   134
        pkg set-property propname propvalue
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 542
diff changeset
   135
        pkg unset-property propname ...
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 542
diff changeset
   136
        pkg property [-H] [propname ...]
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 542
diff changeset
   137
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 542
diff changeset
   138
        pkg set-authority [-P] [-k ssl_key] [-c ssl_cert] [--reset-uuid]
461
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 443
diff changeset
   139
            [-O origin_url] [-m mirror to add | --add-mirror=mirror to add]
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 443
diff changeset
   140
            [-M mirror to remove | --remove-mirror=mirror to remove] authority
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
   141
        pkg unset-authority authority ...
410
403886a7592b 1259 Need CLI option to retrieve preferred authority
Shawn Walker <swalker@opensolaris.org>
parents: 409
diff changeset
   142
        pkg authority [-HP] [authname]
539
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
   143
        pkg history [-Hl]
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
   144
        pkg purge-history
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 427
diff changeset
   145
        pkg rebuild-index
26
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   146
0
f08899079fb4 implemented open, add (file case), close for transactions
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
   147
Options:
362
d974bb176266 1341 pkg(1) - pkg contents example#3 doesn't work and "pkg verify" synopsis does not match subcommand description
Danek Duvall <danek.duvall@sun.com>
parents: 361
diff changeset
   148
        -R dir
584
22bc748edce6 577 need service action for smf(5) manifests
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 583
diff changeset
   149
        -D/--debug name=value
0
f08899079fb4 implemented open, add (file case), close for transactions
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
   150
f08899079fb4 implemented open, add (file case), close for transactions
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
   151
Environment:
384
9d4746e5dd3e 115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents: 362
diff changeset
   152
        PKG_IMAGE"""))
0
f08899079fb4 implemented open, add (file case), close for transactions
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
   153
        sys.exit(2)
f08899079fb4 implemented open, add (file case), close for transactions
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
   154
104
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 103
diff changeset
   155
# XXX Subcommands to implement:
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 103
diff changeset
   156
#        pkg image-set name value
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 103
diff changeset
   157
#        pkg image-unset name
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 103
diff changeset
   158
#        pkg image-get [name ...]
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 103
diff changeset
   159
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 427
diff changeset
   160
INCONSISTENT_INDEX_ERROR_MESSAGE = "The search index appears corrupted.  " + \
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 427
diff changeset
   161
    "Please rebuild the index with 'pkg rebuild-index'."
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 427
diff changeset
   162
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 427
diff changeset
   163
PROBLEMATIC_PERMISSIONS_ERROR_MESSAGE = " (Failure of consistent use " + \
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 427
diff changeset
   164
    "of pfexec when running pkg commands is often a source of this problem.)"
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 427
diff changeset
   165
526
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 523
diff changeset
   166
def check_fmri_args(args):
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 523
diff changeset
   167
        """ Convenience routine to check that input args are valid fmris. """
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 523
diff changeset
   168
        ret = True
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 523
diff changeset
   169
        for x in args:
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 523
diff changeset
   170
                try:
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 523
diff changeset
   171
                        #
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 523
diff changeset
   172
                        # Pass a bogus build release-- needed to satisfy
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 523
diff changeset
   173
                        # fmri's checks in the common case that a version but
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 523
diff changeset
   174
                        # no build release was specified by the user.
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 523
diff changeset
   175
                        #
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 523
diff changeset
   176
                        fmri.MatchingPkgFmri(x, build_release="1.0")
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 523
diff changeset
   177
                except fmri.IllegalFmri, e:
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 523
diff changeset
   178
                        error(e)
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 523
diff changeset
   179
                        ret = False
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 523
diff changeset
   180
        return ret
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 523
diff changeset
   181
301
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
   182
def list_inventory(img, args):
219
f303ff108edd 60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents: 217
diff changeset
   183
        all_known = False
221
e1dbb27a23b5 52 catalog can leave inventory behind, making pkg(1) blind
Stephen Hahn <sch@Sun.COM>
parents: 219
diff changeset
   184
        display_headers = True
219
f303ff108edd 60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents: 217
diff changeset
   185
        upgradable_only = False
221
e1dbb27a23b5 52 catalog can leave inventory behind, making pkg(1) blind
Stephen Hahn <sch@Sun.COM>
parents: 219
diff changeset
   186
        verbose = False
301
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
   187
        summary = False
575
09bfbff29dc0 1929 pkg list should give an option to display only current latest package
Brock Pytlik <bpytlik@sun.com>
parents: 569
diff changeset
   188
        all_versions = True
221
e1dbb27a23b5 52 catalog can leave inventory behind, making pkg(1) blind
Stephen Hahn <sch@Sun.COM>
parents: 219
diff changeset
   189
575
09bfbff29dc0 1929 pkg list should give an option to display only current latest package
Brock Pytlik <bpytlik@sun.com>
parents: 569
diff changeset
   190
        opts, pargs = getopt.getopt(args, "aHsuvf")
219
f303ff108edd 60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents: 217
diff changeset
   191
f303ff108edd 60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents: 217
diff changeset
   192
        for opt, arg in opts:
f303ff108edd 60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents: 217
diff changeset
   193
                if opt == "-a":
f303ff108edd 60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents: 217
diff changeset
   194
                        all_known = True
221
e1dbb27a23b5 52 catalog can leave inventory behind, making pkg(1) blind
Stephen Hahn <sch@Sun.COM>
parents: 219
diff changeset
   195
                elif opt == "-H":
e1dbb27a23b5 52 catalog can leave inventory behind, making pkg(1) blind
Stephen Hahn <sch@Sun.COM>
parents: 219
diff changeset
   196
                        display_headers = False
301
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
   197
                elif opt == "-s":
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
   198
                        summary = True
219
f303ff108edd 60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents: 217
diff changeset
   199
                elif opt == "-u":
f303ff108edd 60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents: 217
diff changeset
   200
                        upgradable_only = True
f303ff108edd 60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents: 217
diff changeset
   201
                elif opt == "-v":
f303ff108edd 60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents: 217
diff changeset
   202
                        verbose = True
575
09bfbff29dc0 1929 pkg list should give an option to display only current latest package
Brock Pytlik <bpytlik@sun.com>
parents: 569
diff changeset
   203
                elif opt == "-f":
09bfbff29dc0 1929 pkg list should give an option to display only current latest package
Brock Pytlik <bpytlik@sun.com>
parents: 569
diff changeset
   204
                        all_versions = False
219
f303ff108edd 60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents: 217
diff changeset
   205
301
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
   206
        if summary and verbose:
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 427
diff changeset
   207
                usage(_("-s and -v may not be combined"))
301
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
   208
219
f303ff108edd 60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents: 217
diff changeset
   209
        if verbose:
301
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
   210
                fmt_str = "%-64s %-10s %s"
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
   211
        elif summary:
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
   212
                fmt_str = "%-30s %s"
219
f303ff108edd 60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents: 217
diff changeset
   213
        else:
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 306
diff changeset
   214
                fmt_str = "%-45s %-15s %-10s %s"
219
f303ff108edd 60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents: 217
diff changeset
   215
526
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 523
diff changeset
   216
        if not check_fmri_args(pargs):
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 523
diff changeset
   217
                return 1
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 523
diff changeset
   218
556
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 551
diff changeset
   219
        img.history.operation_name = "list"
301
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
   220
        img.load_catalogs(progress.NullProgressTracker())
219
f303ff108edd 60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents: 217
diff changeset
   221
526
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 523
diff changeset
   222
        seen_one_pkg = False
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 523
diff changeset
   223
        found = False
219
f303ff108edd 60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents: 217
diff changeset
   224
        try:
575
09bfbff29dc0 1929 pkg list should give an option to display only current latest package
Brock Pytlik <bpytlik@sun.com>
parents: 569
diff changeset
   225
                most_recent = {}
09bfbff29dc0 1929 pkg list should give an option to display only current latest package
Brock Pytlik <bpytlik@sun.com>
parents: 569
diff changeset
   226
                installed = []
09bfbff29dc0 1929 pkg list should give an option to display only current latest package
Brock Pytlik <bpytlik@sun.com>
parents: 569
diff changeset
   227
                res = img.inventory(pargs, all_known)
09bfbff29dc0 1929 pkg list should give an option to display only current latest package
Brock Pytlik <bpytlik@sun.com>
parents: 569
diff changeset
   228
                # All_Versions reduces the output so that only the most recent
09bfbff29dc0 1929 pkg list should give an option to display only current latest package
Brock Pytlik <bpytlik@sun.com>
parents: 569
diff changeset
   229
                # version and installed version of packages appear.
09bfbff29dc0 1929 pkg list should give an option to display only current latest package
Brock Pytlik <bpytlik@sun.com>
parents: 569
diff changeset
   230
                if all_versions:
09bfbff29dc0 1929 pkg list should give an option to display only current latest package
Brock Pytlik <bpytlik@sun.com>
parents: 569
diff changeset
   231
                        for pfmri, state in res:
09bfbff29dc0 1929 pkg list should give an option to display only current latest package
Brock Pytlik <bpytlik@sun.com>
parents: 569
diff changeset
   232
                                if state["state"] == "installed":
09bfbff29dc0 1929 pkg list should give an option to display only current latest package
Brock Pytlik <bpytlik@sun.com>
parents: 569
diff changeset
   233
                                        installed.append((pfmri, state))
09bfbff29dc0 1929 pkg list should give an option to display only current latest package
Brock Pytlik <bpytlik@sun.com>
parents: 569
diff changeset
   234
                                hv = pfmri.get_pkg_stem(include_pkg=False)
09bfbff29dc0 1929 pkg list should give an option to display only current latest package
Brock Pytlik <bpytlik@sun.com>
parents: 569
diff changeset
   235
                                if hv in most_recent:
09bfbff29dc0 1929 pkg list should give an option to display only current latest package
Brock Pytlik <bpytlik@sun.com>
parents: 569
diff changeset
   236
                                        stored_pfmri, stored_state = \
09bfbff29dc0 1929 pkg list should give an option to display only current latest package
Brock Pytlik <bpytlik@sun.com>
parents: 569
diff changeset
   237
                                            most_recent[hv]
09bfbff29dc0 1929 pkg list should give an option to display only current latest package
Brock Pytlik <bpytlik@sun.com>
parents: 569
diff changeset
   238
                                        if pfmri.is_successor(stored_pfmri):
09bfbff29dc0 1929 pkg list should give an option to display only current latest package
Brock Pytlik <bpytlik@sun.com>
parents: 569
diff changeset
   239
                                                most_recent[hv] = (pfmri, state)
09bfbff29dc0 1929 pkg list should give an option to display only current latest package
Brock Pytlik <bpytlik@sun.com>
parents: 569
diff changeset
   240
                                else:
09bfbff29dc0 1929 pkg list should give an option to display only current latest package
Brock Pytlik <bpytlik@sun.com>
parents: 569
diff changeset
   241
                                        most_recent[hv] = (pfmri, state)
09bfbff29dc0 1929 pkg list should give an option to display only current latest package
Brock Pytlik <bpytlik@sun.com>
parents: 569
diff changeset
   242
                        res = installed + most_recent.values()
09bfbff29dc0 1929 pkg list should give an option to display only current latest package
Brock Pytlik <bpytlik@sun.com>
parents: 569
diff changeset
   243
09bfbff29dc0 1929 pkg list should give an option to display only current latest package
Brock Pytlik <bpytlik@sun.com>
parents: 569
diff changeset
   244
                        # This method is necessary because fmri.__cmp__ does
09bfbff29dc0 1929 pkg list should give an option to display only current latest package
Brock Pytlik <bpytlik@sun.com>
parents: 569
diff changeset
   245
                        # not provide the desired ordering. It uses the same
09bfbff29dc0 1929 pkg list should give an option to display only current latest package
Brock Pytlik <bpytlik@sun.com>
parents: 569
diff changeset
   246
                        # ordering on package names as fmri.__cmp__ but it
09bfbff29dc0 1929 pkg list should give an option to display only current latest package
Brock Pytlik <bpytlik@sun.com>
parents: 569
diff changeset
   247
                        # reverse sorts on version, so that 98 comes before 97.
09bfbff29dc0 1929 pkg list should give an option to display only current latest package
Brock Pytlik <bpytlik@sun.com>
parents: 569
diff changeset
   248
                        # Also, authorities are taken into account so that
09bfbff29dc0 1929 pkg list should give an option to display only current latest package
Brock Pytlik <bpytlik@sun.com>
parents: 569
diff changeset
   249
                        # preferred authorities come before others. Finally,
09bfbff29dc0 1929 pkg list should give an option to display only current latest package
Brock Pytlik <bpytlik@sun.com>
parents: 569
diff changeset
   250
                        # authorties are presented in alphabetical order.
09bfbff29dc0 1929 pkg list should give an option to display only current latest package
Brock Pytlik <bpytlik@sun.com>
parents: 569
diff changeset
   251
                        def __fmri_cmp((f1, s1), (f2, s2)):
09bfbff29dc0 1929 pkg list should give an option to display only current latest package
Brock Pytlik <bpytlik@sun.com>
parents: 569
diff changeset
   252
                                t = cmp(f1.pkg_name, f2.pkg_name)
09bfbff29dc0 1929 pkg list should give an option to display only current latest package
Brock Pytlik <bpytlik@sun.com>
parents: 569
diff changeset
   253
                                if t != 0:
09bfbff29dc0 1929 pkg list should give an option to display only current latest package
Brock Pytlik <bpytlik@sun.com>
parents: 569
diff changeset
   254
                                        return t
09bfbff29dc0 1929 pkg list should give an option to display only current latest package
Brock Pytlik <bpytlik@sun.com>
parents: 569
diff changeset
   255
                                t = cmp(f2, f1)
09bfbff29dc0 1929 pkg list should give an option to display only current latest package
Brock Pytlik <bpytlik@sun.com>
parents: 569
diff changeset
   256
                                if t != 0:
09bfbff29dc0 1929 pkg list should give an option to display only current latest package
Brock Pytlik <bpytlik@sun.com>
parents: 569
diff changeset
   257
                                        return t
09bfbff29dc0 1929 pkg list should give an option to display only current latest package
Brock Pytlik <bpytlik@sun.com>
parents: 569
diff changeset
   258
                                if f1.preferred_authority():
09bfbff29dc0 1929 pkg list should give an option to display only current latest package
Brock Pytlik <bpytlik@sun.com>
parents: 569
diff changeset
   259
                                        return -1
09bfbff29dc0 1929 pkg list should give an option to display only current latest package
Brock Pytlik <bpytlik@sun.com>
parents: 569
diff changeset
   260
                                if f2.preferred_authority():
09bfbff29dc0 1929 pkg list should give an option to display only current latest package
Brock Pytlik <bpytlik@sun.com>
parents: 569
diff changeset
   261
                                        return 1
09bfbff29dc0 1929 pkg list should give an option to display only current latest package
Brock Pytlik <bpytlik@sun.com>
parents: 569
diff changeset
   262
                                return cmp(f1.get_authority(),
09bfbff29dc0 1929 pkg list should give an option to display only current latest package
Brock Pytlik <bpytlik@sun.com>
parents: 569
diff changeset
   263
                                    f2.get_authority())
09bfbff29dc0 1929 pkg list should give an option to display only current latest package
Brock Pytlik <bpytlik@sun.com>
parents: 569
diff changeset
   264
                        
09bfbff29dc0 1929 pkg list should give an option to display only current latest package
Brock Pytlik <bpytlik@sun.com>
parents: 569
diff changeset
   265
                        res.sort(cmp=__fmri_cmp)
09bfbff29dc0 1929 pkg list should give an option to display only current latest package
Brock Pytlik <bpytlik@sun.com>
parents: 569
diff changeset
   266
                prev_pfmri_str = ""
09bfbff29dc0 1929 pkg list should give an option to display only current latest package
Brock Pytlik <bpytlik@sun.com>
parents: 569
diff changeset
   267
                prev_state = None
09bfbff29dc0 1929 pkg list should give an option to display only current latest package
Brock Pytlik <bpytlik@sun.com>
parents: 569
diff changeset
   268
                for pfmri, state in res:
09bfbff29dc0 1929 pkg list should give an option to display only current latest package
Brock Pytlik <bpytlik@sun.com>
parents: 569
diff changeset
   269
                        if all_versions and prev_pfmri_str and \
09bfbff29dc0 1929 pkg list should give an option to display only current latest package
Brock Pytlik <bpytlik@sun.com>
parents: 569
diff changeset
   270
                            prev_pfmri_str == pfmri.get_short_fmri() and \
09bfbff29dc0 1929 pkg list should give an option to display only current latest package
Brock Pytlik <bpytlik@sun.com>
parents: 569
diff changeset
   271
                            prev_state == state:
09bfbff29dc0 1929 pkg list should give an option to display only current latest package
Brock Pytlik <bpytlik@sun.com>
parents: 569
diff changeset
   272
                                continue
09bfbff29dc0 1929 pkg list should give an option to display only current latest package
Brock Pytlik <bpytlik@sun.com>
parents: 569
diff changeset
   273
                        prev_pfmri_str = pfmri.get_short_fmri()
09bfbff29dc0 1929 pkg list should give an option to display only current latest package
Brock Pytlik <bpytlik@sun.com>
parents: 569
diff changeset
   274
                        prev_state = state
526
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 523
diff changeset
   275
                        seen_one_pkg = True
219
f303ff108edd 60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents: 217
diff changeset
   276
                        if upgradable_only and not state["upgradable"]:
f303ff108edd 60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents: 217
diff changeset
   277
                                continue
f303ff108edd 60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents: 217
diff changeset
   278
f303ff108edd 60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents: 217
diff changeset
   279
                        if not found:
221
e1dbb27a23b5 52 catalog can leave inventory behind, making pkg(1) blind
Stephen Hahn <sch@Sun.COM>
parents: 219
diff changeset
   280
                                if display_headers:
301
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
   281
                                        if verbose:
384
9d4746e5dd3e 115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents: 362
diff changeset
   282
                                                msg(fmt_str % \
9d4746e5dd3e 115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents: 362
diff changeset
   283
                                                    ("FMRI", "STATE", "UFIX"))
301
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
   284
                                        elif summary:
384
9d4746e5dd3e 115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents: 362
diff changeset
   285
                                                msg(fmt_str % \
301
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
   286
                                                    ("NAME (AUTHORITY)",
384
9d4746e5dd3e 115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents: 362
diff changeset
   287
                                                    "SUMMARY"))
301
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
   288
                                        else:
384
9d4746e5dd3e 115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents: 362
diff changeset
   289
                                                msg(fmt_str % \
301
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
   290
                                                    ("NAME (AUTHORITY)",
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   291
                                                    "VERSION", "STATE", "UFIX"))
221
e1dbb27a23b5 52 catalog can leave inventory behind, making pkg(1) blind
Stephen Hahn <sch@Sun.COM>
parents: 219
diff changeset
   292
                                found = True
301
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
   293
                        ufix = "%c%c%c%c" % \
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
   294
                            (state["upgradable"] and "u" or "-",
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
   295
                            state["frozen"] and "f" or "-",
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
   296
                            state["incorporated"] and "i" or "-",
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
   297
                            state["excludes"] and "x" or "-")
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
   298
539
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
   299
                        if pfmri.preferred_authority():
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 306
diff changeset
   300
                                auth = ""
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 306
diff changeset
   301
                        else:
539
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
   302
                                auth = " (" + pfmri.get_authority() + ")"
219
f303ff108edd 60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents: 217
diff changeset
   303
301
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
   304
                        if verbose:
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   305
                                pf = pfmri.get_fmri(img.get_default_authority())
384
9d4746e5dd3e 115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents: 362
diff changeset
   306
                                msg("%-64s %-10s %s" % (pf, state["state"],
9d4746e5dd3e 115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents: 362
diff changeset
   307
                                    ufix))
301
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
   308
                        elif summary:
539
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
   309
                                pf = pfmri.get_name() + auth
301
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
   310
539
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
   311
                                m = img.get_manifest(pfmri, filtered=True)
384
9d4746e5dd3e 115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents: 362
diff changeset
   312
                                msg(fmt_str % (pf, m.get("description", "")))
301
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
   313
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
   314
                        else:
539
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
   315
                                pf = pfmri.get_name() + auth
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
   316
                                msg(fmt_str % (pf, pfmri.get_version(),
384
9d4746e5dd3e 115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents: 362
diff changeset
   317
                                    state["state"], ufix))
301
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
   318
219
f303ff108edd 60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents: 217
diff changeset
   319
                if not found:
526
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 523
diff changeset
   320
                        if not seen_one_pkg and not all_known:
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 523
diff changeset
   321
                                emsg(_("no packages installed"))
556
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 551
diff changeset
   322
                                img.history.operation_result = \
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 551
diff changeset
   323
                                    history.RESULT_NOTHING_TO_DO
526
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 523
diff changeset
   324
                                return 1
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 523
diff changeset
   325
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 523
diff changeset
   326
                        if upgradable_only:
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 523
diff changeset
   327
                                if pargs:
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 523
diff changeset
   328
                                        emsg(_("No specified packages have " \
391
23ec5f7ee0d3 2245 client - pylint cleanup needed
Shawn Walker <swalker@opensolaris.org>
parents: 388
diff changeset
   329
                                            "available updates"))
361
5aca6ca29a5d 1612 pkg contents doesn't give me the manifest I asked for
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 344
diff changeset
   330
                                else:
526
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 523
diff changeset
   331
                                        emsg(_("No installed packages have " \
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 523
diff changeset
   332
                                            "available updates"))
556
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 551
diff changeset
   333
                                img.history.operation_result = \
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 551
diff changeset
   334
                                    history.RESULT_NOTHING_TO_DO
526
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 523
diff changeset
   335
                                return 1
556
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 551
diff changeset
   336
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 551
diff changeset
   337
                        img.history.operation_result = \
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 551
diff changeset
   338
                            history.RESULT_NOTHING_TO_DO
221
e1dbb27a23b5 52 catalog can leave inventory behind, making pkg(1) blind
Stephen Hahn <sch@Sun.COM>
parents: 219
diff changeset
   339
                        return 1
556
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 551
diff changeset
   340
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 551
diff changeset
   341
                img.history.operation_result = history.RESULT_SUCCEEDED
219
f303ff108edd 60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents: 217
diff changeset
   342
                return 0
301
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
   343
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   344
        except api_errors.InventoryException, e:
526
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 523
diff changeset
   345
                if e.illegal:
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 523
diff changeset
   346
                        for i in e.illegal:
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 523
diff changeset
   347
                                error(i)
556
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 551
diff changeset
   348
                        img.history.operation_result = \
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 551
diff changeset
   349
                            history.RESULT_FAILED_BAD_REQUEST
219
f303ff108edd 60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents: 217
diff changeset
   350
                        return 1
f303ff108edd 60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents: 217
diff changeset
   351
526
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 523
diff changeset
   352
                if all_known:
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 523
diff changeset
   353
                        state = image.PKG_STATE_KNOWN
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 523
diff changeset
   354
                else:
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 523
diff changeset
   355
                        state = image.PKG_STATE_INSTALLED
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 523
diff changeset
   356
                for pat in e.notfound:
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 417
diff changeset
   357
                        error(_("no packages matching '%s' %s") % (pat, state))
556
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 551
diff changeset
   358
                img.history.operation_result = history.RESULT_NOTHING_TO_DO
219
f303ff108edd 60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents: 217
diff changeset
   359
                return 1
301
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
   360
235
61994d15c39b 373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents: 227
diff changeset
   361
def get_tracker(quiet = False):
61994d15c39b 373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents: 227
diff changeset
   362
        if quiet:
61994d15c39b 373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents: 227
diff changeset
   363
                progresstracker = progress.QuietProgressTracker()
61994d15c39b 373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents: 227
diff changeset
   364
        else:
61994d15c39b 373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents: 227
diff changeset
   365
                try:
236
834909099dab Fancy command line progress was busted (fix for 373)
Dan Price <dp@eng.sun.com>
parents: 235
diff changeset
   366
                        progresstracker = \
251
6c3d70b74865 470 pkg image-update can fail under some conditions
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 243
diff changeset
   367
                            progress.FancyUNIXProgressTracker()
236
834909099dab Fancy command line progress was busted (fix for 373)
Dan Price <dp@eng.sun.com>
parents: 235
diff changeset
   368
                except progress.ProgressTrackerException:
235
61994d15c39b 373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents: 227
diff changeset
   369
                        progresstracker = progress.CommandLineProgressTracker()
61994d15c39b 373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents: 227
diff changeset
   370
        return progresstracker
222
12006bf2a260 4 We need to be able to verify that package(s) is/are correctly installed
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 221
diff changeset
   371
583
fc856572d86e 388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents: 582
diff changeset
   372
def fix_image(img, args):
fc856572d86e 388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents: 582
diff changeset
   373
        progresstracker = get_tracker(False)
fc856572d86e 388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents: 582
diff changeset
   374
        img.load_catalogs(progresstracker)
fc856572d86e 388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents: 582
diff changeset
   375
        fmris, notfound, illegals = img.installed_fmris_from_args(args)
fc856572d86e 388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents: 582
diff changeset
   376
fc856572d86e 388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents: 582
diff changeset
   377
        any_errors = False
fc856572d86e 388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents: 582
diff changeset
   378
        repairs = []
fc856572d86e 388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents: 582
diff changeset
   379
        for f in fmris:
fc856572d86e 388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents: 582
diff changeset
   380
                failed_actions = []
fc856572d86e 388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents: 582
diff changeset
   381
                for err in img.verify(f, progresstracker,
fc856572d86e 388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents: 582
diff changeset
   382
                    verbose=True, forever=True):
fc856572d86e 388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents: 582
diff changeset
   383
                        if not failed_actions:
fc856572d86e 388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents: 582
diff changeset
   384
                                msg("Verifying: %-50s %7s" % 
fc856572d86e 388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents: 582
diff changeset
   385
                                    (f.get_pkg_stem(), "ERROR"))
fc856572d86e 388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents: 582
diff changeset
   386
                        act = err[0]
fc856572d86e 388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents: 582
diff changeset
   387
                        failed_actions.append(act)
fc856572d86e 388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents: 582
diff changeset
   388
                        msg("\t%s" % act.distinguished_name())
fc856572d86e 388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents: 582
diff changeset
   389
                        for x in err[1]:
fc856572d86e 388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents: 582
diff changeset
   390
                                msg("\t\t%s" % x)
fc856572d86e 388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents: 582
diff changeset
   391
                if failed_actions:
fc856572d86e 388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents: 582
diff changeset
   392
                        repairs.append((f, failed_actions))
fc856572d86e 388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents: 582
diff changeset
   393
fc856572d86e 388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents: 582
diff changeset
   394
        # Repair anything we failed to verify
fc856572d86e 388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents: 582
diff changeset
   395
        if repairs:
fc856572d86e 388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents: 582
diff changeset
   396
                # Create a snapshot in case they want to roll back
fc856572d86e 388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents: 582
diff changeset
   397
                try:
fc856572d86e 388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents: 582
diff changeset
   398
                        be = bootenv.BootEnv(img.get_root())
fc856572d86e 388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents: 582
diff changeset
   399
                        msg(_("Created ZFS snapshot: %s" % be.snapshot_name))
fc856572d86e 388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents: 582
diff changeset
   400
                except RuntimeError, e:
fc856572d86e 388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents: 582
diff changeset
   401
                        msg(_("Unable to create ZFS snapshot: %s") % e)
fc856572d86e 388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents: 582
diff changeset
   402
                success = img.repair(repairs, progresstracker)
fc856572d86e 388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents: 582
diff changeset
   403
                if not success:
fc856572d86e 388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents: 582
diff changeset
   404
                        return 1
fc856572d86e 388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents: 582
diff changeset
   405
        return 0
fc856572d86e 388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents: 582
diff changeset
   406
        
235
61994d15c39b 373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents: 227
diff changeset
   407
def verify_image(img, args):
61994d15c39b 373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents: 227
diff changeset
   408
        opts, pargs = getopt.getopt(args, "vfqH")
61994d15c39b 373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents: 227
diff changeset
   409
443
5ffa5b7dac9c 2589 pyc files generate lots of verify chaff
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 442
diff changeset
   410
        quiet = verbose = False
5ffa5b7dac9c 2589 pyc files generate lots of verify chaff
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 442
diff changeset
   411
        # for now, always check contents of files
5ffa5b7dac9c 2589 pyc files generate lots of verify chaff
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 442
diff changeset
   412
        forever = display_headers = True
222
12006bf2a260 4 We need to be able to verify that package(s) is/are correctly installed
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 221
diff changeset
   413
227
faba25c4bce3 368 pkg info -m should display raw manifest
Stephen Hahn <sch@Sun.COM>
parents: 222
diff changeset
   414
        for opt, arg in opts:
235
61994d15c39b 373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents: 227
diff changeset
   415
                if opt == "-H":
61994d15c39b 373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents: 227
diff changeset
   416
                        display_headers = False
227
faba25c4bce3 368 pkg info -m should display raw manifest
Stephen Hahn <sch@Sun.COM>
parents: 222
diff changeset
   417
                if opt == "-v":
faba25c4bce3 368 pkg info -m should display raw manifest
Stephen Hahn <sch@Sun.COM>
parents: 222
diff changeset
   418
                        verbose = True
faba25c4bce3 368 pkg info -m should display raw manifest
Stephen Hahn <sch@Sun.COM>
parents: 222
diff changeset
   419
                elif opt == "-f":
faba25c4bce3 368 pkg info -m should display raw manifest
Stephen Hahn <sch@Sun.COM>
parents: 222
diff changeset
   420
                        forever = True
235
61994d15c39b 373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents: 227
diff changeset
   421
                elif opt == "-q":
61994d15c39b 373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents: 227
diff changeset
   422
                        quiet = True
61994d15c39b 373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents: 227
diff changeset
   423
                        display_headers = False
61994d15c39b 373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents: 227
diff changeset
   424
61994d15c39b 373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents: 227
diff changeset
   425
        if verbose and quiet:
301
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
   426
                usage(_("verify: -v and -q may not be combined"))
235
61994d15c39b 373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents: 227
diff changeset
   427
61994d15c39b 373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents: 227
diff changeset
   428
        progresstracker = get_tracker(quiet)
222
12006bf2a260 4 We need to be able to verify that package(s) is/are correctly installed
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 221
diff changeset
   429
526
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 523
diff changeset
   430
        if not check_fmri_args(pargs):
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 523
diff changeset
   431
                return 1
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 523
diff changeset
   432
266
5e5bff6fedce 582 Importing packages seemingly misrecords dependencies
johansen <johansen@sun.com>
parents: 259
diff changeset
   433
        img.load_catalogs(progresstracker)
5e5bff6fedce 582 Importing packages seemingly misrecords dependencies
johansen <johansen@sun.com>
parents: 259
diff changeset
   434
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   435
        fmris, notfound, illegals = img.installed_fmris_from_args(pargs)
526
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 523
diff changeset
   436
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 523
diff changeset
   437
        if illegals:
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 523
diff changeset
   438
                for i in illegals:
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 523
diff changeset
   439
                        emsg(str(i))
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 523
diff changeset
   440
                return 1
222
12006bf2a260 4 We need to be able to verify that package(s) is/are correctly installed
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 221
diff changeset
   441
227
faba25c4bce3 368 pkg info -m should display raw manifest
Stephen Hahn <sch@Sun.COM>
parents: 222
diff changeset
   442
        any_errors = False
222
12006bf2a260 4 We need to be able to verify that package(s) is/are correctly installed
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 221
diff changeset
   443
235
61994d15c39b 373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents: 227
diff changeset
   444
        header = False
301
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
   445
        for f in fmris:
227
faba25c4bce3 368 pkg info -m should display raw manifest
Stephen Hahn <sch@Sun.COM>
parents: 222
diff changeset
   446
                pkgerr = False
301
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
   447
                for err in img.verify(f, progresstracker,
235
61994d15c39b 373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents: 227
diff changeset
   448
                    verbose=verbose, forever=forever):
61994d15c39b 373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents: 227
diff changeset
   449
                        #
61994d15c39b 373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents: 227
diff changeset
   450
                        # Eventually this code should probably
61994d15c39b 373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents: 227
diff changeset
   451
                        # move into the progresstracker
61994d15c39b 373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents: 227
diff changeset
   452
                        #
227
faba25c4bce3 368 pkg info -m should display raw manifest
Stephen Hahn <sch@Sun.COM>
parents: 222
diff changeset
   453
                        if not pkgerr:
235
61994d15c39b 373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents: 227
diff changeset
   454
                                if display_headers and not header:
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   455
                                        msg("%-50s %7s" % ("PACKAGE", "STATUS"))
235
61994d15c39b 373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents: 227
diff changeset
   456
                                        header = True
61994d15c39b 373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents: 227
diff changeset
   457
61994d15c39b 373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents: 227
diff changeset
   458
                                if not quiet:
391
23ec5f7ee0d3 2245 client - pylint cleanup needed
Shawn Walker <swalker@opensolaris.org>
parents: 388
diff changeset
   459
                                        msg("%-50s %7s" % (f.get_pkg_stem(),
23ec5f7ee0d3 2245 client - pylint cleanup needed
Shawn Walker <swalker@opensolaris.org>
parents: 388
diff changeset
   460
                                            "ERROR"))
227
faba25c4bce3 368 pkg info -m should display raw manifest
Stephen Hahn <sch@Sun.COM>
parents: 222
diff changeset
   461
                                pkgerr = True
235
61994d15c39b 373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents: 227
diff changeset
   462
61994d15c39b 373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents: 227
diff changeset
   463
                        if not quiet:
583
fc856572d86e 388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents: 582
diff changeset
   464
                                msg("\t%s" % err[0].distinguished_name())
301
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
   465
                                for x in err[1]:
384
9d4746e5dd3e 115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents: 362
diff changeset
   466
                                        msg("\t\t%s" % x)
227
faba25c4bce3 368 pkg info -m should display raw manifest
Stephen Hahn <sch@Sun.COM>
parents: 222
diff changeset
   467
                if verbose and not pkgerr:
235
61994d15c39b 373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents: 227
diff changeset
   468
                        if display_headers and not header:
384
9d4746e5dd3e 115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents: 362
diff changeset
   469
                                msg("%-50s %7s" % ("PACKAGE", "STATUS"))
235
61994d15c39b 373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents: 227
diff changeset
   470
                                header = True
384
9d4746e5dd3e 115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents: 362
diff changeset
   471
                        msg("%-50s %7s" % (f.get_pkg_stem(), "OK"))
222
12006bf2a260 4 We need to be able to verify that package(s) is/are correctly installed
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 221
diff changeset
   472
227
faba25c4bce3 368 pkg info -m should display raw manifest
Stephen Hahn <sch@Sun.COM>
parents: 222
diff changeset
   473
                any_errors = any_errors or pkgerr
222
12006bf2a260 4 We need to be able to verify that package(s) is/are correctly installed
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 221
diff changeset
   474
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 417
diff changeset
   475
        if fmris:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 417
diff changeset
   476
                progresstracker.verify_done()
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 417
diff changeset
   477
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 417
diff changeset
   478
        if notfound:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 417
diff changeset
   479
                if fmris:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 417
diff changeset
   480
                        emsg()
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 417
diff changeset
   481
                emsg(_("""\
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 417
diff changeset
   482
pkg: no packages matching the following patterns you specified are
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 417
diff changeset
   483
installed on the system.\n"""))
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 417
diff changeset
   484
                for p in notfound:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 417
diff changeset
   485
                        emsg("        %s" % p)
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 417
diff changeset
   486
                if fmris:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 417
diff changeset
   487
                        if any_errors:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 417
diff changeset
   488
                                msg2 = "See above for\nverification failures."
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 417
diff changeset
   489
                        else:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 417
diff changeset
   490
                                msg2 = "No packages failed\nverification."
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 417
diff changeset
   491
                        emsg(_("\nAll other patterns matched installed "
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 417
diff changeset
   492
                            "packages.  %s" % msg2))
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 417
diff changeset
   493
                any_errors = True
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 417
diff changeset
   494
227
faba25c4bce3 368 pkg info -m should display raw manifest
Stephen Hahn <sch@Sun.COM>
parents: 222
diff changeset
   495
        if any_errors:
faba25c4bce3 368 pkg info -m should display raw manifest
Stephen Hahn <sch@Sun.COM>
parents: 222
diff changeset
   496
                return 1
faba25c4bce3 368 pkg info -m should display raw manifest
Stephen Hahn <sch@Sun.COM>
parents: 222
diff changeset
   497
        return 0
222
12006bf2a260 4 We need to be able to verify that package(s) is/are correctly installed
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 221
diff changeset
   498
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   499
def image_update(img_dir, args):
172
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 165
diff changeset
   500
        """Attempt to take all installed packages specified to latest
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 165
diff changeset
   501
        version."""
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 165
diff changeset
   502
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 165
diff changeset
   503
        # XXX Authority-catalog issues.
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 165
diff changeset
   504
        # XXX Are filters appropriate for an image update?
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 165
diff changeset
   505
        # XXX Leaf package refinements.
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 165
diff changeset
   506
537
3dc9fc9b5fee 1540 changes to authorities should include refresh
Brock Pytlik <bpytlik@sun.com>
parents: 526
diff changeset
   507
        opts, pargs = getopt.getopt(args, "b:fnvq", ["no-refresh"])
172
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 165
diff changeset
   508
442
01fb28d438b3 2418 'pkg version', 'pkg image-update' should error on additional arguments
Dan Price <dp@eng.sun.com>
parents: 432
diff changeset
   509
        force = quiet = noexecute = verbose = False
537
3dc9fc9b5fee 1540 changes to authorities should include refresh
Brock Pytlik <bpytlik@sun.com>
parents: 526
diff changeset
   510
        refresh_catalogs = True
172
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 165
diff changeset
   511
        for opt, arg in opts:
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 165
diff changeset
   512
                if opt == "-n":
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 165
diff changeset
   513
                        noexecute = True
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 165
diff changeset
   514
                elif opt == "-v":
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 165
diff changeset
   515
                        verbose = True
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 165
diff changeset
   516
                elif opt == "-b":
235
61994d15c39b 373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents: 227
diff changeset
   517
                        filelist.FileList.maxbytes_default = int(arg)
61994d15c39b 373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents: 227
diff changeset
   518
                elif opt == "-q":
61994d15c39b 373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents: 227
diff changeset
   519
                        quiet = True
442
01fb28d438b3 2418 'pkg version', 'pkg image-update' should error on additional arguments
Dan Price <dp@eng.sun.com>
parents: 432
diff changeset
   520
                elif opt == "-f":
01fb28d438b3 2418 'pkg version', 'pkg image-update' should error on additional arguments
Dan Price <dp@eng.sun.com>
parents: 432
diff changeset
   521
                        force = True
537
3dc9fc9b5fee 1540 changes to authorities should include refresh
Brock Pytlik <bpytlik@sun.com>
parents: 526
diff changeset
   522
                elif opt == "--no-refresh":
3dc9fc9b5fee 1540 changes to authorities should include refresh
Brock Pytlik <bpytlik@sun.com>
parents: 526
diff changeset
   523
                        refresh_catalogs = False
172
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 165
diff changeset
   524
326
0f1ba0508d1b 583 src/pkg-server.xml missing a CDDL block
Dan Price <dp@eng.sun.com>
parents: 323
diff changeset
   525
        if verbose and quiet:
0f1ba0508d1b 583 src/pkg-server.xml missing a CDDL block
Dan Price <dp@eng.sun.com>
parents: 323
diff changeset
   526
                usage(_("image-update: -v and -q may not be combined"))
0f1ba0508d1b 583 src/pkg-server.xml missing a CDDL block
Dan Price <dp@eng.sun.com>
parents: 323
diff changeset
   527
442
01fb28d438b3 2418 'pkg version', 'pkg image-update' should error on additional arguments
Dan Price <dp@eng.sun.com>
parents: 432
diff changeset
   528
        if pargs:
01fb28d438b3 2418 'pkg version', 'pkg image-update' should error on additional arguments
Dan Price <dp@eng.sun.com>
parents: 432
diff changeset
   529
                usage(_("image-update: command does not take operands " \
01fb28d438b3 2418 'pkg version', 'pkg image-update' should error on additional arguments
Dan Price <dp@eng.sun.com>
parents: 432
diff changeset
   530
                    "('%s')") % " ".join(pargs))
01fb28d438b3 2418 'pkg version', 'pkg image-update' should error on additional arguments
Dan Price <dp@eng.sun.com>
parents: 432
diff changeset
   531
327
6c6bd07efe8d 1031 authority prefix needs validation
johansen <johansen@sun.com>
parents: 326
diff changeset
   532
        progresstracker = get_tracker(quiet)
309
b2902ce9dc7a 863 pkg image-update should recover from a failed attempt
Tim Knitter <Tim.Knitter@Sun.COM>
parents: 307
diff changeset
   533
329
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
   534
        try:
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   535
                api_inst = api.ImageInterface(img_dir, CLIENT_API_VERSION,
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   536
                    progresstracker, cancel_state_callable=None,
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   537
                    pkg_client_name=PKG_CLIENT_NAME)
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   538
        except api_errors.ImageNotFoundException, e:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   539
                error(_("No image rooted at '%s'") % e.user_dir)
361
5aca6ca29a5d 1612 pkg contents doesn't give me the manifest I asked for
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 344
diff changeset
   540
                return 1
5aca6ca29a5d 1612 pkg contents doesn't give me the manifest I asked for
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 344
diff changeset
   541
172
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 165
diff changeset
   542
        try:
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   543
                # cre is either None or a catalog refresh exception which was
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   544
                # caught while planning.
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   545
                stuff_to_do, opensolaris_image, cre = \
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   546
                    api_inst.plan_update_all(sys.argv[0], refresh_catalogs,
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   547
                        noexecute, force=force, verbose=verbose)
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   548
                if cre and not display_catalog_failures(cre):
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   549
                        raise RuntimeError("Catalog refresh failed during"
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   550
                            " image-update.")
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   551
                if not stuff_to_do:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   552
                        msg(_("No updates available for this image."))
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   553
                        return 0
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   554
        except api_errors.CatalogRefreshException, e:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   555
                if display_catalog_failures(e) == 0:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   556
                        if not noexecute:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   557
                                return 1
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   558
                else:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   559
                        raise RuntimeError("Catalog refresh failed during"
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   560
                            " image-update.")
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   561
        except (api_errors.PlanCreationException,
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   562
            api_errors.NetworkUnavailableException), e:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   563
                msg(str(e))
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   564
                return 1
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   565
        except api_errors.IpkgOutOfDateException:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   566
                msg(_("WARNING: pkg(5) appears to be out of date, and should " \
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   567
                    "be updated before\nrunning image-update.\n"))
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   568
                msg(_("Please update pkg(5) using 'pfexec pkg install " \
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   569
                    "SUNWipkg' and then retry\nthe image-update."))
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   570
                return 1
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   571
        except api_errors.ImageNotFoundException, e:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   572
                error(_("No image rooted at '%s'") % e.user_dir)
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   573
                return 1
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   574
        if noexecute:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   575
                return 0
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   576
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   577
        ret_code = 0
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   578
        
576
6ee6de304041 3777 PKG_TIMEOUT_MAX is a placebo setting
Dan Price <dp@eng.sun.com>
parents: 575
diff changeset
   579
        # Exceptions which happen here are printed in the above level, with
6ee6de304041 3777 PKG_TIMEOUT_MAX is a placebo setting
Dan Price <dp@eng.sun.com>
parents: 575
diff changeset
   580
        # or without some extra decoration done here.
6ee6de304041 3777 PKG_TIMEOUT_MAX is a placebo setting
Dan Price <dp@eng.sun.com>
parents: 575
diff changeset
   581
        # XXX would be nice to kick the progress tracker.
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   582
        try:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   583
                api_inst.prepare()
576
6ee6de304041 3777 PKG_TIMEOUT_MAX is a placebo setting
Dan Price <dp@eng.sun.com>
parents: 575
diff changeset
   584
        except misc.TransportException:
6ee6de304041 3777 PKG_TIMEOUT_MAX is a placebo setting
Dan Price <dp@eng.sun.com>
parents: 575
diff changeset
   585
                # move past the progress tracker line.
6ee6de304041 3777 PKG_TIMEOUT_MAX is a placebo setting
Dan Price <dp@eng.sun.com>
parents: 575
diff changeset
   586
                msg("\n")
6ee6de304041 3777 PKG_TIMEOUT_MAX is a placebo setting
Dan Price <dp@eng.sun.com>
parents: 575
diff changeset
   587
                raise
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   588
        except KeyboardInterrupt:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   589
                raise
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   590
        except:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   591
                error(_("\nAn unexpected error happened while preparing for " \
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   592
                    "image-update:"))
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   593
                raise
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   594
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   595
        try:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   596
                api_inst.execute_plan()
172
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 165
diff changeset
   597
        except RuntimeError, e:
361
5aca6ca29a5d 1612 pkg contents doesn't give me the manifest I asked for
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 344
diff changeset
   598
                error(_("image-update failed: %s") % e)
251
6c3d70b74865 470 pkg image-update can fail under some conditions
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 243
diff changeset
   599
                ret_code = 1
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   600
        except api_errors.ImageUpdateOnLiveImageException:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   601
                error(_("image-update cannot be done on live image"))
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   602
                ret_code = 1
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   603
        except api_errors.CorruptedIndexException, e:
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 427
diff changeset
   604
                error(INCONSISTENT_INDEX_ERROR_MESSAGE)
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 427
diff changeset
   605
                ret_code = 1
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   606
        except api_errors.ProblematicPermissionsIndexException, e:
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 427
diff changeset
   607
                error(str(e) + PROBLEMATIC_PERMISSIONS_ERROR_MESSAGE)
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 427
diff changeset
   608
                ret_code = 1
576
6ee6de304041 3777 PKG_TIMEOUT_MAX is a placebo setting
Dan Price <dp@eng.sun.com>
parents: 575
diff changeset
   609
        except KeyboardInterrupt:
6ee6de304041 3777 PKG_TIMEOUT_MAX is a placebo setting
Dan Price <dp@eng.sun.com>
parents: 575
diff changeset
   610
                raise
329
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
   611
        except Exception, e:
417
be3c47d9061f 1249 create snapshot & be after downloading package
Brock Pytlik <bpytlik@sun.com>
parents: 410
diff changeset
   612
                error(_("\nAn unexpected error happened during " \
391
23ec5f7ee0d3 2245 client - pylint cleanup needed
Shawn Walker <swalker@opensolaris.org>
parents: 388
diff changeset
   613
                    "image-update: %s") % e)
329
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
   614
                raise
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
   615
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   616
        if ret_code == 0 and opensolaris_image:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   617
                msg("\n" + "-" * 75)
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   618
                msg(_("NOTE: Please review release notes posted at:\n" \
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   619
                    "   http://opensolaris.org/os/project/indiana/" \
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   620
                    "resources/rn3/"))
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   621
                msg("-" * 75 + "\n")
388
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
   622
251
6c3d70b74865 470 pkg image-update can fail under some conditions
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 243
diff changeset
   623
        return ret_code
172
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 165
diff changeset
   624
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   625
def install(img_dir, args):
50
bfcb1661f019 basic image and package plans
Stephen Hahn <sch@sun.com>
parents: 48
diff changeset
   626
        """Attempt to take package specified to INSTALLED state.  The operands
104
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 103
diff changeset
   627
        are interpreted as glob patterns."""
32
c26788b7217c begin client install; sequences are now timestamps; skeleton ELF module
Stephen Hahn <sch@sun.com>
parents: 30
diff changeset
   628
104
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 103
diff changeset
   629
        # XXX Authority-catalog issues.
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 103
diff changeset
   630
537
3dc9fc9b5fee 1540 changes to authorities should include refresh
Brock Pytlik <bpytlik@sun.com>
parents: 526
diff changeset
   631
        opts, pargs = getopt.getopt(args, "nvb:f:q", ["no-refresh"])
32
c26788b7217c begin client install; sequences are now timestamps; skeleton ELF module
Stephen Hahn <sch@sun.com>
parents: 30
diff changeset
   632
242
7bd1830635c8 402 Start on some pylint cleanup, and fix missing imports
Dan Price <dp@eng.sun.com>
parents: 239
diff changeset
   633
        quiet = noexecute = verbose = False
537
3dc9fc9b5fee 1540 changes to authorities should include refresh
Brock Pytlik <bpytlik@sun.com>
parents: 526
diff changeset
   634
        refresh_catalogs = True
111
647c91609117 Client-side filtering.
Danek Duvall <danek.duvall@sun.com>
parents: 106
diff changeset
   635
        filters = []
32
c26788b7217c begin client install; sequences are now timestamps; skeleton ELF module
Stephen Hahn <sch@sun.com>
parents: 30
diff changeset
   636
        for opt, arg in opts:
242
7bd1830635c8 402 Start on some pylint cleanup, and fix missing imports
Dan Price <dp@eng.sun.com>
parents: 239
diff changeset
   637
                if opt == "-n":
63
ba3a4af65479 add -R/$PKG_IMAGE to pkg, and -n and -v to install
Danek Duvall <danek.duvall@sun.com>
parents: 60
diff changeset
   638
                        noexecute = True
ba3a4af65479 add -R/$PKG_IMAGE to pkg, and -n and -v to install
Danek Duvall <danek.duvall@sun.com>
parents: 60
diff changeset
   639
                elif opt == "-v":
ba3a4af65479 add -R/$PKG_IMAGE to pkg, and -n and -v to install
Danek Duvall <danek.duvall@sun.com>
parents: 60
diff changeset
   640
                        verbose = True
119
537d69114be4 Implement bundled file downloads using filelist
johansen <johansen@sun.com>
parents: 116
diff changeset
   641
                elif opt == "-b":
235
61994d15c39b 373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents: 227
diff changeset
   642
                        filelist.FileList.maxbytes_default = int(arg)
111
647c91609117 Client-side filtering.
Danek Duvall <danek.duvall@sun.com>
parents: 106
diff changeset
   643
                elif opt == "-f":
647c91609117 Client-side filtering.
Danek Duvall <danek.duvall@sun.com>
parents: 106
diff changeset
   644
                        filters += [ arg ]
235
61994d15c39b 373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents: 227
diff changeset
   645
                elif opt == "-q":
61994d15c39b 373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents: 227
diff changeset
   646
                        quiet = True
537
3dc9fc9b5fee 1540 changes to authorities should include refresh
Brock Pytlik <bpytlik@sun.com>
parents: 526
diff changeset
   647
                elif opt == "--no-refresh":
3dc9fc9b5fee 1540 changes to authorities should include refresh
Brock Pytlik <bpytlik@sun.com>
parents: 526
diff changeset
   648
                        refresh_catalogs = False
32
c26788b7217c begin client install; sequences are now timestamps; skeleton ELF module
Stephen Hahn <sch@sun.com>
parents: 30
diff changeset
   649
321
19d23a8acb5f 1098 running "pkg install" without args does not return for about 5 seconds
Danek Duvall <danek.duvall@sun.com>
parents: 318
diff changeset
   650
        if not pargs:
19d23a8acb5f 1098 running "pkg install" without args does not return for about 5 seconds
Danek Duvall <danek.duvall@sun.com>
parents: 318
diff changeset
   651
                usage(_("install: at least one package name required"))
19d23a8acb5f 1098 running "pkg install" without args does not return for about 5 seconds
Danek Duvall <danek.duvall@sun.com>
parents: 318
diff changeset
   652
326
0f1ba0508d1b 583 src/pkg-server.xml missing a CDDL block
Dan Price <dp@eng.sun.com>
parents: 323
diff changeset
   653
        if verbose and quiet:
0f1ba0508d1b 583 src/pkg-server.xml missing a CDDL block
Dan Price <dp@eng.sun.com>
parents: 323
diff changeset
   654
                usage(_("install: -v and -q may not be combined"))
0f1ba0508d1b 583 src/pkg-server.xml missing a CDDL block
Dan Price <dp@eng.sun.com>
parents: 323
diff changeset
   655
235
61994d15c39b 373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents: 227
diff changeset
   656
        progresstracker = get_tracker(quiet)
36
b31b3587fb1c begin client catalog evaluation; fix bugs from refactoring
"Stephen Hahn <sch@sun.com>"
parents: 32
diff changeset
   657
526
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 523
diff changeset
   658
        if not check_fmri_args(pargs):
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 523
diff changeset
   659
                return 1
537
3dc9fc9b5fee 1540 changes to authorities should include refresh
Brock Pytlik <bpytlik@sun.com>
parents: 526
diff changeset
   660
        
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   661
        # XXX not sure where this should live
172
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 165
diff changeset
   662
        pkg_list = [ pat.replace("*", ".*").replace("?", ".")
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 165
diff changeset
   663
            for pat in pargs ]
39
37b18a02b3ae initial Manifest class; client uses is_same_pkg() and max() to select version
"Stephen Hahn <sch@sun.com>"
parents: 36
diff changeset
   664
172
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 165
diff changeset
   665
        try:
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   666
                api_inst = api.ImageInterface(img_dir, CLIENT_API_VERSION,
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   667
                    progresstracker, None, PKG_CLIENT_NAME)
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   668
        except api_errors.ImageNotFoundException, e:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   669
                error(_("'%s' is not an install image") % e.user_dir)
329
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
   670
                return 1
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   671
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   672
        try:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   673
                if not api_inst.plan_install(pkg_list, filters,
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   674
                    refresh_catalogs, noexecute, verbose=verbose):
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   675
                        msg(_("Nothing to install in this image (is this "
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   676
                            "package already installed?)"))
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   677
                        return 0
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   678
        except api_errors.InvalidCertException:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   679
                return 1
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   680
        except (api_errors.PlanCreationException,
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   681
            api_errors.NetworkUnavailableException), e:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   682
                msg(str(e))
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   683
                return 1
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   684
        except api_errors.InventoryException, e:
542
c24405fc75be 3483 InventoryException needs __str__() method
Dan Price <Daniel.Price@Sun.COM>
parents: 539
diff changeset
   685
                error(_("install failed (inventory exception): %s") % e)
526
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 523
diff changeset
   686
                return 1
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 523
diff changeset
   687
        except fmri.IllegalFmri, e:
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 523
diff changeset
   688
                error(e)
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 523
diff changeset
   689
                return 1
329
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
   690
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
   691
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
   692
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
   693
        if noexecute:
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   694
                return 0
329
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
   695
576
6ee6de304041 3777 PKG_TIMEOUT_MAX is a placebo setting
Dan Price <dp@eng.sun.com>
parents: 575
diff changeset
   696
        # Exceptions which happen here are printed in the above level, with
6ee6de304041 3777 PKG_TIMEOUT_MAX is a placebo setting
Dan Price <dp@eng.sun.com>
parents: 575
diff changeset
   697
        # or without some extra decoration done here.
6ee6de304041 3777 PKG_TIMEOUT_MAX is a placebo setting
Dan Price <dp@eng.sun.com>
parents: 575
diff changeset
   698
        # XXX would be nice to kick the progress tracker.
329
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
   699
        try:
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   700
                api_inst.prepare()
576
6ee6de304041 3777 PKG_TIMEOUT_MAX is a placebo setting
Dan Price <dp@eng.sun.com>
parents: 575
diff changeset
   701
        except misc.TransportException:
6ee6de304041 3777 PKG_TIMEOUT_MAX is a placebo setting
Dan Price <dp@eng.sun.com>
parents: 575
diff changeset
   702
                # move past the progress tracker line.
6ee6de304041 3777 PKG_TIMEOUT_MAX is a placebo setting
Dan Price <dp@eng.sun.com>
parents: 575
diff changeset
   703
                msg("\n")
6ee6de304041 3777 PKG_TIMEOUT_MAX is a placebo setting
Dan Price <dp@eng.sun.com>
parents: 575
diff changeset
   704
                raise
6ee6de304041 3777 PKG_TIMEOUT_MAX is a placebo setting
Dan Price <dp@eng.sun.com>
parents: 575
diff changeset
   705
        except KeyboardInterrupt:
6ee6de304041 3777 PKG_TIMEOUT_MAX is a placebo setting
Dan Price <dp@eng.sun.com>
parents: 575
diff changeset
   706
                raise
6ee6de304041 3777 PKG_TIMEOUT_MAX is a placebo setting
Dan Price <dp@eng.sun.com>
parents: 575
diff changeset
   707
        except:
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   708
                error(_("\nAn unexpected error happened while preparing for " \
417
be3c47d9061f 1249 create snapshot & be after downloading package
Brock Pytlik <bpytlik@sun.com>
parents: 410
diff changeset
   709
                    "install:"))
be3c47d9061f 1249 create snapshot & be after downloading package
Brock Pytlik <bpytlik@sun.com>
parents: 410
diff changeset
   710
                raise
be3c47d9061f 1249 create snapshot & be after downloading package
Brock Pytlik <bpytlik@sun.com>
parents: 410
diff changeset
   711
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   712
        ret_code = 0
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   713
        
329
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
   714
        try:
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   715
                api_inst.execute_plan()
329
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
   716
        except RuntimeError, e:
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
   717
                error(_("installation failed: %s") % e)
251
6c3d70b74865 470 pkg image-update can fail under some conditions
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 243
diff changeset
   718
                ret_code = 1
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   719
        except api_errors.CorruptedIndexException, e:
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 427
diff changeset
   720
                error(INCONSISTENT_INDEX_ERROR_MESSAGE)
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 427
diff changeset
   721
                ret_code = 1
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   722
        except api_errors.ProblematicPermissionsIndexException, e:
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 427
diff changeset
   723
                error(str(e) + PROBLEMATIC_PERMISSIONS_ERROR_MESSAGE)
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 427
diff changeset
   724
                ret_code = 1
576
6ee6de304041 3777 PKG_TIMEOUT_MAX is a placebo setting
Dan Price <dp@eng.sun.com>
parents: 575
diff changeset
   725
        except KeyboardInterrupt:
6ee6de304041 3777 PKG_TIMEOUT_MAX is a placebo setting
Dan Price <dp@eng.sun.com>
parents: 575
diff changeset
   726
                raise
329
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
   727
        except Exception, e:
391
23ec5f7ee0d3 2245 client - pylint cleanup needed
Shawn Walker <swalker@opensolaris.org>
parents: 388
diff changeset
   728
                error(_("An unexpected error happened during " \
23ec5f7ee0d3 2245 client - pylint cleanup needed
Shawn Walker <swalker@opensolaris.org>
parents: 388
diff changeset
   729
                    "installation: %s") % e)
271
ec8a7669bff2 659 package that delivers existing automounter mountpoint fails installation
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 266
diff changeset
   730
                raise
ec8a7669bff2 659 package that delivers existing automounter mountpoint fails installation
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 266
diff changeset
   731
251
6c3d70b74865 470 pkg image-update can fail under some conditions
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 243
diff changeset
   732
        return ret_code
0
f08899079fb4 implemented open, add (file case), close for transactions
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
   733
329
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
   734
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   735
def uninstall(img_dir, args):
14
969c85e852af start pkg graph management, annotate pkgsend with server states
"Stephen Hahn <sch@sun.com>"
parents: 3
diff changeset
   736
        """Attempt to take package specified to DELETED state."""
66
e307f4f837c3 support package removal
Danek Duvall <danek.duvall@sun.com>
parents: 63
diff changeset
   737
235
61994d15c39b 373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents: 227
diff changeset
   738
        opts, pargs = getopt.getopt(args, "nrvq")
66
e307f4f837c3 support package removal
Danek Duvall <danek.duvall@sun.com>
parents: 63
diff changeset
   739
235
61994d15c39b 373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents: 227
diff changeset
   740
        quiet = noexecute = recursive_removal = verbose = False
66
e307f4f837c3 support package removal
Danek Duvall <danek.duvall@sun.com>
parents: 63
diff changeset
   741
        for opt, arg in opts:
e307f4f837c3 support package removal
Danek Duvall <danek.duvall@sun.com>
parents: 63
diff changeset
   742
                if opt == "-n":
e307f4f837c3 support package removal
Danek Duvall <danek.duvall@sun.com>
parents: 63
diff changeset
   743
                        noexecute = True
67
62c897652bbc Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents: 66
diff changeset
   744
                elif opt == "-r":
62c897652bbc Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents: 66
diff changeset
   745
                        recursive_removal = True
66
e307f4f837c3 support package removal
Danek Duvall <danek.duvall@sun.com>
parents: 63
diff changeset
   746
                elif opt == "-v":
e307f4f837c3 support package removal
Danek Duvall <danek.duvall@sun.com>
parents: 63
diff changeset
   747
                        verbose = True
235
61994d15c39b 373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents: 227
diff changeset
   748
                elif opt == "-q":
61994d15c39b 373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents: 227
diff changeset
   749
                        quiet = True
66
e307f4f837c3 support package removal
Danek Duvall <danek.duvall@sun.com>
parents: 63
diff changeset
   750
361
5aca6ca29a5d 1612 pkg contents doesn't give me the manifest I asked for
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 344
diff changeset
   751
        if not pargs:
344
4c887185d780 528 pkg list -u gives confusing output
Dan Price <dp@eng.sun.com>
parents: 343
diff changeset
   752
                usage(_("uninstall: at least one package name required"))
4c887185d780 528 pkg list -u gives confusing output
Dan Price <dp@eng.sun.com>
parents: 343
diff changeset
   753
326
0f1ba0508d1b 583 src/pkg-server.xml missing a CDDL block
Dan Price <dp@eng.sun.com>
parents: 323
diff changeset
   754
        if verbose and quiet:
0f1ba0508d1b 583 src/pkg-server.xml missing a CDDL block
Dan Price <dp@eng.sun.com>
parents: 323
diff changeset
   755
                usage(_("uninstall: -v and -q may not be combined"))
0f1ba0508d1b 583 src/pkg-server.xml missing a CDDL block
Dan Price <dp@eng.sun.com>
parents: 323
diff changeset
   756
235
61994d15c39b 373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents: 227
diff changeset
   757
        progresstracker = get_tracker(quiet)
66
e307f4f837c3 support package removal
Danek Duvall <danek.duvall@sun.com>
parents: 63
diff changeset
   758
526
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 523
diff changeset
   759
        if not check_fmri_args(pargs):
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 523
diff changeset
   760
                return 1
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 523
diff changeset
   761
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   762
        # XXX not sure where this should live
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   763
        pkg_list = [ pat.replace("*", ".*").replace("?", ".")
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   764
            for pat in pargs ]
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   765
        
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   766
        try:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   767
                api_inst = api.ImageInterface(img_dir, CLIENT_API_VERSION,
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   768
                    progresstracker, None, PKG_CLIENT_NAME)
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   769
        except api_errors.ImageNotFoundException, e:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   770
                error(_("'%s' is not an install image") % e.user_dir)
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   771
                return 1
66
e307f4f837c3 support package removal
Danek Duvall <danek.duvall@sun.com>
parents: 63
diff changeset
   772
432
578875da6e04 48 Removing a dependency is not flagged, and recovery is not obvious
Danek Duvall <danek.duvall@sun.com>
parents: 431
diff changeset
   773
        try:
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   774
                if not api_inst.plan_uninstall(pkg_list, recursive_removal,
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   775
                    noexecute, verbose=verbose):
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   776
                        assert 0
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   777
        except api_errors.NonLeafPackageException, e:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   778
                error("""Cannot remove '%s' due to
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   779
the following packages that depend on it:""" % e[0])
432
578875da6e04 48 Removing a dependency is not flagged, and recovery is not obvious
Danek Duvall <danek.duvall@sun.com>
parents: 431
diff changeset
   780
                for d in e[1]:
578875da6e04 48 Removing a dependency is not flagged, and recovery is not obvious
Danek Duvall <danek.duvall@sun.com>
parents: 431
diff changeset
   781
                        emsg("  %s" % d)
578875da6e04 48 Removing a dependency is not flagged, and recovery is not obvious
Danek Duvall <danek.duvall@sun.com>
parents: 431
diff changeset
   782
                return 1
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   783
        except (api_errors.PlanCreationException,
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   784
            api_errors.NetworkUnavailableException), e:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   785
                msg(str(e))
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   786
                return 1
66
e307f4f837c3 support package removal
Danek Duvall <danek.duvall@sun.com>
parents: 63
diff changeset
   787
329
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
   788
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
   789
        if noexecute:
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
   790
                return 0
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
   791
576
6ee6de304041 3777 PKG_TIMEOUT_MAX is a placebo setting
Dan Price <dp@eng.sun.com>
parents: 575
diff changeset
   792
6ee6de304041 3777 PKG_TIMEOUT_MAX is a placebo setting
Dan Price <dp@eng.sun.com>
parents: 575
diff changeset
   793
        # Exceptions which happen here are printed in the above level, with
6ee6de304041 3777 PKG_TIMEOUT_MAX is a placebo setting
Dan Price <dp@eng.sun.com>
parents: 575
diff changeset
   794
        # or without some extra decoration done here.
6ee6de304041 3777 PKG_TIMEOUT_MAX is a placebo setting
Dan Price <dp@eng.sun.com>
parents: 575
diff changeset
   795
        # XXX would be nice to kick the progress tracker.
361
5aca6ca29a5d 1612 pkg contents doesn't give me the manifest I asked for
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 344
diff changeset
   796
        try:
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   797
                api_inst.prepare()
576
6ee6de304041 3777 PKG_TIMEOUT_MAX is a placebo setting
Dan Price <dp@eng.sun.com>
parents: 575
diff changeset
   798
        except misc.TransportException:
6ee6de304041 3777 PKG_TIMEOUT_MAX is a placebo setting
Dan Price <dp@eng.sun.com>
parents: 575
diff changeset
   799
                # move past the progress tracker line.
6ee6de304041 3777 PKG_TIMEOUT_MAX is a placebo setting
Dan Price <dp@eng.sun.com>
parents: 575
diff changeset
   800
                msg("\n")
6ee6de304041 3777 PKG_TIMEOUT_MAX is a placebo setting
Dan Price <dp@eng.sun.com>
parents: 575
diff changeset
   801
                raise
6ee6de304041 3777 PKG_TIMEOUT_MAX is a placebo setting
Dan Price <dp@eng.sun.com>
parents: 575
diff changeset
   802
        except KeyboardInterrupt:
6ee6de304041 3777 PKG_TIMEOUT_MAX is a placebo setting
Dan Price <dp@eng.sun.com>
parents: 575
diff changeset
   803
                raise
6ee6de304041 3777 PKG_TIMEOUT_MAX is a placebo setting
Dan Price <dp@eng.sun.com>
parents: 575
diff changeset
   804
        except:
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   805
                error(_("\nAn unexpected error happened while preparing for " \
576
6ee6de304041 3777 PKG_TIMEOUT_MAX is a placebo setting
Dan Price <dp@eng.sun.com>
parents: 575
diff changeset
   806
                    "install:"))
417
be3c47d9061f 1249 create snapshot & be after downloading package
Brock Pytlik <bpytlik@sun.com>
parents: 410
diff changeset
   807
                raise
be3c47d9061f 1249 create snapshot & be after downloading package
Brock Pytlik <bpytlik@sun.com>
parents: 410
diff changeset
   808
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   809
        ret_code = 0
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   810
        
417
be3c47d9061f 1249 create snapshot & be after downloading package
Brock Pytlik <bpytlik@sun.com>
parents: 410
diff changeset
   811
        try:
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   812
                api_inst.execute_plan()
329
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
   813
        except RuntimeError, e:
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   814
                error(_("uninstallation failed: %s") % e)
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   815
                ret_code = 1
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   816
        except api_errors.CorruptedIndexException, e:
495
e420b536e34e 2989 errors during index update shouldn't prevent the operation from succeding
Brock Pytlik <bpytlik@sun.com>
parents: 479
diff changeset
   817
                error(INCONSISTENT_INDEX_ERROR_MESSAGE)
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   818
                ret_code = 1
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   819
        except api_errors.ProblematicPermissionsIndexException, e:
495
e420b536e34e 2989 errors during index update shouldn't prevent the operation from succeding
Brock Pytlik <bpytlik@sun.com>
parents: 479
diff changeset
   820
                error(str(e) + PROBLEMATIC_PERMISSIONS_ERROR_MESSAGE)
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   821
                ret_code = 1
576
6ee6de304041 3777 PKG_TIMEOUT_MAX is a placebo setting
Dan Price <dp@eng.sun.com>
parents: 575
diff changeset
   822
        except KeyboardInterrupt:
6ee6de304041 3777 PKG_TIMEOUT_MAX is a placebo setting
Dan Price <dp@eng.sun.com>
parents: 575
diff changeset
   823
                raise
361
5aca6ca29a5d 1612 pkg contents doesn't give me the manifest I asked for
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 344
diff changeset
   824
        except Exception, e:
391
23ec5f7ee0d3 2245 client - pylint cleanup needed
Shawn Walker <swalker@opensolaris.org>
parents: 388
diff changeset
   825
                error(_("An unexpected error happened during " \
23ec5f7ee0d3 2245 client - pylint cleanup needed
Shawn Walker <swalker@opensolaris.org>
parents: 388
diff changeset
   826
                    "uninstallation: %s") % e)
361
5aca6ca29a5d 1612 pkg contents doesn't give me the manifest I asked for
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 344
diff changeset
   827
                raise
329
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
   828
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   829
        return ret_code
219
f303ff108edd 60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents: 217
diff changeset
   830
104
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 103
diff changeset
   831
def freeze(img, args):
14
969c85e852af start pkg graph management, annotate pkgsend with server states
"Stephen Hahn <sch@sun.com>"
parents: 3
diff changeset
   832
        """Attempt to take package specified to FROZEN state, with given
116
9c9942a52984 (image flag day) remove pkg catalog, improve pkg status, localize pkg(1), use
Stephen Hahn <sch@Sun.COM>
parents: 111
diff changeset
   833
        restrictions.  Package must have been in the INSTALLED state."""
219
f303ff108edd 60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents: 217
diff changeset
   834
        return 0
0
f08899079fb4 implemented open, add (file case), close for transactions
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
   835
104
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 103
diff changeset
   836
def unfreeze(img, args):
30
f06ad6cb4b3f stop using flavour terminology
Stephen Hahn <sch@sun.com>
parents: 29
diff changeset
   837
        """Attempt to return package specified to INSTALLED state from FROZEN
f06ad6cb4b3f stop using flavour terminology
Stephen Hahn <sch@sun.com>
parents: 29
diff changeset
   838
        state."""
219
f303ff108edd 60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents: 217
diff changeset
   839
        return 0
30
f06ad6cb4b3f stop using flavour terminology
Stephen Hahn <sch@sun.com>
parents: 29
diff changeset
   840
104
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 103
diff changeset
   841
def search(img, args):
60
6bd5cd83cfb1 Reverse index database and searching support.
Danek Duvall <danek.duvall@sun.com>
parents: 59
diff changeset
   842
        """Search through the reverse index databases for the given token."""
6bd5cd83cfb1 Reverse index database and searching support.
Danek Duvall <danek.duvall@sun.com>
parents: 59
diff changeset
   843
479
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 461
diff changeset
   844
        # Verify validity of certificates before attempting network operations
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 461
diff changeset
   845
        if not img.check_cert_validity():
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 461
diff changeset
   846
                return 1
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 461
diff changeset
   847
499
ff214b0daeb1 2672 Search should allow for case insensitive search.
Brock Pytlik <bpytlik@sun.com>
parents: 497
diff changeset
   848
        opts, pargs = getopt.getopt(args, "lrs:I")
204
8f650d596aec 72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents: 201
diff changeset
   849
499
ff214b0daeb1 2672 Search should allow for case insensitive search.
Brock Pytlik <bpytlik@sun.com>
parents: 497
diff changeset
   850
        local = remote = case_sensitive = False
204
8f650d596aec 72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents: 201
diff changeset
   851
        servers = []
8f650d596aec 72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents: 201
diff changeset
   852
        for opt, arg in opts:
8f650d596aec 72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents: 201
diff changeset
   853
                if opt == "-l":
8f650d596aec 72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents: 201
diff changeset
   854
                        local = True
222
12006bf2a260 4 We need to be able to verify that package(s) is/are correctly installed
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 221
diff changeset
   855
                elif opt == "-r":
204
8f650d596aec 72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents: 201
diff changeset
   856
                        remote = True
8f650d596aec 72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents: 201
diff changeset
   857
                elif opt == "-s":
8f650d596aec 72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents: 201
diff changeset
   858
                        if not arg.startswith("http://") and \
8f650d596aec 72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents: 201
diff changeset
   859
                            not arg.startswith("https://"):
8f650d596aec 72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents: 201
diff changeset
   860
                                arg = "http://" + arg
8f650d596aec 72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents: 201
diff changeset
   861
                        remote = True
8f650d596aec 72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents: 201
diff changeset
   862
                        servers.append({"origin": arg})
499
ff214b0daeb1 2672 Search should allow for case insensitive search.
Brock Pytlik <bpytlik@sun.com>
parents: 497
diff changeset
   863
                elif opt == "-I":
ff214b0daeb1 2672 Search should allow for case insensitive search.
Brock Pytlik <bpytlik@sun.com>
parents: 497
diff changeset
   864
                        case_sensitive = True
204
8f650d596aec 72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents: 201
diff changeset
   865
8f650d596aec 72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents: 201
diff changeset
   866
        if not local and not remote:
8f650d596aec 72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents: 201
diff changeset
   867
                local = True
8f650d596aec 72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents: 201
diff changeset
   868
499
ff214b0daeb1 2672 Search should allow for case insensitive search.
Brock Pytlik <bpytlik@sun.com>
parents: 497
diff changeset
   869
        if remote and case_sensitive:
ff214b0daeb1 2672 Search should allow for case insensitive search.
Brock Pytlik <bpytlik@sun.com>
parents: 497
diff changeset
   870
                emsg("Case sensitive remote search not currently supported.")
ff214b0daeb1 2672 Search should allow for case insensitive search.
Brock Pytlik <bpytlik@sun.com>
parents: 497
diff changeset
   871
                usage()
539
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
   872
204
8f650d596aec 72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents: 201
diff changeset
   873
        if not pargs:
8f650d596aec 72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents: 201
diff changeset
   874
                usage()
8f650d596aec 72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents: 201
diff changeset
   875
8f650d596aec 72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents: 201
diff changeset
   876
        searches = []
8f650d596aec 72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents: 201
diff changeset
   877
        if local:
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 427
diff changeset
   878
                try:
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   879
                        searches.append(img.local_search(pargs, case_sensitive))
516
53da6297fb65 3039 Install and Image-update should check index consistency with installed packages
Brock Pytlik <bpytlik@sun.com>
parents: 515
diff changeset
   880
                except (search_errors.InconsistentIndexException,
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   881
                        search_errors.IncorrectIndexFileHash):
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 427
diff changeset
   882
                        error("The search index appears corrupted.  Please "
431
7138d94688c9 2679 Traceback when searching without an index
Brock Pytlik <bpytlik@sun.com>
parents: 429
diff changeset
   883
                            "rebuild the index with 'pkg rebuild-index'.")
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 427
diff changeset
   884
                        return 1
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 427
diff changeset
   885
204
8f650d596aec 72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents: 201
diff changeset
   886
        if remote:
8f650d596aec 72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents: 201
diff changeset
   887
                searches.append(img.remote_search(pargs, servers))
8f650d596aec 72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents: 201
diff changeset
   888
8f650d596aec 72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents: 201
diff changeset
   889
        # By default assume we don't find anything.
8f650d596aec 72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents: 201
diff changeset
   890
        retcode = 1
8f650d596aec 72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents: 201
diff changeset
   891
8f650d596aec 72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents: 201
diff changeset
   892
        try:
329
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
   893
                first = True
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
   894
                for index, mfmri, action, value in itertools.chain(*searches):
204
8f650d596aec 72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents: 201
diff changeset
   895
                        retcode = 0
329
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
   896
                        if first:
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
   897
                                if action and value:
384
9d4746e5dd3e 115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents: 362
diff changeset
   898
                                        msg("%-10s %-9s %-25s %s" % ("INDEX",
9d4746e5dd3e 115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents: 362
diff changeset
   899
                                            "ACTION", "VALUE", "PACKAGE"))
329
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
   900
                                else:
384
9d4746e5dd3e 115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents: 362
diff changeset
   901
                                        msg("%-10s %s" % ("INDEX", "PACKAGE"))
329
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
   902
                                first = False
302
a5268194080e 981 pkg search could have more useful output
Danek Duvall <danek.duvall@sun.com>
parents: 301
diff changeset
   903
                        if action and value:
384
9d4746e5dd3e 115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents: 362
diff changeset
   904
                                msg("%-10s %-9s %-25s %s" % (index, action,
9d4746e5dd3e 115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents: 362
diff changeset
   905
                                    value, fmri.PkgFmri(str(mfmri)
9d4746e5dd3e 115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents: 362
diff changeset
   906
                                    ).get_short_fmri()))
302
a5268194080e 981 pkg search could have more useful output
Danek Duvall <danek.duvall@sun.com>
parents: 301
diff changeset
   907
                        else:
384
9d4746e5dd3e 115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents: 362
diff changeset
   908
                                msg("%-10s %s" % (index, mfmri))
302
a5268194080e 981 pkg search could have more useful output
Danek Duvall <danek.duvall@sun.com>
parents: 301
diff changeset
   909
204
8f650d596aec 72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents: 201
diff changeset
   910
        except RuntimeError, failed:
384
9d4746e5dd3e 115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents: 362
diff changeset
   911
                emsg("Some servers failed to respond:")
204
8f650d596aec 72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents: 201
diff changeset
   912
                for auth, err in failed.args[0]:
8f650d596aec 72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents: 201
diff changeset
   913
                        if isinstance(err, urllib2.HTTPError):
384
9d4746e5dd3e 115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents: 362
diff changeset
   914
                                emsg("    %s: %s (%d)" % \
9d4746e5dd3e 115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents: 362
diff changeset
   915
                                    (auth["origin"], err.msg, err.code))
204
8f650d596aec 72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents: 201
diff changeset
   916
                        elif isinstance(err, urllib2.URLError):
306
88f8e588cf60 748 Timeout for download operation
Danek Duvall <danek.duvall@sun.com>
parents: 302
diff changeset
   917
                                if isinstance(err.args[0], socket.timeout):
384
9d4746e5dd3e 115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents: 362
diff changeset
   918
                                        emsg("    %s: %s" % \
9d4746e5dd3e 115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents: 362
diff changeset
   919
                                            (auth["origin"], "timeout"))
306
88f8e588cf60 748 Timeout for download operation
Danek Duvall <danek.duvall@sun.com>
parents: 302
diff changeset
   920
                                else:
384
9d4746e5dd3e 115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents: 362
diff changeset
   921
                                        emsg("    %s: %s" % \
9d4746e5dd3e 115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents: 362
diff changeset
   922
                                            (auth["origin"], err.args[0][1]))
204
8f650d596aec 72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents: 201
diff changeset
   923
8f650d596aec 72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents: 201
diff changeset
   924
                retcode = 4
8f650d596aec 72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents: 201
diff changeset
   925
8f650d596aec 72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents: 201
diff changeset
   926
        return retcode
60
6bd5cd83cfb1 Reverse index database and searching support.
Danek Duvall <danek.duvall@sun.com>
parents: 59
diff changeset
   927
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   928
def info(img_dir, args):
301
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
   929
        """Display information about a package or packages.
162
275856fd67a7 Implement simple 'info' and 'list' subcommands.
Danek Duvall <danek.duvall@sun.com>
parents: 161
diff changeset
   930
        """
195
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   931
342
5e1f4d8429bf 669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
   932
        display_license = False
5e1f4d8429bf 669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
   933
        info_local = False
5e1f4d8429bf 669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
   934
        info_remote = False
195
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   935
342
5e1f4d8429bf 669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
   936
        opts, pargs = getopt.getopt(args, "lr", ["license"])
5e1f4d8429bf 669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
   937
        for opt, arg in opts:
5e1f4d8429bf 669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
   938
                if opt == "-l":
5e1f4d8429bf 669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
   939
                        info_local = True
5e1f4d8429bf 669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
   940
                elif opt == "-r":
5e1f4d8429bf 669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
   941
                        info_remote = True
5e1f4d8429bf 669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
   942
                elif opt == "--license":
5e1f4d8429bf 669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
   943
                        display_license = True
5e1f4d8429bf 669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
   944
5e1f4d8429bf 669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
   945
        if not info_local and not info_remote:
5e1f4d8429bf 669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
   946
                info_local = True
5e1f4d8429bf 669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
   947
        elif info_local and info_remote:
5e1f4d8429bf 669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
   948
                usage(_("info: -l and -r may not be combined"))
5e1f4d8429bf 669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
   949
5e1f4d8429bf 669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
   950
        if info_remote and not pargs:
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   951
                usage(_("info: must request remote info for specific packages"))
162
275856fd67a7 Implement simple 'info' and 'list' subcommands.
Danek Duvall <danek.duvall@sun.com>
parents: 161
diff changeset
   952
526
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 523
diff changeset
   953
        if not check_fmri_args(pargs):
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 523
diff changeset
   954
                return 1
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 523
diff changeset
   955
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 417
diff changeset
   956
        err = 0
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 417
diff changeset
   957
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   958
        api_inst = api.ImageInterface(img_dir, CLIENT_API_VERSION,
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   959
            progress.NullProgressTracker(), None, PKG_CLIENT_NAME)
342
5e1f4d8429bf 669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
   960
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   961
        try:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   962
                ret = api_inst.info(pargs, info_local, display_license)
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   963
                pis = ret[api.ImageInterface.INFO_FOUND]
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   964
                notfound = ret[api.ImageInterface.INFO_MISSING]
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   965
                illegals = ret[api.ImageInterface.INFO_ILLEGALS]
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   966
                multi_match = ret[api.ImageInterface.INFO_MULTI_MATCH]
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   967
                
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   968
        except api_errors.NoPackagesInstalledException:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   969
                error(_("no packages installed"))
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   970
                return 1
342
5e1f4d8429bf 669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
   971
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   972
        for i, pi in enumerate(pis):
301
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
   973
                if i > 0:
384
9d4746e5dd3e 115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents: 362
diff changeset
   974
                        msg("")
162
275856fd67a7 Implement simple 'info' and 'list' subcommands.
Danek Duvall <danek.duvall@sun.com>
parents: 161
diff changeset
   975
342
5e1f4d8429bf 669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
   976
                if display_license:
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   977
                        for lic in pi.licenses:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   978
                                msg(lic)
342
5e1f4d8429bf 669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
   979
                        continue
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   980
                
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   981
                if pi.state == api.PackageInfo.INSTALLED:
342
5e1f4d8429bf 669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
   982
                        state = _("Installed")
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   983
                elif pi.state == api.PackageInfo.NOT_INSTALLED:
342
5e1f4d8429bf 669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
   984
                        state = _("Not installed")
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   985
                else:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   986
                        raise RuntimeError("Encountered unknown package "
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   987
                            "information state: %d" % pi.state )
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   988
                
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   989
                msg("          Name:", pi.pkg_stem)
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   990
                msg("       Summary:", pi.summary)
384
9d4746e5dd3e 115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents: 362
diff changeset
   991
                msg("         State:", state)
162
275856fd67a7 Implement simple 'info' and 'list' subcommands.
Danek Duvall <danek.duvall@sun.com>
parents: 161
diff changeset
   992
301
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
   993
                # XXX even more info on the authority would be nice?
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   994
                msg("     Authority:", pi.authority)
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   995
                msg("       Version:", pi.version)
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   996
                msg(" Build Release:", pi.build_release)
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   997
                msg("        Branch:", pi.branch)
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   998
                msg("Packaging Date:", pi.packaging_date)
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   999
                msg("          Size: %s", misc.bytes_to_str(pi.size))
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  1000
                msg("          FMRI:", pi.fmri)
301
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1001
                # XXX add license/copyright info here?
162
275856fd67a7 Implement simple 'info' and 'list' subcommands.
Danek Duvall <danek.duvall@sun.com>
parents: 161
diff changeset
  1002
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 417
diff changeset
  1003
        if notfound:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 417
diff changeset
  1004
                err = 1
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  1005
                if pis:
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 417
diff changeset
  1006
                        emsg()
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 417
diff changeset
  1007
                if info_local:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 417
diff changeset
  1008
                        emsg(_("""\
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 417
diff changeset
  1009
pkg: no packages matching the following patterns you specified are
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 417
diff changeset
  1010
installed on the system.  Try specifying -r to query remotely:"""))
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 417
diff changeset
  1011
                elif info_remote:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 417
diff changeset
  1012
                        emsg(_("""\
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 417
diff changeset
  1013
pkg: no packages matching the following patterns you specified were
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 417
diff changeset
  1014
found in the catalog.  Try relaxing the patterns, refreshing, and/or
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 417
diff changeset
  1015
examining the catalogs:"""))
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 417
diff changeset
  1016
                emsg()
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 417
diff changeset
  1017
                for p in notfound:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 417
diff changeset
  1018
                        emsg("        %s" % p)
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  1019
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  1020
        if illegals:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  1021
                for i in illegals:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  1022
                        emsg(str(i))
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  1023
                err = 1
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  1024
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  1025
        if multi_match:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  1026
                err = 1
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  1027
                for pfmri, matches in  multi_match:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  1028
                        error(_("'%s' matches multiple packages") % pfmri)
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  1029
                        for k in matches:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  1030
                                msg("\t%s" % k[0])
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 417
diff changeset
  1031
        return err
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 417
diff changeset
  1032
301
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1033
def display_contents_results(actionlist, attrs, sort_attrs, action_types,
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1034
    display_headers):
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 427
diff changeset
  1035
        """Print results of a "list" operation """
162
275856fd67a7 Implement simple 'info' and 'list' subcommands.
Danek Duvall <danek.duvall@sun.com>
parents: 161
diff changeset
  1036
275856fd67a7 Implement simple 'info' and 'list' subcommands.
Danek Duvall <danek.duvall@sun.com>
parents: 161
diff changeset
  1037
        # widths is a list of tuples of column width and justification.  Start
301
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1038
        # with the widths of the column headers.
162
275856fd67a7 Implement simple 'info' and 'list' subcommands.
Danek Duvall <danek.duvall@sun.com>
parents: 161
diff changeset
  1039
        JUST_UNKN = 0
275856fd67a7 Implement simple 'info' and 'list' subcommands.
Danek Duvall <danek.duvall@sun.com>
parents: 161
diff changeset
  1040
        JUST_LEFT = -1
275856fd67a7 Implement simple 'info' and 'list' subcommands.
Danek Duvall <danek.duvall@sun.com>
parents: 161
diff changeset
  1041
        JUST_RIGHT = 1
221
e1dbb27a23b5 52 catalog can leave inventory behind, making pkg(1) blind
Stephen Hahn <sch@Sun.COM>
parents: 219
diff changeset
  1042
        widths = [ (len(attr) - attr.find(".") - 1, JUST_UNKN)
e1dbb27a23b5 52 catalog can leave inventory behind, making pkg(1) blind
Stephen Hahn <sch@Sun.COM>
parents: 219
diff changeset
  1043
            for attr in attrs ]
e1dbb27a23b5 52 catalog can leave inventory behind, making pkg(1) blind
Stephen Hahn <sch@Sun.COM>
parents: 219
diff changeset
  1044
        lines = []
e1dbb27a23b5 52 catalog can leave inventory behind, making pkg(1) blind
Stephen Hahn <sch@Sun.COM>
parents: 219
diff changeset
  1045
301
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1046
        for manifest, action in actionlist:
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1047
                if action_types and action.name not in action_types:
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1048
                        continue
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1049
                line = []
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1050
                for i, attr in enumerate(attrs):
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1051
                        just = JUST_UNKN
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1052
                        # As a first approximation, numeric attributes
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1053
                        # are right justified, non-numerics left.
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1054
                        try:
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1055
                                int(action.attrs[attr])
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1056
                                just = JUST_RIGHT
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1057
                        # attribute is non-numeric or is something like
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1058
                        # a list.
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1059
                        except (ValueError, TypeError):
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1060
                                just = JUST_LEFT
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1061
                        # attribute isn't in the list, so we don't know
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1062
                        # what it might be
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1063
                        except KeyError:
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1064
                                pass
162
275856fd67a7 Implement simple 'info' and 'list' subcommands.
Danek Duvall <danek.duvall@sun.com>
parents: 161
diff changeset
  1065
301
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1066
                        if attr in action.attrs:
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1067
                                a = action.attrs[attr]
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1068
                        elif attr == "action.name":
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1069
                                a = action.name
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1070
                                just = JUST_LEFT
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1071
                        elif attr == "action.key":
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1072
                                a = action.attrs[action.key_attr]
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1073
                                just = JUST_LEFT
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1074
                        elif attr == "action.raw":
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1075
                                a = action
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1076
                                just = JUST_LEFT
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1077
                        elif attr == "pkg.name":
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1078
                                a = manifest.fmri.get_name()
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1079
                                just = JUST_LEFT
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1080
                        elif attr == "pkg.fmri":
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1081
                                a = manifest.fmri
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1082
                                just = JUST_LEFT
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1083
                        elif attr == "pkg.shortfmri":
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1084
                                a = manifest.fmri.get_short_fmri()
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1085
                                just = JUST_LEFT
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1086
                        elif attr == "pkg.authority":
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1087
                                a = manifest.fmri.get_authority()
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1088
                                just = JUST_LEFT
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1089
                        else:
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1090
                                a = ""
162
275856fd67a7 Implement simple 'info' and 'list' subcommands.
Danek Duvall <danek.duvall@sun.com>
parents: 161
diff changeset
  1091
301
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1092
                        line.append(a)
162
275856fd67a7 Implement simple 'info' and 'list' subcommands.
Danek Duvall <danek.duvall@sun.com>
parents: 161
diff changeset
  1093
301
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1094
                        # XXX What to do when a column's justification
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1095
                        # changes?
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1096
                        if just != JUST_UNKN:
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1097
                                widths[i] = \
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1098
                                    (max(widths[i][0], len(str(a))), just)
162
275856fd67a7 Implement simple 'info' and 'list' subcommands.
Danek Duvall <danek.duvall@sun.com>
parents: 161
diff changeset
  1099
391
23ec5f7ee0d3 2245 client - pylint cleanup needed
Shawn Walker <swalker@opensolaris.org>
parents: 388
diff changeset
  1100
                if line and [l for l in line if str(l) != ""]:
301
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1101
                        lines.append(line)
162
275856fd67a7 Implement simple 'info' and 'list' subcommands.
Danek Duvall <danek.duvall@sun.com>
parents: 161
diff changeset
  1102
275856fd67a7 Implement simple 'info' and 'list' subcommands.
Danek Duvall <danek.duvall@sun.com>
parents: 161
diff changeset
  1103
        sortidx = 0
275856fd67a7 Implement simple 'info' and 'list' subcommands.
Danek Duvall <danek.duvall@sun.com>
parents: 161
diff changeset
  1104
        for i, attr in enumerate(attrs):
275856fd67a7 Implement simple 'info' and 'list' subcommands.
Danek Duvall <danek.duvall@sun.com>
parents: 161
diff changeset
  1105
                if attr == sort_attrs[0]:
275856fd67a7 Implement simple 'info' and 'list' subcommands.
Danek Duvall <danek.duvall@sun.com>
parents: 161
diff changeset
  1106
                        sortidx = i
275856fd67a7 Implement simple 'info' and 'list' subcommands.
Danek Duvall <danek.duvall@sun.com>
parents: 161
diff changeset
  1107
                        break
275856fd67a7 Implement simple 'info' and 'list' subcommands.
Danek Duvall <danek.duvall@sun.com>
parents: 161
diff changeset
  1108
275856fd67a7 Implement simple 'info' and 'list' subcommands.
Danek Duvall <danek.duvall@sun.com>
parents: 161
diff changeset
  1109
        # Sort numeric columns numerically.
275856fd67a7 Implement simple 'info' and 'list' subcommands.
Danek Duvall <danek.duvall@sun.com>
parents: 161
diff changeset
  1110
        if widths[sortidx][1] == JUST_RIGHT:
275856fd67a7 Implement simple 'info' and 'list' subcommands.
Danek Duvall <danek.duvall@sun.com>
parents: 161
diff changeset
  1111
                def key_extract(x):
275856fd67a7 Implement simple 'info' and 'list' subcommands.
Danek Duvall <danek.duvall@sun.com>
parents: 161
diff changeset
  1112
                        try:
275856fd67a7 Implement simple 'info' and 'list' subcommands.
Danek Duvall <danek.duvall@sun.com>
parents: 161
diff changeset
  1113
                                return int(x[sortidx])
275856fd67a7 Implement simple 'info' and 'list' subcommands.
Danek Duvall <danek.duvall@sun.com>
parents: 161
diff changeset
  1114
                        except (ValueError, TypeError):
275856fd67a7 Implement simple 'info' and 'list' subcommands.
Danek Duvall <danek.duvall@sun.com>
parents: 161
diff changeset
  1115
                                return 0
275856fd67a7 Implement simple 'info' and 'list' subcommands.
Danek Duvall <danek.duvall@sun.com>
parents: 161
diff changeset
  1116
        else:
275856fd67a7 Implement simple 'info' and 'list' subcommands.
Danek Duvall <danek.duvall@sun.com>
parents: 161
diff changeset
  1117
                key_extract = lambda x: x[sortidx]
275856fd67a7 Implement simple 'info' and 'list' subcommands.
Danek Duvall <danek.duvall@sun.com>
parents: 161
diff changeset
  1118
221
e1dbb27a23b5 52 catalog can leave inventory behind, making pkg(1) blind
Stephen Hahn <sch@Sun.COM>
parents: 219
diff changeset
  1119
        if display_headers:
301
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1120
                headers = []
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1121
                for i, attr in enumerate(attrs):
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 306
diff changeset
  1122
                        headers.append(str(attr.upper()))
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 306
diff changeset
  1123
                        widths[i] = \
301
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1124
                            (max(widths[i][0], len(attr)), widths[i][1])
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1125
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1126
                # Now that we know all the widths, multiply them by the
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1127
                # justification values to get positive or negative numbers to
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1128
                # pass to the %-expander.
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1129
                widths = [ e[0] * e[1] for e in widths ]
221
e1dbb27a23b5 52 catalog can leave inventory behind, making pkg(1) blind
Stephen Hahn <sch@Sun.COM>
parents: 219
diff changeset
  1130
                fmt = ("%%%ss " * len(widths)) % tuple(widths)
e1dbb27a23b5 52 catalog can leave inventory behind, making pkg(1) blind
Stephen Hahn <sch@Sun.COM>
parents: 219
diff changeset
  1131
384
9d4746e5dd3e 115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents: 362
diff changeset
  1132
                msg((fmt % tuple(headers)).rstrip())
221
e1dbb27a23b5 52 catalog can leave inventory behind, making pkg(1) blind
Stephen Hahn <sch@Sun.COM>
parents: 219
diff changeset
  1133
        else:
e1dbb27a23b5 52 catalog can leave inventory behind, making pkg(1) blind
Stephen Hahn <sch@Sun.COM>
parents: 219
diff changeset
  1134
                fmt = "%s\t" * len(widths)
e1dbb27a23b5 52 catalog can leave inventory behind, making pkg(1) blind
Stephen Hahn <sch@Sun.COM>
parents: 219
diff changeset
  1135
                fmt.rstrip("\t")
e1dbb27a23b5 52 catalog can leave inventory behind, making pkg(1) blind
Stephen Hahn <sch@Sun.COM>
parents: 219
diff changeset
  1136
539
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1137
        for line in sorted(lines, key=key_extract):
384
9d4746e5dd3e 115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents: 362
diff changeset
  1138
                msg((fmt % tuple(line)).rstrip())
162
275856fd67a7 Implement simple 'info' and 'list' subcommands.
Danek Duvall <danek.duvall@sun.com>
parents: 161
diff changeset
  1139
301
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1140
def list_contents(img, args):
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1141
        """List package contents.
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1142
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1143
        If no arguments are given, display for all locally installed packages.
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1144
        With -H omit headers and use a tab-delimited format; with -o select
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1145
        attributes to display; with -s, specify attributes to sort on; with -t,
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1146
        specify which action types to list."""
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1147
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1148
        # XXX Need remote-info option, to request equivalent information
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1149
        # from repository.
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1150
342
5e1f4d8429bf 669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  1151
        opts, pargs = getopt.getopt(args, "Ho:s:t:mfr")
301
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1152
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1153
        valid_special_attrs = [ "action.name", "action.key", "action.raw",
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1154
            "pkg.name", "pkg.fmri", "pkg.shortfmri", "pkg.authority",
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1155
            "pkg.size" ]
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1156
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1157
        display_headers = True
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1158
        display_raw = False
329
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
  1159
        display_nofilters = False
342
5e1f4d8429bf 669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  1160
        remote = False
5e1f4d8429bf 669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  1161
        local = False
301
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1162
        attrs = []
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1163
        sort_attrs = []
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1164
        action_types = []
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1165
        for opt, arg in opts:
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1166
                if opt == "-H":
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1167
                        display_headers = False
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1168
                elif opt == "-o":
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1169
                        attrs.extend(arg.split(","))
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1170
                elif opt == "-s":
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1171
                        sort_attrs.append(arg)
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1172
                elif opt == "-t":
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1173
                        action_types.extend(arg.split(","))
342
5e1f4d8429bf 669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  1174
                elif opt == "-r":
5e1f4d8429bf 669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  1175
                        remote = True
301
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1176
                elif opt == "-m":
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1177
                        display_raw = True
329
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
  1178
                elif opt == "-f":
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
  1179
                        # Undocumented, for now.
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
  1180
                        display_nofilters = True
301
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1181
342
5e1f4d8429bf 669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  1182
        if not remote and not local:
5e1f4d8429bf 669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  1183
                local = True
5e1f4d8429bf 669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  1184
        elif local and remote:
5e1f4d8429bf 669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  1185
                usage(_("contents: -l and -r may not be combined"))
5e1f4d8429bf 669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  1186
442
01fb28d438b3 2418 'pkg version', 'pkg image-update' should error on additional arguments
Dan Price <dp@eng.sun.com>
parents: 432
diff changeset
  1187
        if remote and not pargs:
539
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1188
                usage(_("contents: must request remote contents for specific "
442
01fb28d438b3 2418 'pkg version', 'pkg image-update' should error on additional arguments
Dan Price <dp@eng.sun.com>
parents: 432
diff changeset
  1189
                   "packages"))
01fb28d438b3 2418 'pkg version', 'pkg image-update' should error on additional arguments
Dan Price <dp@eng.sun.com>
parents: 432
diff changeset
  1190
526
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 523
diff changeset
  1191
        if not check_fmri_args(pargs):
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 523
diff changeset
  1192
                return 1
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 523
diff changeset
  1193
301
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1194
        if display_raw:
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 306
diff changeset
  1195
                display_headers = False
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 306
diff changeset
  1196
                attrs = [ "action.raw" ]
301
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1197
391
23ec5f7ee0d3 2245 client - pylint cleanup needed
Shawn Walker <swalker@opensolaris.org>
parents: 388
diff changeset
  1198
                invalid = set(("-H", "-o", "-t")). \
23ec5f7ee0d3 2245 client - pylint cleanup needed
Shawn Walker <swalker@opensolaris.org>
parents: 388
diff changeset
  1199
                    intersection(set([x[0] for x in opts]))
301
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1200
391
23ec5f7ee0d3 2245 client - pylint cleanup needed
Shawn Walker <swalker@opensolaris.org>
parents: 388
diff changeset
  1201
                if len(invalid) > 0:
23ec5f7ee0d3 2245 client - pylint cleanup needed
Shawn Walker <swalker@opensolaris.org>
parents: 388
diff changeset
  1202
                        usage(_("contents: -m and %s may not be specified " \
23ec5f7ee0d3 2245 client - pylint cleanup needed
Shawn Walker <swalker@opensolaris.org>
parents: 388
diff changeset
  1203
                            "at the same time") % invalid.pop())
301
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1204
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1205
        for a in attrs:
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1206
                if a.startswith("action.") and not a in valid_special_attrs:
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1207
                        usage(_("Invalid attribute '%s'") % a)
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1208
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1209
                if a.startswith("pkg.") and not a in valid_special_attrs:
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1210
                        usage(_("Invalid attribute '%s'") % a)
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1211
556
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 551
diff changeset
  1212
        img.history.operation_name = "contents"
301
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1213
        img.load_catalogs(progress.NullProgressTracker())
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1214
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 417
diff changeset
  1215
        err = 0
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 417
diff changeset
  1216
342
5e1f4d8429bf 669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  1217
        if local:
526
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 523
diff changeset
  1218
                fmris, notfound, illegals = \
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  1219
                    img.installed_fmris_from_args(pargs)
526
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 523
diff changeset
  1220
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 523
diff changeset
  1221
                if illegals:
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 523
diff changeset
  1222
                        for i in illegals:
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 523
diff changeset
  1223
                                emsg(i)
556
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 551
diff changeset
  1224
                        img.history.operation_result = \
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 551
diff changeset
  1225
                            history.RESULT_FAILED_BAD_REQUEST
526
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 523
diff changeset
  1226
                        return 1
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 523
diff changeset
  1227
427
0472f8f466a5 2254 "pkg info" in an empty image should return 1, provide message to stderr.
Danek Duvall <danek.duvall@sun.com>
parents: 423
diff changeset
  1228
                if not fmris and not notfound:
0472f8f466a5 2254 "pkg info" in an empty image should return 1, provide message to stderr.
Danek Duvall <danek.duvall@sun.com>
parents: 423
diff changeset
  1229
                        error(_("no packages installed"))
556
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 551
diff changeset
  1230
                        img.history.operation_result = \
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 551
diff changeset
  1231
                            history.RESULT_NOTHING_TO_DO
427
0472f8f466a5 2254 "pkg info" in an empty image should return 1, provide message to stderr.
Danek Duvall <danek.duvall@sun.com>
parents: 423
diff changeset
  1232
                        return 1
342
5e1f4d8429bf 669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  1233
        elif remote:
479
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 461
diff changeset
  1234
                # Verify validity of certificates before attempting network
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 461
diff changeset
  1235
                # operations
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 461
diff changeset
  1236
                if not img.check_cert_validity():
556
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 551
diff changeset
  1237
                        img.history.operation_result = \
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 551
diff changeset
  1238
                            history.RESULT_FAILED_TRANSPORT
479
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 461
diff changeset
  1239
                        return 1
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 461
diff changeset
  1240
342
5e1f4d8429bf 669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  1241
                fmris = []
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 417
diff changeset
  1242
                notfound = []
342
5e1f4d8429bf 669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  1243
5e1f4d8429bf 669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  1244
                # XXX This loop really needs not to be copied from
5e1f4d8429bf 669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  1245
                # Image.make_install_plan()!
5e1f4d8429bf 669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  1246
                for p in pargs:
5e1f4d8429bf 669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  1247
                        try:
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 417
diff changeset
  1248
                                matches = list(img.inventory([ p ],
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 417
diff changeset
  1249
                                    all_known = True))
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  1250
                        except api_errors.InventoryException, e:
526
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 523
diff changeset
  1251
                                assert(len(e.notfound) == 1)
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 523
diff changeset
  1252
                                notfound.append(e.notfound[0])
342
5e1f4d8429bf 669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  1253
                                continue
5e1f4d8429bf 669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  1254
5e1f4d8429bf 669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  1255
                        pnames = {}
5e1f4d8429bf 669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  1256
                        pmatch = []
5e1f4d8429bf 669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  1257
                        npnames = {}
5e1f4d8429bf 669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  1258
                        npmatch = []
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 417
diff changeset
  1259
                        for m, state in matches:
342
5e1f4d8429bf 669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  1260
                                if m.preferred_authority():
5e1f4d8429bf 669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  1261
                                        pnames[m.get_pkg_stem()] = 1
5e1f4d8429bf 669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  1262
                                        pmatch.append(m)
5e1f4d8429bf 669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  1263
                                else:
5e1f4d8429bf 669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  1264
                                        npnames[m.get_pkg_stem()] = 1
5e1f4d8429bf 669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  1265
                                        npmatch.append(m)
5e1f4d8429bf 669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  1266
5e1f4d8429bf 669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  1267
                        if len(pnames.keys()) > 1:
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  1268
                                msg(_("pkg: '%s' matches multiple packages") % \
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  1269
                                    p)
342
5e1f4d8429bf 669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  1270
                                for k in pnames.keys():
384
9d4746e5dd3e 115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents: 362
diff changeset
  1271
                                        msg("\t%s" % k)
342
5e1f4d8429bf 669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  1272
                                continue
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  1273
                        elif len(pnames.keys()) < 1 and len(npnames.keys()) > 1:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  1274
                                msg(_("pkg: '%s' matches multiple packages") % \
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  1275
                                    p)
342
5e1f4d8429bf 669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  1276
                                for k in npnames.keys():
384
9d4746e5dd3e 115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents: 362
diff changeset
  1277
                                        msg("\t%s" % k)
342
5e1f4d8429bf 669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  1278
                                continue
5e1f4d8429bf 669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  1279
5e1f4d8429bf 669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  1280
                        # matches is a list reverse sorted by version, so take
5e1f4d8429bf 669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  1281
                        # the first; i.e., the latest.
5e1f4d8429bf 669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  1282
                        if len(pmatch) > 0:
5e1f4d8429bf 669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  1283
                                fmris.append(pmatch[0])
5e1f4d8429bf 669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  1284
                        else:
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 427
diff changeset
  1285
                                fmris.append(npmatch[0])
301
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1286
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1287
        #
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1288
        # If the user specifies no specific attrs, and no specific
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1289
        # sort order, then we fill in some defaults.
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1290
        #
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1291
        if not attrs:
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1292
                # XXX Possibly have multiple exclusive attributes per column?
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1293
                # If listing dependencies and files, you could have a path/fmri
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1294
                # column which would list paths for files and fmris for
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1295
                # dependencies.
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1296
                attrs = [ "path" ]
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1297
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1298
        if not sort_attrs:
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1299
                # XXX reverse sorting
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1300
                # Most likely want to sort by path, so don't force people to
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1301
                # make it explicit
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1302
                if "path" in attrs:
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1303
                        sort_attrs = [ "path" ]
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1304
                else:
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1305
                        sort_attrs = attrs[:1]
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1306
329
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
  1307
        filt = not display_nofilters
539
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1308
        manifests = ( img.get_manifest(f, filtered=filt) for f in fmris )
301
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1309
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1310
        actionlist = [ (m, a)
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1311
                    for m in manifests
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1312
                    for a in m.actions ]
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1313
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 417
diff changeset
  1314
        if fmris:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 417
diff changeset
  1315
                display_contents_results(actionlist, attrs, sort_attrs,
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 417
diff changeset
  1316
                    action_types, display_headers)
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 417
diff changeset
  1317
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 417
diff changeset
  1318
        if notfound:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 417
diff changeset
  1319
                err = 1
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 417
diff changeset
  1320
                if fmris:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 417
diff changeset
  1321
                        emsg()
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 417
diff changeset
  1322
                if local:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 417
diff changeset
  1323
                        emsg(_("""\
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 417
diff changeset
  1324
pkg: no packages matching the following patterns you specified are
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 417
diff changeset
  1325
installed on the system.  Try specifying -r to query remotely:"""))
442
01fb28d438b3 2418 'pkg version', 'pkg image-update' should error on additional arguments
Dan Price <dp@eng.sun.com>
parents: 432
diff changeset
  1326
                elif remote:
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 417
diff changeset
  1327
                        emsg(_("""\
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 417
diff changeset
  1328
pkg: no packages matching the following patterns you specified were
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 417
diff changeset
  1329
found in the catalog.  Try relaxing the patterns, refreshing, and/or
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 417
diff changeset
  1330
examining the catalogs:"""))
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 417
diff changeset
  1331
                emsg()
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 417
diff changeset
  1332
                for p in notfound:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 417
diff changeset
  1333
                        emsg("        %s" % p)
556
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 551
diff changeset
  1334
                img.history.operation_result = history.RESULT_NOTHING_TO_DO
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 551
diff changeset
  1335
        else:
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 551
diff changeset
  1336
                img.history.operation_result = history.RESULT_SUCCEEDED
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 417
diff changeset
  1337
        return err
301
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1338
537
3dc9fc9b5fee 1540 changes to authorities should include refresh
Brock Pytlik <bpytlik@sun.com>
parents: 526
diff changeset
  1339
def display_catalog_failures(cre):
3dc9fc9b5fee 1540 changes to authorities should include refresh
Brock Pytlik <bpytlik@sun.com>
parents: 526
diff changeset
  1340
        total = cre.total
3dc9fc9b5fee 1540 changes to authorities should include refresh
Brock Pytlik <bpytlik@sun.com>
parents: 526
diff changeset
  1341
        succeeded = cre.succeeded
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  1342
        msg(_("pkg: %s/%s catalogs successfully updated:") % (succeeded, total))
259
5083c093ab6c 563 server problems on image-create give traceback
Stephen Hahn <sch@Sun.COM>
parents: 251
diff changeset
  1343
537
3dc9fc9b5fee 1540 changes to authorities should include refresh
Brock Pytlik <bpytlik@sun.com>
parents: 526
diff changeset
  1344
        for auth, err in cre.failed:
259
5083c093ab6c 563 server problems on image-create give traceback
Stephen Hahn <sch@Sun.COM>
parents: 251
diff changeset
  1345
                if isinstance(err, urllib2.HTTPError):
384
9d4746e5dd3e 115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents: 362
diff changeset
  1346
                        emsg("   %s: %s - %s" % \
9d4746e5dd3e 115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents: 362
diff changeset
  1347
                            (err.filename, err.code, err.msg))
259
5083c093ab6c 563 server problems on image-create give traceback
Stephen Hahn <sch@Sun.COM>
parents: 251
diff changeset
  1348
                elif isinstance(err, urllib2.URLError):
5083c093ab6c 563 server problems on image-create give traceback
Stephen Hahn <sch@Sun.COM>
parents: 251
diff changeset
  1349
                        if err.args[0][0] == 8:
384
9d4746e5dd3e 115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents: 362
diff changeset
  1350
                                emsg("    %s: %s" % \
9d4746e5dd3e 115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents: 362
diff changeset
  1351
                                    (urlparse.urlsplit(
9d4746e5dd3e 115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents: 362
diff changeset
  1352
                                        auth["origin"])[1].split(":")[0],
9d4746e5dd3e 115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents: 362
diff changeset
  1353
                                    err.args[0][1]))
259
5083c093ab6c 563 server problems on image-create give traceback
Stephen Hahn <sch@Sun.COM>
parents: 251
diff changeset
  1354
                        else:
306
88f8e588cf60 748 Timeout for download operation
Danek Duvall <danek.duvall@sun.com>
parents: 302
diff changeset
  1355
                                if isinstance(err.args[0], socket.timeout):
384
9d4746e5dd3e 115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents: 362
diff changeset
  1356
                                        emsg("    %s: %s" % \
9d4746e5dd3e 115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents: 362
diff changeset
  1357
                                            (auth["origin"], "timeout"))
306
88f8e588cf60 748 Timeout for download operation
Danek Duvall <danek.duvall@sun.com>
parents: 302
diff changeset
  1358
                                else:
384
9d4746e5dd3e 115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents: 362
diff changeset
  1359
                                        emsg("    %s: %s" % \
9d4746e5dd3e 115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents: 362
diff changeset
  1360
                                            (auth["origin"], err.args[0][1]))
285
538afd6a9d3e 763 pkg image-create /foo , pkg image-create /tmp/foo both yield (different) tracebacks
Danek Duvall <danek.duvall@sun.com>
parents: 271
diff changeset
  1361
                else:
384
9d4746e5dd3e 115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents: 362
diff changeset
  1362
                        emsg("   ", err)
259
5083c093ab6c 563 server problems on image-create give traceback
Stephen Hahn <sch@Sun.COM>
parents: 251
diff changeset
  1363
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  1364
        if cre.message:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  1365
                emsg(cre.message)
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  1366
                        
259
5083c093ab6c 563 server problems on image-create give traceback
Stephen Hahn <sch@Sun.COM>
parents: 251
diff changeset
  1367
        return succeeded
5083c093ab6c 563 server problems on image-create give traceback
Stephen Hahn <sch@Sun.COM>
parents: 251
diff changeset
  1368
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  1369
def catalog_refresh(img_dir, args):
259
5083c093ab6c 563 server problems on image-create give traceback
Stephen Hahn <sch@Sun.COM>
parents: 251
diff changeset
  1370
        """Update image's catalogs."""
5083c093ab6c 563 server problems on image-create give traceback
Stephen Hahn <sch@Sun.COM>
parents: 251
diff changeset
  1371
5083c093ab6c 563 server problems on image-create give traceback
Stephen Hahn <sch@Sun.COM>
parents: 251
diff changeset
  1372
        # XXX will need to show available content series for each package
5083c093ab6c 563 server problems on image-create give traceback
Stephen Hahn <sch@Sun.COM>
parents: 251
diff changeset
  1373
        full_refresh = False
523
69a22d5d368c 3387 pkg refresh --full gives a syntax error
Brock Pytlik <bpytlik@sun.com>
parents: 518
diff changeset
  1374
        opts, pargs = getopt.getopt(args, "", ["full"])
327
6c6bd07efe8d 1031 authority prefix needs validation
johansen <johansen@sun.com>
parents: 326
diff changeset
  1375
        for opt, arg in opts:
6c6bd07efe8d 1031 authority prefix needs validation
johansen <johansen@sun.com>
parents: 326
diff changeset
  1376
                if opt == "--full":
6c6bd07efe8d 1031 authority prefix needs validation
johansen <johansen@sun.com>
parents: 326
diff changeset
  1377
                        full_refresh = True
259
5083c093ab6c 563 server problems on image-create give traceback
Stephen Hahn <sch@Sun.COM>
parents: 251
diff changeset
  1378
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  1379
        progresstracker = get_tracker(True)
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  1380
                        
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  1381
        try:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  1382
                api_inst = api.ImageInterface(img_dir, CLIENT_API_VERSION,
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  1383
                    progresstracker, None, PKG_CLIENT_NAME)
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  1384
        except api_errors.ImageNotFoundException, e:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  1385
                error(_("'%s' is not an install image") % e.user_dir)
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  1386
                return 1
259
5083c093ab6c 563 server problems on image-create give traceback
Stephen Hahn <sch@Sun.COM>
parents: 251
diff changeset
  1387
5083c093ab6c 563 server problems on image-create give traceback
Stephen Hahn <sch@Sun.COM>
parents: 251
diff changeset
  1388
        try:
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  1389
                api_inst.refresh(full_refresh, pargs)
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  1390
        except api_errors.UnrecognizedAuthorityException, e:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  1391
                tmp = _("%s is not a recognized authority to " \
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  1392
                    "refresh. \n'pkg authority' will show a" \
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  1393
                    " list of authorities.")
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  1394
                error(tmp % e.auth)
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  1395
                return 1
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  1396
        except api_errors.CatalogRefreshException, e:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  1397
                if display_catalog_failures(e) == 0:
259
5083c093ab6c 563 server problems on image-create give traceback
Stephen Hahn <sch@Sun.COM>
parents: 251
diff changeset
  1398
                        return 1
5083c093ab6c 563 server problems on image-create give traceback
Stephen Hahn <sch@Sun.COM>
parents: 251
diff changeset
  1399
                else:
5083c093ab6c 563 server problems on image-create give traceback
Stephen Hahn <sch@Sun.COM>
parents: 251
diff changeset
  1400
                        return 3
5083c093ab6c 563 server problems on image-create give traceback
Stephen Hahn <sch@Sun.COM>
parents: 251
diff changeset
  1401
        else:
5083c093ab6c 563 server problems on image-create give traceback
Stephen Hahn <sch@Sun.COM>
parents: 251
diff changeset
  1402
                return 0
5083c093ab6c 563 server problems on image-create give traceback
Stephen Hahn <sch@Sun.COM>
parents: 251
diff changeset
  1403
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1404
def authority_set(img, args):
551
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 542
diff changeset
  1405
        """pkg set-authority [-P] [-k ssl_key] [-c ssl_cert] [--reset-uuid]
537
3dc9fc9b5fee 1540 changes to authorities should include refresh
Brock Pytlik <bpytlik@sun.com>
parents: 526
diff changeset
  1406
            [-O origin_url] [-m mirror to add] [-M mirror to remove] 
3dc9fc9b5fee 1540 changes to authorities should include refresh
Brock Pytlik <bpytlik@sun.com>
parents: 526
diff changeset
  1407
            [--no-refresh] authority"""
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1408
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1409
        preferred = False
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1410
        ssl_key = None
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1411
        ssl_cert = None
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1412
        origin_url = None
551
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 542
diff changeset
  1413
        reset_uuid = False
461
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 443
diff changeset
  1414
        add_mirror = None
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 443
diff changeset
  1415
        remove_mirror = None
537
3dc9fc9b5fee 1540 changes to authorities should include refresh
Brock Pytlik <bpytlik@sun.com>
parents: 526
diff changeset
  1416
        refresh_catalogs = True
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1417
461
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 443
diff changeset
  1418
        opts, pargs = getopt.getopt(args, "Pk:c:O:M:m:",
551
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 542
diff changeset
  1419
            ["add-mirror=", "remove-mirror=", "no-refresh", "reset-uuid"])
461
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 443
diff changeset
  1420
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1421
        for opt, arg in opts:
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1422
                if opt == "-P":
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1423
                        preferred = True
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1424
                if opt == "-k":
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1425
                        ssl_key = arg
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1426
                if opt == "-c":
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1427
                        ssl_cert = arg
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1428
                if opt == "-O":
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1429
                        origin_url = arg
461
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 443
diff changeset
  1430
                if opt == "-m" or opt == "--add-mirror":
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 443
diff changeset
  1431
                        add_mirror = arg
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 443
diff changeset
  1432
                if opt == "-M" or opt == "--remove-mirror":
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 443
diff changeset
  1433
                        remove_mirror = arg
537
3dc9fc9b5fee 1540 changes to authorities should include refresh
Brock Pytlik <bpytlik@sun.com>
parents: 526
diff changeset
  1434
                if opt == "--no-refresh":
3dc9fc9b5fee 1540 changes to authorities should include refresh
Brock Pytlik <bpytlik@sun.com>
parents: 526
diff changeset
  1435
                        refresh_catalogs = False
551
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 542
diff changeset
  1436
                if opt == "--reset-uuid":
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 542
diff changeset
  1437
                        reset_uuid = True
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1438
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1439
        if len(pargs) != 1:
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1440
                usage(
391
23ec5f7ee0d3 2245 client - pylint cleanup needed
Shawn Walker <swalker@opensolaris.org>
parents: 388
diff changeset
  1441
                    _("pkg: set-authority: one and only one authority " \
23ec5f7ee0d3 2245 client - pylint cleanup needed
Shawn Walker <swalker@opensolaris.org>
parents: 388
diff changeset
  1442
                        "may be set"))
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1443
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1444
        auth = pargs[0]
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1445
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1446
        if ssl_key:
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1447
                ssl_key = os.path.abspath(ssl_key)
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1448
                if not os.path.exists(ssl_key):
391
23ec5f7ee0d3 2245 client - pylint cleanup needed
Shawn Walker <swalker@opensolaris.org>
parents: 388
diff changeset
  1449
                        error(_("set-authority: SSL key file '%s' does not " \
23ec5f7ee0d3 2245 client - pylint cleanup needed
Shawn Walker <swalker@opensolaris.org>
parents: 388
diff changeset
  1450
                            "exist") % ssl_key)
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1451
                        return 1
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1452
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1453
        if ssl_cert:
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1454
                ssl_cert = os.path.abspath(ssl_cert)
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1455
                if not os.path.exists(ssl_cert):
391
23ec5f7ee0d3 2245 client - pylint cleanup needed
Shawn Walker <swalker@opensolaris.org>
parents: 388
diff changeset
  1456
                        error(_("set-authority: SSL key cert '%s' does not " \
23ec5f7ee0d3 2245 client - pylint cleanup needed
Shawn Walker <swalker@opensolaris.org>
parents: 388
diff changeset
  1457
                            "exist") % ssl_cert)
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1458
                        return 1
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1459
327
6c6bd07efe8d 1031 authority prefix needs validation
johansen <johansen@sun.com>
parents: 326
diff changeset
  1460
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1461
        if not img.has_authority(auth) and origin_url == None:
461
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 443
diff changeset
  1462
                error(_("set-authority: authority does not exist. Use " \
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 443
diff changeset
  1463
                    "-O to define origin URL for new authority"))
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1464
                return 1
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1465
327
6c6bd07efe8d 1031 authority prefix needs validation
johansen <johansen@sun.com>
parents: 326
diff changeset
  1466
        elif not img.has_authority(auth) and not misc.valid_auth_prefix(auth):
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  1467
                error(_("set-authority: authority name has invalid characters"))
327
6c6bd07efe8d 1031 authority prefix needs validation
johansen <johansen@sun.com>
parents: 326
diff changeset
  1468
                return 1
6c6bd07efe8d 1031 authority prefix needs validation
johansen <johansen@sun.com>
parents: 326
diff changeset
  1469
6c6bd07efe8d 1031 authority prefix needs validation
johansen <johansen@sun.com>
parents: 326
diff changeset
  1470
        if origin_url and not misc.valid_auth_url(origin_url):
6c6bd07efe8d 1031 authority prefix needs validation
johansen <johansen@sun.com>
parents: 326
diff changeset
  1471
                error(_("set-authority: authority URL is invalid"))
6c6bd07efe8d 1031 authority prefix needs validation
johansen <johansen@sun.com>
parents: 326
diff changeset
  1472
                return 1
6c6bd07efe8d 1031 authority prefix needs validation
johansen <johansen@sun.com>
parents: 326
diff changeset
  1473
551
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 542
diff changeset
  1474
        uuid = None
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 542
diff changeset
  1475
        if reset_uuid:
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 542
diff changeset
  1476
                uuid = pkg.Uuid25.uuid1()
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 542
diff changeset
  1477
393
8e888cb6ef1f 1122 normal user gets a traceback when trying to change the preferred authority
Brad Hall <bhall@bgh.hallgroup.org>
parents: 391
diff changeset
  1478
        try:
539
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1479
                img.set_authority(auth, origin_url=origin_url,
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1480
                    ssl_key=ssl_key, ssl_cert=ssl_cert,
551
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 542
diff changeset
  1481
                    refresh_allowed=refresh_catalogs, uuid=uuid)
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  1482
        except api_errors.CatalogRefreshException, e:
393
8e888cb6ef1f 1122 normal user gets a traceback when trying to change the preferred authority
Brad Hall <bhall@bgh.hallgroup.org>
parents: 391
diff changeset
  1483
                error(_("set-authority failed: %s") % e)
8e888cb6ef1f 1122 normal user gets a traceback when trying to change the preferred authority
Brad Hall <bhall@bgh.hallgroup.org>
parents: 391
diff changeset
  1484
                return 1
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1485
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1486
        if preferred:
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1487
                img.set_preferred_authority(auth)
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1488
461
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 443
diff changeset
  1489
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 443
diff changeset
  1490
        if add_mirror:
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 443
diff changeset
  1491
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 443
diff changeset
  1492
                if not misc.valid_auth_url(add_mirror):
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  1493
                        error(_("set-authority: added mirror's URL is invalid"))
461
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 443
diff changeset
  1494
                        return 1
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 443
diff changeset
  1495
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 443
diff changeset
  1496
                if img.has_mirror(auth, add_mirror):
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 443
diff changeset
  1497
                        error(_("set-authority: mirror already exists"))
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 443
diff changeset
  1498
                        return 1
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 443
diff changeset
  1499
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 443
diff changeset
  1500
                img.add_mirror(auth, add_mirror)
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 443
diff changeset
  1501
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 443
diff changeset
  1502
        if remove_mirror:
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 443
diff changeset
  1503
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 443
diff changeset
  1504
                if not misc.valid_auth_url(remove_mirror):
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 443
diff changeset
  1505
                        error(_("set-authority: removed mirror has bad URL"))
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 443
diff changeset
  1506
                        return 1
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 443
diff changeset
  1507
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 443
diff changeset
  1508
                if not img.has_mirror(auth, remove_mirror):
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 443
diff changeset
  1509
                        error(_("set-authority: mirror does not exist"))
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 443
diff changeset
  1510
                        return 1
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 443
diff changeset
  1511
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 443
diff changeset
  1512
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 443
diff changeset
  1513
                img.del_mirror(auth, remove_mirror)
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 443
diff changeset
  1514
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 443
diff changeset
  1515
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  1516
        return 0
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1517
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1518
def authority_unset(img, args):
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1519
        """pkg unset-authority authority ..."""
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1520
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1521
        # is this an existing authority in our image?
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1522
        # if so, delete it
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1523
        # if not, error
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1524
        preferred_auth = img.get_default_authority()
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1525
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1526
        if len(args) == 0:
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1527
                usage()
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1528
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1529
        for a in args:
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1530
                if not img.has_authority(a):
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1531
                        error(_("unset-authority: no such authority: %s") \
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1532
                            % a)
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1533
                        return 1
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1534
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1535
                if a == preferred_auth:
391
23ec5f7ee0d3 2245 client - pylint cleanup needed
Shawn Walker <swalker@opensolaris.org>
parents: 388
diff changeset
  1536
                        error(_("unset-authority: removal of preferred " \
23ec5f7ee0d3 2245 client - pylint cleanup needed
Shawn Walker <swalker@opensolaris.org>
parents: 388
diff changeset
  1537
                            "authority not allowed."))
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1538
                        return 1
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1539
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1540
                img.delete_authority(a)
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1541
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1542
        return 0
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1543
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1544
def authority_list(img, args):
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1545
        """pkg authorities"""
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1546
        omit_headers = False
410
403886a7592b 1259 Need CLI option to retrieve preferred authority
Shawn Walker <swalker@opensolaris.org>
parents: 409
diff changeset
  1547
        preferred_only = False
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1548
        preferred_authority = img.get_default_authority()
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1549
410
403886a7592b 1259 Need CLI option to retrieve preferred authority
Shawn Walker <swalker@opensolaris.org>
parents: 409
diff changeset
  1550
        opts, pargs = getopt.getopt(args, "HP")
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1551
        for opt, arg in opts:
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1552
                if opt == "-H":
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1553
                        omit_headers = True
410
403886a7592b 1259 Need CLI option to retrieve preferred authority
Shawn Walker <swalker@opensolaris.org>
parents: 409
diff changeset
  1554
                if opt == "-P":
403886a7592b 1259 Need CLI option to retrieve preferred authority
Shawn Walker <swalker@opensolaris.org>
parents: 409
diff changeset
  1555
                        preferred_only = True
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1556
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1557
        if len(pargs) == 0:
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1558
                if not omit_headers:
384
9d4746e5dd3e 115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents: 362
diff changeset
  1559
                        msg("%-35s %s" % ("AUTHORITY", "URL"))
410
403886a7592b 1259 Need CLI option to retrieve preferred authority
Shawn Walker <swalker@opensolaris.org>
parents: 409
diff changeset
  1560
403886a7592b 1259 Need CLI option to retrieve preferred authority
Shawn Walker <swalker@opensolaris.org>
parents: 409
diff changeset
  1561
                if preferred_only:
403886a7592b 1259 Need CLI option to retrieve preferred authority
Shawn Walker <swalker@opensolaris.org>
parents: 409
diff changeset
  1562
                        auths = [img.get_authority(preferred_authority)]
403886a7592b 1259 Need CLI option to retrieve preferred authority
Shawn Walker <swalker@opensolaris.org>
parents: 409
diff changeset
  1563
                else:
403886a7592b 1259 Need CLI option to retrieve preferred authority
Shawn Walker <swalker@opensolaris.org>
parents: 409
diff changeset
  1564
                        auths = img.gen_authorities()
403886a7592b 1259 Need CLI option to retrieve preferred authority
Shawn Walker <swalker@opensolaris.org>
parents: 409
diff changeset
  1565
403886a7592b 1259 Need CLI option to retrieve preferred authority
Shawn Walker <swalker@opensolaris.org>
parents: 409
diff changeset
  1566
                for a in auths:
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1567
                        # summary list
461
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 443
diff changeset
  1568
                        pfx, url, ssl_key, ssl_cert, dt, mir = \
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 443
diff changeset
  1569
                            img.split_authority(a)
410
403886a7592b 1259 Need CLI option to retrieve preferred authority
Shawn Walker <swalker@opensolaris.org>
parents: 409
diff changeset
  1570
403886a7592b 1259 Need CLI option to retrieve preferred authority
Shawn Walker <swalker@opensolaris.org>
parents: 409
diff changeset
  1571
                        if not preferred_only and pfx == preferred_authority:
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1572
                                pfx += " (preferred)"
384
9d4746e5dd3e 115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents: 362
diff changeset
  1573
                        msg("%-35s %s" % (pfx, url))
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1574
        else:
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1575
                img.load_catalogs(get_tracker())
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1576
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1577
                for a in pargs:
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1578
                        if not img.has_authority(a):
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1579
                                error(_("authority: no such authority: %s") \
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1580
                                    % a)
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1581
                                return 1
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1582
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1583
                        # detailed print
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1584
                        auth = img.get_authority(a)
461
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 443
diff changeset
  1585
                        pfx, url, ssl_key, ssl_cert, dt, mir = \
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1586
                            img.split_authority(auth)
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1587
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1588
                        if dt:
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1589
                                dt = dt.ctime()
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1590
518
1d9021e9f558 2584 pkg needs to handle proxy error
johansen <johansen@sun.com>
parents: 516
diff changeset
  1591
                        if ssl_cert:
479
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 461
diff changeset
  1592
                                try:
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 461
diff changeset
  1593
                                        cert = img.build_cert(ssl_cert)
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 461
diff changeset
  1594
                                except (IOError, OpenSSL.crypto.Error):
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 461
diff changeset
  1595
                                        error(_("SSL certificate for %s" \
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 461
diff changeset
  1596
                                            "is invalid or non-existent.") % \
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 461
diff changeset
  1597
                                            pfx)
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 461
diff changeset
  1598
                                        error(_("Please check file at %s") %\
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 461
diff changeset
  1599
                                            ssl_cert)
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 461
diff changeset
  1600
                                        continue
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 461
diff changeset
  1601
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 461
diff changeset
  1602
                                nb = cert.get_notBefore()
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 461
diff changeset
  1603
                                t = time.strptime(nb, "%Y%m%d%H%M%SZ")
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 461
diff changeset
  1604
                                nb = datetime.datetime.utcfromtimestamp(
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 461
diff changeset
  1605
                                    calendar.timegm(t))
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 461
diff changeset
  1606
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 461
diff changeset
  1607
                                na = cert.get_notAfter()
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 461
diff changeset
  1608
                                t = time.strptime(na, "%Y%m%d%H%M%SZ")
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 461
diff changeset
  1609
                                na = datetime.datetime.utcfromtimestamp(
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 461
diff changeset
  1610
                                    calendar.timegm(t))
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 461
diff changeset
  1611
                        else:
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 461
diff changeset
  1612
                                cert = None
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 461
diff changeset
  1613
384
9d4746e5dd3e 115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents: 362
diff changeset
  1614
                        msg("")
479
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 461
diff changeset
  1615
                        msg("           Authority:", pfx)
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 461
diff changeset
  1616
                        msg("          Origin URL:", url)
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 461
diff changeset
  1617
                        msg("             SSL Key:", ssl_key)
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 461
diff changeset
  1618
                        msg("            SSL Cert:", ssl_cert)
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 461
diff changeset
  1619
                        if cert:
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 461
diff changeset
  1620
                                msg(" Cert Effective Date:", nb.ctime())
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 461
diff changeset
  1621
                                msg("Cert Expiration Date:", na.ctime())
551
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 542
diff changeset
  1622
                        msg("                UUID:", auth["uuid"])
479
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 461
diff changeset
  1623
                        msg("     Catalog Updated:", dt)
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 461
diff changeset
  1624
                        msg("             Mirrors:", mir)
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1625
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1626
        return 0
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1627
551
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 542
diff changeset
  1628
def property_set(img, args):
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 542
diff changeset
  1629
        """pkg set-property propname propvalue"""
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 542
diff changeset
  1630
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 542
diff changeset
  1631
        # ensure no options are passed in
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 542
diff changeset
  1632
        opts, pargs = getopt.getopt(args, "")
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 542
diff changeset
  1633
        try:
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 542
diff changeset
  1634
                propname, propvalue = pargs
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 542
diff changeset
  1635
        except ValueError:
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 542
diff changeset
  1636
                usage(
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 542
diff changeset
  1637
                    _("pkg: set-property: requires a property name and value"))
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 542
diff changeset
  1638
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 542
diff changeset
  1639
        try:
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 542
diff changeset
  1640
                img.set_property(propname, propvalue)
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 542
diff changeset
  1641
        except RuntimeError, e:
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 542
diff changeset
  1642
                error(_("set-property failed: %s") % e)
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 542
diff changeset
  1643
                return 1
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 542
diff changeset
  1644
        return 0
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 542
diff changeset
  1645
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 542
diff changeset
  1646
def property_unset(img, args):
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 542
diff changeset
  1647
        """pkg unset-property propname ..."""
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 542
diff changeset
  1648
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 542
diff changeset
  1649
        # is this an existing property in our image?
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 542
diff changeset
  1650
        # if so, delete it
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 542
diff changeset
  1651
        # if not, error
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 542
diff changeset
  1652
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 542
diff changeset
  1653
        # ensure no options are passed in
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 542
diff changeset
  1654
        opts, pargs = getopt.getopt(args, "")
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 542
diff changeset
  1655
        if not pargs:
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 542
diff changeset
  1656
                usage(
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 542
diff changeset
  1657
                    _("pkg: unset-property requires at least one property name"))
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 542
diff changeset
  1658
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 542
diff changeset
  1659
        for p in pargs:
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 542
diff changeset
  1660
                try:
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 542
diff changeset
  1661
                        img.delete_property(p)
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 542
diff changeset
  1662
                except KeyError:
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 542
diff changeset
  1663
                        error(_("unset-property: no such property: %s") % p)
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 542
diff changeset
  1664
                        return 1
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 542
diff changeset
  1665
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 542
diff changeset
  1666
        return 0
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 542
diff changeset
  1667
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 542
diff changeset
  1668
def property_list(img, args):
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 542
diff changeset
  1669
        """pkg property [-H] [propname ...]"""
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 542
diff changeset
  1670
        omit_headers = False
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 542
diff changeset
  1671
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 542
diff changeset
  1672
        opts, pargs = getopt.getopt(args, "H")
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 542
diff changeset
  1673
        for opt, arg in opts:
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 542
diff changeset
  1674
                if opt == "-H":
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 542
diff changeset
  1675
                        omit_headers = True
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 542
diff changeset
  1676
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 542
diff changeset
  1677
        for p in pargs:
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 542
diff changeset
  1678
                if not img.has_property(p):
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 542
diff changeset
  1679
                        error(_("property: no such property: %s") % p)
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 542
diff changeset
  1680
                        return 1
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 542
diff changeset
  1681
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 542
diff changeset
  1682
        if not pargs:
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 542
diff changeset
  1683
                pargs = img.properties()
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 542
diff changeset
  1684
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 542
diff changeset
  1685
        width = max(max([len(p) for p in pargs]), 8)
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 542
diff changeset
  1686
        fmt = "%%-%ss %%s" % width
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 542
diff changeset
  1687
        if not omit_headers:
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 542
diff changeset
  1688
                msg(fmt % ("PROPERTY", "VALUE"))
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 542
diff changeset
  1689
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 542
diff changeset
  1690
        for p in pargs:
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 542
diff changeset
  1691
                msg(fmt % (p, img.get_property(p)))
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 542
diff changeset
  1692
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 542
diff changeset
  1693
        return 0
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 542
diff changeset
  1694
172
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 165
diff changeset
  1695
def image_create(img, args):
116
9c9942a52984 (image flag day) remove pkg catalog, improve pkg status, localize pkg(1), use
Stephen Hahn <sch@Sun.COM>
parents: 111
diff changeset
  1696
        """Create an image of the requested kind, at the given path.  Load
9c9942a52984 (image flag day) remove pkg catalog, improve pkg status, localize pkg(1), use
Stephen Hahn <sch@Sun.COM>
parents: 111
diff changeset
  1697
        catalog for initial authority for convenience.
9c9942a52984 (image flag day) remove pkg catalog, improve pkg status, localize pkg(1), use
Stephen Hahn <sch@Sun.COM>
parents: 111
diff changeset
  1698
9c9942a52984 (image flag day) remove pkg catalog, improve pkg status, localize pkg(1), use
Stephen Hahn <sch@Sun.COM>
parents: 111
diff changeset
  1699
        At present, it is legitimate for a user image to specify that it will be
9c9942a52984 (image flag day) remove pkg catalog, improve pkg status, localize pkg(1), use
Stephen Hahn <sch@Sun.COM>
parents: 111
diff changeset
  1700
        deployed in a zone.  An easy example would be a program with an optional
9c9942a52984 (image flag day) remove pkg catalog, improve pkg status, localize pkg(1), use
Stephen Hahn <sch@Sun.COM>
parents: 111
diff changeset
  1701
        component that consumes global zone-only information, such as various
9c9942a52984 (image flag day) remove pkg catalog, improve pkg status, localize pkg(1), use
Stephen Hahn <sch@Sun.COM>
parents: 111
diff changeset
  1702
        kernel statistics or device information."""
30
f06ad6cb4b3f stop using flavour terminology
Stephen Hahn <sch@sun.com>
parents: 29
diff changeset
  1703
242
7bd1830635c8 402 Start on some pylint cleanup, and fix missing imports
Dan Price <dp@eng.sun.com>
parents: 239
diff changeset
  1704
        imgtype = image.IMG_USER
104
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 103
diff changeset
  1705
        is_zone = False
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1706
        ssl_key = None
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1707
        ssl_cert = None
104
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 103
diff changeset
  1708
        auth_name = None
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 103
diff changeset
  1709
        auth_url = None
537
3dc9fc9b5fee 1540 changes to authorities should include refresh
Brock Pytlik <bpytlik@sun.com>
parents: 526
diff changeset
  1710
        refresh_catalogs = True
582
303fa3b78f93 3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents: 576
diff changeset
  1711
        force = False
30
f06ad6cb4b3f stop using flavour terminology
Stephen Hahn <sch@sun.com>
parents: 29
diff changeset
  1712
582
303fa3b78f93 3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents: 576
diff changeset
  1713
        opts, pargs = getopt.getopt(args, "fFPUza:k:c:",
303fa3b78f93 3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents: 576
diff changeset
  1714
            ["force", "full", "partial", "user", "zone", "authority=",
303fa3b78f93 3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents: 576
diff changeset
  1715
                "no-refresh"])
30
f06ad6cb4b3f stop using flavour terminology
Stephen Hahn <sch@sun.com>
parents: 29
diff changeset
  1716
f06ad6cb4b3f stop using flavour terminology
Stephen Hahn <sch@sun.com>
parents: 29
diff changeset
  1717
        for opt, arg in opts:
582
303fa3b78f93 3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents: 576
diff changeset
  1718
                if opt == "-f" or opt == "--force":
303fa3b78f93 3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents: 576
diff changeset
  1719
                        force = True
221
e1dbb27a23b5 52 catalog can leave inventory behind, making pkg(1) blind
Stephen Hahn <sch@Sun.COM>
parents: 219
diff changeset
  1720
                if opt == "-F" or opt == "--full":
242
7bd1830635c8 402 Start on some pylint cleanup, and fix missing imports
Dan Price <dp@eng.sun.com>
parents: 239
diff changeset
  1721
                        imgtype = image.IMG_ENTIRE
221
e1dbb27a23b5 52 catalog can leave inventory behind, making pkg(1) blind
Stephen Hahn <sch@Sun.COM>
parents: 219
diff changeset
  1722
                if opt == "-P" or opt == "--partial":
242
7bd1830635c8 402 Start on some pylint cleanup, and fix missing imports
Dan Price <dp@eng.sun.com>
parents: 239
diff changeset
  1723
                        imgtype = image.IMG_PARTIAL
221
e1dbb27a23b5 52 catalog can leave inventory behind, making pkg(1) blind
Stephen Hahn <sch@Sun.COM>
parents: 219
diff changeset
  1724
                if opt == "-U" or opt == "--user":
242
7bd1830635c8 402 Start on some pylint cleanup, and fix missing imports
Dan Price <dp@eng.sun.com>
parents: 239
diff changeset
  1725
                        imgtype = image.IMG_USER
221
e1dbb27a23b5 52 catalog can leave inventory behind, making pkg(1) blind
Stephen Hahn <sch@Sun.COM>
parents: 219
diff changeset
  1726
                if opt == "-z" or opt == "--zone":
104
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 103
diff changeset
  1727
                        is_zone = True
537
3dc9fc9b5fee 1540 changes to authorities should include refresh
Brock Pytlik <bpytlik@sun.com>
parents: 526
diff changeset
  1728
                if opt == "--no-refresh":
3dc9fc9b5fee 1540 changes to authorities should include refresh
Brock Pytlik <bpytlik@sun.com>
parents: 526
diff changeset
  1729
                        refresh_catalogs = False
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1730
                if opt == "-k":
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1731
                        ssl_key = arg
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1732
                if opt == "-c":
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1733
                        ssl_cert = arg
221
e1dbb27a23b5 52 catalog can leave inventory behind, making pkg(1) blind
Stephen Hahn <sch@Sun.COM>
parents: 219
diff changeset
  1734
                if opt == "-a" or opt == "--authority":
285
538afd6a9d3e 763 pkg image-create /foo , pkg image-create /tmp/foo both yield (different) tracebacks
Danek Duvall <danek.duvall@sun.com>
parents: 271
diff changeset
  1735
                        try:
538afd6a9d3e 763 pkg image-create /foo , pkg image-create /tmp/foo both yield (different) tracebacks
Danek Duvall <danek.duvall@sun.com>
parents: 271
diff changeset
  1736
                                auth_name, auth_url = arg.split("=", 1)
538afd6a9d3e 763 pkg image-create /foo , pkg image-create /tmp/foo both yield (different) tracebacks
Danek Duvall <danek.duvall@sun.com>
parents: 271
diff changeset
  1737
                        except ValueError:
301
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1738
                                usage(_("image-create requires authority "
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1739
                                    "argument to be of the form "
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1740
                                    "'<prefix>=<url>'."))
30
f06ad6cb4b3f stop using flavour terminology
Stephen Hahn <sch@sun.com>
parents: 29
diff changeset
  1741
221
e1dbb27a23b5 52 catalog can leave inventory behind, making pkg(1) blind
Stephen Hahn <sch@Sun.COM>
parents: 219
diff changeset
  1742
        if len(pargs) != 1:
301
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1743
                usage(_("image-create requires a single image directory path"))
221
e1dbb27a23b5 52 catalog can leave inventory behind, making pkg(1) blind
Stephen Hahn <sch@Sun.COM>
parents: 219
diff changeset
  1744
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1745
        if ssl_key:
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1746
                ssl_key = os.path.abspath(ssl_key)
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1747
                if not os.path.exists(ssl_key):
391
23ec5f7ee0d3 2245 client - pylint cleanup needed
Shawn Walker <swalker@opensolaris.org>
parents: 388
diff changeset
  1748
                        msg(_("pkg: set-authority: SSL key file '%s' does " \
23ec5f7ee0d3 2245 client - pylint cleanup needed
Shawn Walker <swalker@opensolaris.org>
parents: 388
diff changeset
  1749
                            "not exist") % ssl_key)
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1750
                        return 1
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1751
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1752
        if ssl_cert:
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1753
                ssl_cert = os.path.abspath(ssl_cert)
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1754
                if not os.path.exists(ssl_cert):
391
23ec5f7ee0d3 2245 client - pylint cleanup needed
Shawn Walker <swalker@opensolaris.org>
parents: 388
diff changeset
  1755
                        msg(_("pkg: set-authority: SSL key cert '%s' does " \
23ec5f7ee0d3 2245 client - pylint cleanup needed
Shawn Walker <swalker@opensolaris.org>
parents: 388
diff changeset
  1756
                            "not exist") % ssl_cert)
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1757
                        return 1
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  1758
285
538afd6a9d3e 763 pkg image-create /foo , pkg image-create /tmp/foo both yield (different) tracebacks
Danek Duvall <danek.duvall@sun.com>
parents: 271
diff changeset
  1759
        if not auth_name and not auth_url:
301
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1760
                usage("image-create requires an authority argument")
285
538afd6a9d3e 763 pkg image-create /foo , pkg image-create /tmp/foo both yield (different) tracebacks
Danek Duvall <danek.duvall@sun.com>
parents: 271
diff changeset
  1761
538afd6a9d3e 763 pkg image-create /foo , pkg image-create /tmp/foo both yield (different) tracebacks
Danek Duvall <danek.duvall@sun.com>
parents: 271
diff changeset
  1762
        if not auth_name or not auth_url:
301
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1763
                usage(_("image-create requires authority argument to be of "
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1764
                    "the form '<prefix>=<url>'."))
285
538afd6a9d3e 763 pkg image-create /foo , pkg image-create /tmp/foo both yield (different) tracebacks
Danek Duvall <danek.duvall@sun.com>
parents: 271
diff changeset
  1765
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1766
        if auth_name.startswith(fmri.PREF_AUTH_PFX):
327
6c6bd07efe8d 1031 authority prefix needs validation
johansen <johansen@sun.com>
parents: 326
diff changeset
  1767
                error(_("image-create requires that a prefix not match: %s"
6c6bd07efe8d 1031 authority prefix needs validation
johansen <johansen@sun.com>
parents: 326
diff changeset
  1768
                        % fmri.PREF_AUTH_PFX))
6c6bd07efe8d 1031 authority prefix needs validation
johansen <johansen@sun.com>
parents: 326
diff changeset
  1769
                return 1
6c6bd07efe8d 1031 authority prefix needs validation
johansen <johansen@sun.com>
parents: 326
diff changeset
  1770
6c6bd07efe8d 1031 authority prefix needs validation
johansen <johansen@sun.com>
parents: 326
diff changeset
  1771
        if not misc.valid_auth_prefix(auth_name):
391
23ec5f7ee0d3 2245 client - pylint cleanup needed
Shawn Walker <swalker@opensolaris.org>
parents: 388
diff changeset
  1772
                error(_("image-create: authority prefix has invalid " \
23ec5f7ee0d3 2245 client - pylint cleanup needed
Shawn Walker <swalker@opensolaris.org>
parents: 388
diff changeset
  1773
                    "characters"))
327
6c6bd07efe8d 1031 authority prefix needs validation
johansen <johansen@sun.com>
parents: 326
diff changeset
  1774
                return 1
6c6bd07efe8d 1031 authority prefix needs validation
johansen <johansen@sun.com>
parents: 326
diff changeset
  1775
6c6bd07efe8d 1031 authority prefix needs validation
johansen <johansen@sun.com>
parents: 326
diff changeset
  1776
        if not misc.valid_auth_url(auth_url):
6c6bd07efe8d 1031 authority prefix needs validation
johansen <johansen@sun.com>
parents: 326
diff changeset
  1777
                error(_("image-create: authority URL is invalid"))
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 427
diff changeset
  1778
                return 1
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1779
582
303fa3b78f93 3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents: 576
diff changeset
  1780
        image_dir = pargs[0]
303fa3b78f93 3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents: 576
diff changeset
  1781
303fa3b78f93 3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents: 576
diff changeset
  1782
        # Bail if there is already an image there
303fa3b78f93 3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents: 576
diff changeset
  1783
        if img.image_type(image_dir) != None and not force:
303fa3b78f93 3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents: 576
diff changeset
  1784
                error(_("there is already an image at: %s") % image_dir)
303fa3b78f93 3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents: 576
diff changeset
  1785
                error(_("To override, use the -f (force) option."))
303fa3b78f93 3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents: 576
diff changeset
  1786
                return 1
303fa3b78f93 3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents: 576
diff changeset
  1787
303fa3b78f93 3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents: 576
diff changeset
  1788
        # Bail if the directory exists but isn't empty
303fa3b78f93 3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents: 576
diff changeset
  1789
        if os.path.exists(image_dir) and \
303fa3b78f93 3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents: 576
diff changeset
  1790
            len(os.listdir(image_dir)) > 0 and not force:
303fa3b78f93 3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents: 576
diff changeset
  1791
                error(_("Non-empty directory: %s") % image_dir)
303fa3b78f93 3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents: 576
diff changeset
  1792
                error(_("To override, use the -f (force) option."))
303fa3b78f93 3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents: 576
diff changeset
  1793
                return 1
303fa3b78f93 3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents: 576
diff changeset
  1794
285
538afd6a9d3e 763 pkg image-create /foo , pkg image-create /tmp/foo both yield (different) tracebacks
Danek Duvall <danek.duvall@sun.com>
parents: 271
diff changeset
  1795
        try:
582
303fa3b78f93 3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents: 576
diff changeset
  1796
                img.set_attrs(imgtype, image_dir, is_zone, auth_name, auth_url,
539
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1797
                    ssl_key=ssl_key, ssl_cert=ssl_cert)
285
538afd6a9d3e 763 pkg image-create /foo , pkg image-create /tmp/foo both yield (different) tracebacks
Danek Duvall <danek.duvall@sun.com>
parents: 271
diff changeset
  1798
        except OSError, e:
301
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1799
                error(_("cannot create image at %s: %s") % \
582
303fa3b78f93 3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents: 576
diff changeset
  1800
                    (image_dir, e.args[1]))
285
538afd6a9d3e 763 pkg image-create /foo , pkg image-create /tmp/foo both yield (different) tracebacks
Danek Duvall <danek.duvall@sun.com>
parents: 271
diff changeset
  1801
                return 1
30
f06ad6cb4b3f stop using flavour terminology
Stephen Hahn <sch@sun.com>
parents: 29
diff changeset
  1802
537
3dc9fc9b5fee 1540 changes to authorities should include refresh
Brock Pytlik <bpytlik@sun.com>
parents: 526
diff changeset
  1803
        if refresh_catalogs:
3dc9fc9b5fee 1540 changes to authorities should include refresh
Brock Pytlik <bpytlik@sun.com>
parents: 526
diff changeset
  1804
                try:
3dc9fc9b5fee 1540 changes to authorities should include refresh
Brock Pytlik <bpytlik@sun.com>
parents: 526
diff changeset
  1805
                        img.retrieve_catalogs()
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  1806
                except api_errors.CatalogRefreshException, cre:
537
3dc9fc9b5fee 1540 changes to authorities should include refresh
Brock Pytlik <bpytlik@sun.com>
parents: 526
diff changeset
  1807
                        if display_catalog_failures(cre) == 0:
3dc9fc9b5fee 1540 changes to authorities should include refresh
Brock Pytlik <bpytlik@sun.com>
parents: 526
diff changeset
  1808
                                return 1
3dc9fc9b5fee 1540 changes to authorities should include refresh
Brock Pytlik <bpytlik@sun.com>
parents: 526
diff changeset
  1809
                        else:
3dc9fc9b5fee 1540 changes to authorities should include refresh
Brock Pytlik <bpytlik@sun.com>
parents: 526
diff changeset
  1810
                                return 3
3dc9fc9b5fee 1540 changes to authorities should include refresh
Brock Pytlik <bpytlik@sun.com>
parents: 526
diff changeset
  1811
        return 0
0
f08899079fb4 implemented open, add (file case), close for transactions
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
  1812
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 427
diff changeset
  1813
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 427
diff changeset
  1814
def rebuild_index(img, pargs):
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 427
diff changeset
  1815
        """pkg rebuild-index
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 427
diff changeset
  1816
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 427
diff changeset
  1817
        Forcibly rebuild the search indexes. Will remove existing indexes
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 427
diff changeset
  1818
        and build new ones from scratch."""
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 427
diff changeset
  1819
        quiet = False
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 427
diff changeset
  1820
442
01fb28d438b3 2418 'pkg version', 'pkg image-update' should error on additional arguments
Dan Price <dp@eng.sun.com>
parents: 432
diff changeset
  1821
        if pargs:
01fb28d438b3 2418 'pkg version', 'pkg image-update' should error on additional arguments
Dan Price <dp@eng.sun.com>
parents: 432
diff changeset
  1822
                usage(_("rebuild-index: command does not take operands " \
01fb28d438b3 2418 'pkg version', 'pkg image-update' should error on additional arguments
Dan Price <dp@eng.sun.com>
parents: 432
diff changeset
  1823
                    "('%s')") % " ".join(pargs))
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 427
diff changeset
  1824
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 427
diff changeset
  1825
        try:
539
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1826
                img.history.operation_name = "rebuild-index"
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 427
diff changeset
  1827
                img.rebuild_search_index(get_tracker(quiet))
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  1828
        except api_errors.CorruptedIndexException:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  1829
                img.history.operation_result = RESULT_FAILED_SEARCH
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 427
diff changeset
  1830
                error(INCONSISTENT_INDEX_ERROR_MESSAGE)
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 427
diff changeset
  1831
                return 1
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  1832
        except api_errors.ProblematicPermissionsIndexException, e:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  1833
                img.history.operation_result = RESULT_FAILED_STORAGE
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  1834
                error(str(e) + PROBLEMATIC_PERMISSIONS_ERROR_MESSAGE)
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 427
diff changeset
  1835
                return 1
539
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1836
        else:
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  1837
                img.history.operation_result = RESULT_SUCCEEDED
539
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1838
                return 0
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1839
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1840
def history_list(img, args):
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1841
        """Display history about the current image.
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1842
        """
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1843
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1844
        omit_headers = False
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1845
        long_format = False
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1846
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1847
        opts, pargs = getopt.getopt(args, "Hl")
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1848
        for opt, arg in opts:
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1849
                if opt == "-H":
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1850
                        omit_headers = True
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1851
                elif opt == "-l":
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1852
                        long_format = True
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1853
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1854
        if omit_headers and long_format:
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1855
                usage(_("history: -H and -l may not be combined"))
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1856
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1857
        if not long_format:
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1858
                if not omit_headers:
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1859
                        msg("%-19s %-25s %-15s %s" % (_("TIME"),
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1860
                            _("OPERATION"), _("CLIENT"), _("OUTCOME")))
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1861
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1862
        for entry in sorted(os.listdir(img.history.path)):
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1863
                # Load the history entry.
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1864
                he = history.History(root_dir=img.history.root_dir,
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1865
                    filename=entry)
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1866
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1867
                # Retrieve and format some of the data shared between each
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1868
                # output format.
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1869
                start_time = misc.timestamp_to_time(
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1870
                    he.operation_start_time)
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1871
                start_time = datetime.datetime.fromtimestamp(
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1872
                    start_time).isoformat()
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1873
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1874
                res = he.operation_result
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1875
                if len(res) > 1:
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1876
                        outcome = "%s (%s)" % (_(res[0]), _(res[1]))
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1877
                else:
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1878
                        outcome = _(res[0])
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1879
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1880
                if long_format:
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1881
                        data = []
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1882
                        data.append(("Operation", he.operation_name))
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1883
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1884
                        data.append(("Outcome", outcome))
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1885
                        data.append(("Client", he.client_name))
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1886
                        data.append(("Version", he.client_version))
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1887
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1888
                        data.append(("User", "%s (%s)" % \
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1889
                            (he.operation_username, he.operation_userid)))
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1890
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1891
                        data.append(("Start Time", start_time))
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1892
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1893
                        end_time = misc.timestamp_to_time(
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1894
                            he.operation_end_time)
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1895
                        end_time = datetime.datetime.fromtimestamp(
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1896
                            end_time).isoformat()
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1897
                        data.append(("End Time", end_time))
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1898
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1899
                        data.append(("Command", " ".join(he.client_args)))
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1900
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1901
                        state = he.operation_start_state
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1902
                        if state:
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1903
                                data.append(("Start State", "\n" + state))
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1904
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1905
                        state = he.operation_end_state
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1906
                        if state:
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1907
                                data.append(("End State", "\n" + state))
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1908
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1909
                        errors = "\n".join(he.operation_errors)
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1910
                        if errors:
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1911
                                data.append(("Errors", "\n" + errors))
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1912
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1913
                        for field, value in data:
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1914
                                msg("%15s: %s" % (_(field), value))
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1915
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1916
                        # Separate log entries with a blank line.
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1917
                        msg("")
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1918
                else:
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1919
                        msg("%-19s %-25s %-15s %s" % (start_time,
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1920
                            he.operation_name, he.client_name, outcome))
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1921
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1922
        return 0
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1923
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1924
# To allow exception handler access to the image.
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1925
__img = None
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 427
diff changeset
  1926
242
7bd1830635c8 402 Start on some pylint cleanup, and fix missing imports
Dan Price <dp@eng.sun.com>
parents: 239
diff changeset
  1927
def main_func():
539
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1928
        global __img
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  1929
        __img = img = image.Image()
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  1930
        img.history.client_name = PKG_CLIENT_NAME
0
f08899079fb4 implemented open, add (file case), close for transactions
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
  1931
116
9c9942a52984 (image flag day) remove pkg catalog, improve pkg status, localize pkg(1), use
Stephen Hahn <sch@Sun.COM>
parents: 111
diff changeset
  1932
        # XXX /usr/lib/locale is OpenSolaris-specific.
9c9942a52984 (image flag day) remove pkg catalog, improve pkg status, localize pkg(1), use
Stephen Hahn <sch@Sun.COM>
parents: 111
diff changeset
  1933
        gettext.install("pkg", "/usr/lib/locale")
9c9942a52984 (image flag day) remove pkg catalog, improve pkg status, localize pkg(1), use
Stephen Hahn <sch@Sun.COM>
parents: 111
diff changeset
  1934
0
f08899079fb4 implemented open, add (file case), close for transactions
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
  1935
        try:
584
22bc748edce6 577 need service action for smf(5) manifests
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 583
diff changeset
  1936
                opts, pargs = getopt.getopt(sys.argv[1:], "R:D:", ["debug="])
52
d7c452ef7ae1 Sanitize getopt exception handling
Danek Duvall <danek.duvall@sun.com>
parents: 50
diff changeset
  1937
        except getopt.GetoptError, e:
301
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1938
                usage(_("illegal global option -- %s") % e.opt)
0
f08899079fb4 implemented open, add (file case), close for transactions
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
  1939
584
22bc748edce6 577 need service action for smf(5) manifests
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 583
diff changeset
  1940
        for opt, arg in opts:
22bc748edce6 577 need service action for smf(5) manifests
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 583
diff changeset
  1941
                if opt == "-D" or opt == "--debug":
22bc748edce6 577 need service action for smf(5) manifests
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 583
diff changeset
  1942
                        try:
22bc748edce6 577 need service action for smf(5) manifests
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 583
diff changeset
  1943
                                key, value = arg.split('=', 1)
22bc748edce6 577 need service action for smf(5) manifests
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 583
diff changeset
  1944
                        except:
22bc748edce6 577 need service action for smf(5) manifests
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 583
diff changeset
  1945
                                usage(_("%s takes argument of form name=value, not %s")
22bc748edce6 577 need service action for smf(5) manifests
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 583
diff changeset
  1946
                                    % (opt, arg))
22bc748edce6 577 need service action for smf(5) manifests
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 583
diff changeset
  1947
                        DebugValues.set_value(key, value)
22bc748edce6 577 need service action for smf(5) manifests
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 583
diff changeset
  1948
                elif opt == "-R":
22bc748edce6 577 need service action for smf(5) manifests
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 583
diff changeset
  1949
                        mydir = arg
22bc748edce6 577 need service action for smf(5) manifests
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 583
diff changeset
  1950
22
379f0f6809ff pkgsend open, pkgsend add file, pkgsend close; Transaction object
"Stephen Hahn <sch@sun.com>"
parents: 14
diff changeset
  1951
        if pargs == None or len(pargs) == 0:
0
f08899079fb4 implemented open, add (file case), close for transactions
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
  1952
                usage()
f08899079fb4 implemented open, add (file case), close for transactions
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
  1953
f08899079fb4 implemented open, add (file case), close for transactions
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
  1954
        subcommand = pargs[0]
f08899079fb4 implemented open, add (file case), close for transactions
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
  1955
        del pargs[0]
f08899079fb4 implemented open, add (file case), close for transactions
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
  1956
306
88f8e588cf60 748 Timeout for download operation
Danek Duvall <danek.duvall@sun.com>
parents: 302
diff changeset
  1957
        socket.setdefaulttimeout(
88f8e588cf60 748 Timeout for download operation
Danek Duvall <danek.duvall@sun.com>
parents: 302
diff changeset
  1958
            int(os.environ.get("PKG_CLIENT_TIMEOUT", "30"))) # in seconds
88f8e588cf60 748 Timeout for download operation
Danek Duvall <danek.duvall@sun.com>
parents: 302
diff changeset
  1959
576
6ee6de304041 3777 PKG_TIMEOUT_MAX is a placebo setting
Dan Price <dp@eng.sun.com>
parents: 575
diff changeset
  1960
        # Override default PKG_TIMEOUT_MAX if a value has been specified
388
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  1961
        # in the environment.
576
6ee6de304041 3777 PKG_TIMEOUT_MAX is a placebo setting
Dan Price <dp@eng.sun.com>
parents: 575
diff changeset
  1962
        global_settings.PKG_TIMEOUT_MAX = int(os.environ.get("PKG_TIMEOUT_MAX",
6ee6de304041 3777 PKG_TIMEOUT_MAX is a placebo setting
Dan Price <dp@eng.sun.com>
parents: 575
diff changeset
  1963
            global_settings.PKG_TIMEOUT_MAX))
388
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  1964
104
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 103
diff changeset
  1965
        if subcommand == "image-create":
584
22bc748edce6 577 need service action for smf(5) manifests
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 583
diff changeset
  1966
                if "mydir" in locals():
22bc748edce6 577 need service action for smf(5) manifests
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 583
diff changeset
  1967
                        usage(_("-R not allowed for %s subcommand") % 
22bc748edce6 577 need service action for smf(5) manifests
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 583
diff changeset
  1968
                              subcommand)
221
e1dbb27a23b5 52 catalog can leave inventory behind, making pkg(1) blind
Stephen Hahn <sch@Sun.COM>
parents: 219
diff changeset
  1969
                try:
e1dbb27a23b5 52 catalog can leave inventory behind, making pkg(1) blind
Stephen Hahn <sch@Sun.COM>
parents: 219
diff changeset
  1970
                        ret = image_create(img, pargs)
e1dbb27a23b5 52 catalog can leave inventory behind, making pkg(1) blind
Stephen Hahn <sch@Sun.COM>
parents: 219
diff changeset
  1971
                except getopt.GetoptError, e:
301
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1972
                        usage(_("illegal %s option -- %s") % \
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  1973
                            (subcommand, e.opt))
221
e1dbb27a23b5 52 catalog can leave inventory behind, making pkg(1) blind
Stephen Hahn <sch@Sun.COM>
parents: 219
diff changeset
  1974
                return ret
362
d974bb176266 1341 pkg(1) - pkg contents example#3 doesn't work and "pkg verify" synopsis does not match subcommand description
Danek Duvall <danek.duvall@sun.com>
parents: 361
diff changeset
  1975
        elif subcommand == "version":
584
22bc748edce6 577 need service action for smf(5) manifests
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 583
diff changeset
  1976
                if "mydir" in locals():
22bc748edce6 577 need service action for smf(5) manifests
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 583
diff changeset
  1977
                        usage(_("-R not allowed for %s subcommand") % 
22bc748edce6 577 need service action for smf(5) manifests
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 583
diff changeset
  1978
                              subcommand)
442
01fb28d438b3 2418 'pkg version', 'pkg image-update' should error on additional arguments
Dan Price <dp@eng.sun.com>
parents: 432
diff changeset
  1979
                if pargs:
01fb28d438b3 2418 'pkg version', 'pkg image-update' should error on additional arguments
Dan Price <dp@eng.sun.com>
parents: 432
diff changeset
  1980
                        usage(_("version: command does not take operands " \
01fb28d438b3 2418 'pkg version', 'pkg image-update' should error on additional arguments
Dan Price <dp@eng.sun.com>
parents: 432
diff changeset
  1981
                            "('%s')") % " ".join(pargs))
384
9d4746e5dd3e 115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents: 362
diff changeset
  1982
                msg(pkg.VERSION)
362
d974bb176266 1341 pkg(1) - pkg contents example#3 doesn't work and "pkg verify" synopsis does not match subcommand description
Danek Duvall <danek.duvall@sun.com>
parents: 361
diff changeset
  1983
                return 0
d974bb176266 1341 pkg(1) - pkg contents example#3 doesn't work and "pkg verify" synopsis does not match subcommand description
Danek Duvall <danek.duvall@sun.com>
parents: 361
diff changeset
  1984
        elif subcommand == "help":
d974bb176266 1341 pkg(1) - pkg contents example#3 doesn't work and "pkg verify" synopsis does not match subcommand description
Danek Duvall <danek.duvall@sun.com>
parents: 361
diff changeset
  1985
                try:
d974bb176266 1341 pkg(1) - pkg contents example#3 doesn't work and "pkg verify" synopsis does not match subcommand description
Danek Duvall <danek.duvall@sun.com>
parents: 361
diff changeset
  1986
                        usage()
d974bb176266 1341 pkg(1) - pkg contents example#3 doesn't work and "pkg verify" synopsis does not match subcommand description
Danek Duvall <danek.duvall@sun.com>
parents: 361
diff changeset
  1987
                except SystemExit:
d974bb176266 1341 pkg(1) - pkg contents example#3 doesn't work and "pkg verify" synopsis does not match subcommand description
Danek Duvall <danek.duvall@sun.com>
parents: 361
diff changeset
  1988
                        return 0
50
bfcb1661f019 basic image and package plans
Stephen Hahn <sch@sun.com>
parents: 48
diff changeset
  1989
561
be1ad23e7704 1651 pkg treats -R <bogus-dir> as "use the image at /"
Brock Pytlik <bpytlik@sun.com>
parents: 556
diff changeset
  1990
        provided_image_dir = True
be1ad23e7704 1651 pkg treats -R <bogus-dir> as "use the image at /"
Brock Pytlik <bpytlik@sun.com>
parents: 556
diff changeset
  1991
        pkg_image_used = False
be1ad23e7704 1651 pkg treats -R <bogus-dir> as "use the image at /"
Brock Pytlik <bpytlik@sun.com>
parents: 556
diff changeset
  1992
                
242
7bd1830635c8 402 Start on some pylint cleanup, and fix missing imports
Dan Price <dp@eng.sun.com>
parents: 239
diff changeset
  1993
        if "mydir" not in locals():
63
ba3a4af65479 add -R/$PKG_IMAGE to pkg, and -n and -v to install
Danek Duvall <danek.duvall@sun.com>
parents: 60
diff changeset
  1994
                try:
242
7bd1830635c8 402 Start on some pylint cleanup, and fix missing imports
Dan Price <dp@eng.sun.com>
parents: 239
diff changeset
  1995
                        mydir = os.environ["PKG_IMAGE"]
561
be1ad23e7704 1651 pkg treats -R <bogus-dir> as "use the image at /"
Brock Pytlik <bpytlik@sun.com>
parents: 556
diff changeset
  1996
                        pkg_image_used = True
63
ba3a4af65479 add -R/$PKG_IMAGE to pkg, and -n and -v to install
Danek Duvall <danek.duvall@sun.com>
parents: 60
diff changeset
  1997
                except KeyError:
515
888fa3187f68 2964 better error handling may be needed when working directory does not exist
Danek Duvall <danek.duvall@sun.com>
parents: 499
diff changeset
  1998
                        try:
561
be1ad23e7704 1651 pkg treats -R <bogus-dir> as "use the image at /"
Brock Pytlik <bpytlik@sun.com>
parents: 556
diff changeset
  1999
                                provided_image_dir = False
515
888fa3187f68 2964 better error handling may be needed when working directory does not exist
Danek Duvall <danek.duvall@sun.com>
parents: 499
diff changeset
  2000
                                mydir = os.getcwd()
888fa3187f68 2964 better error handling may be needed when working directory does not exist
Danek Duvall <danek.duvall@sun.com>
parents: 499
diff changeset
  2001
                        except OSError, e:
888fa3187f68 2964 better error handling may be needed when working directory does not exist
Danek Duvall <danek.duvall@sun.com>
parents: 499
diff changeset
  2002
                                try:
888fa3187f68 2964 better error handling may be needed when working directory does not exist
Danek Duvall <danek.duvall@sun.com>
parents: 499
diff changeset
  2003
                                        mydir = os.environ["PWD"]
888fa3187f68 2964 better error handling may be needed when working directory does not exist
Danek Duvall <danek.duvall@sun.com>
parents: 499
diff changeset
  2004
                                        if not mydir or mydir[0] != "/":
888fa3187f68 2964 better error handling may be needed when working directory does not exist
Danek Duvall <danek.duvall@sun.com>
parents: 499
diff changeset
  2005
                                                mydir = None
888fa3187f68 2964 better error handling may be needed when working directory does not exist
Danek Duvall <danek.duvall@sun.com>
parents: 499
diff changeset
  2006
                                except KeyError:
888fa3187f68 2964 better error handling may be needed when working directory does not exist
Danek Duvall <danek.duvall@sun.com>
parents: 499
diff changeset
  2007
                                        mydir = None
888fa3187f68 2964 better error handling may be needed when working directory does not exist
Danek Duvall <danek.duvall@sun.com>
parents: 499
diff changeset
  2008
888fa3187f68 2964 better error handling may be needed when working directory does not exist
Danek Duvall <danek.duvall@sun.com>
parents: 499
diff changeset
  2009
        if mydir == None:
888fa3187f68 2964 better error handling may be needed when working directory does not exist
Danek Duvall <danek.duvall@sun.com>
parents: 499
diff changeset
  2010
                error(_("Could not find image.  Use the -R option or set "
888fa3187f68 2964 better error handling may be needed when working directory does not exist
Danek Duvall <danek.duvall@sun.com>
parents: 499
diff changeset
  2011
                    "$PKG_IMAGE to point\nto an image, or change the working "
888fa3187f68 2964 better error handling may be needed when working directory does not exist
Danek Duvall <danek.duvall@sun.com>
parents: 499
diff changeset
  2012
                    "directory to one inside the image."))
888fa3187f68 2964 better error handling may be needed when working directory does not exist
Danek Duvall <danek.duvall@sun.com>
parents: 499
diff changeset
  2013
                return 1
63
ba3a4af65479 add -R/$PKG_IMAGE to pkg, and -n and -v to install
Danek Duvall <danek.duvall@sun.com>
parents: 60
diff changeset
  2014
ba3a4af65479 add -R/$PKG_IMAGE to pkg, and -n and -v to install
Danek Duvall <danek.duvall@sun.com>
parents: 60
diff changeset
  2015
        try:
561
be1ad23e7704 1651 pkg treats -R <bogus-dir> as "use the image at /"
Brock Pytlik <bpytlik@sun.com>
parents: 556
diff changeset
  2016
                img.find_root(mydir, provided_image_dir)
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2017
        except api_errors.ImageNotFoundException, e:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2018
                if e.user_specified:
561
be1ad23e7704 1651 pkg treats -R <bogus-dir> as "use the image at /"
Brock Pytlik <bpytlik@sun.com>
parents: 556
diff changeset
  2019
                        m = "No image rooted at '%s'"
be1ad23e7704 1651 pkg treats -R <bogus-dir> as "use the image at /"
Brock Pytlik <bpytlik@sun.com>
parents: 556
diff changeset
  2020
                        if pkg_image_used:
be1ad23e7704 1651 pkg treats -R <bogus-dir> as "use the image at /"
Brock Pytlik <bpytlik@sun.com>
parents: 556
diff changeset
  2021
                                m += " (set by $PKG_IMAGE)"
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2022
                        error(_(m) % e.user_dir)
561
be1ad23e7704 1651 pkg treats -R <bogus-dir> as "use the image at /"
Brock Pytlik <bpytlik@sun.com>
parents: 556
diff changeset
  2023
                else:
be1ad23e7704 1651 pkg treats -R <bogus-dir> as "use the image at /"
Brock Pytlik <bpytlik@sun.com>
parents: 556
diff changeset
  2024
                        error(_("No image found."))
192
0c6f1066777b 58 getopt handling needs cleanup
Dan Price <dp@eng.sun.com>
parents: 177
diff changeset
  2025
                return 1
50
bfcb1661f019 basic image and package plans
Stephen Hahn <sch@sun.com>
parents: 48
diff changeset
  2026
104
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 103
diff changeset
  2027
        img.load_config()
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 103
diff changeset
  2028
192
0c6f1066777b 58 getopt handling needs cleanup
Dan Price <dp@eng.sun.com>
parents: 177
diff changeset
  2029
        try:
0c6f1066777b 58 getopt handling needs cleanup
Dan Price <dp@eng.sun.com>
parents: 177
diff changeset
  2030
                if subcommand == "refresh":
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2031
                        return catalog_refresh(mydir, pargs)
301
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  2032
                elif subcommand == "list":
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  2033
                        return list_inventory(img, pargs)
192
0c6f1066777b 58 getopt handling needs cleanup
Dan Price <dp@eng.sun.com>
parents: 177
diff changeset
  2034
                elif subcommand == "image-update":
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2035
                        return image_update(mydir, pargs)
192
0c6f1066777b 58 getopt handling needs cleanup
Dan Price <dp@eng.sun.com>
parents: 177
diff changeset
  2036
                elif subcommand == "install":
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2037
                        return install(mydir, pargs)
192
0c6f1066777b 58 getopt handling needs cleanup
Dan Price <dp@eng.sun.com>
parents: 177
diff changeset
  2038
                elif subcommand == "uninstall":
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2039
                        return uninstall(mydir, pargs)
192
0c6f1066777b 58 getopt handling needs cleanup
Dan Price <dp@eng.sun.com>
parents: 177
diff changeset
  2040
                elif subcommand == "freeze":
219
f303ff108edd 60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents: 217
diff changeset
  2041
                        return freeze(img, pargs)
192
0c6f1066777b 58 getopt handling needs cleanup
Dan Price <dp@eng.sun.com>
parents: 177
diff changeset
  2042
                elif subcommand == "unfreeze":
219
f303ff108edd 60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents: 217
diff changeset
  2043
                        return unfreeze(img, pargs)
192
0c6f1066777b 58 getopt handling needs cleanup
Dan Price <dp@eng.sun.com>
parents: 177
diff changeset
  2044
                elif subcommand == "search":
204
8f650d596aec 72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents: 201
diff changeset
  2045
                        return search(img, pargs)
192
0c6f1066777b 58 getopt handling needs cleanup
Dan Price <dp@eng.sun.com>
parents: 177
diff changeset
  2046
                elif subcommand == "info":
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2047
                        return info(mydir, pargs)
301
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  2048
                elif subcommand == "contents":
219
f303ff108edd 60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents: 217
diff changeset
  2049
                        return list_contents(img, pargs)
583
fc856572d86e 388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents: 582
diff changeset
  2050
                elif subcommand == "fix":
fc856572d86e 388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents: 582
diff changeset
  2051
                        return fix_image(img, pargs)
227
faba25c4bce3 368 pkg info -m should display raw manifest
Stephen Hahn <sch@Sun.COM>
parents: 222
diff changeset
  2052
                elif subcommand == "verify":
faba25c4bce3 368 pkg info -m should display raw manifest
Stephen Hahn <sch@Sun.COM>
parents: 222
diff changeset
  2053
                        return verify_image(img, pargs)
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  2054
                elif subcommand == "set-authority":
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  2055
                        return authority_set(img, pargs)
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  2056
                elif subcommand == "unset-authority":
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  2057
                        return authority_unset(img, pargs)
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  2058
                elif subcommand == "authority":
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 309
diff changeset
  2059
                        return authority_list(img, pargs)
551
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 542
diff changeset
  2060
                elif subcommand == "set-property":
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 542
diff changeset
  2061
                        return property_set(img, pargs)
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 542
diff changeset
  2062
                elif subcommand == "unset-property":
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 542
diff changeset
  2063
                        return property_unset(img, pargs)
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 542
diff changeset
  2064
                elif subcommand == "property":
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2065
                        return property_list(img, pargs)                
539
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  2066
                elif subcommand == "history":
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  2067
                        return history_list(img, pargs)
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  2068
                elif subcommand == "purge-history":
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  2069
                        ret_code = img.history.purge()
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  2070
                        if ret_code == 0:
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  2071
                                msg(_("History purged."))
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  2072
                        return ret_code
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 427
diff changeset
  2073
                elif subcommand == "rebuild-index":
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 427
diff changeset
  2074
                        return rebuild_index(img, pargs)
192
0c6f1066777b 58 getopt handling needs cleanup
Dan Price <dp@eng.sun.com>
parents: 177
diff changeset
  2075
                else:
301
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  2076
                        usage(_("unknown subcommand '%s'") % subcommand)
192
0c6f1066777b 58 getopt handling needs cleanup
Dan Price <dp@eng.sun.com>
parents: 177
diff changeset
  2077
0c6f1066777b 58 getopt handling needs cleanup
Dan Price <dp@eng.sun.com>
parents: 177
diff changeset
  2078
        except getopt.GetoptError, e:
301
35f03c7a3adc Rework status,list,info subcommands -> list,contents,info
Dan Price <dp@eng.sun.com>
parents: 296
diff changeset
  2079
                usage(_("illegal %s option -- %s") % (subcommand, e.opt))
192
0c6f1066777b 58 getopt handling needs cleanup
Dan Price <dp@eng.sun.com>
parents: 177
diff changeset
  2080
0c6f1066777b 58 getopt handling needs cleanup
Dan Price <dp@eng.sun.com>
parents: 177
diff changeset
  2081
0c6f1066777b 58 getopt handling needs cleanup
Dan Price <dp@eng.sun.com>
parents: 177
diff changeset
  2082
#
0c6f1066777b 58 getopt handling needs cleanup
Dan Price <dp@eng.sun.com>
parents: 177
diff changeset
  2083
# Establish a specific exit status which means: "python barfed an exception"
0c6f1066777b 58 getopt handling needs cleanup
Dan Price <dp@eng.sun.com>
parents: 177
diff changeset
  2084
# so that we can more easily detect these in testing of the CLI commands.
0c6f1066777b 58 getopt handling needs cleanup
Dan Price <dp@eng.sun.com>
parents: 177
diff changeset
  2085
#
0c6f1066777b 58 getopt handling needs cleanup
Dan Price <dp@eng.sun.com>
parents: 177
diff changeset
  2086
if __name__ == "__main__":
221
e1dbb27a23b5 52 catalog can leave inventory behind, making pkg(1) blind
Stephen Hahn <sch@Sun.COM>
parents: 219
diff changeset
  2087
        try:
539
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  2088
                __ret = main_func()
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  2089
        except SystemExit, __e:
569
48f7e9d2b1ac 3715 permission or read-only filesystem errors cause history traceback
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 565
diff changeset
  2090
                if __img:
48f7e9d2b1ac 3715 permission or read-only filesystem errors cause history traceback
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 565
diff changeset
  2091
                        __img.history.abort(RESULT_FAILED_UNKNOWN)
539
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  2092
                raise __e
384
9d4746e5dd3e 115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents: 362
diff changeset
  2093
        except (PipeError, KeyboardInterrupt):
569
48f7e9d2b1ac 3715 permission or read-only filesystem errors cause history traceback
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 565
diff changeset
  2094
                if __img:
48f7e9d2b1ac 3715 permission or read-only filesystem errors cause history traceback
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 565
diff changeset
  2095
                        __img.history.abort(RESULT_CANCELED)
539
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  2096
                # We don't want to display any messages here to prevent
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  2097
                # possible further broken pipe (EPIPE) errors.
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  2098
                __ret = 1
576
6ee6de304041 3777 PKG_TIMEOUT_MAX is a placebo setting
Dan Price <dp@eng.sun.com>
parents: 575
diff changeset
  2099
        except misc.TransportException, __e:
569
48f7e9d2b1ac 3715 permission or read-only filesystem errors cause history traceback
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 565
diff changeset
  2100
                if __img:
48f7e9d2b1ac 3715 permission or read-only filesystem errors cause history traceback
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 565
diff changeset
  2101
                        __img.history.abort(RESULT_FAILED_TRANSPORT)
576
6ee6de304041 3777 PKG_TIMEOUT_MAX is a placebo setting
Dan Price <dp@eng.sun.com>
parents: 575
diff changeset
  2102
                error(_("\nMaximum (%d) network retries exceeded during "
6ee6de304041 3777 PKG_TIMEOUT_MAX is a placebo setting
Dan Price <dp@eng.sun.com>
parents: 575
diff changeset
  2103
                    "download. Details follow:\n%s") %
6ee6de304041 3777 PKG_TIMEOUT_MAX is a placebo setting
Dan Price <dp@eng.sun.com>
parents: 575
diff changeset
  2104
                      (global_settings.PKG_TIMEOUT_MAX, __e))
539
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  2105
                __ret = 1
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2106
        except (ManifestRetrievalError,
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2107
            DatastreamRetrievalError), __e:
569
48f7e9d2b1ac 3715 permission or read-only filesystem errors cause history traceback
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 565
diff changeset
  2108
                if __img:
48f7e9d2b1ac 3715 permission or read-only filesystem errors cause history traceback
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 565
diff changeset
  2109
                        __img.history.abort(RESULT_FAILED_TRANSPORT)
562
afe71b27984d 3618 Manifest retrieval error needs more info and to not show a traceback
Brock Pytlik <bpytlik@sun.com>
parents: 561
diff changeset
  2110
                error(_("An error was encountered while attempting to retrieve"
afe71b27984d 3618 Manifest retrieval error needs more info and to not show a traceback
Brock Pytlik <bpytlik@sun.com>
parents: 561
diff changeset
  2111
                    " package or file data for the requested operation."))
569
48f7e9d2b1ac 3715 permission or read-only filesystem errors cause history traceback
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 565
diff changeset
  2112
                error(__e)
48f7e9d2b1ac 3715 permission or read-only filesystem errors cause history traceback
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 565
diff changeset
  2113
                __ret = 1
48f7e9d2b1ac 3715 permission or read-only filesystem errors cause history traceback
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 565
diff changeset
  2114
        except history.HistoryLoadException, __e:
48f7e9d2b1ac 3715 permission or read-only filesystem errors cause history traceback
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 565
diff changeset
  2115
                # Since a history related error occurred, discard all
48f7e9d2b1ac 3715 permission or read-only filesystem errors cause history traceback
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 565
diff changeset
  2116
                # information about the current operation(s) in progress.
48f7e9d2b1ac 3715 permission or read-only filesystem errors cause history traceback
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 565
diff changeset
  2117
                if __img:
48f7e9d2b1ac 3715 permission or read-only filesystem errors cause history traceback
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 565
diff changeset
  2118
                        __img.history.clear()
48f7e9d2b1ac 3715 permission or read-only filesystem errors cause history traceback
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 565
diff changeset
  2119
                error(_("An error was encountered while attempting to load "
48f7e9d2b1ac 3715 permission or read-only filesystem errors cause history traceback
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 565
diff changeset
  2120
                    "history information\nabout past client operations."))
48f7e9d2b1ac 3715 permission or read-only filesystem errors cause history traceback
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 565
diff changeset
  2121
                error(__e)
48f7e9d2b1ac 3715 permission or read-only filesystem errors cause history traceback
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 565
diff changeset
  2122
                __ret = 1
48f7e9d2b1ac 3715 permission or read-only filesystem errors cause history traceback
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 565
diff changeset
  2123
        except history.HistoryStoreException, __e:
48f7e9d2b1ac 3715 permission or read-only filesystem errors cause history traceback
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 565
diff changeset
  2124
                # Since a history related error occurred, discard all
48f7e9d2b1ac 3715 permission or read-only filesystem errors cause history traceback
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 565
diff changeset
  2125
                # information about the current operation(s) in progress.
48f7e9d2b1ac 3715 permission or read-only filesystem errors cause history traceback
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 565
diff changeset
  2126
                if __img:
48f7e9d2b1ac 3715 permission or read-only filesystem errors cause history traceback
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 565
diff changeset
  2127
                        __img.history.clear()
48f7e9d2b1ac 3715 permission or read-only filesystem errors cause history traceback
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 565
diff changeset
  2128
                error(_("An error was encountered while attempting to store "
48f7e9d2b1ac 3715 permission or read-only filesystem errors cause history traceback
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 565
diff changeset
  2129
                    "information about the\ncurrent operation in client "
48f7e9d2b1ac 3715 permission or read-only filesystem errors cause history traceback
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 565
diff changeset
  2130
                    "history."))
48f7e9d2b1ac 3715 permission or read-only filesystem errors cause history traceback
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 565
diff changeset
  2131
                error(__e)
48f7e9d2b1ac 3715 permission or read-only filesystem errors cause history traceback
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 565
diff changeset
  2132
                __ret = 1
48f7e9d2b1ac 3715 permission or read-only filesystem errors cause history traceback
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 565
diff changeset
  2133
        except history.HistoryPurgeException, __e:
48f7e9d2b1ac 3715 permission or read-only filesystem errors cause history traceback
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 565
diff changeset
  2134
                # Since a history related error occurred, discard all
48f7e9d2b1ac 3715 permission or read-only filesystem errors cause history traceback
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 565
diff changeset
  2135
                # information about the current operation(s) in progress.
48f7e9d2b1ac 3715 permission or read-only filesystem errors cause history traceback
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 565
diff changeset
  2136
                if __img:
48f7e9d2b1ac 3715 permission or read-only filesystem errors cause history traceback
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 565
diff changeset
  2137
                        __img.history.clear()
48f7e9d2b1ac 3715 permission or read-only filesystem errors cause history traceback
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 565
diff changeset
  2138
                error(_("An error was encountered while attempting to purge "
48f7e9d2b1ac 3715 permission or read-only filesystem errors cause history traceback
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 565
diff changeset
  2139
                    "client history."))
48f7e9d2b1ac 3715 permission or read-only filesystem errors cause history traceback
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 565
diff changeset
  2140
                error(__e)
562
afe71b27984d 3618 Manifest retrieval error needs more info and to not show a traceback
Brock Pytlik <bpytlik@sun.com>
parents: 561
diff changeset
  2141
                __ret = 1
221
e1dbb27a23b5 52 catalog can leave inventory behind, making pkg(1) blind
Stephen Hahn <sch@Sun.COM>
parents: 219
diff changeset
  2142
        except:
569
48f7e9d2b1ac 3715 permission or read-only filesystem errors cause history traceback
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 565
diff changeset
  2143
                if __img:
48f7e9d2b1ac 3715 permission or read-only filesystem errors cause history traceback
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 565
diff changeset
  2144
                        __img.history.abort(RESULT_FAILED_UNKNOWN)
221
e1dbb27a23b5 52 catalog can leave inventory behind, making pkg(1) blind
Stephen Hahn <sch@Sun.COM>
parents: 219
diff changeset
  2145
                traceback.print_exc()
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 427
diff changeset
  2146
                error(
569
48f7e9d2b1ac 3715 permission or read-only filesystem errors cause history traceback
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 565
diff changeset
  2147
                    _("\n\nThis is an internal error.  Please let the "
48f7e9d2b1ac 3715 permission or read-only filesystem errors cause history traceback
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 565
diff changeset
  2148
                    "developers know about this\nproblem by filing a bug at"
48f7e9d2b1ac 3715 permission or read-only filesystem errors cause history traceback
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 565
diff changeset
  2149
                    "http://defect.opensolaris.org and including the\nabove"
48f7e9d2b1ac 3715 permission or read-only filesystem errors cause history traceback
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 565
diff changeset
  2150
                    "traceback and this message.  The version of pkg(5) is "
48f7e9d2b1ac 3715 permission or read-only filesystem errors cause history traceback
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 565
diff changeset
  2151
                    "'%s'.") % pkg.VERSION)
539
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  2152
                __ret = 99
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  2153
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  2154
        sys.exit(__ret)