src/modules/client/image.py
author Shawn Walker <Shawn.Walker@Sun.COM>
Thu, 16 Oct 2008 08:49:28 -0500
changeset 596 f4519e2a99bc
parent 583 fc856572d86e
child 616 6d307b088d92
permissions -rw-r--r--
3704 InventoryException raised if optional dependencies not in catalog 3890 ImageNotFoundException created with wrong number of arguments
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: 405
diff changeset
     1
#!/usr/bin/python2.4
19
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
     2
#
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
     3
# CDDL HEADER START
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
     4
#
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
     5
# The contents of this file are subject to the terms of the
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
     6
# Common Development and Distribution License (the "License").
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
     7
# You may not use this file except in compliance with the License.
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
     8
#
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
     9
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    10
# or http://www.opensolaris.org/os/licensing.
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    11
# See the License for the specific language governing permissions
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    12
# and limitations under the License.
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    13
#
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    14
# When distributing Covered Code, include this CDDL HEADER in each
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    15
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    16
# If applicable, add the following below this CDDL HEADER, with the
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    17
# fields enclosed by brackets "[]" replaced with your own identifying
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    18
# information: Portions Copyright [yyyy] [name of copyright owner]
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    19
#
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    20
# CDDL HEADER END
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    21
#
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    22
221
e1dbb27a23b5 52 catalog can leave inventory behind, making pkg(1) blind
Stephen Hahn <sch@Sun.COM>
parents: 219
diff changeset
    23
# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
19
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    24
# Use is subject to license terms.
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    25
144
ce619e0b453f Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents: 139
diff changeset
    26
import cPickle
161
e0322fe7842c Simplify and correct the package matching code.
Danek Duvall <danek.duvall@sun.com>
parents: 157
diff changeset
    27
import errno
26
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
    28
import os
388
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
    29
import socket
45
8a3f00dea14f catalog refresh; basic catalog listing; precise manifest pulls
Stephen Hahn <sch@sun.com>
parents: 39
diff changeset
    30
import urllib
201
63e78f600aa7 185 traceback on pkg refresh when hostname lookup fails
Danek Duvall <danek.duvall@sun.com>
parents: 195
diff changeset
    31
import urllib2
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
    32
import httplib
251
6c3d70b74865 470 pkg image-update can fail under some conditions
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 243
diff changeset
    33
import shutil
462
910600c14093 45 "move" action for files that are renamed, but must be preserved
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 461
diff changeset
    34
import tempfile
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
    35
import time
479
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
    36
import datetime
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
    37
import calendar
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
    38
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
    39
import OpenSSL.crypto as osc
384
9d4746e5dd3e 115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents: 383
diff changeset
    40
9d4746e5dd3e 115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents: 383
diff changeset
    41
from pkg.misc import msg, emsg
9d4746e5dd3e 115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents: 383
diff changeset
    42
104
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
    43
# import uuid           # XXX interesting 2.5 module
34
8b9613402116 refactor catalog and package to be common; improve bump-server
Stephen Hahn <sch@sun.com>
parents: 33
diff changeset
    44
8b9613402116 refactor catalog and package to be common; improve bump-server
Stephen Hahn <sch@sun.com>
parents: 33
diff changeset
    45
import pkg.catalog as catalog
215
c10719939c6d 245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents: 208
diff changeset
    46
import pkg.updatelog as updatelog
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
    47
import pkg.fmri
50
bfcb1661f019 basic image and package plans
Stephen Hahn <sch@sun.com>
parents: 45
diff changeset
    48
import pkg.manifest as manifest
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
    49
import pkg.misc as misc
551
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
    50
import pkg.Uuid25
539
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
    51
import pkg.version
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
    52
import pkg.client.history as history
104
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
    53
import pkg.client.imageconfig as imageconfig
172
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
    54
import pkg.client.imageplan as imageplan
583
fc856572d86e 388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents: 582
diff changeset
    55
import pkg.client.pkgplan as pkgplan
556
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
    56
import pkg.client.imagestate as imagestate
161
e0322fe7842c Simplify and correct the package matching code.
Danek Duvall <danek.duvall@sun.com>
parents: 157
diff changeset
    57
import pkg.client.retrieve as retrieve
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
    58
import pkg.client.progress as progress
289
c2e63370fb2b 160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents: 285
diff changeset
    59
import pkg.portable as portable
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
    60
import pkg.client.query_engine as query_e
516
53da6297fb65 3039 Install and Image-update should check index consistency with installed packages
Brock Pytlik <bpytlik@sun.com>
parents: 499
diff changeset
    61
import pkg.client.indexer as indexer
449
615045a660d4 2797 Without indexes, search should fall back
Brock Pytlik <bpytlik@sun.com>
parents: 434
diff changeset
    62
import pkg.search_errors as search_errors
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
    63
import pkg.client.api_errors as api_errors
104
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
    64
145
08bee7fd13f6 Add versioning to the protocols
Danek Duvall <danek.duvall@sun.com>
parents: 144
diff changeset
    65
from pkg.misc import versioned_urlopen
576
6ee6de304041 3777 PKG_TIMEOUT_MAX is a placebo setting
Dan Price <dp@eng.sun.com>
parents: 573
diff changeset
    66
from pkg.misc import TransportException
388
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
    67
from pkg.misc import TransferTimedOutException
576
6ee6de304041 3777 PKG_TIMEOUT_MAX is a placebo setting
Dan Price <dp@eng.sun.com>
parents: 573
diff changeset
    68
from pkg.misc import TransportFailures
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
    69
from pkg.misc import CLIENT_DEFAULT_MEM_USE_KB
576
6ee6de304041 3777 PKG_TIMEOUT_MAX is a placebo setting
Dan Price <dp@eng.sun.com>
parents: 573
diff changeset
    70
from pkg.client import global_settings
319
39b8b5c538bf 1104 want custom user-agent string
Danek Duvall <danek.duvall@sun.com>
parents: 316
diff changeset
    71
from pkg.client.imagetypes import *
19
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    72
26
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
    73
img_user_prefix = ".org.opensolaris,pkg"
30
f06ad6cb4b3f stop using flavour terminology
Stephen Hahn <sch@sun.com>
parents: 29
diff changeset
    74
img_root_prefix = "var/pkg"
26
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
    75
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
    76
PKG_STATE_INSTALLED = "installed"
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
    77
PKG_STATE_KNOWN = "known"
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
    78
479
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
    79
# Minimum number of days to issue warning before a certificate expires
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
    80
MIN_WARN_DAYS = datetime.timedelta(days=30)
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
    81
19
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    82
class Image(object):
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    83
        """An Image object is a directory tree containing the laid-down contents
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    84
        of a self-consistent graph of Packages.
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    85
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    86
        An Image has a root path.
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    87
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    88
        An Image of type IMG_ENTIRE does not have a parent Image.  Other Image
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    89
        types must have a parent Image.  The external state of the parent Image
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    90
        must be accessible from the Image's context, or duplicated within the
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    91
        Image (IMG_PARTIAL for zones, for instance).
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    92
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    93
        The parent of a user Image can be a partial Image.  The parent of a
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    94
        partial Image must be an entire Image.
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    95
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    96
        An Image of type IMG_USER stores its external state at self.root +
26
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
    97
        ".org.opensolaris,pkg".
19
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    98
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    99
        An Image of type IMG_ENTIRE or IMG_PARTIAL stores its external state at
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
   100
        self.root + "/var/pkg".
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
   101
26
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   102
        An Image needs to be able to have a different repository set than the
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   103
        system's root Image.
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   104
29
f621f1df0849 fix install target; correct imports for module renames
"Stephen Hahn <sch@sun.com>"
parents: 26
diff changeset
   105
        Directory layout
f621f1df0849 fix install target; correct imports for module renames
"Stephen Hahn <sch@sun.com>"
parents: 26
diff changeset
   106
f621f1df0849 fix install target; correct imports for module renames
"Stephen Hahn <sch@sun.com>"
parents: 26
diff changeset
   107
          $IROOT/catalog
f621f1df0849 fix install target; correct imports for module renames
"Stephen Hahn <sch@sun.com>"
parents: 26
diff changeset
   108
               Directory containing catalogs for URIs of interest.  Filename is
f621f1df0849 fix install target; correct imports for module renames
"Stephen Hahn <sch@sun.com>"
parents: 26
diff changeset
   109
               the escaped URI of the catalog.
f621f1df0849 fix install target; correct imports for module renames
"Stephen Hahn <sch@sun.com>"
parents: 26
diff changeset
   110
30
f06ad6cb4b3f stop using flavour terminology
Stephen Hahn <sch@sun.com>
parents: 29
diff changeset
   111
          $IROOT/file
f06ad6cb4b3f stop using flavour terminology
Stephen Hahn <sch@sun.com>
parents: 29
diff changeset
   112
               Directory containing file hashes of installed packages.
f06ad6cb4b3f stop using flavour terminology
Stephen Hahn <sch@sun.com>
parents: 29
diff changeset
   113
f06ad6cb4b3f stop using flavour terminology
Stephen Hahn <sch@sun.com>
parents: 29
diff changeset
   114
          $IROOT/pkg
f06ad6cb4b3f stop using flavour terminology
Stephen Hahn <sch@sun.com>
parents: 29
diff changeset
   115
               Directory containing manifests and states of installed packages.
f06ad6cb4b3f stop using flavour terminology
Stephen Hahn <sch@sun.com>
parents: 29
diff changeset
   116
60
6bd5cd83cfb1 Reverse index database and searching support.
Danek Duvall <danek.duvall@sun.com>
parents: 59
diff changeset
   117
          $IROOT/index
6bd5cd83cfb1 Reverse index database and searching support.
Danek Duvall <danek.duvall@sun.com>
parents: 59
diff changeset
   118
               Directory containing reverse-index databases.
6bd5cd83cfb1 Reverse index database and searching support.
Danek Duvall <danek.duvall@sun.com>
parents: 59
diff changeset
   119
104
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   120
          $IROOT/cfg_cache
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   121
               File containing image's cached configuration.
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   122
418
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
   123
          $IROOT/opaque
104
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   124
               File containing image's opaque state.
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   125
418
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
   126
          $IROOT/state/installed
434
48c05c66cdd2 2595 List speedup changes don't work on Windows
Tom Mueller <Tom.Mueller@sun.com>
parents: 432
diff changeset
   127
               Directory containing files whose names identify the installed
48c05c66cdd2 2595 List speedup changes don't work on Windows
Tom Mueller <Tom.Mueller@sun.com>
parents: 432
diff changeset
   128
               packages.
418
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
   129
397
617be57c5f2b 777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents: 394
diff changeset
   130
        All of these directories and files other than state are considered
617be57c5f2b 777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents: 394
diff changeset
   131
        essential for any image to be complete. To add a new essential file or
617be57c5f2b 777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents: 394
diff changeset
   132
        subdirectory, the following steps should be done.
617be57c5f2b 777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents: 394
diff changeset
   133
617be57c5f2b 777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents: 394
diff changeset
   134
        If it's a directory, add it to the image_subdirs list below and it will
617be57c5f2b 777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents: 394
diff changeset
   135
        be created automatically. The programmer must fill the directory as
617be57c5f2b 777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents: 394
diff changeset
   136
        needed. If a file is added, the programmer is responsible for creating
617be57c5f2b 777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents: 394
diff changeset
   137
        that file during image creation at an appropriate place and time.
617be57c5f2b 777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents: 394
diff changeset
   138
418
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
   139
        If a directory is required to be present in order for an image to be
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
   140
        identifiable as such, it should go into required_subdirs instead.
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
   141
        However, upgrade issues abound; this list should probably not change.
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
   142
397
617be57c5f2b 777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents: 394
diff changeset
   143
        Once those steps have been carried out, the change should be added
617be57c5f2b 777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents: 394
diff changeset
   144
        to the test suite for image corruption (t_pkg_install_corrupt_image.py).
617be57c5f2b 777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents: 394
diff changeset
   145
        This will likely also involve a change to
617be57c5f2b 777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents: 394
diff changeset
   146
        SingleDepotTestCaseCorruptImage in testutils.py. Each of these files
617be57c5f2b 777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents: 394
diff changeset
   147
        outline what must be updated.
617be57c5f2b 777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents: 394
diff changeset
   148
19
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
   149
        XXX Root path probably can't be absolute, so that we can combine or
30
f06ad6cb4b3f stop using flavour terminology
Stephen Hahn <sch@sun.com>
parents: 29
diff changeset
   150
        reuse Image contents.
26
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   151
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   152
        XXX Image file format?  Image file manipulation API?"""
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   153
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
   154
        required_subdirs = [ "catalog", "file", "pkg" ]
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
   155
        image_subdirs = required_subdirs + [ "index", "state/installed" ]
397
617be57c5f2b 777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents: 394
diff changeset
   156
26
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   157
        def __init__(self):
104
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   158
                self.cfg_cache = None
26
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   159
                self.type = None
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   160
                self.root = None
539
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
   161
                self.history = history.History()
30
f06ad6cb4b3f stop using flavour terminology
Stephen Hahn <sch@sun.com>
parents: 29
diff changeset
   162
                self.imgdir = None
271
ec8a7669bff2 659 package that delivers existing automounter mountpoint fails installation
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 268
diff changeset
   163
                self.img_prefix = None
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
   164
                self.index_dir = None
26
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   165
                self.repo_uris = []
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   166
                self.filter_tags = {}
32
c26788b7217c begin client install; sequences are now timestamps; skeleton ELF module
Stephen Hahn <sch@sun.com>
parents: 30
diff changeset
   167
                self.catalogs = {}
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
   168
                self._catalog = {}
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
   169
                self.pkg_states = None
554
fe196874250d 3508 zone install should utilize/populate global zone d/l cache
Dan Price <dp@eng.sun.com>
parents: 552
diff changeset
   170
                self.dl_cache_dir = None
fe196874250d 3508 zone install should utilize/populate global zone d/l cache
Dan Price <dp@eng.sun.com>
parents: 552
diff changeset
   171
                self.dl_cache_incoming = None
fe196874250d 3508 zone install should utilize/populate global zone d/l cache
Dan Price <dp@eng.sun.com>
parents: 552
diff changeset
   172
                self.is_user_cache_dir = False
556
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   173
                self.state = imagestate.ImageState()
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   174
                self.attrs = {
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   175
                    "Policy-Require-Optional": False,
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   176
                    "Policy-Pursue-Latest": True
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   177
                }
32
c26788b7217c begin client install; sequences are now timestamps; skeleton ELF module
Stephen Hahn <sch@sun.com>
parents: 30
diff changeset
   178
556
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   179
                self.imageplan = None # valid after evaluation succeeds
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
   180
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   181
                # contains a dictionary w/ key = pkgname, value is miminum
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   182
                # frmi.XXX  Needs rewrite using graph follower
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   183
                self.optional_dependencies = {}
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   184
462
910600c14093 45 "move" action for files that are renamed, but must be preserved
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 461
diff changeset
   185
                # a place to keep info about saved_files; needed by file action
910600c14093 45 "move" action for files that are renamed, but must be preserved
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 461
diff changeset
   186
                self.saved_files = {}
556
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   187
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   188
                # A place to keep track of which manifests (based on fmri and
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   189
                # operation) have already provided intent information.
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   190
                self.__touched_manifests = {}
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   191
567
ea1d96e269a4 3505 client action and manifest creation are wasteful
johansen <johansen@sun.com>
parents: 565
diff changeset
   192
                self.__manifest_cache = {}
ea1d96e269a4 3505 client action and manifest creation are wasteful
johansen <johansen@sun.com>
parents: 565
diff changeset
   193
582
303fa3b78f93 3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents: 577
diff changeset
   194
        def _check_subdirs(self, sub_d, prefix):
303fa3b78f93 3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents: 577
diff changeset
   195
                for n in self.required_subdirs:
303fa3b78f93 3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents: 577
diff changeset
   196
                        if not os.path.isdir(os.path.join(sub_d, prefix, n)):
303fa3b78f93 3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents: 577
diff changeset
   197
                                return False
303fa3b78f93 3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents: 577
diff changeset
   198
                return True
397
617be57c5f2b 777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents: 394
diff changeset
   199
582
303fa3b78f93 3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents: 577
diff changeset
   200
        def image_type(self, d):
303fa3b78f93 3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents: 577
diff changeset
   201
                """Returns the type of image at directory: d; or None"""
303fa3b78f93 3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents: 577
diff changeset
   202
                rv = None
303fa3b78f93 3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents: 577
diff changeset
   203
                if os.path.isdir(os.path.join(d, img_user_prefix)) and \
303fa3b78f93 3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents: 577
diff changeset
   204
                        os.path.isfile(os.path.join(d, img_user_prefix,
303fa3b78f93 3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents: 577
diff changeset
   205
                            "cfg_cache")) and \
303fa3b78f93 3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents: 577
diff changeset
   206
                            self._check_subdirs(d, img_user_prefix):
303fa3b78f93 3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents: 577
diff changeset
   207
                        rv = IMG_USER
303fa3b78f93 3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents: 577
diff changeset
   208
                elif os.path.isdir(os.path.join(d, img_root_prefix)) \
303fa3b78f93 3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents: 577
diff changeset
   209
                         and os.path.isfile(os.path.join(d,
303fa3b78f93 3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents: 577
diff changeset
   210
                             img_root_prefix, "cfg_cache")) and \
303fa3b78f93 3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents: 577
diff changeset
   211
                             self._check_subdirs(d, img_root_prefix):
303fa3b78f93 3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents: 577
diff changeset
   212
                        rv = IMG_ENTIRE
303fa3b78f93 3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents: 577
diff changeset
   213
                return rv
303fa3b78f93 3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents: 577
diff changeset
   214
                
303fa3b78f93 3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents: 577
diff changeset
   215
        def find_root(self, d, exact_match=False):
289
c2e63370fb2b 160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents: 285
diff changeset
   216
                # Ascend from the given directory d to find first
561
be1ad23e7704 1651 pkg treats -R <bogus-dir> as "use the image at /"
Brock Pytlik <bpytlik@sun.com>
parents: 560
diff changeset
   217
                # encountered image. If exact_match is true, if the
be1ad23e7704 1651 pkg treats -R <bogus-dir> as "use the image at /"
Brock Pytlik <bpytlik@sun.com>
parents: 560
diff changeset
   218
                # image found doesn't match startd, raise an
be1ad23e7704 1651 pkg treats -R <bogus-dir> as "use the image at /"
Brock Pytlik <bpytlik@sun.com>
parents: 560
diff changeset
   219
                # ImageNotFoundException.
289
c2e63370fb2b 160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents: 285
diff changeset
   220
                startd = d
c2e63370fb2b 160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents: 285
diff changeset
   221
                # eliminate problem if relative path such as "." is passed in
c2e63370fb2b 160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents: 285
diff changeset
   222
                d = os.path.realpath(d)
26
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   223
                while True:
582
303fa3b78f93 3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents: 577
diff changeset
   224
                        imgtype = self.image_type(d)
303fa3b78f93 3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents: 577
diff changeset
   225
                        if imgtype == IMG_USER:
26
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   226
                                # XXX Look at image file to determine filter
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   227
                                # tags and repo URIs.
561
be1ad23e7704 1651 pkg treats -R <bogus-dir> as "use the image at /"
Brock Pytlik <bpytlik@sun.com>
parents: 560
diff changeset
   228
                                if exact_match and \
be1ad23e7704 1651 pkg treats -R <bogus-dir> as "use the image at /"
Brock Pytlik <bpytlik@sun.com>
parents: 560
diff changeset
   229
                                    os.path.realpath(startd) != \
be1ad23e7704 1651 pkg treats -R <bogus-dir> as "use the image at /"
Brock Pytlik <bpytlik@sun.com>
parents: 560
diff changeset
   230
                                    os.path.realpath(d):
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   231
                                        raise api_errors.ImageNotFoundException(
561
be1ad23e7704 1651 pkg treats -R <bogus-dir> as "use the image at /"
Brock Pytlik <bpytlik@sun.com>
parents: 560
diff changeset
   232
                                            exact_match, startd, d)
582
303fa3b78f93 3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents: 577
diff changeset
   233
                                self.__set_dirs(imgtype=imgtype, root=d)
59
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
   234
                                self.attrs["Build-Release"] = "5.11"
26
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   235
                                return
582
303fa3b78f93 3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents: 577
diff changeset
   236
                        elif imgtype == IMG_ENTIRE:
26
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   237
                                # XXX Look at image file to determine filter
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   238
                                # tags and repo URIs.
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   239
                                # XXX Look at image file to determine if this
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   240
                                # image is a partial image.
561
be1ad23e7704 1651 pkg treats -R <bogus-dir> as "use the image at /"
Brock Pytlik <bpytlik@sun.com>
parents: 560
diff changeset
   241
                                if exact_match and \
be1ad23e7704 1651 pkg treats -R <bogus-dir> as "use the image at /"
Brock Pytlik <bpytlik@sun.com>
parents: 560
diff changeset
   242
                                    os.path.realpath(startd) != \
be1ad23e7704 1651 pkg treats -R <bogus-dir> as "use the image at /"
Brock Pytlik <bpytlik@sun.com>
parents: 560
diff changeset
   243
                                    os.path.realpath(d):
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   244
                                        raise api_errors.ImageNotFoundException(
561
be1ad23e7704 1651 pkg treats -R <bogus-dir> as "use the image at /"
Brock Pytlik <bpytlik@sun.com>
parents: 560
diff changeset
   245
                                            exact_match, startd, d)
582
303fa3b78f93 3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents: 577
diff changeset
   246
                                self.__set_dirs(imgtype=imgtype, root=d)
59
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
   247
                                self.attrs["Build-Release"] = "5.11"
26
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   248
                                return
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   249
289
c2e63370fb2b 160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents: 285
diff changeset
   250
                        # XXX follow symlinks or not?
c2e63370fb2b 160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents: 285
diff changeset
   251
                        oldpath = d
c2e63370fb2b 160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents: 285
diff changeset
   252
                        d = os.path.normpath(os.path.join(d, os.path.pardir))
26
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   253
289
c2e63370fb2b 160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents: 285
diff changeset
   254
                        # Make sure we are making progress and aren't in an
c2e63370fb2b 160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents: 285
diff changeset
   255
                        # infinite loop.
c2e63370fb2b 160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents: 285
diff changeset
   256
                        #
c2e63370fb2b 160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents: 285
diff changeset
   257
                        # (XXX - Need to deal with symlinks here too)
c2e63370fb2b 160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents: 285
diff changeset
   258
                        if d == oldpath:
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   259
                                raise api_errors.ImageNotFoundException(
596
f4519e2a99bc 3704 InventoryException raised if optional dependencies not in catalog
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 583
diff changeset
   260
                                    exact_match, startd, d)
26
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   261
104
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   262
        def load_config(self):
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   263
                """Load this image's cached configuration from the default
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   264
                location."""
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   265
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   266
                # XXX Incomplete with respect to doc/image.txt description of
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   267
                # configuration.
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   268
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   269
                if self.root == None:
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   270
                        raise RuntimeError, "self.root must be set"
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   271
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   272
                ic = imageconfig.ImageConfig()
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   273
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   274
                if os.path.isfile("%s/cfg_cache" % self.imgdir):
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   275
                        ic.read("%s/cfg_cache" % self.imgdir)
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   276
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   277
                self.cfg_cache = ic
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   278
551
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
   279
        def save_config(self):
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
   280
                self.cfg_cache.write("%s/cfg_cache" % self.imgdir)
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
   281
104
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   282
        # XXX mkdirs and set_attrs() need to be combined into a create
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   283
        # operation.
29
f621f1df0849 fix install target; correct imports for module renames
"Stephen Hahn <sch@sun.com>"
parents: 26
diff changeset
   284
        def mkdirs(self):
397
617be57c5f2b 777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents: 394
diff changeset
   285
                for sd in self.image_subdirs:
617be57c5f2b 777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents: 394
diff changeset
   286
                        if not os.path.isdir(os.path.join(self.imgdir, sd)):
617be57c5f2b 777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents: 394
diff changeset
   287
                                os.makedirs(os.path.join(self.imgdir, sd))
29
f621f1df0849 fix install target; correct imports for module renames
"Stephen Hahn <sch@sun.com>"
parents: 26
diff changeset
   288
554
fe196874250d 3508 zone install should utilize/populate global zone d/l cache
Dan Price <dp@eng.sun.com>
parents: 552
diff changeset
   289
        def __set_dirs(self, imgtype, root):
fe196874250d 3508 zone install should utilize/populate global zone d/l cache
Dan Price <dp@eng.sun.com>
parents: 552
diff changeset
   290
                self.type = imgtype
22
379f0f6809ff pkgsend open, pkgsend add file, pkgsend close; Transaction object
"Stephen Hahn <sch@sun.com>"
parents: 19
diff changeset
   291
                self.root = root
379f0f6809ff pkgsend open, pkgsend add file, pkgsend close; Transaction object
"Stephen Hahn <sch@sun.com>"
parents: 19
diff changeset
   292
                if self.type == IMG_USER:
271
ec8a7669bff2 659 package that delivers existing automounter mountpoint fails installation
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 268
diff changeset
   293
                        self.img_prefix = img_user_prefix
22
379f0f6809ff pkgsend open, pkgsend add file, pkgsend close; Transaction object
"Stephen Hahn <sch@sun.com>"
parents: 19
diff changeset
   294
                else:
271
ec8a7669bff2 659 package that delivers existing automounter mountpoint fails installation
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 268
diff changeset
   295
                        self.img_prefix = img_root_prefix
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
   296
                self.imgdir = os.path.join(self.root, self.img_prefix)
539
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
   297
                self.history.root_dir = self.imgdir
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
   298
554
fe196874250d 3508 zone install should utilize/populate global zone d/l cache
Dan Price <dp@eng.sun.com>
parents: 552
diff changeset
   299
                if "PKG_CACHEDIR" in os.environ:
fe196874250d 3508 zone install should utilize/populate global zone d/l cache
Dan Price <dp@eng.sun.com>
parents: 552
diff changeset
   300
                        self.dl_cache_dir = os.path.normpath( \
fe196874250d 3508 zone install should utilize/populate global zone d/l cache
Dan Price <dp@eng.sun.com>
parents: 552
diff changeset
   301
                            os.environ["PKG_CACHEDIR"])
fe196874250d 3508 zone install should utilize/populate global zone d/l cache
Dan Price <dp@eng.sun.com>
parents: 552
diff changeset
   302
                        self.is_user_cache_dir = True
fe196874250d 3508 zone install should utilize/populate global zone d/l cache
Dan Price <dp@eng.sun.com>
parents: 552
diff changeset
   303
                else:
fe196874250d 3508 zone install should utilize/populate global zone d/l cache
Dan Price <dp@eng.sun.com>
parents: 552
diff changeset
   304
                        self.dl_cache_dir = os.path.normpath( \
fe196874250d 3508 zone install should utilize/populate global zone d/l cache
Dan Price <dp@eng.sun.com>
parents: 552
diff changeset
   305
                            os.path.join(self.imgdir, "download"))
fe196874250d 3508 zone install should utilize/populate global zone d/l cache
Dan Price <dp@eng.sun.com>
parents: 552
diff changeset
   306
                self.dl_cache_incoming = os.path.normpath(os.path.join(
fe196874250d 3508 zone install should utilize/populate global zone d/l cache
Dan Price <dp@eng.sun.com>
parents: 552
diff changeset
   307
                    self.dl_cache_dir, "incoming-%d" % os.getpid()))
fe196874250d 3508 zone install should utilize/populate global zone d/l cache
Dan Price <dp@eng.sun.com>
parents: 552
diff changeset
   308
fe196874250d 3508 zone install should utilize/populate global zone d/l cache
Dan Price <dp@eng.sun.com>
parents: 552
diff changeset
   309
        def set_attrs(self, type, root, is_zone, auth_name, auth_url,
fe196874250d 3508 zone install should utilize/populate global zone d/l cache
Dan Price <dp@eng.sun.com>
parents: 552
diff changeset
   310
            ssl_key = None, ssl_cert = None):
fe196874250d 3508 zone install should utilize/populate global zone d/l cache
Dan Price <dp@eng.sun.com>
parents: 552
diff changeset
   311
                self.__set_dirs(imgtype=type, root=root)
fe196874250d 3508 zone install should utilize/populate global zone d/l cache
Dan Price <dp@eng.sun.com>
parents: 552
diff changeset
   312
539
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
   313
                if not os.path.exists(os.path.join(self.imgdir, "cfg_cache")):
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
   314
                        self.history.operation_name = "image-create"
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
   315
                else:
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
   316
                        self.history.operation_name = "image-set-attributes"
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
   317
104
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   318
                self.mkdirs()
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   319
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   320
                self.cfg_cache = imageconfig.ImageConfig()
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   321
111
647c91609117 Client-side filtering.
Danek Duvall <danek.duvall@sun.com>
parents: 107
diff changeset
   322
                if is_zone:
647c91609117 Client-side filtering.
Danek Duvall <danek.duvall@sun.com>
parents: 107
diff changeset
   323
                        self.cfg_cache.filters["opensolaris.zone"] = "nonglobal"
104
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   324
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   325
                self.cfg_cache.authorities[auth_name] = {}
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   326
                self.cfg_cache.authorities[auth_name]["prefix"] = auth_name
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   327
                self.cfg_cache.authorities[auth_name]["origin"] = \
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   328
                    misc.url_affix_trailing_slash(auth_url)
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   329
                self.cfg_cache.authorities[auth_name]["mirrors"] = []
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   330
                self.cfg_cache.authorities[auth_name]["ssl_key"] = ssl_key
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   331
                self.cfg_cache.authorities[auth_name]["ssl_cert"] = ssl_cert
551
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
   332
                self.cfg_cache.authorities[auth_name]["uuid"] = pkg.Uuid25.uuid1()
104
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   333
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   334
                self.cfg_cache.preferred_authority = auth_name
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   335
551
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
   336
                self.save_config()
539
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
   337
                self.history.operation_result = history.RESULT_SUCCEEDED
104
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   338
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   339
        def is_liveroot(self):
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   340
                return self.root == "/"
281
81a0bb7f7d63 217 packages need to be able to [un]install users (groups, roles, etc)
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 271
diff changeset
   341
344
4c887185d780 528 pkg list -u gives confusing output
Dan Price <dp@eng.sun.com>
parents: 342
diff changeset
   342
        def is_zone(self):
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
   343
                zone = self.cfg_cache.filters.get("opensolaris.zone", "")
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
   344
                return zone == "nonglobal"
344
4c887185d780 528 pkg list -u gives confusing output
Dan Price <dp@eng.sun.com>
parents: 342
diff changeset
   345
29
f621f1df0849 fix install target; correct imports for module renames
"Stephen Hahn <sch@sun.com>"
parents: 26
diff changeset
   346
        def get_root(self):
f621f1df0849 fix install target; correct imports for module renames
"Stephen Hahn <sch@sun.com>"
parents: 26
diff changeset
   347
                return self.root
f621f1df0849 fix install target; correct imports for module renames
"Stephen Hahn <sch@sun.com>"
parents: 26
diff changeset
   348
104
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   349
        def gen_authorities(self):
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   350
                if not self.cfg_cache:
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   351
                        raise RuntimeError, "empty ImageConfig"
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   352
                if not self.cfg_cache.authorities:
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   353
                        raise RuntimeError, "no defined authorities"
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   354
                for a in self.cfg_cache.authorities:
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   355
                        yield self.cfg_cache.authorities[a]
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   356
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   357
        def get_url_by_authority(self, authority = None):
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   358
                """Return the URL prefix associated with the given authority.
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   359
                For the undefined case, represented by None, return the
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   360
                preferred authority."""
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   361
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   362
                # XXX This function is a possible location to insert one or more
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   363
                # policies regarding use of mirror responses, etc.
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   364
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   365
                if authority == None:
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   366
                        authority = self.cfg_cache.preferred_authority
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   367
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   368
                try:
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   369
                        o = self.cfg_cache.authorities[authority]["origin"]
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   370
                except KeyError:
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   371
                        # If the authority that we're trying to get no longer
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   372
                        # exists, fall back to preferred authority.
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   373
                        authority = self.cfg_cache.preferred_authority
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   374
                        o = self.cfg_cache.authorities[authority]["origin"]
106
ed11fcd45545 pkg status -a; allow trailing / in URL; don't write 404 into manifest;
"Stephen Hahn <sch@sun.com>"
parents: 104
diff changeset
   375
146
9b9fcd56b8b2 Reduce use of the re module, for performance.
Danek Duvall <danek.duvall@sun.com>
parents: 145
diff changeset
   376
                return o.rstrip("/")
104
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   377
461
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   378
        def select_mirror(self, auth = None, chosen_set = None):
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   379
                """For the given authority, look through the status of
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   380
                the mirrors.  Pick the best one.  This method returns
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   381
                a DepotStatus object or None.  The chosen_set argument
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   382
                contains a set object that lists the mirrors that were
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   383
                previously chosen.  This allows us to choose both
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   384
                by depot status statistics and ensures we don't
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   385
                always pick the same depot."""
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   386
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   387
                if auth == None:
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   388
                        auth = self.cfg_cache.preferred_authority
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   389
                try:
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   390
                        slst = self.cfg_cache.mirror_status[auth]
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   391
                except KeyError:
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   392
                        # If the authority that we're trying to get no longer
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   393
                        # exists, fall back to preferred authority.
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   394
                        auth = self.cfg_cache.preferred_authority
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   395
                        slst = self.cfg_cache.mirror_status[auth]
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   396
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   397
                if len(slst) == 0:
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   398
                        if auth in self.cfg_cache.authority_status:
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   399
                                return self.cfg_cache.authority_status[auth]
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   400
                        else:
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   401
                                return None
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   402
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   403
                # Choose mirror with fewest errors.
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   404
                # If mirrors have same number of errors, choose mirror
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   405
                # with smaller number of good transactions.  Assume it's
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   406
                # being underused, not high-latency.
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   407
                #
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   408
                # XXX Will need to revisit the above assumption.
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   409
                def cmp_depotstatus(a, b):
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   410
                        res = cmp(a.errors, b.errors)
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   411
                        if res == 0:
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   412
                                return cmp(a.good_tx, b.good_tx)
556
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   413
                        return res
461
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   414
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   415
                slst.sort(cmp = cmp_depotstatus)
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   416
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   417
                if chosen_set and len(chosen_set) == len(slst):
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   418
                        chosen_set.clear()
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   419
                        chosen_set = None
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   420
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   421
                if chosen_set and slst[0] in chosen_set:
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   422
                        for ds in slst:
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   423
                                if ds not in chosen_set:
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   424
                                        return ds
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   425
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   426
                return slst[0]
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   427
322
e1b078577730 1101 pkg search -s <server> returns a traceback
Danek Duvall <danek.duvall@sun.com>
parents: 319
diff changeset
   428
        def get_ssl_credentials(self, authority = None, origin = None):
e1b078577730 1101 pkg search -s <server> returns a traceback
Danek Duvall <danek.duvall@sun.com>
parents: 319
diff changeset
   429
                """Return a tuple containing (ssl_key, ssl_cert) for the
e1b078577730 1101 pkg search -s <server> returns a traceback
Danek Duvall <danek.duvall@sun.com>
parents: 319
diff changeset
   430
                specified authority prefix.  If the authority isn't specified,
e1b078577730 1101 pkg search -s <server> returns a traceback
Danek Duvall <danek.duvall@sun.com>
parents: 319
diff changeset
   431
                attempt to determine the authority by the given origin.  If
e1b078577730 1101 pkg search -s <server> returns a traceback
Danek Duvall <danek.duvall@sun.com>
parents: 319
diff changeset
   432
                neither is specified, use the preferred authority.
e1b078577730 1101 pkg search -s <server> returns a traceback
Danek Duvall <danek.duvall@sun.com>
parents: 319
diff changeset
   433
                """
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   434
322
e1b078577730 1101 pkg search -s <server> returns a traceback
Danek Duvall <danek.duvall@sun.com>
parents: 319
diff changeset
   435
                if authority is None:
e1b078577730 1101 pkg search -s <server> returns a traceback
Danek Duvall <danek.duvall@sun.com>
parents: 319
diff changeset
   436
                        if origin is None:
e1b078577730 1101 pkg search -s <server> returns a traceback
Danek Duvall <danek.duvall@sun.com>
parents: 319
diff changeset
   437
                                authority = self.cfg_cache.preferred_authority
e1b078577730 1101 pkg search -s <server> returns a traceback
Danek Duvall <danek.duvall@sun.com>
parents: 319
diff changeset
   438
                        else:
e1b078577730 1101 pkg search -s <server> returns a traceback
Danek Duvall <danek.duvall@sun.com>
parents: 319
diff changeset
   439
                                auths = self.cfg_cache.authorities
e1b078577730 1101 pkg search -s <server> returns a traceback
Danek Duvall <danek.duvall@sun.com>
parents: 319
diff changeset
   440
                                for pfx, auth in auths.iteritems():
e1b078577730 1101 pkg search -s <server> returns a traceback
Danek Duvall <danek.duvall@sun.com>
parents: 319
diff changeset
   441
                                        if auth["origin"] == origin:
e1b078577730 1101 pkg search -s <server> returns a traceback
Danek Duvall <danek.duvall@sun.com>
parents: 319
diff changeset
   442
                                                authority = pfx
e1b078577730 1101 pkg search -s <server> returns a traceback
Danek Duvall <danek.duvall@sun.com>
parents: 319
diff changeset
   443
                                                break
e1b078577730 1101 pkg search -s <server> returns a traceback
Danek Duvall <danek.duvall@sun.com>
parents: 319
diff changeset
   444
                                else:
e1b078577730 1101 pkg search -s <server> returns a traceback
Danek Duvall <danek.duvall@sun.com>
parents: 319
diff changeset
   445
                                        return None
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   446
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   447
                try:
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   448
                        authent = self.cfg_cache.authorities[authority]
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   449
                except KeyError:
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   450
                        authority = self.cfg_cache.preferred_authority
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   451
                        authent = self.cfg_cache.authorities[authority]
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   452
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   453
                return (authent["ssl_key"], authent["ssl_cert"])
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   454
479
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
   455
        @staticmethod
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
   456
        def build_cert(path):
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
   457
                """Take the file given in path, open it, and use it to create
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
   458
                an X509 certificate object."""
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
   459
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
   460
                cf = file(path, "rb")
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
   461
                certdata = cf.read()
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
   462
                cf.close()
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
   463
                cert = osc.load_certificate(osc.FILETYPE_PEM, certdata)
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
   464
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
   465
                return cert
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
   466
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
   467
        def check_cert_validity(self):
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
   468
                """Look through the authorities defined for the image.  Print
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
   469
                a message and exit with an error if one of the certificates
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
   470
                has expired.  If certificates are getting close to expiration,
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
   471
                print a warning instead."""
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
   472
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
   473
                for a in self.gen_authorities():
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
   474
                        pfx, url, ssl_key, ssl_cert, dt, mir = \
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
   475
                            self.split_authority(a)
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
   476
518
1d9021e9f558 2584 pkg needs to handle proxy error
johansen <johansen@sun.com>
parents: 516
diff changeset
   477
                        if not ssl_cert:
479
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
   478
                                continue
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
   479
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
   480
                        try:
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
   481
                                cert = self.build_cert(ssl_cert)
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
   482
                        except IOError, e:
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
   483
                                if e.errno == errno.ENOENT:
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
   484
                                        emsg(_("Certificate for authority %s" \
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
   485
                                            " not found") % pfx)
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
   486
                                        emsg(_("File was supposed to exist at" \
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
   487
                                           "  path %s") % ssl_cert)
556
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   488
                                        return False
479
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
   489
                                else:
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
   490
                                        raise
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
   491
                        # OpenSSL.crypto.Error
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
   492
                        except osc.Error, e:
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
   493
                                emsg(_("Certificate for authority %s at" \
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
   494
                                    " %s has an invalid format.") % \
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
   495
                                    (pfx, ssl_cert))
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
   496
                                return False
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
   497
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
   498
                        if cert.has_expired():
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
   499
                                emsg(_("Certificate for authority %s" \
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
   500
                                    " has expired") % pfx)
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
   501
                                emsg(_("Please install a valid certificate"))
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
   502
                                return False
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
   503
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
   504
                        now = datetime.datetime.utcnow()
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
   505
                        nb = cert.get_notBefore()
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
   506
                        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: 462
diff changeset
   507
                        nbdt = datetime.datetime.utcfromtimestamp(
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
   508
                            calendar.timegm(t))
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
   509
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
   510
                        # PyOpenSSL's has_expired() doesn't validate the notBefore
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
   511
                        # time on the certificate.  Don't ask me why.
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
   512
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
   513
                        if nbdt > now:
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
   514
                                emsg(_("Certificate for authority %s is" \
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
   515
                                    " invalid") % pfx)
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
   516
                                emsg(_("Certificate effective date is in" \
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
   517
                                    " the future"))
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
   518
                                return False
556
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   519
479
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
   520
                        na = cert.get_notAfter()
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
   521
                        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: 462
diff changeset
   522
                        nadt = datetime.datetime.utcfromtimestamp(
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
   523
                            calendar.timegm(t))
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
   524
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
   525
                        diff = nadt - now
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
   526
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
   527
                        if diff <= MIN_WARN_DAYS:
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
   528
                                emsg(_("Certificate for authority %s will" \
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
   529
                                    " expire in %d days" % (pfx, diff.days)))
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
   530
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
   531
                return True
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
   532
551
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
   533
        def get_uuid(self, authority):
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
   534
                """Return the UUID for the specified authority prefix.  If the
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
   535
                policy for sending the UUID is set to false, return None.
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
   536
                """
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
   537
                if not self.cfg_cache.get_policy(imageconfig.SEND_UUID):
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
   538
                        return None
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
   539
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
   540
                try:
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
   541
                        return self.cfg_cache.authorities[authority]["uuid"]
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
   542
                except KeyError:
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
   543
                        return None
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
   544
                        
104
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   545
        def get_default_authority(self):
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   546
                return self.cfg_cache.preferred_authority
19
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
   547
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   548
        def has_authority(self, auth_name):
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   549
                return auth_name in self.cfg_cache.authorities
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   550
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   551
        def delete_authority(self, auth_name):
539
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
   552
                self.history.operation_name = "delete-authority"
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   553
                if not self.has_authority(auth_name):
539
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
   554
                        error = "no such authority '%s'" % auth_name
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
   555
                        self.history.operation_errors.append(error)
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
   556
                        self.history.operation_result = \
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
   557
                            history.RESULT_FAILED_UNKNOWN
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
   558
                        raise KeyError, error
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   559
                self.cfg_cache.delete_authority(auth_name)
551
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
   560
                self.save_config()
537
3dc9fc9b5fee 1540 changes to authorities should include refresh
Brock Pytlik <bpytlik@sun.com>
parents: 526
diff changeset
   561
                self.destroy_catalog(auth_name)
3dc9fc9b5fee 1540 changes to authorities should include refresh
Brock Pytlik <bpytlik@sun.com>
parents: 526
diff changeset
   562
                self.cache_catalogs()
539
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
   563
                self.history.operation_result = history.RESULT_SUCCEEDED
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   564
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   565
        def get_authority(self, auth_name):
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   566
                if not self.has_authority(auth_name):
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   567
                        raise KeyError, "no such authority '%s'" % auth_name
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   568
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   569
                return self.cfg_cache.authorities[auth_name]
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   570
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   571
        def split_authority(self, auth):
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   572
                prefix = auth["prefix"]
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   573
                update_dt = None
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   574
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   575
                try:
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   576
                        cat = self.catalogs[prefix]
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   577
                except KeyError:
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   578
                        cat = None
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   579
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   580
                if cat:
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   581
                        update_dt = cat.last_modified()
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   582
                        if update_dt:
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   583
                                update_dt = catalog.ts_to_datetime(update_dt)
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   584
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   585
                return (prefix, auth["origin"], auth["ssl_key"],
461
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   586
                    auth["ssl_cert"], update_dt, auth["mirrors"])
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   587
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   588
        def set_preferred_authority(self, auth_name):
539
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
   589
                self.history.operation_name = "set-preferred-authority"
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   590
                if not self.has_authority(auth_name):
539
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
   591
                        error = "no such authority '%s'" % auth_name
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
   592
                        self.history.operation_errors.append(error)
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
   593
                        self.history.operation_result = \
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
   594
                            history.RESULT_FAILED_UNKNOWN
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
   595
                        raise KeyError, error
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   596
                self.cfg_cache.preferred_authority = auth_name
551
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
   597
                self.save_config()
539
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
   598
                self.history.operation_result = history.RESULT_SUCCEEDED
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   599
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   600
        def set_authority(self, auth_name, origin_url = None, ssl_key = None,
551
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
   601
            ssl_cert = None, refresh_allowed = True, uuid = None):
539
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
   602
                self.history.operation_name = "set-authority"
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   603
                auths = self.cfg_cache.authorities
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   604
537
3dc9fc9b5fee 1540 changes to authorities should include refresh
Brock Pytlik <bpytlik@sun.com>
parents: 526
diff changeset
   605
                refresh_needed = False
3dc9fc9b5fee 1540 changes to authorities should include refresh
Brock Pytlik <bpytlik@sun.com>
parents: 526
diff changeset
   606
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   607
                if auth_name in auths:
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   608
                        # If authority already exists, only update non-NULL
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   609
                        # values passed to set_authority
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   610
                        if origin_url:
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   611
                                auths[auth_name]["origin"] = \
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   612
                                    misc.url_affix_trailing_slash(origin_url)
537
3dc9fc9b5fee 1540 changes to authorities should include refresh
Brock Pytlik <bpytlik@sun.com>
parents: 526
diff changeset
   613
                                refresh_needed = True
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   614
                        if ssl_key:
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   615
                                auths[auth_name]["ssl_key"] = ssl_key
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   616
                        if ssl_cert:
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   617
                                auths[auth_name]["ssl_cert"] = ssl_cert
551
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
   618
                        if uuid:
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
   619
                                auths[auth_name]["uuid"] = uuid
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   620
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   621
                else:
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   622
                        auths[auth_name] = {}
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   623
                        auths[auth_name]["prefix"] = auth_name
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   624
                        auths[auth_name]["origin"] = \
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   625
                            misc.url_affix_trailing_slash(origin_url)
461
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   626
                        auths[auth_name]["mirrors"] = []
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   627
                        auths[auth_name]["ssl_key"] = ssl_key
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   628
                        auths[auth_name]["ssl_cert"] = ssl_cert
551
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
   629
                        if not uuid:
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
   630
                                uuid = pkg.Uuid25.uuid1()
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
   631
                        auths[auth_name]["uuid"] = uuid
537
3dc9fc9b5fee 1540 changes to authorities should include refresh
Brock Pytlik <bpytlik@sun.com>
parents: 526
diff changeset
   632
                        refresh_needed = True
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   633
551
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
   634
                self.save_config()
556
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   635
537
3dc9fc9b5fee 1540 changes to authorities should include refresh
Brock Pytlik <bpytlik@sun.com>
parents: 526
diff changeset
   636
                if refresh_needed and refresh_allowed:
3dc9fc9b5fee 1540 changes to authorities should include refresh
Brock Pytlik <bpytlik@sun.com>
parents: 526
diff changeset
   637
                        self.destroy_catalog(auth_name)
3dc9fc9b5fee 1540 changes to authorities should include refresh
Brock Pytlik <bpytlik@sun.com>
parents: 526
diff changeset
   638
                        self.destroy_catalog_cache()
3dc9fc9b5fee 1540 changes to authorities should include refresh
Brock Pytlik <bpytlik@sun.com>
parents: 526
diff changeset
   639
                        self.retrieve_catalogs(full_refresh=True,
3dc9fc9b5fee 1540 changes to authorities should include refresh
Brock Pytlik <bpytlik@sun.com>
parents: 526
diff changeset
   640
                            auths=[auths[auth_name]])
539
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
   641
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
   642
                self.history.operation_result = history.RESULT_SUCCEEDED
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
   643
551
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
   644
        def set_property(self, prop_name, prop_value):
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
   645
                self.cfg_cache.properties[prop_name] = prop_value
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
   646
                self.save_config()
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
   647
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
   648
        def get_property(self, prop_name):
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
   649
                return self.cfg_cache.properties[prop_name]
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
   650
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
   651
        def has_property(self, prop_name):
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
   652
                return prop_name in self.cfg_cache.properties
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
   653
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
   654
        def delete_property(self, prop_name):
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
   655
                del self.cfg_cache.properties[prop_name]
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
   656
                self.save_config()
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
   657
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
   658
        def properties(self):
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
   659
                for p in self.cfg_cache.properties:
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
   660
                        yield p
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
   661
461
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   662
        def add_mirror(self, auth_name, mirror):
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   663
                """Add the mirror URL contained in mirror to
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   664
                auth_name's list of mirrors."""
539
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
   665
                self.history.operation_name = "add-mirror"
461
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   666
                auths = self.cfg_cache.authorities
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   667
                auths[auth_name]["mirrors"].append(mirror)
551
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
   668
                self.save_config()
539
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
   669
                self.history.operation_result = history.RESULT_SUCCEEDED
461
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   670
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   671
        def has_mirror(self, auth_name, url):
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   672
                """Returns true if url is in auth_name's list of mirrors."""
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   673
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   674
                return url in self.cfg_cache.authorities[auth_name]["mirrors"]
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   675
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   676
        def del_mirror(self, auth_name, mirror):
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   677
                """Remove the mirror URL contained in mirror from
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   678
                auth_name's list of mirrors."""
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   679
539
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
   680
                self.history.operation_name = "delete-mirror"
461
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   681
                auths = self.cfg_cache.authorities
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   682
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   683
                if mirror in self.cfg_cache.authorities[auth_name]["mirrors"]:
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   684
                        auths[auth_name]["mirrors"].remove(mirror)
551
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
   685
                        self.save_config()
539
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
   686
                self.history.operation_result = history.RESULT_SUCCEEDED
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
   687
235
61994d15c39b 373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents: 226
diff changeset
   688
        def verify(self, fmri, progresstracker, **args):
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
   689
                """generator that returns any errors in installed pkgs
235
61994d15c39b 373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents: 226
diff changeset
   690
                as tuple of action, list of errors"""
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
   691
235
61994d15c39b 373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents: 226
diff changeset
   692
                for act in self.get_manifest(fmri, filtered = True).actions:
61994d15c39b 373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents: 226
diff changeset
   693
                        errors = act.verify(self, pkg_fmri=fmri, **args)
61994d15c39b 373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents: 226
diff changeset
   694
                        progresstracker.verify_add_progress(fmri)
61994d15c39b 373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents: 226
diff changeset
   695
                        actname = act.distinguished_name()
61994d15c39b 373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents: 226
diff changeset
   696
                        if errors:
61994d15c39b 373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents: 226
diff changeset
   697
                                progresstracker.verify_yield_error(actname,
61994d15c39b 373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents: 226
diff changeset
   698
                                    errors)
583
fc856572d86e 388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents: 582
diff changeset
   699
                                yield (act, errors)
fc856572d86e 388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents: 582
diff changeset
   700
fc856572d86e 388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents: 582
diff changeset
   701
        def repair(self, repairs, progtrack):
fc856572d86e 388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents: 582
diff changeset
   702
                """Repair any actions in the fmri that failed a verify."""
fc856572d86e 388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents: 582
diff changeset
   703
                pps = []
fc856572d86e 388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents: 582
diff changeset
   704
                for fmri, actions in repairs:
fc856572d86e 388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents: 582
diff changeset
   705
                        msg("Repairing: %-50s" % fmri.get_pkg_stem())
fc856572d86e 388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents: 582
diff changeset
   706
                        m = self.get_manifest(fmri, filtered=True)
fc856572d86e 388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents: 582
diff changeset
   707
                        pp = pkgplan.PkgPlan(self, progtrack, False)
fc856572d86e 388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents: 582
diff changeset
   708
fc856572d86e 388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents: 582
diff changeset
   709
                        pp.propose_repair(fmri, m, actions)
fc856572d86e 388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents: 582
diff changeset
   710
                        pp.evaluate()
fc856572d86e 388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents: 582
diff changeset
   711
                        pps.append(pp)
fc856572d86e 388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents: 582
diff changeset
   712
fc856572d86e 388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents: 582
diff changeset
   713
                ip = imageplan.ImagePlan(self, progtrack, False)
fc856572d86e 388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents: 582
diff changeset
   714
                ip.pkg_plans = pps
fc856572d86e 388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents: 582
diff changeset
   715
                try:
fc856572d86e 388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents: 582
diff changeset
   716
                        ip.evaluate()
fc856572d86e 388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents: 582
diff changeset
   717
                        ip.preexecute()
fc856572d86e 388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents: 582
diff changeset
   718
                        ip.execute()
fc856572d86e 388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents: 582
diff changeset
   719
                except KeyboardInterrupt:
fc856572d86e 388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents: 582
diff changeset
   720
                        raise
fc856572d86e 388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents: 582
diff changeset
   721
                except:
fc856572d86e 388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents: 582
diff changeset
   722
                        return False
fc856572d86e 388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents: 582
diff changeset
   723
fc856572d86e 388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents: 582
diff changeset
   724
                return 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
   725
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
   726
        def get_fmri_manifest_pairs(self):
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
   727
                """For each installed fmri, finds the path to its manifest file
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
   728
                and adds the pair of the fmri and the path to a list. Once all
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
   729
                installed fmris have been processed, the list is returned."""
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
   730
                return [
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
   731
                    (fmri, self.get_manifest_path(fmri))
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
   732
                    for fmri in self.gen_installed_pkgs()
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
   733
                ]
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
   734
50
bfcb1661f019 basic image and package plans
Stephen Hahn <sch@sun.com>
parents: 45
diff changeset
   735
        def has_manifest(self, fmri):
45
8a3f00dea14f catalog refresh; basic catalog listing; precise manifest pulls
Stephen Hahn <sch@sun.com>
parents: 39
diff changeset
   736
                mpath = fmri.get_dir_path()
8a3f00dea14f catalog refresh; basic catalog listing; precise manifest pulls
Stephen Hahn <sch@sun.com>
parents: 39
diff changeset
   737
8a3f00dea14f catalog refresh; basic catalog listing; precise manifest pulls
Stephen Hahn <sch@sun.com>
parents: 39
diff changeset
   738
                local_mpath = "%s/pkg/%s/manifest" % (self.imgdir, mpath)
8a3f00dea14f catalog refresh; basic catalog listing; precise manifest pulls
Stephen Hahn <sch@sun.com>
parents: 39
diff changeset
   739
8a3f00dea14f catalog refresh; basic catalog listing; precise manifest pulls
Stephen Hahn <sch@sun.com>
parents: 39
diff changeset
   740
                if (os.path.exists(local_mpath)):
50
bfcb1661f019 basic image and package plans
Stephen Hahn <sch@sun.com>
parents: 45
diff changeset
   741
                        return True
bfcb1661f019 basic image and package plans
Stephen Hahn <sch@sun.com>
parents: 45
diff changeset
   742
bfcb1661f019 basic image and package plans
Stephen Hahn <sch@sun.com>
parents: 45
diff changeset
   743
                return False
45
8a3f00dea14f catalog refresh; basic catalog listing; precise manifest pulls
Stephen Hahn <sch@sun.com>
parents: 39
diff changeset
   744
556
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   745
        def __fetch_manifest_with_retries(self, fmri):
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   746
                """Wrapper function around __fetch_manifest to handle some
388
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
   747
                exceptions and keep track of additional state."""
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
   748
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
   749
                m = None
576
6ee6de304041 3777 PKG_TIMEOUT_MAX is a placebo setting
Dan Price <dp@eng.sun.com>
parents: 573
diff changeset
   750
                retry_count = global_settings.PKG_TIMEOUT_MAX
6ee6de304041 3777 PKG_TIMEOUT_MAX is a placebo setting
Dan Price <dp@eng.sun.com>
parents: 573
diff changeset
   751
                failures = TransportFailures()
388
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
   752
399
e594d9c5bd60 2295 pkg forgets to raise TransferTimedOutException
johansen <johansen@sun.com>
parents: 397
diff changeset
   753
                while not m:
388
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
   754
                        try:
556
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   755
                                m = self.__fetch_manifest(fmri)
576
6ee6de304041 3777 PKG_TIMEOUT_MAX is a placebo setting
Dan Price <dp@eng.sun.com>
parents: 573
diff changeset
   756
                        except TransportException, e:
399
e594d9c5bd60 2295 pkg forgets to raise TransferTimedOutException
johansen <johansen@sun.com>
parents: 397
diff changeset
   757
                                retry_count -= 1
576
6ee6de304041 3777 PKG_TIMEOUT_MAX is a placebo setting
Dan Price <dp@eng.sun.com>
parents: 573
diff changeset
   758
                                failures.append(e)
399
e594d9c5bd60 2295 pkg forgets to raise TransferTimedOutException
johansen <johansen@sun.com>
parents: 397
diff changeset
   759
e594d9c5bd60 2295 pkg forgets to raise TransferTimedOutException
johansen <johansen@sun.com>
parents: 397
diff changeset
   760
                                if retry_count <= 0:
576
6ee6de304041 3777 PKG_TIMEOUT_MAX is a placebo setting
Dan Price <dp@eng.sun.com>
parents: 573
diff changeset
   761
                                        raise failures
556
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   762
388
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
   763
                return m
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
   764
556
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   765
        def __get_touched_manifest(self, fmri):
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   766
                """Returns whether intent information has been provided for the
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   767
                given fmri."""
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   768
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   769
                op = self.history.operation_name
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   770
                if not op:
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   771
                        # The client may not have provided the name of the
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   772
                        # operation it is performing.
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   773
                        op = "unknown"
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   774
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   775
                if op not in self.__touched_manifests:
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   776
                        # No intent information has been provided for fmris
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   777
                        # for the current operation.
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   778
                        return False
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   779
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   780
                f = str(fmri)
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   781
                if f not in self.__touched_manifests[op]:
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   782
                        # No intent information has been provided for this
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   783
                        # fmri for the current operation.
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   784
                        return False
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   785
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   786
                return True
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   787
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   788
        def __set_touched_manifest(self, fmri):
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   789
                """Records that intent information has been provided for the
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   790
                given fmri's manifest."""
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   791
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   792
                op = self.history.operation_name
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   793
                if not op:
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   794
                        # The client may not have provided the name of the
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   795
                        # operation it is performing.
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   796
                        op = "unknown"
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   797
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   798
                if op not in self.__touched_manifests:
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   799
                        # No intent information has yet been provided for fmris
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   800
                        # for the current operation.
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   801
                        self.__touched_manifests[op] = {}
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   802
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   803
                f = str(fmri)
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   804
                if f not in self.__touched_manifests[op]:
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   805
                        # No intent information has yet been provided for this
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   806
                        # fmri for the current operation.
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   807
                        self.__touched_manifests[op][f] = None
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   808
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   809
        def __touch_manifest(self, fmri):
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   810
                """Perform steps necessary to 'touch' a manifest to provide
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   811
                intent information.  Ignores most exceptions as this operation
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   812
                is only for informational purposes."""
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   813
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   814
                if not self.__get_touched_manifest(fmri):
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   815
                        # If the manifest for this fmri hasn't been "seen"
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   816
                        # before, determine if intent information needs to be
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   817
                        # provided.
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   818
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   819
                        # What is the client currently processing?
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   820
                        target, intent = self.state.get_target()
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   821
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   822
                        if target and intent != imagestate.INTENT_EVALUATE:
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   823
                                # If the client is currently performing an
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   824
                                # image-modifying operation, not just an
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   825
                                # an evaluation, then perform further checks.
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   826
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   827
                                # Ignore the authority for comparison.
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   828
                                na_target = target.get_fmri(anarchy=True)
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   829
                                na_fmri = target.get_fmri(anarchy=True)
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   830
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   831
                                if na_target == na_fmri:
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   832
                                        # If the client is currently processing
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   833
                                        # the given fmri (for an install, etc.)
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   834
                                        # then intent information is needed.
573
f77bbd68c975 3726 pkg uninstall fails if old manifest cannot be retrieved
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 568
diff changeset
   835
                                        retrieve.touch_manifest(self, fmri)
556
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   836
                                        self.__set_touched_manifest(fmri)
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   837
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   838
        def __fetch_manifest(self, fmri):
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   839
                """Perform steps necessary to get manifest from remote host
329
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
   840
                and write resulting contents to disk.  Helper routine for
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
   841
                get_manifest.  Does not filter the results, caller must do
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
   842
                that.  """
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   843
50
bfcb1661f019 basic image and package plans
Stephen Hahn <sch@sun.com>
parents: 45
diff changeset
   844
                m = manifest.Manifest()
315
989c801f050b 1076 action __cmp__, action __str__ and manifest loading could all be faster
Dan Price <dp@eng.sun.com>
parents: 313
diff changeset
   845
                m.set_fmri(self, fmri)
72
9deed41412b3 Support for proper package upgrade.
Danek Duvall <danek.duvall@sun.com>
parents: 69
diff changeset
   846
144
ce619e0b453f Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents: 139
diff changeset
   847
                fmri_dir_path = os.path.join(self.imgdir, "pkg",
ce619e0b453f Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents: 139
diff changeset
   848
                    fmri.get_dir_path())
ce619e0b453f Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents: 139
diff changeset
   849
                mpath = os.path.join(fmri_dir_path, "manifest")
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   850
315
989c801f050b 1076 action __cmp__, action __str__ and manifest loading could all be faster
Dan Price <dp@eng.sun.com>
parents: 313
diff changeset
   851
                # Get manifest as a string from the remote host, then build
989c801f050b 1076 action __cmp__, action __str__ and manifest loading could all be faster
Dan Price <dp@eng.sun.com>
parents: 313
diff changeset
   852
                # it up into an in-memory manifest, then write the finished
576
6ee6de304041 3777 PKG_TIMEOUT_MAX is a placebo setting
Dan Price <dp@eng.sun.com>
parents: 573
diff changeset
   853
                # representation to disk.  Note that this may throw a
6ee6de304041 3777 PKG_TIMEOUT_MAX is a placebo setting
Dan Price <dp@eng.sun.com>
parents: 573
diff changeset
   854
                # TransportException of some sort; we let upper layers
6ee6de304041 3777 PKG_TIMEOUT_MAX is a placebo setting
Dan Price <dp@eng.sun.com>
parents: 573
diff changeset
   855
                # handle that.
6ee6de304041 3777 PKG_TIMEOUT_MAX is a placebo setting
Dan Price <dp@eng.sun.com>
parents: 573
diff changeset
   856
                mcontent = retrieve.get_manifest(self, fmri)
6ee6de304041 3777 PKG_TIMEOUT_MAX is a placebo setting
Dan Price <dp@eng.sun.com>
parents: 573
diff changeset
   857
                m.set_content(mcontent)
144
ce619e0b453f Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents: 139
diff changeset
   858
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   859
                # Write the originating authority into the manifest.
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   860
                # Manifests prior to this change won't contain this information.
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   861
                # In that case, the client attempts to re-download the manifest
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   862
                # from the depot.
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   863
                if not fmri.has_authority():
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   864
                        m["authority"] = self.get_default_authority()
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   865
                else:
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   866
                        m["authority"] = fmri.get_authority()
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   867
341
42383445191b 1144 "pkg list -as" fails when unable to write to the pkg directory
Danek Duvall <danek.duvall@sun.com>
parents: 340
diff changeset
   868
                try:
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
   869
                        m.store(mpath)
347
d3768c3508b2 1397 fix for 1144 incomplete
Danek Duvall <danek.duvall@sun.com>
parents: 344
diff changeset
   870
                except EnvironmentError, e:
341
42383445191b 1144 "pkg list -as" fails when unable to write to the pkg directory
Danek Duvall <danek.duvall@sun.com>
parents: 340
diff changeset
   871
                        if e.errno not in (errno.EROFS, errno.EACCES):
42383445191b 1144 "pkg list -as" fails when unable to write to the pkg directory
Danek Duvall <danek.duvall@sun.com>
parents: 340
diff changeset
   872
                                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
   873
556
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   874
                self.__set_touched_manifest(fmri)
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   875
50
bfcb1661f019 basic image and package plans
Stephen Hahn <sch@sun.com>
parents: 45
diff changeset
   876
                return m
45
8a3f00dea14f catalog refresh; basic catalog listing; precise manifest pulls
Stephen Hahn <sch@sun.com>
parents: 39
diff changeset
   877
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   878
        def _valid_manifest(self, fmri, manifest):
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   879
                """Check authority attached to manifest.  Make sure
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   880
                it matches authority specified in FMRI."""
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   881
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   882
                authority = fmri.get_authority()
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   883
                if not authority:
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   884
                        authority = self.get_default_authority()
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   885
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   886
                if not "authority" in manifest:
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   887
                        return False
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   888
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   889
                if manifest["authority"] != authority:
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   890
                        return False
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   891
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   892
                return True
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   893
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
   894
        def get_manifest_path(self, fmri):
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
   895
                """Find on-disk manifest and create in-memory Manifest
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
   896
                object, applying appropriate filters as needed."""
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
   897
                mpath = os.path.join(self.imgdir, "pkg",
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
   898
                    fmri.get_dir_path(), "manifest")
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
   899
                return mpath
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
   900
556
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   901
        def __get_manifest(self, fmri):
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   902
                """Find on-disk manifest and create in-memory Manifest
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   903
                object."""
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   904
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   905
                m = None
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   906
                mpath = os.path.join(self.imgdir, "pkg", fmri.get_dir_path(),
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   907
                    "manifest")
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   908
                if os.path.exists(mpath):
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   909
                        # If the manifest already exists, load it from storage.
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   910
                        m = manifest.Manifest()
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   911
                        mcontent = file(mpath).read()
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   912
                        m.set_fmri(self, fmri)
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   913
                        m.set_content(mcontent)
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   914
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   915
                try:
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   916
                        # If the manifest didn't already exist, or isn't from
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   917
                        # the correct authority, or no authority is attached
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   918
                        # to the manifest, attempt to download a new one.
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   919
                        if not m or not self._valid_manifest(fmri, m):
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   920
                                m = self.__fetch_manifest_with_retries(fmri)
562
afe71b27984d 3618 Manifest retrieval error needs more info and to not show a traceback
Brock Pytlik <bpytlik@sun.com>
parents: 561
diff changeset
   921
                except (retrieve.ManifestRetrievalError,
afe71b27984d 3618 Manifest retrieval error needs more info and to not show a traceback
Brock Pytlik <bpytlik@sun.com>
parents: 561
diff changeset
   922
                    retrieve.DatastreamRetrievalError):
556
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   923
                        # In this case, the client has failed to download a new
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   924
                        # manifest or re-download an existing one with the same
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   925
                        # name.
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   926
                        if not m:
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   927
                                # Since an older copy doesn't exist, give up.
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   928
                                raise
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   929
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   930
                        # Since the old manifest exists, keep it, and drive on.
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   931
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   932
                return m
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   933
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   934
        def get_manifest(self, fmri, filtered = False):
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   935
                """Find on-disk manifest and create in-memory Manifest
329
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
   936
                object, applying appropriate filters as needed."""
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   937
567
ea1d96e269a4 3505 client action and manifest creation are wasteful
johansen <johansen@sun.com>
parents: 565
diff changeset
   938
                if fmri in self.__manifest_cache:
ea1d96e269a4 3505 client action and manifest creation are wasteful
johansen <johansen@sun.com>
parents: 565
diff changeset
   939
                        m = self.__manifest_cache[fmri]
ea1d96e269a4 3505 client action and manifest creation are wasteful
johansen <johansen@sun.com>
parents: 565
diff changeset
   940
                else:
ea1d96e269a4 3505 client action and manifest creation are wasteful
johansen <johansen@sun.com>
parents: 565
diff changeset
   941
                        m = self.__get_manifest(fmri)
ea1d96e269a4 3505 client action and manifest creation are wasteful
johansen <johansen@sun.com>
parents: 565
diff changeset
   942
                        self.__manifest_cache[fmri] = m
ea1d96e269a4 3505 client action and manifest creation are wasteful
johansen <johansen@sun.com>
parents: 565
diff changeset
   943
556
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   944
                self.__touch_manifest(fmri)
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   945
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
   946
                # XXX perhaps all of the below should live in Manifest.filter()?
329
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
   947
                if filtered:
556
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   948
                        fmri_dir_path = os.path.join(self.imgdir, "pkg",
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   949
                            fmri.get_dir_path())
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   950
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
   951
                        filters = []
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
   952
                        try:
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
   953
                                f = file("%s/filters" % fmri_dir_path, "r")
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
   954
                        except IOError, e:
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
   955
                                if e.errno != errno.ENOENT:
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
   956
                                        raise
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
   957
                        else:
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
   958
                                filters = [
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
   959
                                    (l.strip(), compile(
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
   960
                                        l.strip(), "<filter string>", "eval"))
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
   961
                                    for l in f.readlines()
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
   962
                                ]
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
   963
                        m.filter(filters)
329
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
   964
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   965
                return m
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   966
331
4f332d6b4036 1266 Client loses track of authority preference, chaos ensues
johansen <johansen@sun.com>
parents: 329
diff changeset
   967
        def installed_file_authority(self, filepath):
195
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   968
                """Find the pkg's installed file named by filepath.
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   969
                Return the authority that installed this package."""
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   970
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   971
                read_only = False
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   972
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   973
                try:
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   974
                        f = file(filepath, "r+")
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   975
                except IOError, e:
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   976
                        if e.errno == errno.EACCES or e.errno == errno.EROFS:
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   977
                                read_only = True
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   978
                        else:
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   979
                                raise
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   980
                if read_only:
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   981
                        f = file(filepath, "r")
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   982
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   983
                flines = f.readlines()
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   984
                newauth = None
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   985
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   986
                try:
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   987
                        version, auth = flines
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   988
                except ValueError:
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   989
                        # If we get a ValueError, we've encoutered an
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   990
                        # installed file of a previous format.  If we want
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   991
                        # upgrade to work in this situation, it's necessary
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   992
                        # to assume that the package was installed from
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   993
                        # the preferred authority.  Here, we set up
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   994
                        # the authority to record that.
356
672e0af33ea8 1536 empty installed files generate tracebacks
johansen <johansen@sun.com>
parents: 347
diff changeset
   995
                        if flines:
672e0af33ea8 1536 empty installed files generate tracebacks
johansen <johansen@sun.com>
parents: 347
diff changeset
   996
                                auth = flines[0]
672e0af33ea8 1536 empty installed files generate tracebacks
johansen <johansen@sun.com>
parents: 347
diff changeset
   997
                                auth = auth.strip()
672e0af33ea8 1536 empty installed files generate tracebacks
johansen <johansen@sun.com>
parents: 347
diff changeset
   998
                                newauth = "%s_%s" % (pkg.fmri.PREF_AUTH_PFX,
672e0af33ea8 1536 empty installed files generate tracebacks
johansen <johansen@sun.com>
parents: 347
diff changeset
   999
                                    auth)
672e0af33ea8 1536 empty installed files generate tracebacks
johansen <johansen@sun.com>
parents: 347
diff changeset
  1000
                        else:
672e0af33ea8 1536 empty installed files generate tracebacks
johansen <johansen@sun.com>
parents: 347
diff changeset
  1001
                                newauth = "%s_%s" % (pkg.fmri.PREF_AUTH_PFX,
672e0af33ea8 1536 empty installed files generate tracebacks
johansen <johansen@sun.com>
parents: 347
diff changeset
  1002
                                    self.get_default_authority())
672e0af33ea8 1536 empty installed files generate tracebacks
johansen <johansen@sun.com>
parents: 347
diff changeset
  1003
672e0af33ea8 1536 empty installed files generate tracebacks
johansen <johansen@sun.com>
parents: 347
diff changeset
  1004
                        # Exception handler is only part of this code that
672e0af33ea8 1536 empty installed files generate tracebacks
johansen <johansen@sun.com>
parents: 347
diff changeset
  1005
                        # sets newauth
672e0af33ea8 1536 empty installed files generate tracebacks
johansen <johansen@sun.com>
parents: 347
diff changeset
  1006
                        auth = newauth
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1007
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
  1008
                if newauth and not read_only:
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
  1009
                        # This is where we actually update the installed
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
  1010
                        # file with the new authority.
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1011
                        f.seek(0)
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1012
                        f.writelines(["VERSION_1\n", newauth])
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1013
195
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
  1014
                f.close()
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
  1015
356
672e0af33ea8 1536 empty installed files generate tracebacks
johansen <johansen@sun.com>
parents: 347
diff changeset
  1016
                assert auth
331
4f332d6b4036 1266 Client loses track of authority preference, chaos ensues
johansen <johansen@sun.com>
parents: 329
diff changeset
  1017
195
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
  1018
                return auth
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
  1019
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1020
        def _install_file(self, fmri):
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1021
                """Returns the path to the "installed" file for a given fmri."""
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1022
                return "%s/pkg/%s/installed" % (self.imgdir, fmri.get_dir_path())
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1023
195
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
  1024
        def install_file_present(self, fmri):
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
  1025
                """Returns true if the package named by the fmri is installed
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
  1026
                on the system.  Otherwise, returns false."""
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
  1027
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1028
                return os.path.exists(self._install_file(fmri))
195
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
  1029
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
  1030
        def add_install_file(self, fmri):
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
  1031
                """Take an image and fmri. Write a file to disk that
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
  1032
                indicates that the package named by the fmri has been
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
  1033
                installed."""
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
  1034
418
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
  1035
                # XXX This can be removed at some point in the future once we
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
  1036
                # think this link is available on all systems
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
  1037
                if not os.path.isdir("%s/state/installed" % self.imgdir):
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
  1038
                        self.update_installed_pkgs()
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
  1039
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1040
                f = file(self._install_file(fmri), "w")
195
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
  1041
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1042
                f.writelines(["VERSION_1\n", fmri.get_authority_str()])
195
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
  1043
                f.close()
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
  1044
434
48c05c66cdd2 2595 List speedup changes don't work on Windows
Tom Mueller <Tom.Mueller@sun.com>
parents: 432
diff changeset
  1045
                fi = file("%s/state/installed/%s" % (self.imgdir,
48c05c66cdd2 2595 List speedup changes don't work on Windows
Tom Mueller <Tom.Mueller@sun.com>
parents: 432
diff changeset
  1046
                    fmri.get_link_path()), "w")
48c05c66cdd2 2595 List speedup changes don't work on Windows
Tom Mueller <Tom.Mueller@sun.com>
parents: 432
diff changeset
  1047
                fi.close()
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1048
                self.pkg_states[urllib.unquote(fmri.get_link_path())] = \
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1049
                    (PKG_STATE_INSTALLED, fmri)
418
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
  1050
195
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
  1051
        def remove_install_file(self, fmri):
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
  1052
                """Take an image and a fmri.  Remove the file from disk
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
  1053
                that indicates that the package named by the fmri has been
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
  1054
                installed."""
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
  1055
418
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
  1056
                # XXX This can be removed at some point in the future once we
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
  1057
                # think this link is available on all systems
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
  1058
                if not os.path.isdir("%s/state/installed" % self.imgdir):
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
  1059
                        self.update_installed_pkgs()
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
  1060
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1061
                os.unlink(self._install_file(fmri))
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1062
                try:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1063
                        os.unlink("%s/state/installed/%s" % (self.imgdir,
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1064
                            fmri.get_link_path()))
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1065
                except EnvironmentError, e:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1066
                        if e.errno != errno.ENOENT:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1067
                                raise
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1068
                self.pkg_states[urllib.unquote(fmri.get_link_path())] = \
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1069
                    (PKG_STATE_KNOWN, fmri)
418
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
  1070
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
  1071
        def update_installed_pkgs(self):
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
  1072
                """Take the image's record of installed packages from the
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
  1073
                prototype layout, with an installed file in each
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
  1074
                $META/pkg/stem/version directory, to the $META/state/installed
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
  1075
                summary directory form."""
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
  1076
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1077
                tmpdir = "%s/state/installed.build" % self.imgdir
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1078
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1079
                # Create the link forest in a temporary directory.  We should
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1080
                # only execute this method once (if ever) in the lifetime of an
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1081
                # image, but if the path already exists and makedirs() blows up,
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1082
                # just be quiet if it's already a directory.  If it's not a
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1083
                # directory or something else weird happens, re-raise.
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1084
                try:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1085
                        os.makedirs(tmpdir)
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1086
                except OSError, e:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1087
                        if e.errno != errno.EEXIST or \
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1088
                            not os.path.isdir(tmpdir):
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1089
                                raise
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1090
                        return
418
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
  1091
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
  1092
                proot = "%s/pkg" % self.imgdir
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
  1093
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1094
                for pd, vd in (
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1095
                    (p, v)
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1096
                    for p in sorted(os.listdir(proot))
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1097
                    for v in sorted(os.listdir("%s/%s" % (proot, p)))
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1098
                    ):
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1099
                        path = "%s/%s/%s/installed" % (proot, pd, vd)
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1100
                        if not os.path.exists(path):
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1101
                                continue
418
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
  1102
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1103
                        fmristr = urllib.unquote("%s@%s" % (pd, vd))
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1104
                        auth = self.installed_file_authority(path)
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1105
                        f = pkg.fmri.PkgFmri(fmristr, authority = auth)
434
48c05c66cdd2 2595 List speedup changes don't work on Windows
Tom Mueller <Tom.Mueller@sun.com>
parents: 432
diff changeset
  1106
                        fi = file("%s/%s" % (tmpdir, f.get_link_path()), "w")
48c05c66cdd2 2595 List speedup changes don't work on Windows
Tom Mueller <Tom.Mueller@sun.com>
parents: 432
diff changeset
  1107
                        fi.close()
418
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
  1108
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1109
                # Someone may have already created this directory.  Junk the
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1110
                # directory we just populated if that's the case.
418
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
  1111
                try:
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1112
                        portable.rename(tmpdir, "%s/state/installed" % self.imgdir)
418
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
  1113
                except EnvironmentError, e:
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
  1114
                        if e.errno != errno.EEXIST:
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
  1115
                                raise
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1116
                        shutil.rmtree(tmpdir)
418
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
  1117
556
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
  1118
        def get_version_installed(self, pfmri):
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
  1119
                """Returns an fmri of the installed package matching the
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
  1120
                package stem of the given fmri or None if no match is found."""
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
  1121
                for f in self.gen_installed_pkgs():
568
52eea0be5030 3714 cannot uninstall package after authority removal
Danek Duvall <danek.duvall@sun.com>
parents: 567
diff changeset
  1122
                        if self.fmri_is_same_pkg(f, pfmri):
556
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
  1123
                                return f
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
  1124
                return None
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
  1125
104
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
  1126
        def get_pkg_state_by_fmri(self, pfmri):
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
  1127
                """Given pfmri, determine the local state of the package."""
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
  1128
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1129
                return self.pkg_states.get(pfmri.get_fmri(anarchy = True)[5:],
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1130
                    (PKG_STATE_KNOWN, None))[0]
104
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
  1131
423
5c756997bf67 2253 With the latest build of the pkg repo, can't install packages from additional authorities
Danek Duvall <danek.duvall@sun.com>
parents: 419
diff changeset
  1132
        def get_pkg_auth_by_fmri(self, pfmri):
5c756997bf67 2253 With the latest build of the pkg repo, can't install packages from additional authorities
Danek Duvall <danek.duvall@sun.com>
parents: 419
diff changeset
  1133
                """Return the authority from which 'pfmri' was installed."""
5c756997bf67 2253 With the latest build of the pkg repo, can't install packages from additional authorities
Danek Duvall <danek.duvall@sun.com>
parents: 419
diff changeset
  1134
5c756997bf67 2253 With the latest build of the pkg repo, can't install packages from additional authorities
Danek Duvall <danek.duvall@sun.com>
parents: 419
diff changeset
  1135
                f = self.pkg_states.get(pfmri.get_fmri(anarchy = True)[5:],
5c756997bf67 2253 With the latest build of the pkg repo, can't install packages from additional authorities
Danek Duvall <danek.duvall@sun.com>
parents: 419
diff changeset
  1136
                    (PKG_STATE_KNOWN, None))[1]
5c756997bf67 2253 With the latest build of the pkg repo, can't install packages from additional authorities
Danek Duvall <danek.duvall@sun.com>
parents: 419
diff changeset
  1137
                if f:
5c756997bf67 2253 With the latest build of the pkg repo, can't install packages from additional authorities
Danek Duvall <danek.duvall@sun.com>
parents: 419
diff changeset
  1138
                        # Return the non-preferred-prefixed name
5c756997bf67 2253 With the latest build of the pkg repo, can't install packages from additional authorities
Danek Duvall <danek.duvall@sun.com>
parents: 419
diff changeset
  1139
                        return f.get_authority()
5c756997bf67 2253 With the latest build of the pkg repo, can't install packages from additional authorities
Danek Duvall <danek.duvall@sun.com>
parents: 419
diff changeset
  1140
                return None
5c756997bf67 2253 With the latest build of the pkg repo, can't install packages from additional authorities
Danek Duvall <danek.duvall@sun.com>
parents: 419
diff changeset
  1141
195
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
  1142
        def fmri_set_default_authority(self, fmri):
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
  1143
                """If the FMRI supplied as an argument does not have
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
  1144
                an authority, set it to the image's preferred authority."""
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
  1145
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1146
                if fmri.has_authority():
195
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
  1147
                        return
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
  1148
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1149
                fmri.set_authority(self.get_default_authority(), True)
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1150
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1151
        def get_catalog(self, fmri, exception = False):
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1152
                """Given a FMRI, look at the authority and return the
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1153
                correct catalog for this image."""
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1154
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1155
                # If FMRI has no authority, or is default authority,
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1156
                # then return the catalog for the preferred authority
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1157
                if not fmri.has_authority() or fmri.preferred_authority():
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1158
                        cat = self.catalogs[self.get_default_authority()]
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1159
                else:
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1160
                        try:
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1161
                                cat = self.catalogs[fmri.get_authority()]
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1162
                        except KeyError:
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1163
                                # If the authority that installed this package
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1164
                                # has vanished, pick the default authority
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1165
                                # instead.
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1166
                                if exception:
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1167
                                        raise
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1168
                                else:
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1169
                                        cat = self.catalogs[\
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1170
                                            self.get_default_authority()]
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1171
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1172
                return cat
195
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
  1173
135
a1e20e9a9845 add CLI test suite, correct bugs found by test suite, ration out CLI options
Stephen Hahn <sch@Sun.COM>
parents: 116
diff changeset
  1174
        def has_version_installed(self, fmri):
59
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
  1175
                """Check that the version given in the FMRI or a successor is
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1176
                installed in the current image."""
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1177
560
4c8d82d58131 3569 pkg state code obviates use of _get_version_installed
Shawn Walker <shawn.walker@sun.com>
parents: 556
diff changeset
  1178
                v = self.get_version_installed(fmri)
59
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
  1179
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1180
                if v and not fmri.has_authority():
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1181
                        fmri.set_authority(v.get_authority_str())
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1182
                elif not fmri.has_authority():
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1183
                        fmri.set_authority(self.get_default_authority(), True)
266
5e5bff6fedce 582 Importing packages seemingly misrecords dependencies
johansen <johansen@sun.com>
parents: 260
diff changeset
  1184
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1185
                if v and self.fmri_is_successor(v, fmri):
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1186
                        return True
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1187
                else:
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1188
                        try:
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1189
                                cat = self.get_catalog(fmri, exception = True)
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1190
                        except KeyError:
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1191
                                return False
59
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
  1192
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1193
                        # If fmri has been renamed, get the list of newer
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1194
                        # packages that are equivalent to fmri.
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1195
                        rpkgs = cat.rename_newer_pkgs(fmri)
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1196
                        for f in rpkgs:
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1197
560
4c8d82d58131 3569 pkg state code obviates use of _get_version_installed
Shawn Walker <shawn.walker@sun.com>
parents: 556
diff changeset
  1198
                                v = self.get_version_installed(f)
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1199
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1200
                                if v and self.fmri_is_successor(v, fmri):
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1201
                                        return True
59
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
  1202
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
  1203
                return False
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
  1204
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1205
        def older_version_installed(self, fmri):
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1206
                """This method is used by the package plan to determine if an
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1207
                older version of the package is installed.  This takes
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1208
                the destination fmri and checks if an older package exists.
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1209
                This looks first under the existing name, and then sees
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1210
                if an older version is installed under another name.  This
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1211
                allows upgrade correctly locate the src fmri, if one exists."""
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1212
560
4c8d82d58131 3569 pkg state code obviates use of _get_version_installed
Shawn Walker <shawn.walker@sun.com>
parents: 556
diff changeset
  1213
                v = self.get_version_installed(fmri)
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1214
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1215
                assert fmri.has_authority()
268
3d53da66d4a4 582 Importing packages seemingly misrecords dependencies
johansen <johansen@sun.com>
parents: 266
diff changeset
  1216
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1217
                if v:
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1218
                        return v
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1219
                else:
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1220
                        cat = self.get_catalog(fmri)
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1221
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1222
                        rpkgs = cat.rename_older_pkgs(fmri)
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1223
                        for f in rpkgs:
560
4c8d82d58131 3569 pkg state code obviates use of _get_version_installed
Shawn Walker <shawn.walker@sun.com>
parents: 556
diff changeset
  1224
                                v = self.get_version_installed(f)
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1225
                                if v and self.fmri_is_successor(fmri, v):
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1226
                                        return v
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1227
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1228
                return None
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1229
135
a1e20e9a9845 add CLI test suite, correct bugs found by test suite, ration out CLI options
Stephen Hahn <sch@Sun.COM>
parents: 116
diff changeset
  1230
        def is_installed(self, fmri):
a1e20e9a9845 add CLI test suite, correct bugs found by test suite, ration out CLI options
Stephen Hahn <sch@Sun.COM>
parents: 116
diff changeset
  1231
                """Check that the exact version given in the FMRI is installed
a1e20e9a9845 add CLI test suite, correct bugs found by test suite, ration out CLI options
Stephen Hahn <sch@Sun.COM>
parents: 116
diff changeset
  1232
                in the current image."""
a1e20e9a9845 add CLI test suite, correct bugs found by test suite, ration out CLI options
Stephen Hahn <sch@Sun.COM>
parents: 116
diff changeset
  1233
195
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
  1234
                # All FMRIs passed to is_installed shall have an authority
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1235
                assert fmri.has_authority()
195
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
  1236
560
4c8d82d58131 3569 pkg state code obviates use of _get_version_installed
Shawn Walker <shawn.walker@sun.com>
parents: 556
diff changeset
  1237
                v = self.get_version_installed(fmri)
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1238
                if not v:
135
a1e20e9a9845 add CLI test suite, correct bugs found by test suite, ration out CLI options
Stephen Hahn <sch@Sun.COM>
parents: 116
diff changeset
  1239
                        return False
a1e20e9a9845 add CLI test suite, correct bugs found by test suite, ration out CLI options
Stephen Hahn <sch@Sun.COM>
parents: 116
diff changeset
  1240
a1e20e9a9845 add CLI test suite, correct bugs found by test suite, ration out CLI options
Stephen Hahn <sch@Sun.COM>
parents: 116
diff changeset
  1241
                return v == fmri
a1e20e9a9845 add CLI test suite, correct bugs found by test suite, ration out CLI options
Stephen Hahn <sch@Sun.COM>
parents: 116
diff changeset
  1242
432
578875da6e04 48 Removing a dependency is not flagged, and recovery is not obvious
Danek Duvall <danek.duvall@sun.com>
parents: 429
diff changeset
  1243
        def __build_dependents(self, progtrack):
578875da6e04 48 Removing a dependency is not flagged, and recovery is not obvious
Danek Duvall <danek.duvall@sun.com>
parents: 429
diff changeset
  1244
                """Build a dictionary mapping packages to the list of packages
578875da6e04 48 Removing a dependency is not flagged, and recovery is not obvious
Danek Duvall <danek.duvall@sun.com>
parents: 429
diff changeset
  1245
                that have required dependencies on them."""
578875da6e04 48 Removing a dependency is not flagged, and recovery is not obvious
Danek Duvall <danek.duvall@sun.com>
parents: 429
diff changeset
  1246
                self.__req_dependents = {}
578875da6e04 48 Removing a dependency is not flagged, and recovery is not obvious
Danek Duvall <danek.duvall@sun.com>
parents: 429
diff changeset
  1247
578875da6e04 48 Removing a dependency is not flagged, and recovery is not obvious
Danek Duvall <danek.duvall@sun.com>
parents: 429
diff changeset
  1248
                for fmri in self.gen_installed_pkgs():
577
cd4e8df4322b 873 Text is wrong in the General Info tab
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 576
diff changeset
  1249
                        progtrack.evaluate_progress(fmri)
432
578875da6e04 48 Removing a dependency is not flagged, and recovery is not obvious
Danek Duvall <danek.duvall@sun.com>
parents: 429
diff changeset
  1250
                        mfst = self.get_manifest(fmri, filtered = True)
578875da6e04 48 Removing a dependency is not flagged, and recovery is not obvious
Danek Duvall <danek.duvall@sun.com>
parents: 429
diff changeset
  1251
578875da6e04 48 Removing a dependency is not flagged, and recovery is not obvious
Danek Duvall <danek.duvall@sun.com>
parents: 429
diff changeset
  1252
                        for dep in mfst.gen_actions_by_type("depend"):
578875da6e04 48 Removing a dependency is not flagged, and recovery is not obvious
Danek Duvall <danek.duvall@sun.com>
parents: 429
diff changeset
  1253
                                if dep.attrs["type"] != "require":
578875da6e04 48 Removing a dependency is not flagged, and recovery is not obvious
Danek Duvall <danek.duvall@sun.com>
parents: 429
diff changeset
  1254
                                        continue
578875da6e04 48 Removing a dependency is not flagged, and recovery is not obvious
Danek Duvall <danek.duvall@sun.com>
parents: 429
diff changeset
  1255
                                dfmri = self.strtofmri(dep.attrs["fmri"])
578875da6e04 48 Removing a dependency is not flagged, and recovery is not obvious
Danek Duvall <danek.duvall@sun.com>
parents: 429
diff changeset
  1256
                                if dfmri not in self.__req_dependents:
578875da6e04 48 Removing a dependency is not flagged, and recovery is not obvious
Danek Duvall <danek.duvall@sun.com>
parents: 429
diff changeset
  1257
                                        self.__req_dependents[dfmri] = []
578875da6e04 48 Removing a dependency is not flagged, and recovery is not obvious
Danek Duvall <danek.duvall@sun.com>
parents: 429
diff changeset
  1258
                                self.__req_dependents[dfmri].append(fmri)
578875da6e04 48 Removing a dependency is not flagged, and recovery is not obvious
Danek Duvall <danek.duvall@sun.com>
parents: 429
diff changeset
  1259
578875da6e04 48 Removing a dependency is not flagged, and recovery is not obvious
Danek Duvall <danek.duvall@sun.com>
parents: 429
diff changeset
  1260
        def get_dependents(self, pfmri, progtrack):
104
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
  1261
                """Return a list of the packages directly dependent on the given
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
  1262
                FMRI."""
67
62c897652bbc Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents: 63
diff changeset
  1263
432
578875da6e04 48 Removing a dependency is not flagged, and recovery is not obvious
Danek Duvall <danek.duvall@sun.com>
parents: 429
diff changeset
  1264
                if not hasattr(self, "_Image__req_dependents"):
578875da6e04 48 Removing a dependency is not flagged, and recovery is not obvious
Danek Duvall <danek.duvall@sun.com>
parents: 429
diff changeset
  1265
                        self.__build_dependents(progtrack)
67
62c897652bbc Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents: 63
diff changeset
  1266
432
578875da6e04 48 Removing a dependency is not flagged, and recovery is not obvious
Danek Duvall <danek.duvall@sun.com>
parents: 429
diff changeset
  1267
                dependents = []
578875da6e04 48 Removing a dependency is not flagged, and recovery is not obvious
Danek Duvall <danek.duvall@sun.com>
parents: 429
diff changeset
  1268
                # We run through all the keys, in case a package is depended
578875da6e04 48 Removing a dependency is not flagged, and recovery is not obvious
Danek Duvall <danek.duvall@sun.com>
parents: 429
diff changeset
  1269
                # upon under multiple versions.  That is, if pkgA depends on
578875da6e04 48 Removing a dependency is not flagged, and recovery is not obvious
Danek Duvall <danek.duvall@sun.com>
parents: 429
diff changeset
  1270
                # libc@1 and pkgB depends on libc@2, we need to return both pkgA
578875da6e04 48 Removing a dependency is not flagged, and recovery is not obvious
Danek Duvall <danek.duvall@sun.com>
parents: 429
diff changeset
  1271
                # and pkgB.  If we used package names as keys, this would be
578875da6e04 48 Removing a dependency is not flagged, and recovery is not obvious
Danek Duvall <danek.duvall@sun.com>
parents: 429
diff changeset
  1272
                # simpler, but it wouldn't handle package rename.
578875da6e04 48 Removing a dependency is not flagged, and recovery is not obvious
Danek Duvall <danek.duvall@sun.com>
parents: 429
diff changeset
  1273
                for f in self.__req_dependents.iterkeys():
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1274
                        if self.fmri_is_successor(pfmri, f):
432
578875da6e04 48 Removing a dependency is not flagged, and recovery is not obvious
Danek Duvall <danek.duvall@sun.com>
parents: 429
diff changeset
  1275
                                dependents.extend(self.__req_dependents[f])
67
62c897652bbc Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents: 63
diff changeset
  1276
                return dependents
62c897652bbc Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents: 63
diff changeset
  1277
496
d36d6700c011 2917 pkg refresh should allow refreshing specific repository(ies)
Brock Pytlik <bpytlik@sun.com>
parents: 479
diff changeset
  1278
        def retrieve_catalogs(self, full_refresh = False,
d36d6700c011 2917 pkg refresh should allow refreshing specific repository(ies)
Brock Pytlik <bpytlik@sun.com>
parents: 479
diff changeset
  1279
            auths = None):
201
63e78f600aa7 185 traceback on pkg refresh when hostname lookup fails
Danek Duvall <danek.duvall@sun.com>
parents: 195
diff changeset
  1280
                failed = []
63e78f600aa7 185 traceback on pkg refresh when hostname lookup fails
Danek Duvall <danek.duvall@sun.com>
parents: 195
diff changeset
  1281
                total = 0
63e78f600aa7 185 traceback on pkg refresh when hostname lookup fails
Danek Duvall <danek.duvall@sun.com>
parents: 195
diff changeset
  1282
                succeeded = 0
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
  1283
                cat = None
215
c10719939c6d 245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents: 208
diff changeset
  1284
                ts = 0
201
63e78f600aa7 185 traceback on pkg refresh when hostname lookup fails
Danek Duvall <danek.duvall@sun.com>
parents: 195
diff changeset
  1285
496
d36d6700c011 2917 pkg refresh should allow refreshing specific repository(ies)
Brock Pytlik <bpytlik@sun.com>
parents: 479
diff changeset
  1286
                if not auths:
d36d6700c011 2917 pkg refresh should allow refreshing specific repository(ies)
Brock Pytlik <bpytlik@sun.com>
parents: 479
diff changeset
  1287
                        auths = self.gen_authorities()
d36d6700c011 2917 pkg refresh should allow refreshing specific repository(ies)
Brock Pytlik <bpytlik@sun.com>
parents: 479
diff changeset
  1288
d36d6700c011 2917 pkg refresh should allow refreshing specific repository(ies)
Brock Pytlik <bpytlik@sun.com>
parents: 479
diff changeset
  1289
                for auth in auths:
201
63e78f600aa7 185 traceback on pkg refresh when hostname lookup fails
Danek Duvall <danek.duvall@sun.com>
parents: 195
diff changeset
  1290
                        total += 1
215
c10719939c6d 245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents: 208
diff changeset
  1291
496
d36d6700c011 2917 pkg refresh should allow refreshing specific repository(ies)
Brock Pytlik <bpytlik@sun.com>
parents: 479
diff changeset
  1292
                        full_refresh_this_auth = False
556
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
  1293
215
c10719939c6d 245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents: 208
diff changeset
  1294
                        if auth["prefix"] in self.catalogs:
c10719939c6d 245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents: 208
diff changeset
  1295
                                cat = self.catalogs[auth["prefix"]]
c10719939c6d 245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents: 208
diff changeset
  1296
                                ts = cat.last_modified()
c10719939c6d 245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents: 208
diff changeset
  1297
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
  1298
                                # Although we may have a catalog with a
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
  1299
                                # timestamp, the user may have changed the
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
  1300
                                # origin URL for the authority.  If this has
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
  1301
                                # occurred, we need to perform a full refresh.
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
  1302
                                if cat.origin() != auth["origin"]:
496
d36d6700c011 2917 pkg refresh should allow refreshing specific repository(ies)
Brock Pytlik <bpytlik@sun.com>
parents: 479
diff changeset
  1303
                                        full_refresh_this_auth = True
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
  1304
496
d36d6700c011 2917 pkg refresh should allow refreshing specific repository(ies)
Brock Pytlik <bpytlik@sun.com>
parents: 479
diff changeset
  1305
                        if ts and not full_refresh and \
d36d6700c011 2917 pkg refresh should allow refreshing specific repository(ies)
Brock Pytlik <bpytlik@sun.com>
parents: 479
diff changeset
  1306
                            not full_refresh_this_auth:
215
c10719939c6d 245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents: 208
diff changeset
  1307
                                hdr = {'If-Modified-Since': ts}
c10719939c6d 245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents: 208
diff changeset
  1308
                        else:
c10719939c6d 245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents: 208
diff changeset
  1309
                                hdr = {}
c10719939c6d 245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents: 208
diff changeset
  1310
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
  1311
                        ssl_tuple = self.get_ssl_credentials(auth["prefix"])
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
  1312
116
9c9942a52984 (image flag day) remove pkg catalog, improve pkg status, localize pkg(1), use
Stephen Hahn <sch@Sun.COM>
parents: 111
diff changeset
  1313
                        # XXX Mirror selection and retrieval policy?
235
61994d15c39b 373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents: 226
diff changeset
  1314
                        try:
201
63e78f600aa7 185 traceback on pkg refresh when hostname lookup fails
Danek Duvall <danek.duvall@sun.com>
parents: 195
diff changeset
  1315
                                c, v = versioned_urlopen(auth["origin"],
551
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
  1316
                                    "catalog", [0], ssl_creds=ssl_tuple,
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
  1317
                                    headers=hdr, imgtype=self.type,
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
  1318
                                    uuid=self.get_uuid(auth["prefix"]))
215
c10719939c6d 245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents: 208
diff changeset
  1319
                        except urllib2.HTTPError, e:
260
a1b77322abb2 255 Symbolic HTTP response codes should be used
Shawn Walker <swalker@opensolaris.org>
parents: 259
diff changeset
  1320
                                # Server returns NOT_MODIFIED if catalog is up
a1b77322abb2 255 Symbolic HTTP response codes should be used
Shawn Walker <swalker@opensolaris.org>
parents: 259
diff changeset
  1321
                                # to date
a1b77322abb2 255 Symbolic HTTP response codes should be used
Shawn Walker <swalker@opensolaris.org>
parents: 259
diff changeset
  1322
                                if e.code == httplib.NOT_MODIFIED:
215
c10719939c6d 245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents: 208
diff changeset
  1323
                                        succeeded += 1
c10719939c6d 245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents: 208
diff changeset
  1324
                                else:
c10719939c6d 245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents: 208
diff changeset
  1325
                                        failed.append((auth, e))
c10719939c6d 245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents: 208
diff changeset
  1326
                                continue
c10719939c6d 245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents: 208
diff changeset
  1327
201
63e78f600aa7 185 traceback on pkg refresh when hostname lookup fails
Danek Duvall <danek.duvall@sun.com>
parents: 195
diff changeset
  1328
                        except urllib2.URLError, e:
63e78f600aa7 185 traceback on pkg refresh when hostname lookup fails
Danek Duvall <danek.duvall@sun.com>
parents: 195
diff changeset
  1329
                                failed.append((auth, e))
63e78f600aa7 185 traceback on pkg refresh when hostname lookup fails
Danek Duvall <danek.duvall@sun.com>
parents: 195
diff changeset
  1330
                                continue
285
538afd6a9d3e 763 pkg image-create /foo , pkg image-create /tmp/foo both yield (different) tracebacks
Danek Duvall <danek.duvall@sun.com>
parents: 281
diff changeset
  1331
                        except ValueError, e:
538afd6a9d3e 763 pkg image-create /foo , pkg image-create /tmp/foo both yield (different) tracebacks
Danek Duvall <danek.duvall@sun.com>
parents: 281
diff changeset
  1332
                                failed.append((auth, e))
538afd6a9d3e 763 pkg image-create /foo , pkg image-create /tmp/foo both yield (different) tracebacks
Danek Duvall <danek.duvall@sun.com>
parents: 281
diff changeset
  1333
                                continue
243
ca57127811b8 399 pkg list on explicit packages fails with no output, exit status of 1
Stephen Hahn <sch@Sun.COM>
parents: 239
diff changeset
  1334
157
504b9e6d213c Catalog should be on-disk instead of in memory
johansen <johansen@sun.com>
parents: 146
diff changeset
  1335
                        # root for this catalog
504b9e6d213c Catalog should be on-disk instead of in memory
johansen <johansen@sun.com>
parents: 146
diff changeset
  1336
                        croot = "%s/catalog/%s" % (self.imgdir, auth["prefix"])
504b9e6d213c Catalog should be on-disk instead of in memory
johansen <johansen@sun.com>
parents: 146
diff changeset
  1337
201
63e78f600aa7 185 traceback on pkg refresh when hostname lookup fails
Danek Duvall <danek.duvall@sun.com>
parents: 195
diff changeset
  1338
                        try:
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
  1339
                                updatelog.recv(c, croot, ts, auth)
201
63e78f600aa7 185 traceback on pkg refresh when hostname lookup fails
Danek Duvall <danek.duvall@sun.com>
parents: 195
diff changeset
  1340
                        except IOError, e:
63e78f600aa7 185 traceback on pkg refresh when hostname lookup fails
Danek Duvall <danek.duvall@sun.com>
parents: 195
diff changeset
  1341
                                failed.append((auth, e))
388
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  1342
                        except socket.timeout, e:
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  1343
                                failed.append((auth, e))
201
63e78f600aa7 185 traceback on pkg refresh when hostname lookup fails
Danek Duvall <danek.duvall@sun.com>
parents: 195
diff changeset
  1344
                        else:
63e78f600aa7 185 traceback on pkg refresh when hostname lookup fails
Danek Duvall <danek.duvall@sun.com>
parents: 195
diff changeset
  1345
                                succeeded += 1
243
ca57127811b8 399 pkg list on explicit packages fails with no output, exit status of 1
Stephen Hahn <sch@Sun.COM>
parents: 239
diff changeset
  1346
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1347
                self.cache_catalogs()
556
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
  1348
201
63e78f600aa7 185 traceback on pkg refresh when hostname lookup fails
Danek Duvall <danek.duvall@sun.com>
parents: 195
diff changeset
  1349
                if failed:
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  1350
                        raise api_errors.CatalogRefreshException(failed, total,
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  1351
                            succeeded)
116
9c9942a52984 (image flag day) remove pkg catalog, improve pkg status, localize pkg(1), use
Stephen Hahn <sch@Sun.COM>
parents: 111
diff changeset
  1352
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1353
        CATALOG_CACHE_VERSION = 1
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1354
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1355
        def cache_catalogs(self):
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1356
                """Read in all the catalogs and cache the data."""
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1357
                cache = {}
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1358
                for auth in self.gen_authorities():
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1359
                        croot = "%s/catalog/%s" % (self.imgdir, auth["prefix"])
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1360
                        # XXX Should I be removing pkg_names.pkl now that we're
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1361
                        # not using it anymore?
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1362
                        try:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1363
                                catalog.Catalog.read_catalog(cache,
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1364
                                    croot, auth = auth["prefix"])
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1365
                        except EnvironmentError, e:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1366
                                # If a catalog file is just missing, ignore it.
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1367
                                # If there's a worse error, make sure the user
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1368
                                # knows about it.
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1369
                                if e.errno == errno.ENOENT:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1370
                                        pass
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1371
                                else:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1372
                                        raise
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1373
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1374
                pickle_file = os.path.join(self.imgdir, "catalog/catalog.pkl")
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1375
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1376
                try:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1377
                        pf = file(pickle_file, "wb")
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1378
                        # Version the dump file
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1379
                        cPickle.dump((self.CATALOG_CACHE_VERSION, cache), pf,
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1380
                            protocol = cPickle.HIGHEST_PROTOCOL)
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1381
                        pf.close()
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1382
                except (cPickle.PickleError, EnvironmentError):
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1383
                        try:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1384
                                os.remove(pickle_file)
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1385
                        except EnvironmentError:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1386
                                pass
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1387
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1388
                self._catalog = cache
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1389
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1390
        def load_catalog_cache(self):
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1391
                """Read in the cached catalog data."""
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1392
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1393
                self.__load_pkg_states()
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1394
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1395
                cache_file = os.path.join(self.imgdir, "catalog/catalog.pkl")
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1396
                try:
434
48c05c66cdd2 2595 List speedup changes don't work on Windows
Tom Mueller <Tom.Mueller@sun.com>
parents: 432
diff changeset
  1397
                        version, self._catalog = \
48c05c66cdd2 2595 List speedup changes don't work on Windows
Tom Mueller <Tom.Mueller@sun.com>
parents: 432
diff changeset
  1398
                            cPickle.load(file(cache_file, "rb"))
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1399
                except (cPickle.PickleError, EnvironmentError):
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1400
                        raise RuntimeError
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1401
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1402
                # If we don't recognize the version, complain.
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1403
                if version != self.CATALOG_CACHE_VERSION:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1404
                        raise RuntimeError
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1405
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1406
                # Add the packages which are installed, but not in the catalog.
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1407
                # XXX Should we have a different state for these, so we can flag
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1408
                # them to the user?
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1409
                for state, f in self.pkg_states.values():
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1410
                        if state != PKG_STATE_INSTALLED:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1411
                                continue
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1412
                        auth, name, vers = f.tuple()
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1413
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1414
                        if name not in self._catalog or \
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1415
                            vers not in self._catalog[name]["versions"]:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1416
                                catalog.Catalog.cache_fmri(self._catalog, f,
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1417
                                    f.get_authority())
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1418
235
61994d15c39b 373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents: 226
diff changeset
  1419
        def load_catalogs(self, progresstracker):
157
504b9e6d213c Catalog should be on-disk instead of in memory
johansen <johansen@sun.com>
parents: 146
diff changeset
  1420
                for auth in self.gen_authorities():
504b9e6d213c Catalog should be on-disk instead of in memory
johansen <johansen@sun.com>
parents: 146
diff changeset
  1421
                        croot = "%s/catalog/%s" % (self.imgdir, auth["prefix"])
235
61994d15c39b 373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents: 226
diff changeset
  1422
                        progresstracker.catalog_start(auth["prefix"])
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1423
                        if auth["prefix"] == self.cfg_cache.preferred_authority:
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1424
                                authpfx = "%s_%s" % (pkg.fmri.PREF_AUTH_PFX,
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1425
                                    auth["prefix"])
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
  1426
                                c = catalog.Catalog(croot,
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
  1427
                                    authority=authpfx)
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1428
                        else:
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1429
                                c = catalog.Catalog(croot,
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1430
                                    authority = auth["prefix"])
116
9c9942a52984 (image flag day) remove pkg catalog, improve pkg status, localize pkg(1), use
Stephen Hahn <sch@Sun.COM>
parents: 111
diff changeset
  1431
                        self.catalogs[auth["prefix"]] = c
235
61994d15c39b 373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents: 226
diff changeset
  1432
                        progresstracker.catalog_done()
59
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
  1433
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1434
                # Try to load the catalog cache file.  If that fails, load the
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1435
                # data from the canonical text copies of the catalogs from each
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1436
                # authority.  Try to save it, to spare the time in the future.
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1437
                # XXX Given that this is a read operation, should we be writing?
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1438
                try:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1439
                        self.load_catalog_cache()
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1440
                except RuntimeError:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1441
                        self.cache_catalogs()
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1442
537
3dc9fc9b5fee 1540 changes to authorities should include refresh
Brock Pytlik <bpytlik@sun.com>
parents: 526
diff changeset
  1443
        def destroy_catalog_cache(self):
3dc9fc9b5fee 1540 changes to authorities should include refresh
Brock Pytlik <bpytlik@sun.com>
parents: 526
diff changeset
  1444
                pickle_file = os.path.join(self.imgdir, "catalog/catalog.pkl")
3dc9fc9b5fee 1540 changes to authorities should include refresh
Brock Pytlik <bpytlik@sun.com>
parents: 526
diff changeset
  1445
                try:
3dc9fc9b5fee 1540 changes to authorities should include refresh
Brock Pytlik <bpytlik@sun.com>
parents: 526
diff changeset
  1446
                        portable.remove(pickle_file)
3dc9fc9b5fee 1540 changes to authorities should include refresh
Brock Pytlik <bpytlik@sun.com>
parents: 526
diff changeset
  1447
                except OSError, e:
3dc9fc9b5fee 1540 changes to authorities should include refresh
Brock Pytlik <bpytlik@sun.com>
parents: 526
diff changeset
  1448
                        if e.errno != errno.ENOENT:
3dc9fc9b5fee 1540 changes to authorities should include refresh
Brock Pytlik <bpytlik@sun.com>
parents: 526
diff changeset
  1449
                                raise
556
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
  1450
537
3dc9fc9b5fee 1540 changes to authorities should include refresh
Brock Pytlik <bpytlik@sun.com>
parents: 526
diff changeset
  1451
        def destroy_catalog(self, auth_name):
3dc9fc9b5fee 1540 changes to authorities should include refresh
Brock Pytlik <bpytlik@sun.com>
parents: 526
diff changeset
  1452
                try:
3dc9fc9b5fee 1540 changes to authorities should include refresh
Brock Pytlik <bpytlik@sun.com>
parents: 526
diff changeset
  1453
                        shutil.rmtree("%s/catalog/%s" %
3dc9fc9b5fee 1540 changes to authorities should include refresh
Brock Pytlik <bpytlik@sun.com>
parents: 526
diff changeset
  1454
                            (self.imgdir, auth_name))
3dc9fc9b5fee 1540 changes to authorities should include refresh
Brock Pytlik <bpytlik@sun.com>
parents: 526
diff changeset
  1455
                except OSError, e:
3dc9fc9b5fee 1540 changes to authorities should include refresh
Brock Pytlik <bpytlik@sun.com>
parents: 526
diff changeset
  1456
                        if e.errno != errno.ENOENT:
3dc9fc9b5fee 1540 changes to authorities should include refresh
Brock Pytlik <bpytlik@sun.com>
parents: 526
diff changeset
  1457
                                raise
3dc9fc9b5fee 1540 changes to authorities should include refresh
Brock Pytlik <bpytlik@sun.com>
parents: 526
diff changeset
  1458
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1459
        def fmri_is_same_pkg(self, cfmri, pfmri):
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1460
                """Determine whether fmri and pfmri share the same package
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1461
                name, even if they're not equivalent versions.  This
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1462
                also checks if two packages with different names are actually
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1463
                the same because of a rename operation."""
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1464
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1465
                # If the catalog has a rename record that names fmri as a
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1466
                # destination, it's possible that pfmri could be the same pkg by
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1467
                # rename.
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1468
                if cfmri.is_same_pkg(pfmri):
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1469
                        return True
329
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
  1470
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
  1471
                # Get the catalog for the correct authority
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
  1472
                cat = self.get_catalog(cfmri)
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
  1473
                return cat.rename_is_same_pkg(cfmri, pfmri)
329
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
  1474
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1475
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1476
        def fmri_is_successor(self, cfmri, pfmri):
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1477
                """Since the catalog keeps track of renames, it's no longer
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1478
                sufficient to rely on the FMRI class to determine whether a
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1479
                package is a successor.  This routine takes two FMRIs, and
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1480
                if they have the same authority, checks if they've been
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1481
                renamed.  If a rename has occurred, this runs the is_successor
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1482
                routine from the catalog.  Otherwise, this runs the standard
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1483
                fmri.is_successor() code."""
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1484
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1485
                # Get the catalog for the correct authority
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1486
                cat = self.get_catalog(cfmri)
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1487
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1488
                # If the catalog has a rename record that names fmri as a
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1489
                # destination, it's possible that pfmri could be a successor by
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1490
                # rename.
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1491
                if cfmri.is_successor(pfmri):
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1492
                        return True
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1493
                else:
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1494
                        return cat.rename_is_successor(cfmri, pfmri)
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1495
516
53da6297fb65 3039 Install and Image-update should check index consistency with installed packages
Brock Pytlik <bpytlik@sun.com>
parents: 499
diff changeset
  1496
        def gen_installed_pkg_names(self):
53da6297fb65 3039 Install and Image-update should check index consistency with installed packages
Brock Pytlik <bpytlik@sun.com>
parents: 499
diff changeset
  1497
                """Generate the string representation of all installed
53da6297fb65 3039 Install and Image-update should check index consistency with installed packages
Brock Pytlik <bpytlik@sun.com>
parents: 499
diff changeset
  1498
                packages. This is faster than going through gen_installed_pkgs
53da6297fb65 3039 Install and Image-update should check index consistency with installed packages
Brock Pytlik <bpytlik@sun.com>
parents: 499
diff changeset
  1499
                when all that will be done is to extract the strings from
53da6297fb65 3039 Install and Image-update should check index consistency with installed packages
Brock Pytlik <bpytlik@sun.com>
parents: 499
diff changeset
  1500
                the result.
53da6297fb65 3039 Install and Image-update should check index consistency with installed packages
Brock Pytlik <bpytlik@sun.com>
parents: 499
diff changeset
  1501
                """
53da6297fb65 3039 Install and Image-update should check index consistency with installed packages
Brock Pytlik <bpytlik@sun.com>
parents: 499
diff changeset
  1502
                if self.pkg_states is not None:
53da6297fb65 3039 Install and Image-update should check index consistency with installed packages
Brock Pytlik <bpytlik@sun.com>
parents: 499
diff changeset
  1503
                        for i in self.pkg_states.values():
53da6297fb65 3039 Install and Image-update should check index consistency with installed packages
Brock Pytlik <bpytlik@sun.com>
parents: 499
diff changeset
  1504
                                yield i[1].get_fmri(anarchy=True)
53da6297fb65 3039 Install and Image-update should check index consistency with installed packages
Brock Pytlik <bpytlik@sun.com>
parents: 499
diff changeset
  1505
                else:
53da6297fb65 3039 Install and Image-update should check index consistency with installed packages
Brock Pytlik <bpytlik@sun.com>
parents: 499
diff changeset
  1506
                        installed_state_dir = "%s/state/installed" % \
53da6297fb65 3039 Install and Image-update should check index consistency with installed packages
Brock Pytlik <bpytlik@sun.com>
parents: 499
diff changeset
  1507
                            self.imgdir
53da6297fb65 3039 Install and Image-update should check index consistency with installed packages
Brock Pytlik <bpytlik@sun.com>
parents: 499
diff changeset
  1508
                        if os.path.isdir(installed_state_dir):
53da6297fb65 3039 Install and Image-update should check index consistency with installed packages
Brock Pytlik <bpytlik@sun.com>
parents: 499
diff changeset
  1509
                                for pl in os.listdir(installed_state_dir):
53da6297fb65 3039 Install and Image-update should check index consistency with installed packages
Brock Pytlik <bpytlik@sun.com>
parents: 499
diff changeset
  1510
                                        yield "pkg:/" + urllib.unquote(pl)
53da6297fb65 3039 Install and Image-update should check index consistency with installed packages
Brock Pytlik <bpytlik@sun.com>
parents: 499
diff changeset
  1511
                        else:
53da6297fb65 3039 Install and Image-update should check index consistency with installed packages
Brock Pytlik <bpytlik@sun.com>
parents: 499
diff changeset
  1512
                                proot = "%s/pkg" % self.imgdir
53da6297fb65 3039 Install and Image-update should check index consistency with installed packages
Brock Pytlik <bpytlik@sun.com>
parents: 499
diff changeset
  1513
                                for pd in sorted(os.listdir(proot)):
53da6297fb65 3039 Install and Image-update should check index consistency with installed packages
Brock Pytlik <bpytlik@sun.com>
parents: 499
diff changeset
  1514
                                        for vd in \
53da6297fb65 3039 Install and Image-update should check index consistency with installed packages
Brock Pytlik <bpytlik@sun.com>
parents: 499
diff changeset
  1515
                                            sorted(os.listdir("%s/%s" %
53da6297fb65 3039 Install and Image-update should check index consistency with installed packages
Brock Pytlik <bpytlik@sun.com>
parents: 499
diff changeset
  1516
                                            (proot, pd))):
53da6297fb65 3039 Install and Image-update should check index consistency with installed packages
Brock Pytlik <bpytlik@sun.com>
parents: 499
diff changeset
  1517
                                                path = "%s/%s/%s/installed" % \
53da6297fb65 3039 Install and Image-update should check index consistency with installed packages
Brock Pytlik <bpytlik@sun.com>
parents: 499
diff changeset
  1518
                                                    (proot, pd, vd)
53da6297fb65 3039 Install and Image-update should check index consistency with installed packages
Brock Pytlik <bpytlik@sun.com>
parents: 499
diff changeset
  1519
                                                if not os.path.exists(path):
53da6297fb65 3039 Install and Image-update should check index consistency with installed packages
Brock Pytlik <bpytlik@sun.com>
parents: 499
diff changeset
  1520
                                                        continue
53da6297fb65 3039 Install and Image-update should check index consistency with installed packages
Brock Pytlik <bpytlik@sun.com>
parents: 499
diff changeset
  1521
53da6297fb65 3039 Install and Image-update should check index consistency with installed packages
Brock Pytlik <bpytlik@sun.com>
parents: 499
diff changeset
  1522
                                                yield urllib.unquote(
53da6297fb65 3039 Install and Image-update should check index consistency with installed packages
Brock Pytlik <bpytlik@sun.com>
parents: 499
diff changeset
  1523
                                                    "pkg:/%s@%s" % (pd, vd))
53da6297fb65 3039 Install and Image-update should check index consistency with installed packages
Brock Pytlik <bpytlik@sun.com>
parents: 499
diff changeset
  1524
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1525
        # This could simply call self.inventory() (or be replaced by inventory),
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1526
        # but it turns out to be about 20% slower.
221
e1dbb27a23b5 52 catalog can leave inventory behind, making pkg(1) blind
Stephen Hahn <sch@Sun.COM>
parents: 219
diff changeset
  1527
        def gen_installed_pkgs(self):
418
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
  1528
                """Return an iteration through the installed packages."""
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1529
                self.__load_pkg_states()
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1530
                return (i[1] for i in self.pkg_states.values())
315
989c801f050b 1076 action __cmp__, action __str__ and manifest loading could all be faster
Dan Price <dp@eng.sun.com>
parents: 313
diff changeset
  1531
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1532
        def __load_pkg_states(self):
423
5c756997bf67 2253 With the latest build of the pkg repo, can't install packages from additional authorities
Danek Duvall <danek.duvall@sun.com>
parents: 419
diff changeset
  1533
                """Build up the package state dictionary.
526
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 518
diff changeset
  1534
423
5c756997bf67 2253 With the latest build of the pkg repo, can't install packages from additional authorities
Danek Duvall <danek.duvall@sun.com>
parents: 419
diff changeset
  1535
                This dictionary maps the full fmri string to a tuple of the
5c756997bf67 2253 With the latest build of the pkg repo, can't install packages from additional authorities
Danek Duvall <danek.duvall@sun.com>
parents: 419
diff changeset
  1536
                state, the prefix of the authority from which it's installed,
5c756997bf67 2253 With the latest build of the pkg repo, can't install packages from additional authorities
Danek Duvall <danek.duvall@sun.com>
parents: 419
diff changeset
  1537
                and the fmri object.
5c756997bf67 2253 With the latest build of the pkg repo, can't install packages from additional authorities
Danek Duvall <danek.duvall@sun.com>
parents: 419
diff changeset
  1538
5c756997bf67 2253 With the latest build of the pkg repo, can't install packages from additional authorities
Danek Duvall <danek.duvall@sun.com>
parents: 419
diff changeset
  1539
                Note that this dictionary only maps installed packages.  Use
5c756997bf67 2253 With the latest build of the pkg repo, can't install packages from additional authorities
Danek Duvall <danek.duvall@sun.com>
parents: 419
diff changeset
  1540
                get_pkg_state_by_fmri() to retrieve the state for arbitrary
5c756997bf67 2253 With the latest build of the pkg repo, can't install packages from additional authorities
Danek Duvall <danek.duvall@sun.com>
parents: 419
diff changeset
  1541
                packages.
5c756997bf67 2253 With the latest build of the pkg repo, can't install packages from additional authorities
Danek Duvall <danek.duvall@sun.com>
parents: 419
diff changeset
  1542
                """
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1543
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1544
                if self.pkg_states is not None:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1545
                        return
418
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
  1546
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
  1547
                installed_state_dir = "%s/state/installed" % self.imgdir
195
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
  1548
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1549
                self.pkg_states = {}
418
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
  1550
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1551
                # If the state directory structure has already been created,
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1552
                # loading information from it is fast.  The directory is
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1553
                # populated with symlinks, named by their (url-encoded) FMRI,
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1554
                # which point to the "installed" file in the corresponding
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1555
                # directory under /var/pkg.
418
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
  1556
                if os.path.isdir(installed_state_dir):
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
  1557
                        for pl in sorted(os.listdir(installed_state_dir)):
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
  1558
                                fmristr = urllib.unquote(pl)
434
48c05c66cdd2 2595 List speedup changes don't work on Windows
Tom Mueller <Tom.Mueller@sun.com>
parents: 432
diff changeset
  1559
                                tmpf = pkg.fmri.PkgFmri(fmristr)
48c05c66cdd2 2595 List speedup changes don't work on Windows
Tom Mueller <Tom.Mueller@sun.com>
parents: 432
diff changeset
  1560
                                path = self._install_file(tmpf)
418
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
  1561
                                auth = self.installed_file_authority(path)
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
  1562
                                f = pkg.fmri.PkgFmri(fmristr, authority = auth)
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
  1563
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1564
                                self.pkg_states[fmristr] = \
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1565
                                    (PKG_STATE_INSTALLED, f)
418
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
  1566
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
  1567
                        return
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
  1568
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
  1569
                # Otherwise, we must iterate through the earlier installed
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
  1570
                # state.  One day, this can be removed.
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
  1571
                proot = "%s/pkg" % self.imgdir
195
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
  1572
                for pd in sorted(os.listdir(proot)):
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
  1573
                        for vd in sorted(os.listdir("%s/%s" % (proot, pd))):
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
  1574
                                path = "%s/%s/%s/installed" % (proot, pd, vd)
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
  1575
                                if not os.path.exists(path):
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
  1576
                                        continue
226
8939051a496c 376 image must use default authority when none specified
johansen <johansen@sun.com>
parents: 222
diff changeset
  1577
331
4f332d6b4036 1266 Client loses track of authority preference, chaos ensues
johansen <johansen@sun.com>
parents: 329
diff changeset
  1578
                                fmristr = urllib.unquote("%s@%s" % (pd, vd))
226
8939051a496c 376 image must use default authority when none specified
johansen <johansen@sun.com>
parents: 222
diff changeset
  1579
                                auth = self.installed_file_authority(path)
331
4f332d6b4036 1266 Client loses track of authority preference, chaos ensues
johansen <johansen@sun.com>
parents: 329
diff changeset
  1580
                                f = pkg.fmri.PkgFmri(fmristr, authority = auth)
226
8939051a496c 376 image must use default authority when none specified
johansen <johansen@sun.com>
parents: 222
diff changeset
  1581
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1582
                                self.pkg_states[fmristr] = \
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1583
                                    (PKG_STATE_INSTALLED, f)
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1584
516
53da6297fb65 3039 Install and Image-update should check index consistency with installed packages
Brock Pytlik <bpytlik@sun.com>
parents: 499
diff changeset
  1585
        def clear_pkg_state(self):
53da6297fb65 3039 Install and Image-update should check index consistency with installed packages
Brock Pytlik <bpytlik@sun.com>
parents: 499
diff changeset
  1586
                self.pkg_states = None
567
ea1d96e269a4 3505 client action and manifest creation are wasteful
johansen <johansen@sun.com>
parents: 565
diff changeset
  1587
                self.__manifest_cache = {}
516
53da6297fb65 3039 Install and Image-update should check index consistency with installed packages
Brock Pytlik <bpytlik@sun.com>
parents: 499
diff changeset
  1588
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1589
        def strtofmri(self, myfmri):
423
5c756997bf67 2253 With the latest build of the pkg repo, can't install packages from additional authorities
Danek Duvall <danek.duvall@sun.com>
parents: 419
diff changeset
  1590
                return pkg.fmri.PkgFmri(myfmri, self.attrs["Build-Release"])
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1591
526
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 518
diff changeset
  1592
        def strtomatchingfmri(self, myfmri):
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 518
diff changeset
  1593
                return pkg.fmri.MatchingPkgFmri(myfmri, self.attrs["Build-Release"])
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 518
diff changeset
  1594
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1595
        def update_optional_dependency(self, inputfmri):
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1596
                """Updates pkgname to min fmri mapping if fmri is newer"""
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1597
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1598
                myfmri = inputfmri
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1599
552
9dcfb25a9c7e 3187 unicode image path causes traceback within image.make_install_plan
Tom Mueller <Tom.Mueller@sun.com>
parents: 551
diff changeset
  1600
                try:
9dcfb25a9c7e 3187 unicode image path causes traceback within image.make_install_plan
Tom Mueller <Tom.Mueller@sun.com>
parents: 551
diff changeset
  1601
                        name = myfmri.get_name()
9dcfb25a9c7e 3187 unicode image path causes traceback within image.make_install_plan
Tom Mueller <Tom.Mueller@sun.com>
parents: 551
diff changeset
  1602
                except AttributeError:
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1603
                        name = pkg.fmri.extract_pkg_name(myfmri)
526
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 518
diff changeset
  1604
                        myfmri = self.strtomatchingfmri(myfmri)
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1605
423
5c756997bf67 2253 With the latest build of the pkg repo, can't install packages from additional authorities
Danek Duvall <danek.duvall@sun.com>
parents: 419
diff changeset
  1606
                try:
5c756997bf67 2253 With the latest build of the pkg repo, can't install packages from additional authorities
Danek Duvall <danek.duvall@sun.com>
parents: 419
diff changeset
  1607
                        myfmri = self.inventory([ myfmri ], all_known = True,
5c756997bf67 2253 With the latest build of the pkg repo, can't install packages from additional authorities
Danek Duvall <danek.duvall@sun.com>
parents: 419
diff changeset
  1608
                            matcher = pkg.fmri.exact_name_match).next()[0]
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  1609
                except api_errors.InventoryException:
423
5c756997bf67 2253 With the latest build of the pkg repo, can't install packages from additional authorities
Danek Duvall <danek.duvall@sun.com>
parents: 419
diff changeset
  1610
                        # If we didn't find the package in the authority it's
5c756997bf67 2253 With the latest build of the pkg repo, can't install packages from additional authorities
Danek Duvall <danek.duvall@sun.com>
parents: 419
diff changeset
  1611
                        # currently installed from, try again without specifying
5c756997bf67 2253 With the latest build of the pkg repo, can't install packages from additional authorities
Danek Duvall <danek.duvall@sun.com>
parents: 419
diff changeset
  1612
                        # the authority.  This will get the first available
5c756997bf67 2253 With the latest build of the pkg repo, can't install packages from additional authorities
Danek Duvall <danek.duvall@sun.com>
parents: 419
diff changeset
  1613
                        # instance of the package preferring the preferred
5c756997bf67 2253 With the latest build of the pkg repo, can't install packages from additional authorities
Danek Duvall <danek.duvall@sun.com>
parents: 419
diff changeset
  1614
                        # authority.  Make sure to unset the authority on a copy
5c756997bf67 2253 With the latest build of the pkg repo, can't install packages from additional authorities
Danek Duvall <danek.duvall@sun.com>
parents: 419
diff changeset
  1615
                        # of myfmri, just in case myfmri is the same object as
5c756997bf67 2253 With the latest build of the pkg repo, can't install packages from additional authorities
Danek Duvall <danek.duvall@sun.com>
parents: 419
diff changeset
  1616
                        # the input fmri.
5c756997bf67 2253 With the latest build of the pkg repo, can't install packages from additional authorities
Danek Duvall <danek.duvall@sun.com>
parents: 419
diff changeset
  1617
                        myfmri = myfmri.copy()
5c756997bf67 2253 With the latest build of the pkg repo, can't install packages from additional authorities
Danek Duvall <danek.duvall@sun.com>
parents: 419
diff changeset
  1618
                        myfmri.set_authority(None)
5c756997bf67 2253 With the latest build of the pkg repo, can't install packages from additional authorities
Danek Duvall <danek.duvall@sun.com>
parents: 419
diff changeset
  1619
                        myfmri = self.inventory([ myfmri ], all_known = True,
5c756997bf67 2253 With the latest build of the pkg repo, can't install packages from additional authorities
Danek Duvall <danek.duvall@sun.com>
parents: 419
diff changeset
  1620
                            matcher = pkg.fmri.exact_name_match).next()[0]
394
6ffef60e8fbb 2229 Problem using pkg, SUNWj6dev dependency issue
Danek Duvall <danek.duvall@sun.com>
parents: 389
diff changeset
  1621
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1622
                ofmri = self.optional_dependencies.get(name, None)
316
d6ba58c63264 1039 circular dependency in packages is detected at install-time
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 315
diff changeset
  1623
                if not ofmri or self.fmri_is_successor(myfmri, ofmri):
423
5c756997bf67 2253 With the latest build of the pkg repo, can't install packages from additional authorities
Danek Duvall <danek.duvall@sun.com>
parents: 419
diff changeset
  1624
                        self.optional_dependencies[name] = myfmri
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1625
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1626
        def apply_optional_dependencies(self, myfmri):
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1627
                """Updates an fmri if optional dependencies require a newer version.
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1628
                Doesn't handle catalog renames... to ease programming for now,
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1629
                unversioned fmris are returned upgraded"""
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1630
552
9dcfb25a9c7e 3187 unicode image path causes traceback within image.make_install_plan
Tom Mueller <Tom.Mueller@sun.com>
parents: 551
diff changeset
  1631
                try:
9dcfb25a9c7e 3187 unicode image path causes traceback within image.make_install_plan
Tom Mueller <Tom.Mueller@sun.com>
parents: 551
diff changeset
  1632
                        name = myfmri.get_name()
9dcfb25a9c7e 3187 unicode image path causes traceback within image.make_install_plan
Tom Mueller <Tom.Mueller@sun.com>
parents: 551
diff changeset
  1633
                except AttributeError:
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1634
                        name = pkg.fmri.extract_pkg_name(myfmri)
526
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 518
diff changeset
  1635
                        myfmri = self.strtomatchingfmri(myfmri)
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1636
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1637
                minfmri = self.optional_dependencies.get(name, None)
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1638
                if not minfmri:
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1639
                        return myfmri
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1640
316
d6ba58c63264 1039 circular dependency in packages is detected at install-time
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 315
diff changeset
  1641
                if self.fmri_is_successor(minfmri, myfmri):
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1642
                        return minfmri
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1643
                return myfmri
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1644
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1645
        def load_optional_dependencies(self):
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1646
                for fmri in self.gen_installed_pkgs():
342
5e1f4d8429bf 669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents: 341
diff changeset
  1647
                        mfst = self.get_manifest(fmri, filtered = True)
5e1f4d8429bf 669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents: 341
diff changeset
  1648
                        for dep in mfst.gen_actions_by_type("depend"):
5e1f4d8429bf 669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents: 341
diff changeset
  1649
                                required, min_fmri, max_fmri = dep.parse(self)
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1650
                                if required == False:
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1651
                                        self.update_optional_dependency(min_fmri)
195
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
  1652
289
c2e63370fb2b 160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents: 285
diff changeset
  1653
        def get_user_by_name(self, name):
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
  1654
                return portable.get_user_by_name(name, self.root,
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
  1655
                    self.type != IMG_USER)
173
da329417a206 18 Actions should use passwd and group databases from image, if possible
Danek Duvall <danek.duvall@sun.com>
parents: 172
diff changeset
  1656
339
d8e57580599b 1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  1657
        def get_name_by_uid(self, uid, returnuid = False):
173
da329417a206 18 Actions should use passwd and group databases from image, if possible
Danek Duvall <danek.duvall@sun.com>
parents: 172
diff changeset
  1658
                # XXX What to do about IMG_PARTIAL?
339
d8e57580599b 1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  1659
                try:
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
  1660
                        return portable.get_name_by_uid(uid, self.root,
339
d8e57580599b 1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  1661
                            self.type != IMG_USER)
d8e57580599b 1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  1662
                except KeyError:
d8e57580599b 1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  1663
                        if returnuid:
d8e57580599b 1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  1664
                                return uid
d8e57580599b 1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  1665
                        else:
d8e57580599b 1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  1666
                                raise
243
ca57127811b8 399 pkg list on explicit packages fails with no output, exit status of 1
Stephen Hahn <sch@Sun.COM>
parents: 239
diff changeset
  1667
289
c2e63370fb2b 160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents: 285
diff changeset
  1668
        def get_group_by_name(self, name):
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
  1669
                return portable.get_group_by_name(name, self.root,
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
  1670
                    self.type != IMG_USER)
173
da329417a206 18 Actions should use passwd and group databases from image, if possible
Danek Duvall <danek.duvall@sun.com>
parents: 172
diff changeset
  1671
339
d8e57580599b 1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  1672
        def get_name_by_gid(self, gid, returngid = False):
d8e57580599b 1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  1673
                try:
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
  1674
                        return portable.get_name_by_gid(gid, self.root,
339
d8e57580599b 1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  1675
                            self.type != IMG_USER)
d8e57580599b 1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  1676
                except KeyError:
d8e57580599b 1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  1677
                        if returngid:
d8e57580599b 1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  1678
                                return gid
d8e57580599b 1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  1679
                        else:
d8e57580599b 1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  1680
                                raise
173
da329417a206 18 Actions should use passwd and group databases from image, if possible
Danek Duvall <danek.duvall@sun.com>
parents: 172
diff changeset
  1681
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1682
        @staticmethod
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1683
        def __multimatch(name, patterns, matcher):
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1684
                """Applies a matcher to a name across a list of patterns.
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1685
                Returns all tuples of patterns which match the name.  Each tuple
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1686
                contains the index into the original list, the pattern itself,
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1687
                the package version, the authority, and the raw authority
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1688
                string."""
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1689
                return [
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1690
                    (i, pat, pat.tuple()[2],
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1691
                        pat.get_authority(), pat.get_authority_str())
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1692
                    for i, pat in enumerate(patterns)
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1693
                    if matcher(name, pat.tuple()[1])
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1694
                ]
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1695
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1696
        def __inventory(self, patterns = None, all_known = False, matcher = None,
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1697
            constraint = pkg.version.CONSTRAINT_AUTO):
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1698
                """Private method providing the back-end for inventory()."""
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1699
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1700
                if not matcher:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1701
                        matcher = pkg.fmri.fmri_match
59
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
  1702
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1703
                if not patterns:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1704
                        patterns = []
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1705
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1706
                # Store the original patterns before we possibly turn them into
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1707
                # PkgFmri objects, so we can give them back to the user in error
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1708
                # messages.
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1709
                opatterns = patterns[:]
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1710
526
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 518
diff changeset
  1711
                illegals = []
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1712
                for i, pat in enumerate(patterns):
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1713
                        if not isinstance(pat, pkg.fmri.PkgFmri):
526
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 518
diff changeset
  1714
                                try:
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 518
diff changeset
  1715
                                        if "*" in pat or "?" in pat:
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 518
diff changeset
  1716
                                                matcher = pkg.fmri.glob_match
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 518
diff changeset
  1717
                                                patterns[i] = \
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 518
diff changeset
  1718
                                                    pkg.fmri.MatchingPkgFmri(pat,
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 518
diff changeset
  1719
                                                        "5.11")
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 518
diff changeset
  1720
                                        else:
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 518
diff changeset
  1721
                                                patterns[i] = \
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 518
diff changeset
  1722
                                                    pkg.fmri.PkgFmri(pat,
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 518
diff changeset
  1723
                                                    "5.11")
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 518
diff changeset
  1724
                                except pkg.fmri.IllegalFmri, e:
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 518
diff changeset
  1725
                                        illegals.append(e)
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 518
diff changeset
  1726
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 518
diff changeset
  1727
                if 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
  1728
                        raise api_errors.InventoryException(illegal=illegals)
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1729
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1730
                pauth = self.cfg_cache.preferred_authority
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1731
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1732
                # matchingpats is the set of all the patterns which matched a
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1733
                # package in the catalog.  This allows us to return partial
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1734
                # failure if some patterns match and some don't.
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1735
                # XXX It would be nice to keep track of why some patterns failed
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1736
                # to match -- based on name, version, or authority.
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1737
                matchingpats = set()
59
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
  1738
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1739
                # XXX Perhaps we shouldn't sort here, but in the caller, to save
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1740
                # memory?
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1741
                for name in sorted(self._catalog.keys()):
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1742
                        # Eliminate all patterns not matching "name".  If there
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1743
                        # are no patterns left, go on to the next name, but only
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1744
                        # if there were any to start with.
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1745
                        matches = self.__multimatch(name, patterns, matcher)
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1746
                        if patterns and not matches:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1747
                                continue
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1748
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1749
                        newest = self._catalog[name]["versions"][-1]
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1750
                        for ver in reversed(self._catalog[name]["versions"]):
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1751
                                # If a pattern specified a version and that
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1752
                                # version isn't succeeded by "ver", then record
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1753
                                # the pattern for removal from consideration.
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1754
                                nomatch = []
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1755
                                for i, match in enumerate(matches):
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1756
                                        if match[2] and \
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1757
                                            not ver.is_successor(match[2],
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1758
                                                constraint):
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1759
                                                nomatch.append(i)
221
e1dbb27a23b5 52 catalog can leave inventory behind, making pkg(1) blind
Stephen Hahn <sch@Sun.COM>
parents: 219
diff changeset
  1760
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1761
                                # Eliminate the name matches that didn't match
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1762
                                # on versions.  We need to create a new list
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1763
                                # because we need to reuse the original
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1764
                                # "matches" for each new version.
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1765
                                vmatches = [
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1766
                                    matches[i]
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1767
                                    for i, match in enumerate(matches)
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1768
                                    if i not in nomatch
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1769
                                ]
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1770
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1771
                                # If we deleted all contenders (if we had any to
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1772
                                # begin with), go on to the next version.
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1773
                                if matches and not vmatches:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1774
                                        continue
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1775
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1776
                                # Like the version skipping above, do the same
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1777
                                # for authorities.
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1778
                                authlist = set(self._catalog[name][str(ver)][1])
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1779
                                nomatch = []
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1780
                                for i, match in enumerate(vmatches):
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1781
                                        if match[3] and \
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1782
                                            match[3] not in authlist:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1783
                                                nomatch.append(i)
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1784
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1785
                                amatches = [
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1786
                                    vmatches[i]
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1787
                                    for i, match in enumerate(vmatches)
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1788
                                    if i not in nomatch
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1789
                                ]
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1790
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1791
                                if vmatches and not amatches:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1792
                                        continue
104
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
  1793
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1794
                                # If no patterns were specified or any still-
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1795
                                # matching pattern specified no authority, we
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1796
                                # use the entire authlist for this version.
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1797
                                # Otherwise, we use the intersection of authlist
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1798
                                # and the auths in the patterns.
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1799
                                aset = set(i[3] for i in amatches)
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1800
                                if aset and None not in aset:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1801
                                        authlist = set(
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1802
                                            m[3:5]
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1803
                                            for m in amatches
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1804
                                            if m[3] in authlist
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1805
                                        )
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1806
                                else:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1807
                                        authlist = zip(authlist, authlist)
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1808
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1809
                                pfmri = self._catalog[name][str(ver)][0]
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1810
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1811
                                inst_state = self.get_pkg_state_by_fmri(pfmri)
423
5c756997bf67 2253 With the latest build of the pkg repo, can't install packages from additional authorities
Danek Duvall <danek.duvall@sun.com>
parents: 419
diff changeset
  1812
                                inst_auth = self.get_pkg_auth_by_fmri(pfmri)
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1813
                                state = {
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1814
                                    "upgradable": ver != newest,
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1815
                                    "frozen": False,
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1816
                                    "incorporated": False,
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1817
                                    "excludes": False
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1818
                                }
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1819
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1820
                                # We yield copies of the fmri objects in the
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1821
                                # catalog because we add the authorities in, and
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1822
                                # don't want to mess up the canonical catalog.
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1823
                                # If a pattern had specified an authority as
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1824
                                # preferred, be sure to emit an fmri that way,
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1825
                                # too.
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1826
                                yielded = False
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1827
                                if all_known:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1828
                                        for auth, rauth in authlist:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1829
                                                nfmri = pfmri.copy()
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1830
                                                nfmri.set_authority(rauth,
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1831
                                                    auth == pauth)
423
5c756997bf67 2253 With the latest build of the pkg repo, can't install packages from additional authorities
Danek Duvall <danek.duvall@sun.com>
parents: 419
diff changeset
  1832
                                                if auth == inst_auth:
5c756997bf67 2253 With the latest build of the pkg repo, can't install packages from additional authorities
Danek Duvall <danek.duvall@sun.com>
parents: 419
diff changeset
  1833
                                                        state["state"] = \
5c756997bf67 2253 With the latest build of the pkg repo, can't install packages from additional authorities
Danek Duvall <danek.duvall@sun.com>
parents: 419
diff changeset
  1834
                                                            PKG_STATE_INSTALLED
5c756997bf67 2253 With the latest build of the pkg repo, can't install packages from additional authorities
Danek Duvall <danek.duvall@sun.com>
parents: 419
diff changeset
  1835
                                                else:
5c756997bf67 2253 With the latest build of the pkg repo, can't install packages from additional authorities
Danek Duvall <danek.duvall@sun.com>
parents: 419
diff changeset
  1836
                                                        state["state"] = \
5c756997bf67 2253 With the latest build of the pkg repo, can't install packages from additional authorities
Danek Duvall <danek.duvall@sun.com>
parents: 419
diff changeset
  1837
                                                            PKG_STATE_KNOWN
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1838
                                                yield nfmri, state
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1839
                                                yielded = True
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1840
                                elif inst_state == PKG_STATE_INSTALLED:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1841
                                        nfmri = pfmri.copy()
423
5c756997bf67 2253 With the latest build of the pkg repo, can't install packages from additional authorities
Danek Duvall <danek.duvall@sun.com>
parents: 419
diff changeset
  1842
                                        nfmri.set_authority(inst_auth,
5c756997bf67 2253 With the latest build of the pkg repo, can't install packages from additional authorities
Danek Duvall <danek.duvall@sun.com>
parents: 419
diff changeset
  1843
                                            inst_auth == pauth)
5c756997bf67 2253 With the latest build of the pkg repo, can't install packages from additional authorities
Danek Duvall <danek.duvall@sun.com>
parents: 419
diff changeset
  1844
                                        state["state"] = inst_state
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1845
                                        yield nfmri, state
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1846
                                        yielded = True
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1847
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1848
                                if yielded:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1849
                                        matchingpats |= set(i[:2] for i in amatches)
329
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
  1850
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1851
                nonmatchingpats = [
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1852
                    opatterns[i]
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1853
                    for i, f in set(enumerate(patterns)) - matchingpats
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1854
                ]
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1855
                if nonmatchingpats:
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  1856
                        raise api_errors.InventoryException(
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  1857
                            notfound=nonmatchingpats)
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1858
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1859
        def inventory(self, *args, **kwargs):
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1860
                """Enumerate the package FMRIs in the image's catalog.
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1861
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1862
                If "patterns" is None (the default) or an empty sequence, all
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1863
                package names will match.  Otherwise, it is a list of patterns
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1864
                to match against FMRIs in the catalog.
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1865
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1866
                If "all_known" is False (the default), only installed packages
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1867
                will be enumerated.  If True, all known packages will be
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1868
                enumerated.
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1869
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1870
                The "matcher" parameter should specify a function taking two
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1871
                string arguments: a name and a pattern, returning True if the
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1872
                pattern matches the name, and False otherwise.  By default, the
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1873
                matcher will be pkg.fmri.fmri_match().
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1874
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1875
                The "constraint" parameter defines how a version specified in a
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1876
                pattern matches a version in the catalog.  By default, a natural
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1877
                "subsetting" constraint is used."""
161
e0322fe7842c Simplify and correct the package matching code.
Danek Duvall <danek.duvall@sun.com>
parents: 157
diff changeset
  1878
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1879
                # "preferred" and "first_only" are private arguments that are
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1880
                # currently only used in evaluate_fmri(), but could be made more
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1881
                # generally useful.  "preferred" ensures that all potential
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1882
                # matches from the preferred authority are generated before
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1883
                # those from non-preferred authorities.  In the current
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1884
                # implementation, this consumes more memory.  "first_only"
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1885
                # signals us to return only the first match, which allows us to
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1886
                # save all the memory that "preferred" currently eats up.
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1887
                preferred = kwargs.pop("preferred", False)
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1888
                first_only = kwargs.pop("first_only", False)
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1889
                pauth = self.cfg_cache.preferred_authority
59
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
  1890
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1891
                if not preferred:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1892
                        for f in self.__inventory(*args, **kwargs):
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1893
                                yield f
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1894
                else:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1895
                        nplist = []
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1896
                        firstnp = None
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1897
                        for f in self.__inventory(*args, **kwargs):
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1898
                                if f[0].get_authority() == pauth:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1899
                                        yield f
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1900
                                        if first_only:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1901
                                                return
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1902
                                else:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1903
                                        if first_only:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1904
                                                if not firstnp:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1905
                                                        firstnp = f
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1906
                                        else:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1907
                                                nplist.append(f)
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1908
                        if first_only:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1909
                                yield firstnp
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1910
                                return
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1911
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1912
                        for f in nplist:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1913
                                yield f
59
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
  1914
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
  1915
        def update_index_dir(self, postfix="index"):
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
  1916
                """Since the index directory will not reliably be updated when
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
  1917
                the image root is, this should be called prior to using the
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
  1918
                index directory.
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
  1919
                """
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
  1920
                self.index_dir = os.path.join(self.imgdir, postfix)
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
  1921
449
615045a660d4 2797 Without indexes, search should fall back
Brock Pytlik <bpytlik@sun.com>
parents: 434
diff changeset
  1922
        def degraded_local_search(self, args):
615045a660d4 2797 Without indexes, search should fall back
Brock Pytlik <bpytlik@sun.com>
parents: 434
diff changeset
  1923
                msg("Search capabilities and performance are degraded.\n"
615045a660d4 2797 Without indexes, search should fall back
Brock Pytlik <bpytlik@sun.com>
parents: 434
diff changeset
  1924
                    "To improve, run 'pkg rebuild-index'.")
615045a660d4 2797 Without indexes, search should fall back
Brock Pytlik <bpytlik@sun.com>
parents: 434
diff changeset
  1925
                res = []
615045a660d4 2797 Without indexes, search should fall back
Brock Pytlik <bpytlik@sun.com>
parents: 434
diff changeset
  1926
615045a660d4 2797 Without indexes, search should fall back
Brock Pytlik <bpytlik@sun.com>
parents: 434
diff changeset
  1927
                for fmri, mfst in self.get_fmri_manifest_pairs():
615045a660d4 2797 Without indexes, search should fall back
Brock Pytlik <bpytlik@sun.com>
parents: 434
diff changeset
  1928
                        m = manifest.Manifest()
615045a660d4 2797 Without indexes, search should fall back
Brock Pytlik <bpytlik@sun.com>
parents: 434
diff changeset
  1929
                        try:
615045a660d4 2797 Without indexes, search should fall back
Brock Pytlik <bpytlik@sun.com>
parents: 434
diff changeset
  1930
                                mcontent = file(mfst).read()
576
6ee6de304041 3777 PKG_TIMEOUT_MAX is a placebo setting
Dan Price <dp@eng.sun.com>
parents: 573
diff changeset
  1931
                        except EnvironmentError:
449
615045a660d4 2797 Without indexes, search should fall back
Brock Pytlik <bpytlik@sun.com>
parents: 434
diff changeset
  1932
                                # XXX log something?
615045a660d4 2797 Without indexes, search should fall back
Brock Pytlik <bpytlik@sun.com>
parents: 434
diff changeset
  1933
                                continue
615045a660d4 2797 Without indexes, search should fall back
Brock Pytlik <bpytlik@sun.com>
parents: 434
diff changeset
  1934
                        m.set_content(mcontent)
615045a660d4 2797 Without indexes, search should fall back
Brock Pytlik <bpytlik@sun.com>
parents: 434
diff changeset
  1935
                        new_dict = m.search_dict()
615045a660d4 2797 Without indexes, search should fall back
Brock Pytlik <bpytlik@sun.com>
parents: 434
diff changeset
  1936
615045a660d4 2797 Without indexes, search should fall back
Brock Pytlik <bpytlik@sun.com>
parents: 434
diff changeset
  1937
                        tok = args[0]
615045a660d4 2797 Without indexes, search should fall back
Brock Pytlik <bpytlik@sun.com>
parents: 434
diff changeset
  1938
615045a660d4 2797 Without indexes, search should fall back
Brock Pytlik <bpytlik@sun.com>
parents: 434
diff changeset
  1939
                        for tok_type in new_dict.keys():
615045a660d4 2797 Without indexes, search should fall back
Brock Pytlik <bpytlik@sun.com>
parents: 434
diff changeset
  1940
                                if new_dict[tok_type].has_key(tok):
615045a660d4 2797 Without indexes, search should fall back
Brock Pytlik <bpytlik@sun.com>
parents: 434
diff changeset
  1941
                                        ak_list = new_dict[tok_type][tok]
615045a660d4 2797 Without indexes, search should fall back
Brock Pytlik <bpytlik@sun.com>
parents: 434
diff changeset
  1942
                                        for action, keyval in ak_list:
615045a660d4 2797 Without indexes, search should fall back
Brock Pytlik <bpytlik@sun.com>
parents: 434
diff changeset
  1943
                                                res.append((tok_type, fmri, \
615045a660d4 2797 Without indexes, search should fall back
Brock Pytlik <bpytlik@sun.com>
parents: 434
diff changeset
  1944
                                                    action, keyval))
615045a660d4 2797 Without indexes, search should fall back
Brock Pytlik <bpytlik@sun.com>
parents: 434
diff changeset
  1945
                return res
615045a660d4 2797 Without indexes, search should fall back
Brock Pytlik <bpytlik@sun.com>
parents: 434
diff changeset
  1946
499
ff214b0daeb1 2672 Search should allow for case insensitive search.
Brock Pytlik <bpytlik@sun.com>
parents: 496
diff changeset
  1947
        def local_search(self, args, case_sensitive):
144
ce619e0b453f Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents: 139
diff changeset
  1948
                """Search the image for the token in args[0]."""
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
  1949
                assert args[0]
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
  1950
                self.update_index_dir()
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
  1951
                qe = query_e.ClientQueryEngine(self.index_dir)
499
ff214b0daeb1 2672 Search should allow for case insensitive search.
Brock Pytlik <bpytlik@sun.com>
parents: 496
diff changeset
  1952
                query = query_e.Query(args[0], case_sensitive)
449
615045a660d4 2797 Without indexes, search should fall back
Brock Pytlik <bpytlik@sun.com>
parents: 434
diff changeset
  1953
                try:
516
53da6297fb65 3039 Install and Image-update should check index consistency with installed packages
Brock Pytlik <bpytlik@sun.com>
parents: 499
diff changeset
  1954
                        res = qe.search(query, self.gen_installed_pkg_names())
499
ff214b0daeb1 2672 Search should allow for case insensitive search.
Brock Pytlik <bpytlik@sun.com>
parents: 496
diff changeset
  1955
                except search_errors.NoIndexException:
449
615045a660d4 2797 Without indexes, search should fall back
Brock Pytlik <bpytlik@sun.com>
parents: 434
diff changeset
  1956
                        res = self.degraded_local_search(args)
615045a660d4 2797 Without indexes, search should fall back
Brock Pytlik <bpytlik@sun.com>
parents: 434
diff changeset
  1957
                return res
144
ce619e0b453f Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents: 139
diff changeset
  1958
204
8f650d596aec 72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents: 201
diff changeset
  1959
        def remote_search(self, args, servers = None):
8f650d596aec 72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents: 201
diff changeset
  1960
                """Search for the token in args[0] on the servers in 'servers'.
8f650d596aec 72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents: 201
diff changeset
  1961
                If 'servers' is empty or None, search on all known servers."""
8f650d596aec 72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents: 201
diff changeset
  1962
                failed = []
8f650d596aec 72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents: 201
diff changeset
  1963
8f650d596aec 72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents: 201
diff changeset
  1964
                if not servers:
8f650d596aec 72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents: 201
diff changeset
  1965
                        servers = self.gen_authorities()
8f650d596aec 72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents: 201
diff changeset
  1966
8f650d596aec 72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents: 201
diff changeset
  1967
                for auth in servers:
322
e1b078577730 1101 pkg search -s <server> returns a traceback
Danek Duvall <danek.duvall@sun.com>
parents: 319
diff changeset
  1968
                        ssl_tuple = self.get_ssl_credentials(
e1b078577730 1101 pkg search -s <server> returns a traceback
Danek Duvall <danek.duvall@sun.com>
parents: 319
diff changeset
  1969
                            authority = auth.get("prefix", None),
e1b078577730 1101 pkg search -s <server> returns a traceback
Danek Duvall <danek.duvall@sun.com>
parents: 319
diff changeset
  1970
                            origin = auth["origin"])
551
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
  1971
                        try:
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
  1972
                                uuid = self.get_uuid(auth["prefix"])
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
  1973
                        except KeyError:
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
  1974
                                uuid = None
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
  1975
204
8f650d596aec 72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents: 201
diff changeset
  1976
                        try:
8f650d596aec 72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents: 201
diff changeset
  1977
                                res, v = versioned_urlopen(auth["origin"],
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
  1978
                                    "search", [0], urllib.quote(args[0], ""),
551
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
  1979
                                    ssl_creds=ssl_tuple, imgtype=self.type,
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
  1980
                                    uuid=uuid)
204
8f650d596aec 72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents: 201
diff changeset
  1981
                        except urllib2.HTTPError, e:
260
a1b77322abb2 255 Symbolic HTTP response codes should be used
Shawn Walker <swalker@opensolaris.org>
parents: 259
diff changeset
  1982
                                if e.code != httplib.NOT_FOUND:
204
8f650d596aec 72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents: 201
diff changeset
  1983
                                        failed.append((auth, e))
8f650d596aec 72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents: 201
diff changeset
  1984
                                continue
8f650d596aec 72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents: 201
diff changeset
  1985
                        except urllib2.URLError, e:
8f650d596aec 72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents: 201
diff changeset
  1986
                                failed.append((auth, e))
8f650d596aec 72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents: 201
diff changeset
  1987
                                continue
8f650d596aec 72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents: 201
diff changeset
  1988
388
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  1989
                        try:
499
ff214b0daeb1 2672 Search should allow for case insensitive search.
Brock Pytlik <bpytlik@sun.com>
parents: 496
diff changeset
  1990
                                for line in res.read().splitlines():
ff214b0daeb1 2672 Search should allow for case insensitive search.
Brock Pytlik <bpytlik@sun.com>
parents: 496
diff changeset
  1991
                                        fields = line.split()
388
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  1992
                                        if len(fields) < 4:
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
  1993
                                                yield fields[:2] + [ "", "" ]
388
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  1994
                                        else:
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
  1995
                                                yield fields[:4]
388
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  1996
                        except socket.timeout, e:
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  1997
                                failed.append((auth, e))
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  1998
                                continue
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  1999
204
8f650d596aec 72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents: 201
diff changeset
  2000
                if failed:
8f650d596aec 72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents: 201
diff changeset
  2001
                        raise RuntimeError, failed
8f650d596aec 72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents: 201
diff changeset
  2002
388
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  2003
        def incoming_download_dir(self):
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  2004
                """Return the directory path for incoming downloads
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  2005
                that have yet to be completed.  Once a file has been
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  2006
                successfully downloaded, it is moved to the cached download
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  2007
                directory."""
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  2008
554
fe196874250d 3508 zone install should utilize/populate global zone d/l cache
Dan Price <dp@eng.sun.com>
parents: 552
diff changeset
  2009
                return self.dl_cache_incoming
388
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  2010
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  2011
        def cached_download_dir(self):
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  2012
                """Return the directory path for cached content.
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  2013
                Files that have been successfully downloaded live here."""
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  2014
554
fe196874250d 3508 zone install should utilize/populate global zone d/l cache
Dan Price <dp@eng.sun.com>
parents: 552
diff changeset
  2015
                return self.dl_cache_dir
251
6c3d70b74865 470 pkg image-update can fail under some conditions
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 243
diff changeset
  2016
6c3d70b74865 470 pkg image-update can fail under some conditions
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 243
diff changeset
  2017
        def cleanup_downloads(self):
388
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  2018
                """Clean up any downloads that were in progress but that
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  2019
                did not successfully finish."""
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  2020
554
fe196874250d 3508 zone install should utilize/populate global zone d/l cache
Dan Price <dp@eng.sun.com>
parents: 552
diff changeset
  2021
                shutil.rmtree(self.dl_cache_incoming, True)
388
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  2022
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  2023
        def cleanup_cached_content(self):
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  2024
                """Delete the directory that stores all of our cached
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  2025
                downloaded content.  This may take a while for a large
554
fe196874250d 3508 zone install should utilize/populate global zone d/l cache
Dan Price <dp@eng.sun.com>
parents: 552
diff changeset
  2026
                directory hierarchy.  Don't clean up caches if the
fe196874250d 3508 zone install should utilize/populate global zone d/l cache
Dan Price <dp@eng.sun.com>
parents: 552
diff changeset
  2027
                user overrode the underlying setting using PKG_CACHEDIR. """
388
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  2028
554
fe196874250d 3508 zone install should utilize/populate global zone d/l cache
Dan Price <dp@eng.sun.com>
parents: 552
diff changeset
  2029
                if not self.is_user_cache_dir and \
fe196874250d 3508 zone install should utilize/populate global zone d/l cache
Dan Price <dp@eng.sun.com>
parents: 552
diff changeset
  2030
                    self.cfg_cache.get_policy(imageconfig.FLUSH_CONTENT_CACHE):
388
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  2031
                        msg("Deleting content cache")
554
fe196874250d 3508 zone install should utilize/populate global zone d/l cache
Dan Price <dp@eng.sun.com>
parents: 552
diff changeset
  2032
                        shutil.rmtree(self.dl_cache_dir, True)
289
c2e63370fb2b 160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents: 285
diff changeset
  2033
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  2034
        def salvagedir(self, path):
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  2035
                """Called when directory contains something and it's not supposed
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  2036
                to because it's being deleted. XXX Need to work out a better error
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  2037
                passback mechanism. Path is rooted in /...."""
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
  2038
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  2039
                salvagedir = os.path.normpath(
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  2040
                    os.path.join(self.imgdir, "lost+found",
384
9d4746e5dd3e 115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents: 383
diff changeset
  2041
                    path + "-" + time.strftime("%Y%m%dT%H%M%SZ")))
289
c2e63370fb2b 160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents: 285
diff changeset
  2042
405
16824ed83efe 2209 license install failure on Windows if license file already exists
Tom Mueller <Tom.Mueller@sun.com>
parents: 399
diff changeset
  2043
                parent = os.path.dirname(salvagedir)
16824ed83efe 2209 license install failure on Windows if license file already exists
Tom Mueller <Tom.Mueller@sun.com>
parents: 399
diff changeset
  2044
                if not os.path.exists(parent):
16824ed83efe 2209 license install failure on Windows if license file already exists
Tom Mueller <Tom.Mueller@sun.com>
parents: 399
diff changeset
  2045
                        os.makedirs(parent)
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  2046
                shutil.move(os.path.normpath(os.path.join(self.root, path)), salvagedir)
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  2047
                # XXX need a better way to do this.
384
9d4746e5dd3e 115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents: 383
diff changeset
  2048
                emsg("\nWarning - directory %s not empty - contents preserved "
9d4746e5dd3e 115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents: 383
diff changeset
  2049
                        "in %s" % (path, salvagedir))
251
6c3d70b74865 470 pkg image-update can fail under some conditions
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 243
diff changeset
  2050
462
910600c14093 45 "move" action for files that are renamed, but must be preserved
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 461
diff changeset
  2051
        def temporary_file(self):
910600c14093 45 "move" action for files that are renamed, but must be preserved
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 461
diff changeset
  2052
                """ create a temp file under image directory for various purposes"""
910600c14093 45 "move" action for files that are renamed, but must be preserved
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 461
diff changeset
  2053
                tempdir = os.path.normpath(os.path.join(self.imgdir, "tmp"))
910600c14093 45 "move" action for files that are renamed, but must be preserved
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 461
diff changeset
  2054
                if not os.path.exists(tempdir):
910600c14093 45 "move" action for files that are renamed, but must be preserved
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 461
diff changeset
  2055
                        os.makedirs(tempdir)
910600c14093 45 "move" action for files that are renamed, but must be preserved
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 461
diff changeset
  2056
                fd, name = tempfile.mkstemp(dir=tempdir)
910600c14093 45 "move" action for files that are renamed, but must be preserved
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 461
diff changeset
  2057
                os.close(fd)
910600c14093 45 "move" action for files that are renamed, but must be preserved
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 461
diff changeset
  2058
                return name
910600c14093 45 "move" action for files that are renamed, but must be preserved
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 461
diff changeset
  2059
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  2060
        def expanddirs(self, dirs):
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
  2061
                """given a set of directories, return expanded set that includes
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  2062
                all components"""
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  2063
                out = set()
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  2064
                for d in dirs:
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  2065
                        p = d
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  2066
                        while p != "":
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  2067
                                out.add(p)
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  2068
                                p = os.path.dirname(p)
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  2069
                return out
329
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
  2070
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
  2071
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2072
        def make_install_plan(self, pkg_list, prtrack, check_cancelation,
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2073
            noexecute, filters = None, verbose=False):
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  2074
                """Take a list of packages, specified in pkg_list, and attempt
329
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
  2075
                to assemble an appropriate image plan.  This is a helper
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
  2076
                routine for some common operations in the client.
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  2077
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  2078
                This method checks all authorities for a package match;
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  2079
                however, it defaults to choosing the preferred authority
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  2080
                when an ambiguous package name is specified.  If the user
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  2081
                wishes to install a package from a non-preferred authority,
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  2082
                the full FMRI that contains an authority should be used
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  2083
                to name the package."""
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  2084
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2085
                if filters is None:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2086
                        filters = []
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2087
                
172
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  2088
                error = 0
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2089
                ip = imageplan.ImagePlan(self, prtrack, check_cancelation,
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2090
                    filters=filters, noexecute=noexecute)
172
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  2091
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  2092
                self.load_optional_dependencies()
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  2093
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2094
                unfound_fmris = []
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2095
                multiple_matches = []
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2096
                
172
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  2097
                for p in pkg_list:
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  2098
                        try:
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  2099
                                conp = self.apply_optional_dependencies(p)
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2100
                                matches = list(self.inventory([ conp ],
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2101
                                    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
  2102
                        except api_errors.InventoryException:
172
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  2103
                                error = 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
  2104
                                unfound_fmris.append(p)
172
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  2105
                                continue
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  2106
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  2107
                        pnames = {}
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  2108
                        pmatch = []
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  2109
                        npnames = {}
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  2110
                        npmatch = []
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2111
                        for m, state in matches:
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  2112
                                if m.preferred_authority():
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  2113
                                        pnames[m.get_pkg_stem()] = 1
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  2114
                                        pmatch.append(m)
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  2115
                                else:
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  2116
                                        npnames[m.get_pkg_stem()] = 1
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  2117
                                        npmatch.append(m)
172
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  2118
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  2119
                        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
  2120
                                multiple_matches.append((p, pnames.keys()))
172
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  2121
                                error = 1
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  2122
                                continue
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  2123
                        elif len(pnames.keys()) < 1 and len(npnames.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
  2124
                                multiple_matches.append((p, pnames.keys()))
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  2125
                                error = 1
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  2126
                                continue
172
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  2127
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  2128
                        # matches is a list reverse sorted by version, so take
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  2129
                        # the first; i.e., the latest.
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  2130
                        if len(pmatch) > 0:
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  2131
                                ip.propose_fmri(pmatch[0])
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  2132
                        else:
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
  2133
                                ip.propose_fmri(npmatch[0])
172
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  2134
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  2135
                if error != 0:
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2136
                        raise api_errors.PlanCreationException(unfound_fmris,
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2137
                            multiple_matches, None)
172
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  2138
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  2139
                if verbose:
384
9d4746e5dd3e 115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents: 383
diff changeset
  2140
                        msg(_("Before evaluation:"))
9d4746e5dd3e 115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents: 383
diff changeset
  2141
                        msg(ip)
172
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  2142
539
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  2143
                # A plan can be requested without actually performing an
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  2144
                # operation on the image.
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  2145
                if self.history.operation_name:
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  2146
                        self.history.operation_start_state = ip.get_plan()
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  2147
172
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  2148
                ip.evaluate()
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
  2149
                self.imageplan = ip
172
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  2150
539
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  2151
                if self.history.operation_name:
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  2152
                        self.history.operation_end_state = \
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  2153
                            ip.get_plan(full=False)
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  2154
172
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  2155
                if verbose:
384
9d4746e5dd3e 115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents: 383
diff changeset
  2156
                        msg(_("After evaluation:"))
9d4746e5dd3e 115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents: 383
diff changeset
  2157
                        msg(ip.display())
45
8a3f00dea14f catalog refresh; basic catalog listing; precise manifest pulls
Stephen Hahn <sch@sun.com>
parents: 39
diff changeset
  2158
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2159
        def make_uninstall_plan(self, fmri_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
  2160
            progresstracker, check_cancelation, noexecute, verbose=False):
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2161
                ip = imageplan.ImagePlan(self, progresstracker,
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2162
                    check_cancelation, recursive_removal, noexecute=noexecute)
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2163
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2164
                err = 0
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2165
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2166
                unfound_fmris = []
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2167
                multiple_matches = []
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2168
                missing_matches = []
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2169
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2170
                for ppat in fmri_list:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2171
                        try:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2172
                                matches = list(self.inventory([ppat]))
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2173
                        except api_errors.InventoryException:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2174
                                unfound_fmris.append(ppat)
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2175
                                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
  2176
                                continue
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2177
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2178
                        if len(matches) > 1:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2179
                                multiple_matches.append((ppat, matches))
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2180
                                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
  2181
                                continue
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2182
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2183
                        if len(matches) < 1:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2184
                                missing_matches.append(ppat)
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2185
                                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
  2186
                                continue
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2187
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2188
                        # Propose the removal of the first (and only!) match.
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2189
                        ip.propose_fmri_removal(matches[0][0])
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2190
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2191
                if 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
  2192
                        raise api_errors.PlanCreationException(unfound_fmris,
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2193
                            multiple_matches, missing_matches)
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2194
                if verbose:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2195
                        msg(_("Before evaluation:"))
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2196
                        msg(ip)
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2197
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2198
                self.history.operation_start_state = ip.get_plan()
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2199
                ip.evaluate()
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2200
                self.history.operation_end_state = ip.get_plan(full=False)
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2201
                self.imageplan = ip
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2202
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2203
                if verbose:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2204
                        msg(_("After evaluation:"))
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2205
                        ip.display()
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2206
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2207
        def ipkg_is_up_to_date(self, actual_cmd, check_cancelation, noexecute,
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2208
            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
  2209
                """ Test whether SUNWipkg is updated to the latest version
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2210
                    known to be 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
  2211
                #
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2212
                # This routine makes the distinction between the "target image",
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2213
                # which will be altered, and the "running image", which is
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2214
                # to say whatever image appears to contain the version of the 
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2215
                # pkg command we're running.
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2216
                #
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2217
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2218
                #
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2219
                # There are two relevant cases here:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2220
                #     1) Packaging code and image we're updating are the same
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2221
                #        image.  (i.e. 'pkg 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
  2222
                #
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2223
                #     2) Packaging code's image and the image we're updating are
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2224
                #        different (i.e. 'pkg image-update -R')
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2225
                #
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2226
                # In general, we care about getting the user to run the
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2227
                # most recent packaging code available for their build.  So,
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2228
                # if we're not in the liveroot case, we create a new image
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2229
                # which represents "/" on the system.
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2230
                #
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2231
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2232
                # always quiet for this part of the code.
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2233
                progresstracker = progress.QuietProgressTracker()
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2234
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2235
                img = self
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2236
                
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2237
                if not img.is_liveroot():
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2238
                        newimg = Image()
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2239
                        cmdpath = os.path.join(os.getcwd(), actual_cmd)
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2240
                        cmdpath = os.path.realpath(cmdpath)
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2241
                        cmddir = os.path.dirname(os.path.realpath(cmdpath))
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2242
                        #
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2243
                        # Find the path to ourselves, and use that
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2244
                        # as a way to locate the image we're in.  It's
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2245
                        # not perfect-- we could be in a developer's
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2246
                        # workspace, for example.
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2247
                        #
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2248
                        newimg.find_root(cmddir)
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2249
                        newimg.load_config()
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2250
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2251
                        if 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
  2252
                                # Refresh the catalog, so that we can discover
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2253
                                # if a new SUNWipkg is available.
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2254
                                try:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2255
                                        newimg.retrieve_catalogs()
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2256
                                except api_errors.CatalogRefreshException, cre:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2257
                                        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
  2258
                                            _("SUNWipkg update check failed.")
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2259
                                        raise
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2260
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2261
                        # Load catalog.
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2262
                        newimg.load_catalogs(progresstracker)
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2263
                        img = newimg
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2264
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2265
                # XXX call to progress tracker that SUNWipkg is being checked
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2266
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2267
                img.make_install_plan(["SUNWipkg"], progresstracker,
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2268
                    check_cancelation, noexecute, filters = [])
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2269
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2270
                return img.imageplan.nothingtodo()
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2271
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2272
        def installed_fmris_from_args(self, args):
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2273
                """Helper function to translate client command line arguments
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2274
                into a list of installed fmris.  Used by info, contents,
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2275
                verify.
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2276
                """
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2277
                found = []
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2278
                notfound = []
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2279
                illegals = []
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2280
                try:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2281
                        for m in self.inventory(args):
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2282
                                found.append(m[0])
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2283
                except api_errors.InventoryException, e:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2284
                        illegals = e.illegal
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2285
                        notfound = e.notfound
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2286
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2287
                return found, notfound, illegals
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2288
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
  2289
        def rebuild_search_index(self, progtracker):
556
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
  2290
                """Rebuilds the search indexes.  Removes all
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
  2291
                existing indexes and replaces them from scratch rather than
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
  2292
                performing the incremental update which is usually used."""
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
  2293
                self.update_index_dir()
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
  2294
                if not os.path.isdir(self.index_dir):
453
c505827e4ae7 2807 pkg rebuild shouldn't traceback when no index directory is present
Brock Pytlik <bpytlik@sun.com>
parents: 449
diff changeset
  2295
                        self.mkdirs()
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
  2296
                ind = indexer.Indexer(self.index_dir,
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
  2297
                    CLIENT_DEFAULT_MEM_USE_KB, progtracker)
516
53da6297fb65 3039 Install and Image-update should check index consistency with installed packages
Brock Pytlik <bpytlik@sun.com>
parents: 499
diff changeset
  2298
                ind.rebuild_index_from_scratch(self.get_fmri_manifest_pairs())