src/modules/client/image.py
author Brock Pytlik <bpytlik@sun.com>
Fri, 25 Jul 2008 13:56:38 -0700
changeset 429 6c9cbb6e6600
parent 423 5c756997bf67
child 432 578875da6e04
permissions -rw-r--r--
983 pkg search returns just one action per package/token-type combo 1949 pkg search is inordinately slow 2122 catalog file update needs to be atomic with respect to both other updates and reads
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
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
    34
import time
384
9d4746e5dd3e 115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents: 383
diff changeset
    35
9d4746e5dd3e 115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents: 383
diff changeset
    36
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
    37
104
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
    38
# 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
    39
8b9613402116 refactor catalog and package to be common; improve bump-server
Stephen Hahn <sch@sun.com>
parents: 33
diff changeset
    40
import pkg.catalog as catalog
215
c10719939c6d 245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents: 208
diff changeset
    41
import pkg.updatelog as updatelog
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
    42
import pkg.fmri
50
bfcb1661f019 basic image and package plans
Stephen Hahn <sch@sun.com>
parents: 45
diff changeset
    43
import pkg.manifest as manifest
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
    44
import pkg.misc as misc
175
8d591677690b 22 Specifying a version on the "pkg install" commandline makes no difference
Danek Duvall <danek.duvall@sun.com>
parents: 173
diff changeset
    45
import pkg.version as version
104
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
    46
import pkg.client.imageconfig as imageconfig
172
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
    47
import pkg.client.imageplan as imageplan
161
e0322fe7842c Simplify and correct the package matching code.
Danek Duvall <danek.duvall@sun.com>
parents: 157
diff changeset
    48
import pkg.client.retrieve as retrieve
289
c2e63370fb2b 160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents: 285
diff changeset
    49
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
    50
import pkg.client.query_engine as query_e
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
    51
import pkg.indexer as indexer
104
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
    52
145
08bee7fd13f6 Add versioning to the protocols
Danek Duvall <danek.duvall@sun.com>
parents: 144
diff changeset
    53
from pkg.misc import versioned_urlopen
388
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
    54
from pkg.misc import TransferTimedOutException
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
    55
from pkg.misc import CLIENT_DEFAULT_MEM_USE_KB
319
39b8b5c538bf 1104 want custom user-agent string
Danek Duvall <danek.duvall@sun.com>
parents: 316
diff changeset
    56
from pkg.client.imagetypes import *
19
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    57
26
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
    58
img_user_prefix = ".org.opensolaris,pkg"
30
f06ad6cb4b3f stop using flavour terminology
Stephen Hahn <sch@sun.com>
parents: 29
diff changeset
    59
img_root_prefix = "var/pkg"
26
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
    60
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
    61
PKG_STATE_INSTALLED = "installed"
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
    62
PKG_STATE_KNOWN = "known"
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
    63
19
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    64
class Image(object):
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    65
        """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
    66
        of a self-consistent graph of Packages.
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    67
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    68
        An Image has a root path.
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    69
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    70
        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
    71
        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
    72
        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
    73
        Image (IMG_PARTIAL for zones, for instance).
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    74
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    75
        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
    76
        partial Image must be an entire Image.
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    77
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    78
        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
    79
        ".org.opensolaris,pkg".
19
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    80
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    81
        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
    82
        self.root + "/var/pkg".
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    83
26
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
    84
        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
    85
        system's root Image.
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
    86
29
f621f1df0849 fix install target; correct imports for module renames
"Stephen Hahn <sch@sun.com>"
parents: 26
diff changeset
    87
        Directory layout
f621f1df0849 fix install target; correct imports for module renames
"Stephen Hahn <sch@sun.com>"
parents: 26
diff changeset
    88
f621f1df0849 fix install target; correct imports for module renames
"Stephen Hahn <sch@sun.com>"
parents: 26
diff changeset
    89
          $IROOT/catalog
f621f1df0849 fix install target; correct imports for module renames
"Stephen Hahn <sch@sun.com>"
parents: 26
diff changeset
    90
               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
    91
               the escaped URI of the catalog.
f621f1df0849 fix install target; correct imports for module renames
"Stephen Hahn <sch@sun.com>"
parents: 26
diff changeset
    92
30
f06ad6cb4b3f stop using flavour terminology
Stephen Hahn <sch@sun.com>
parents: 29
diff changeset
    93
          $IROOT/file
f06ad6cb4b3f stop using flavour terminology
Stephen Hahn <sch@sun.com>
parents: 29
diff changeset
    94
               Directory containing file hashes of installed packages.
f06ad6cb4b3f stop using flavour terminology
Stephen Hahn <sch@sun.com>
parents: 29
diff changeset
    95
f06ad6cb4b3f stop using flavour terminology
Stephen Hahn <sch@sun.com>
parents: 29
diff changeset
    96
          $IROOT/pkg
f06ad6cb4b3f stop using flavour terminology
Stephen Hahn <sch@sun.com>
parents: 29
diff changeset
    97
               Directory containing manifests and states of installed packages.
f06ad6cb4b3f stop using flavour terminology
Stephen Hahn <sch@sun.com>
parents: 29
diff changeset
    98
60
6bd5cd83cfb1 Reverse index database and searching support.
Danek Duvall <danek.duvall@sun.com>
parents: 59
diff changeset
    99
          $IROOT/index
6bd5cd83cfb1 Reverse index database and searching support.
Danek Duvall <danek.duvall@sun.com>
parents: 59
diff changeset
   100
               Directory containing reverse-index databases.
6bd5cd83cfb1 Reverse index database and searching support.
Danek Duvall <danek.duvall@sun.com>
parents: 59
diff changeset
   101
104
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   102
          $IROOT/cfg_cache
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   103
               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
   104
418
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
   105
          $IROOT/opaque
104
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   106
               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
   107
418
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
   108
          $IROOT/state/installed
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
   109
               Directory containing symbolic links to
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
   110
               $IROOT/pkg/[stem]/[version] for each installed package.  On
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
   111
               platforms lacking symbolic links, the filename must be processed
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
   112
               such that the correct directory can be opened.
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
   113
397
617be57c5f2b 777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents: 394
diff changeset
   114
        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
   115
        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
   116
        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
   117
617be57c5f2b 777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents: 394
diff changeset
   118
        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
   119
        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
   120
        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
   121
        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
   122
418
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
   123
        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
   124
        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
   125
        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
   126
397
617be57c5f2b 777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents: 394
diff changeset
   127
        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
   128
        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
   129
        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
   130
        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
   131
        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
   132
19
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
   133
        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
   134
        reuse Image contents.
26
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   135
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   136
        XXX Image file format?  Image file manipulation API?"""
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   137
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
   138
        required_subdirs = [ "catalog", "file", "pkg" ]
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
   139
        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
   140
26
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   141
        def __init__(self):
104
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   142
                self.cfg_cache = None
26
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   143
                self.type = None
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   144
                self.root = None
30
f06ad6cb4b3f stop using flavour terminology
Stephen Hahn <sch@sun.com>
parents: 29
diff changeset
   145
                self.imgdir = None
271
ec8a7669bff2 659 package that delivers existing automounter mountpoint fails installation
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 268
diff changeset
   146
                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
   147
                self.index_dir = None
26
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   148
                self.repo_uris = []
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   149
                self.filter_tags = {}
32
c26788b7217c begin client install; sequences are now timestamps; skeleton ELF module
Stephen Hahn <sch@sun.com>
parents: 30
diff changeset
   150
                self.catalogs = {}
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
   151
                self._catalog = {}
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
   152
                self.pkg_states = None
32
c26788b7217c begin client install; sequences are now timestamps; skeleton ELF module
Stephen Hahn <sch@sun.com>
parents: 30
diff changeset
   153
50
bfcb1661f019 basic image and package plans
Stephen Hahn <sch@sun.com>
parents: 45
diff changeset
   154
                self.attrs = {}
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   155
                self.link_actions = None
50
bfcb1661f019 basic image and package plans
Stephen Hahn <sch@sun.com>
parents: 45
diff changeset
   156
bfcb1661f019 basic image and package plans
Stephen Hahn <sch@sun.com>
parents: 45
diff changeset
   157
                self.attrs["Policy-Require-Optional"] = False
bfcb1661f019 basic image and package plans
Stephen Hahn <sch@sun.com>
parents: 45
diff changeset
   158
                self.attrs["Policy-Pursue-Latest"] = True
bfcb1661f019 basic image and package plans
Stephen Hahn <sch@sun.com>
parents: 45
diff changeset
   159
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   160
                self.imageplan = None # valid after evaluation succceds
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
   161
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   162
                # 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
   163
                # frmi.XXX  Needs rewrite using graph follower
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   164
                self.optional_dependencies = {}
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   165
104
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   166
        def find_root(self, d):
397
617be57c5f2b 777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents: 394
diff changeset
   167
617be57c5f2b 777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents: 394
diff changeset
   168
                def check_subdirs(sub_d, prefix):
418
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
   169
                        for n in self.required_subdirs:
397
617be57c5f2b 777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents: 394
diff changeset
   170
                                if not os.path.isdir(
617be57c5f2b 777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents: 394
diff changeset
   171
                                    os.path.join(sub_d, prefix, n)):
617be57c5f2b 777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents: 394
diff changeset
   172
                                        return False
617be57c5f2b 777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents: 394
diff changeset
   173
                        return True
617be57c5f2b 777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents: 394
diff changeset
   174
289
c2e63370fb2b 160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents: 285
diff changeset
   175
                # Ascend from the given directory d to find first
26
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   176
                # encountered image.
289
c2e63370fb2b 160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents: 285
diff changeset
   177
                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
   178
                # 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
   179
                d = os.path.realpath(d)
26
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   180
                while True:
397
617be57c5f2b 777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents: 394
diff changeset
   181
                        if os.path.isdir(os.path.join(d, img_user_prefix)) and \
617be57c5f2b 777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents: 394
diff changeset
   182
                            os.path.isfile(os.path.join(d, img_user_prefix,
617be57c5f2b 777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents: 394
diff changeset
   183
                                "cfg_cache")) and \
617be57c5f2b 777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents: 394
diff changeset
   184
                            check_subdirs(d, img_user_prefix):
26
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   185
                                # XXX Look at image file to determine filter
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   186
                                # tags and repo URIs.
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   187
                                self.type = IMG_USER
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   188
                                self.root = d
271
ec8a7669bff2 659 package that delivers existing automounter mountpoint fails installation
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 268
diff changeset
   189
                                self.img_prefix = img_user_prefix
289
c2e63370fb2b 160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents: 285
diff changeset
   190
                                self.imgdir = os.path.join(d, self.img_prefix)
59
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
   191
                                self.attrs["Build-Release"] = "5.11"
26
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   192
                                return
397
617be57c5f2b 777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents: 394
diff changeset
   193
                        elif os.path.isdir(os.path.join(d, img_root_prefix)) \
617be57c5f2b 777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents: 394
diff changeset
   194
                              and os.path.isfile(os.path.join(d,
617be57c5f2b 777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents: 394
diff changeset
   195
                              img_root_prefix,"cfg_cache")) and \
617be57c5f2b 777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents: 394
diff changeset
   196
                              check_subdirs(d, img_root_prefix):
26
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   197
                                # XXX Look at image file to determine filter
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   198
                                # tags and repo URIs.
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   199
                                # XXX Look at image file to determine if this
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   200
                                # image is a partial image.
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   201
                                self.type = IMG_ENTIRE
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   202
                                self.root = d
271
ec8a7669bff2 659 package that delivers existing automounter mountpoint fails installation
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 268
diff changeset
   203
                                self.img_prefix = img_root_prefix
289
c2e63370fb2b 160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents: 285
diff changeset
   204
                                self.imgdir = os.path.join(d, self.img_prefix)
59
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
   205
                                self.attrs["Build-Release"] = "5.11"
26
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   206
                                return
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   207
289
c2e63370fb2b 160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents: 285
diff changeset
   208
                        # 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
   209
                        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
   210
                        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
   211
289
c2e63370fb2b 160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents: 285
diff changeset
   212
                        # 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
   213
                        # 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
   214
                        #
c2e63370fb2b 160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents: 285
diff changeset
   215
                        # (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
   216
                        if d == oldpath:
c2e63370fb2b 160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents: 285
diff changeset
   217
                                raise ValueError, "directory %s not contained within an image" % startd
26
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   218
104
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   219
        def load_config(self):
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   220
                """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
   221
                location."""
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   222
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   223
                # 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
   224
                # configuration.
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   225
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   226
                if self.root == None:
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   227
                        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
   228
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   229
                ic = imageconfig.ImageConfig()
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   230
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   231
                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
   232
                        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
   233
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   234
                self.cfg_cache = ic
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   235
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   236
        # 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
   237
        # operation.
29
f621f1df0849 fix install target; correct imports for module renames
"Stephen Hahn <sch@sun.com>"
parents: 26
diff changeset
   238
        def mkdirs(self):
397
617be57c5f2b 777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents: 394
diff changeset
   239
                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
   240
                        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
   241
                                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
   242
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   243
        def set_attrs(self, type, root, is_zone, auth_name, auth_url,
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   244
            ssl_key = None, ssl_cert = None):
19
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
   245
                self.type = type
22
379f0f6809ff pkgsend open, pkgsend add file, pkgsend close; Transaction object
"Stephen Hahn <sch@sun.com>"
parents: 19
diff changeset
   246
                self.root = root
379f0f6809ff pkgsend open, pkgsend add file, pkgsend close; Transaction object
"Stephen Hahn <sch@sun.com>"
parents: 19
diff changeset
   247
                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
   248
                        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
   249
                else:
271
ec8a7669bff2 659 package that delivers existing automounter mountpoint fails installation
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 268
diff changeset
   250
                        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
   251
                self.imgdir = os.path.join(self.root, self.img_prefix)
104
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   252
                self.mkdirs()
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   253
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   254
                self.cfg_cache = imageconfig.ImageConfig()
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   255
111
647c91609117 Client-side filtering.
Danek Duvall <danek.duvall@sun.com>
parents: 107
diff changeset
   256
                if is_zone:
647c91609117 Client-side filtering.
Danek Duvall <danek.duvall@sun.com>
parents: 107
diff changeset
   257
                        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
   258
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   259
                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
   260
                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
   261
                self.cfg_cache.authorities[auth_name]["origin"] = \
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   262
                    misc.url_affix_trailing_slash(auth_url)
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   263
                self.cfg_cache.authorities[auth_name]["mirrors"] = []
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   264
                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
   265
                self.cfg_cache.authorities[auth_name]["ssl_cert"] = ssl_cert
104
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   266
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   267
                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
   268
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   269
                self.cfg_cache.write("%s/cfg_cache" % self.imgdir)
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   270
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   271
        def is_liveroot(self):
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   272
                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
   273
344
4c887185d780 528 pkg list -u gives confusing output
Dan Price <dp@eng.sun.com>
parents: 342
diff changeset
   274
        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
   275
                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
   276
                return zone == "nonglobal"
344
4c887185d780 528 pkg list -u gives confusing output
Dan Price <dp@eng.sun.com>
parents: 342
diff changeset
   277
29
f621f1df0849 fix install target; correct imports for module renames
"Stephen Hahn <sch@sun.com>"
parents: 26
diff changeset
   278
        def get_root(self):
f621f1df0849 fix install target; correct imports for module renames
"Stephen Hahn <sch@sun.com>"
parents: 26
diff changeset
   279
                return self.root
f621f1df0849 fix install target; correct imports for module renames
"Stephen Hahn <sch@sun.com>"
parents: 26
diff changeset
   280
104
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   281
        def gen_authorities(self):
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   282
                if not self.cfg_cache:
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   283
                        raise RuntimeError, "empty ImageConfig"
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   284
                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
   285
                        raise RuntimeError, "no defined authorities"
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   286
                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
   287
                        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
   288
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   289
        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
   290
                """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
   291
                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
   292
                preferred authority."""
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   293
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   294
                # 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
   295
                # 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
   296
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   297
                if authority == None:
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   298
                        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
   299
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   300
                try:
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   301
                        o = self.cfg_cache.authorities[authority]["origin"]
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   302
                except KeyError:
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   303
                        # 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
   304
                        # exists, fall back to preferred authority.
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   305
                        authority = self.cfg_cache.preferred_authority
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   306
                        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
   307
146
9b9fcd56b8b2 Reduce use of the re module, for performance.
Danek Duvall <danek.duvall@sun.com>
parents: 145
diff changeset
   308
                return o.rstrip("/")
104
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   309
322
e1b078577730 1101 pkg search -s <server> returns a traceback
Danek Duvall <danek.duvall@sun.com>
parents: 319
diff changeset
   310
        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
   311
                """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
   312
                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
   313
                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
   314
                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
   315
                """
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   316
322
e1b078577730 1101 pkg search -s <server> returns a traceback
Danek Duvall <danek.duvall@sun.com>
parents: 319
diff changeset
   317
                if authority is None:
e1b078577730 1101 pkg search -s <server> returns a traceback
Danek Duvall <danek.duvall@sun.com>
parents: 319
diff changeset
   318
                        if origin is None:
e1b078577730 1101 pkg search -s <server> returns a traceback
Danek Duvall <danek.duvall@sun.com>
parents: 319
diff changeset
   319
                                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
   320
                        else:
e1b078577730 1101 pkg search -s <server> returns a traceback
Danek Duvall <danek.duvall@sun.com>
parents: 319
diff changeset
   321
                                auths = self.cfg_cache.authorities
e1b078577730 1101 pkg search -s <server> returns a traceback
Danek Duvall <danek.duvall@sun.com>
parents: 319
diff changeset
   322
                                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
   323
                                        if auth["origin"] == origin:
e1b078577730 1101 pkg search -s <server> returns a traceback
Danek Duvall <danek.duvall@sun.com>
parents: 319
diff changeset
   324
                                                authority = pfx
e1b078577730 1101 pkg search -s <server> returns a traceback
Danek Duvall <danek.duvall@sun.com>
parents: 319
diff changeset
   325
                                                break
e1b078577730 1101 pkg search -s <server> returns a traceback
Danek Duvall <danek.duvall@sun.com>
parents: 319
diff changeset
   326
                                else:
e1b078577730 1101 pkg search -s <server> returns a traceback
Danek Duvall <danek.duvall@sun.com>
parents: 319
diff changeset
   327
                                        return None
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   328
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   329
                try:
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   330
                        authent = self.cfg_cache.authorities[authority]
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   331
                except KeyError:
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   332
                        authority = self.cfg_cache.preferred_authority
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   333
                        authent = self.cfg_cache.authorities[authority]
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   334
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   335
                return (authent["ssl_key"], authent["ssl_cert"])
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   336
104
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   337
        def get_default_authority(self):
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   338
                return self.cfg_cache.preferred_authority
19
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
   339
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   340
        def has_authority(self, auth_name):
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   341
                return auth_name in self.cfg_cache.authorities
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   342
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   343
        def delete_authority(self, auth_name):
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   344
                if not self.has_authority(auth_name):
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   345
                        raise KeyError, "no such authority '%s'" % auth_name
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   346
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   347
                self.cfg_cache.delete_authority(auth_name)
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   348
                self.cfg_cache.write("%s/cfg_cache" % self.imgdir)
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   349
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   350
        def get_authority(self, auth_name):
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   351
                if not self.has_authority(auth_name):
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   352
                        raise KeyError, "no such authority '%s'" % auth_name
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   353
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   354
                return self.cfg_cache.authorities[auth_name]
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   355
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   356
        def split_authority(self, auth):
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   357
                prefix = auth["prefix"]
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   358
                update_dt = None
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   359
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   360
                try:
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   361
                        cat = self.catalogs[prefix]
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   362
                except KeyError:
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   363
                        cat = None
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   364
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   365
                if cat:
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   366
                        update_dt = cat.last_modified()
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   367
                        if update_dt:
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   368
                                update_dt = catalog.ts_to_datetime(update_dt)
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   369
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   370
                return (prefix, auth["origin"], auth["ssl_key"],
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   371
                    auth["ssl_cert"], update_dt)
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   372
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   373
        def set_preferred_authority(self, auth_name):
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   374
                if not self.has_authority(auth_name):
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   375
                        raise KeyError, "no such authority '%s'" % auth_name
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   376
                self.cfg_cache.preferred_authority = auth_name
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   377
                self.cfg_cache.write("%s/cfg_cache" % self.imgdir)
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   378
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   379
        def set_authority(self, auth_name, origin_url = None, ssl_key = None,
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   380
            ssl_cert = None, mirrors = []):
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   381
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   382
                auths = self.cfg_cache.authorities
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   383
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   384
                if auth_name in auths:
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   385
                        # If authority already exists, only update non-NULL
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   386
                        # values passed to set_authority
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   387
                        if origin_url:
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   388
                                auths[auth_name]["origin"] = \
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   389
                                    misc.url_affix_trailing_slash(origin_url)
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   390
                        if ssl_key:
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   391
                                auths[auth_name]["ssl_key"] = ssl_key
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   392
                        if ssl_cert:
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   393
                                auths[auth_name]["ssl_cert"] = ssl_cert
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   394
                        if mirrors:
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   395
                                auths[auth_name]["mirrors"] = mirrors
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   396
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   397
                else:
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   398
                        auths[auth_name] = {}
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   399
                        auths[auth_name]["prefix"] = auth_name
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   400
                        auths[auth_name]["origin"] = \
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   401
                            misc.url_affix_trailing_slash(origin_url)
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   402
                        auths[auth_name]["mirrors"] = mirrors
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   403
                        auths[auth_name]["ssl_key"] = ssl_key
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   404
                        auths[auth_name]["ssl_cert"] = ssl_cert
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   405
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   406
                self.cfg_cache.write("%s/cfg_cache" % self.imgdir)
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   407
235
61994d15c39b 373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents: 226
diff changeset
   408
        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
   409
                """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
   410
                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
   411
235
61994d15c39b 373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents: 226
diff changeset
   412
                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
   413
                        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
   414
                        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
   415
                        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
   416
                        if errors:
61994d15c39b 373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents: 226
diff changeset
   417
                                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
   418
                                    errors)
61994d15c39b 373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents: 226
diff changeset
   419
                                yield (actname, 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
   420
237
6ece196588cb 348 files that move from pkg to pkg can cause problems during upgrade
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 235
diff changeset
   421
        def gen_installed_actions(self):
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
   422
                """generates actions in installed image """
237
6ece196588cb 348 files that move from pkg to pkg can cause problems during upgrade
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 235
diff changeset
   423
6ece196588cb 348 files that move from pkg to pkg can cause problems during upgrade
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 235
diff changeset
   424
                for fmri in self.gen_installed_pkgs():
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
   425
                        for act in self.get_manifest(fmri, filtered = True).actions:
237
6ece196588cb 348 files that move from pkg to pkg can cause problems during upgrade
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 235
diff changeset
   426
                                yield act
6ece196588cb 348 files that move from pkg to pkg can cause problems during upgrade
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 235
diff changeset
   427
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
   428
        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
   429
                """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
   430
                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
   431
                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
   432
                return [
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
   433
                    (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
   434
                    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
   435
                ]
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
   436
237
6ece196588cb 348 files that move from pkg to pkg can cause problems during upgrade
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 235
diff changeset
   437
        def get_link_actions(self):
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
   438
                """return a dictionary of hardlink action lists indexed by
237
6ece196588cb 348 files that move from pkg to pkg can cause problems during upgrade
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 235
diff changeset
   439
                target """
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   440
                if self.link_actions != None:
237
6ece196588cb 348 files that move from pkg to pkg can cause problems during upgrade
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 235
diff changeset
   441
                        return self.link_actions
6ece196588cb 348 files that move from pkg to pkg can cause problems during upgrade
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 235
diff changeset
   442
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
   443
                d = {}
237
6ece196588cb 348 files that move from pkg to pkg can cause problems during upgrade
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 235
diff changeset
   444
                for act in self.gen_installed_actions():
6ece196588cb 348 files that move from pkg to pkg can cause problems during upgrade
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 235
diff changeset
   445
                        if act.name == "hardlink":
6ece196588cb 348 files that move from pkg to pkg can cause problems during upgrade
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 235
diff changeset
   446
                                t = act.get_target_path()
6ece196588cb 348 files that move from pkg to pkg can cause problems during upgrade
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 235
diff changeset
   447
                                if t in d:
6ece196588cb 348 files that move from pkg to pkg can cause problems during upgrade
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 235
diff changeset
   448
                                        d[t].append(act)
6ece196588cb 348 files that move from pkg to pkg can cause problems during upgrade
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 235
diff changeset
   449
                                else:
6ece196588cb 348 files that move from pkg to pkg can cause problems during upgrade
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 235
diff changeset
   450
                                        d[t] = [act]
6ece196588cb 348 files that move from pkg to pkg can cause problems during upgrade
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 235
diff changeset
   451
                self.link_actions = d
6ece196588cb 348 files that move from pkg to pkg can cause problems during upgrade
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 235
diff changeset
   452
                return d
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
   453
50
bfcb1661f019 basic image and package plans
Stephen Hahn <sch@sun.com>
parents: 45
diff changeset
   454
        def has_manifest(self, fmri):
45
8a3f00dea14f catalog refresh; basic catalog listing; precise manifest pulls
Stephen Hahn <sch@sun.com>
parents: 39
diff changeset
   455
                mpath = fmri.get_dir_path()
8a3f00dea14f catalog refresh; basic catalog listing; precise manifest pulls
Stephen Hahn <sch@sun.com>
parents: 39
diff changeset
   456
8a3f00dea14f catalog refresh; basic catalog listing; precise manifest pulls
Stephen Hahn <sch@sun.com>
parents: 39
diff changeset
   457
                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
   458
8a3f00dea14f catalog refresh; basic catalog listing; precise manifest pulls
Stephen Hahn <sch@sun.com>
parents: 39
diff changeset
   459
                if (os.path.exists(local_mpath)):
50
bfcb1661f019 basic image and package plans
Stephen Hahn <sch@sun.com>
parents: 45
diff changeset
   460
                        return True
bfcb1661f019 basic image and package plans
Stephen Hahn <sch@sun.com>
parents: 45
diff changeset
   461
bfcb1661f019 basic image and package plans
Stephen Hahn <sch@sun.com>
parents: 45
diff changeset
   462
                return False
45
8a3f00dea14f catalog refresh; basic catalog listing; precise manifest pulls
Stephen Hahn <sch@sun.com>
parents: 39
diff changeset
   463
388
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
   464
        def _fetch_manifest_with_retries(self, fmri):
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
   465
                """Wrapper function around _fetch_manifest to handle some
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
   466
                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
   467
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
   468
                m = None
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
   469
                retry_count = misc.MAX_TIMEOUT_COUNT
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
   470
399
e594d9c5bd60 2295 pkg forgets to raise TransferTimedOutException
johansen <johansen@sun.com>
parents: 397
diff changeset
   471
                while not m:
388
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
   472
                        try:
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
   473
                                m = self._fetch_manifest(fmri)
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
   474
                        except TransferTimedOutException:
399
e594d9c5bd60 2295 pkg forgets to raise TransferTimedOutException
johansen <johansen@sun.com>
parents: 397
diff changeset
   475
                                retry_count -= 1
e594d9c5bd60 2295 pkg forgets to raise TransferTimedOutException
johansen <johansen@sun.com>
parents: 397
diff changeset
   476
e594d9c5bd60 2295 pkg forgets to raise TransferTimedOutException
johansen <johansen@sun.com>
parents: 397
diff changeset
   477
                                if retry_count <= 0:
388
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
   478
                                        raise
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
   479
                return m
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
   480
329
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
   481
        def _fetch_manifest(self, fmri):
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   482
                """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
   483
                and write resulting contents to disk.  Helper routine for
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
   484
                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
   485
                that.  """
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   486
50
bfcb1661f019 basic image and package plans
Stephen Hahn <sch@sun.com>
parents: 45
diff changeset
   487
                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
   488
                m.set_fmri(self, fmri)
72
9deed41412b3 Support for proper package upgrade.
Danek Duvall <danek.duvall@sun.com>
parents: 69
diff changeset
   489
144
ce619e0b453f Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents: 139
diff changeset
   490
                fmri_dir_path = os.path.join(self.imgdir, "pkg",
ce619e0b453f Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents: 139
diff changeset
   491
                    fmri.get_dir_path())
ce619e0b453f Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents: 139
diff changeset
   492
                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
   493
315
989c801f050b 1076 action __cmp__, action __str__ and manifest loading could all be faster
Dan Price <dp@eng.sun.com>
parents: 313
diff changeset
   494
                # 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
   495
                # it up into an in-memory manifest, then write the finished
989c801f050b 1076 action __cmp__, action __str__ and manifest loading could all be faster
Dan Price <dp@eng.sun.com>
parents: 313
diff changeset
   496
                # representation to disk.
388
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
   497
                try:
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
   498
                        mcontent = retrieve.get_manifest(self, fmri)
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
   499
                        m.set_content(mcontent)
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
   500
                except socket.timeout:
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
   501
                        raise TransferTimedOutException
144
ce619e0b453f Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents: 139
diff changeset
   502
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   503
                # Write the originating authority into the manifest.
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   504
                # 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
   505
                # 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
   506
                # from the depot.
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   507
                if not fmri.has_authority():
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   508
                        m["authority"] = self.get_default_authority()
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   509
                else:
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   510
                        m["authority"] = fmri.get_authority()
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   511
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
   512
                try:
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
   513
                        m.store(mpath)
347
d3768c3508b2 1397 fix for 1144 incomplete
Danek Duvall <danek.duvall@sun.com>
parents: 344
diff changeset
   514
                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
   515
                        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
   516
                                raise
144
ce619e0b453f Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents: 139
diff changeset
   517
50
bfcb1661f019 basic image and package plans
Stephen Hahn <sch@sun.com>
parents: 45
diff changeset
   518
                return m
45
8a3f00dea14f catalog refresh; basic catalog listing; precise manifest pulls
Stephen Hahn <sch@sun.com>
parents: 39
diff changeset
   519
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   520
        def _valid_manifest(self, fmri, manifest):
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   521
                """Check authority attached to manifest.  Make sure
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   522
                it matches authority specified in FMRI."""
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   523
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   524
                authority = fmri.get_authority()
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   525
                if not authority:
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   526
                        authority = self.get_default_authority()
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   527
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   528
                if not "authority" in manifest:
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   529
                        return False
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   530
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   531
                if manifest["authority"] != authority:
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   532
                        return False
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   533
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   534
                return True
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   535
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
   536
        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
   537
                """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
   538
                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
   539
                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
   540
                    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
   541
                return mpath
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
   542
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   543
        def get_manifest(self, fmri, filtered = False):
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   544
                """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
   545
                object, applying appropriate filters as needed."""
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   546
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   547
                m = manifest.Manifest()
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   548
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   549
                fmri_dir_path = os.path.join(self.imgdir, "pkg",
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   550
                    fmri.get_dir_path())
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   551
                mpath = os.path.join(fmri_dir_path, "manifest")
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   552
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   553
                # If the manifest isn't there, download.
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   554
                if not os.path.exists(mpath):
388
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
   555
                        m = self._fetch_manifest_with_retries(fmri)
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   556
                else:
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   557
                        mcontent = file(mpath).read()
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   558
                        m.set_fmri(self, fmri)
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   559
                        m.set_content(mcontent)
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   560
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   561
                # If the manifest isn't from the correct authority, or
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   562
                # no authority is attached to the manifest, download a new one.
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   563
                if not self._valid_manifest(fmri, m):
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   564
                        try:
388
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
   565
                                m = self._fetch_manifest_with_retries(fmri)
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   566
                        except NameError:
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   567
                                # In thise case, the client has failed to
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   568
                                # download a new manifest with the same name.
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   569
                                # We can either give up or drive on.  It makes
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   570
                                # the most sense to do the best we can with what
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   571
                                # we have.  Keep the old manifest and drive on.
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   572
                                pass
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   573
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
   574
                # 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
   575
                if filtered:
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
   576
                        filters = []
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
   577
                        try:
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
   578
                                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
   579
                        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
   580
                                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
   581
                                        raise
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
   582
                        else:
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
   583
                                filters = [
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
   584
                                    (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
   585
                                        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
   586
                                    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
   587
                                ]
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
   588
                        m.filter(filters)
329
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
   589
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   590
                return m
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   591
331
4f332d6b4036 1266 Client loses track of authority preference, chaos ensues
johansen <johansen@sun.com>
parents: 329
diff changeset
   592
        def installed_file_authority(self, filepath):
195
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   593
                """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
   594
                Return the authority that installed this package."""
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   595
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   596
                read_only = False
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   597
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   598
                try:
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   599
                        f = file(filepath, "r+")
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   600
                except IOError, e:
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   601
                        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
   602
                                read_only = True
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   603
                        else:
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   604
                                raise
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   605
                if read_only:
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   606
                        f = file(filepath, "r")
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   607
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   608
                flines = f.readlines()
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   609
                newauth = None
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   610
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   611
                try:
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   612
                        version, auth = flines
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   613
                except ValueError:
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   614
                        # 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
   615
                        # 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
   616
                        # 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
   617
                        # to assume that the package was installed from
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   618
                        # the preferred authority.  Here, we set up
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   619
                        # the authority to record that.
356
672e0af33ea8 1536 empty installed files generate tracebacks
johansen <johansen@sun.com>
parents: 347
diff changeset
   620
                        if flines:
672e0af33ea8 1536 empty installed files generate tracebacks
johansen <johansen@sun.com>
parents: 347
diff changeset
   621
                                auth = flines[0]
672e0af33ea8 1536 empty installed files generate tracebacks
johansen <johansen@sun.com>
parents: 347
diff changeset
   622
                                auth = auth.strip()
672e0af33ea8 1536 empty installed files generate tracebacks
johansen <johansen@sun.com>
parents: 347
diff changeset
   623
                                newauth = "%s_%s" % (pkg.fmri.PREF_AUTH_PFX,
672e0af33ea8 1536 empty installed files generate tracebacks
johansen <johansen@sun.com>
parents: 347
diff changeset
   624
                                    auth)
672e0af33ea8 1536 empty installed files generate tracebacks
johansen <johansen@sun.com>
parents: 347
diff changeset
   625
                        else:
672e0af33ea8 1536 empty installed files generate tracebacks
johansen <johansen@sun.com>
parents: 347
diff changeset
   626
                                newauth = "%s_%s" % (pkg.fmri.PREF_AUTH_PFX,
672e0af33ea8 1536 empty installed files generate tracebacks
johansen <johansen@sun.com>
parents: 347
diff changeset
   627
                                    self.get_default_authority())
672e0af33ea8 1536 empty installed files generate tracebacks
johansen <johansen@sun.com>
parents: 347
diff changeset
   628
672e0af33ea8 1536 empty installed files generate tracebacks
johansen <johansen@sun.com>
parents: 347
diff changeset
   629
                        # Exception handler is only part of this code that
672e0af33ea8 1536 empty installed files generate tracebacks
johansen <johansen@sun.com>
parents: 347
diff changeset
   630
                        # sets newauth
672e0af33ea8 1536 empty installed files generate tracebacks
johansen <johansen@sun.com>
parents: 347
diff changeset
   631
                        auth = newauth
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   632
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   633
                if newauth and not read_only:
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   634
                        # This is where we actually update the installed
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   635
                        # file with the new authority.
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   636
                        f.seek(0)
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   637
                        f.writelines(["VERSION_1\n", newauth])
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   638
195
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   639
                f.close()
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   640
356
672e0af33ea8 1536 empty installed files generate tracebacks
johansen <johansen@sun.com>
parents: 347
diff changeset
   641
                assert auth
331
4f332d6b4036 1266 Client loses track of authority preference, chaos ensues
johansen <johansen@sun.com>
parents: 329
diff changeset
   642
195
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   643
                return auth
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   644
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
   645
        def _install_file(self, fmri):
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
   646
                """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
   647
                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
   648
195
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   649
        def install_file_present(self, fmri):
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   650
                """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
   651
                on the system.  Otherwise, returns false."""
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   652
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
   653
                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
   654
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   655
        def add_install_file(self, fmri):
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   656
                """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
   657
                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
   658
                installed."""
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   659
418
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
   660
                # 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
   661
                # 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
   662
                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
   663
                        self.update_installed_pkgs()
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
   664
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
   665
                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
   666
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   667
                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
   668
                f.close()
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   669
418
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
   670
                os.symlink("../../pkg/%s/installed" % fmri.get_dir_path(),
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
   671
                    "%s/state/installed/%s" % (self.imgdir, fmri.get_link_path()))
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
   672
                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
   673
                    (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
   674
195
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   675
        def remove_install_file(self, fmri):
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   676
                """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
   677
                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
   678
                installed."""
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   679
418
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
   680
                # 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
   681
                # 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
   682
                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
   683
                        self.update_installed_pkgs()
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
   684
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
   685
                os.unlink(self._install_file(fmri))
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
   686
                try:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
   687
                        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
   688
                            fmri.get_link_path()))
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
   689
                except EnvironmentError, e:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
   690
                        if e.errno != errno.ENOENT:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
   691
                                raise
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
   692
                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
   693
                    (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
   694
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
   695
        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
   696
                """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
   697
                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
   698
                $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
   699
                summary directory form."""
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
   700
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
   701
                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
   702
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
   703
                # 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
   704
                # 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
   705
                # 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
   706
                # 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
   707
                # 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
   708
                try:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
   709
                        os.makedirs(tmpdir)
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
   710
                except OSError, e:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
   711
                        if e.errno != errno.EEXIST or \
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
   712
                            not os.path.isdir(tmpdir):
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
   713
                                raise
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
   714
                        return
418
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
   715
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
   716
                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
   717
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
   718
                for pd, vd in (
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
   719
                    (p, v)
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
   720
                    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
   721
                    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
   722
                    ):
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
   723
                        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
   724
                        if not os.path.exists(path):
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
   725
                                continue
418
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
   726
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
   727
                        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
   728
                        auth = self.installed_file_authority(path)
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
   729
                        f = pkg.fmri.PkgFmri(fmristr, authority = auth)
418
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
   730
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
   731
                        relpath = "../../pkg/%s/installed" % f.get_dir_path()
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
   732
                        os.symlink(relpath, "%s/%s" %
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
   733
                            (tmpdir, f.get_link_path()))
418
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
   734
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
   735
                # 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
   736
                # 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
   737
                try:
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
   738
                        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
   739
                except EnvironmentError, e:
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
   740
                        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
   741
                                raise
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
   742
                        shutil.rmtree(tmpdir)
418
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
   743
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   744
        def _get_version_installed(self, pfmri):
59
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
   745
                pd = pfmri.get_pkg_stem()
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
   746
                pdir = "%s/pkg/%s" % (self.imgdir,
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
   747
                    pfmri.get_dir_path(stemonly = True))
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
   748
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
   749
                try:
195
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   750
                        pkgs_inst = [ (urllib.unquote("%s@%s" % (pd, vd)),
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   751
                            "%s/%s/installed" % (pdir, vd))
59
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
   752
                            for vd in os.listdir(pdir)
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
   753
                            if os.path.exists("%s/%s/installed" % (pdir, vd)) ]
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
   754
                except OSError:
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   755
                        return None
59
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
   756
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
   757
                if len(pkgs_inst) == 0:
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   758
                        return None
59
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
   759
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
   760
                assert len(pkgs_inst) <= 1
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
   761
195
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   762
                auth = self.installed_file_authority(pkgs_inst[0][1])
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   763
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   764
                return pkg.fmri.PkgFmri(pkgs_inst[0][0], authority = auth)
59
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
   765
104
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   766
        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
   767
                """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
   768
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
   769
                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
   770
                    (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
   771
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
   772
        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
   773
                """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
   774
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
   775
                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
   776
                    (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
   777
                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
   778
                        # 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
   779
                        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
   780
                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
   781
195
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   782
        def fmri_set_default_authority(self, fmri):
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   783
                """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
   784
                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
   785
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   786
                if fmri.has_authority():
195
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   787
                        return
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   788
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   789
                fmri.set_authority(self.get_default_authority(), True)
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   790
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   791
        def get_catalog(self, fmri, exception = False):
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   792
                """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
   793
                correct catalog for this image."""
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   794
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   795
                # 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
   796
                # then return the catalog for the preferred authority
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   797
                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
   798
                        cat = self.catalogs[self.get_default_authority()]
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   799
                else:
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   800
                        try:
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   801
                                cat = self.catalogs[fmri.get_authority()]
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   802
                        except KeyError:
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   803
                                # If the authority that installed this package
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   804
                                # has vanished, pick the default authority
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   805
                                # instead.
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   806
                                if exception:
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   807
                                        raise
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   808
                                else:
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   809
                                        cat = self.catalogs[\
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   810
                                            self.get_default_authority()]
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   811
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   812
                return cat
195
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   813
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
   814
        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
   815
                """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
   816
                installed in the current image."""
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   817
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   818
                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
   819
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   820
                if v and not fmri.has_authority():
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   821
                        fmri.set_authority(v.get_authority_str())
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   822
                elif not fmri.has_authority():
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   823
                        fmri.set_authority(self.get_default_authority(), True)
266
5e5bff6fedce 582 Importing packages seemingly misrecords dependencies
johansen <johansen@sun.com>
parents: 260
diff changeset
   824
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   825
                if v and self.fmri_is_successor(v, fmri):
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   826
                        return True
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   827
                else:
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   828
                        try:
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   829
                                cat = self.get_catalog(fmri, exception = True)
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   830
                        except KeyError:
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   831
                                return False
59
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
   832
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   833
                        # 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
   834
                        # packages that are equivalent to fmri.
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   835
                        rpkgs = cat.rename_newer_pkgs(fmri)
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   836
                        for f in rpkgs:
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   837
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   838
                                v = self._get_version_installed(f)
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   839
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   840
                                if v and self.fmri_is_successor(v, fmri):
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   841
                                        return True
59
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
   842
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
   843
                return False
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
   844
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   845
        def older_version_installed(self, fmri):
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   846
                """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
   847
                older version of the package is installed.  This takes
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   848
                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
   849
                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
   850
                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
   851
                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
   852
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   853
                v = self._get_version_installed(fmri)
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   854
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   855
                assert fmri.has_authority()
268
3d53da66d4a4 582 Importing packages seemingly misrecords dependencies
johansen <johansen@sun.com>
parents: 266
diff changeset
   856
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   857
                if v:
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   858
                        return v
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   859
                else:
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   860
                        cat = self.get_catalog(fmri)
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   861
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   862
                        rpkgs = cat.rename_older_pkgs(fmri)
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   863
                        for f in rpkgs:
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   864
                                v = self._get_version_installed(f)
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   865
                                if v and self.fmri_is_successor(fmri, v):
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   866
                                        return v
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   867
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   868
                return None
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   869
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
   870
        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
   871
                """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
   872
                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
   873
195
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   874
                # 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
   875
                assert fmri.has_authority()
195
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   876
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   877
                v = self._get_version_installed(fmri)
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   878
                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
   879
                        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
   880
a1e20e9a9845 add CLI test suite, correct bugs found by test suite, ration out CLI options
Stephen Hahn <sch@Sun.COM>
parents: 116
diff changeset
   881
                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
   882
67
62c897652bbc Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents: 63
diff changeset
   883
        def get_dependents(self, pfmri):
104
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   884
                """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
   885
                FMRI."""
67
62c897652bbc Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents: 63
diff changeset
   886
62c897652bbc Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents: 63
diff changeset
   887
                thedir = os.path.join(self.imgdir, "index", "depend",
62c897652bbc Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents: 63
diff changeset
   888
                    urllib.quote(str(pfmri.get_pkg_stem())[5:], ""))
62c897652bbc Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents: 63
diff changeset
   889
62c897652bbc Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents: 63
diff changeset
   890
                if not os.path.isdir(thedir):
62c897652bbc Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents: 63
diff changeset
   891
                        return []
62c897652bbc Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents: 63
diff changeset
   892
62c897652bbc Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents: 63
diff changeset
   893
                for v in os.listdir(thedir):
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   894
                        f = pkg.fmri.PkgFmri(pfmri.get_pkg_stem() + "@" + v,
67
62c897652bbc Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents: 63
diff changeset
   895
                            self.attrs["Build-Release"])
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   896
                        if self.fmri_is_successor(pfmri, f):
67
62c897652bbc Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents: 63
diff changeset
   897
                                dependents = [
62c897652bbc Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents: 63
diff changeset
   898
                                    urllib.unquote(d)
62c897652bbc Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents: 63
diff changeset
   899
                                    for d in os.listdir(os.path.join(thedir, v))
139
1861fdf62519 on uninstall, don't complain about uninstalled dependents
Danek Duvall <danek.duvall@sun.com>
parents: 135
diff changeset
   900
                                    if os.path.exists(
1861fdf62519 on uninstall, don't complain about uninstalled dependents
Danek Duvall <danek.duvall@sun.com>
parents: 135
diff changeset
   901
                                        os.path.join(thedir, v, d, "installed"))
67
62c897652bbc Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents: 63
diff changeset
   902
                                ]
62c897652bbc Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents: 63
diff changeset
   903
62c897652bbc Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents: 63
diff changeset
   904
                return dependents
62c897652bbc Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents: 63
diff changeset
   905
215
c10719939c6d 245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents: 208
diff changeset
   906
        def retrieve_catalogs(self, full_refresh = False):
201
63e78f600aa7 185 traceback on pkg refresh when hostname lookup fails
Danek Duvall <danek.duvall@sun.com>
parents: 195
diff changeset
   907
                failed = []
63e78f600aa7 185 traceback on pkg refresh when hostname lookup fails
Danek Duvall <danek.duvall@sun.com>
parents: 195
diff changeset
   908
                total = 0
63e78f600aa7 185 traceback on pkg refresh when hostname lookup fails
Danek Duvall <danek.duvall@sun.com>
parents: 195
diff changeset
   909
                succeeded = 0
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   910
                cat = None
215
c10719939c6d 245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents: 208
diff changeset
   911
                ts = 0
201
63e78f600aa7 185 traceback on pkg refresh when hostname lookup fails
Danek Duvall <danek.duvall@sun.com>
parents: 195
diff changeset
   912
116
9c9942a52984 (image flag day) remove pkg catalog, improve pkg status, localize pkg(1), use
Stephen Hahn <sch@Sun.COM>
parents: 111
diff changeset
   913
                for auth in self.gen_authorities():
201
63e78f600aa7 185 traceback on pkg refresh when hostname lookup fails
Danek Duvall <danek.duvall@sun.com>
parents: 195
diff changeset
   914
                        total += 1
215
c10719939c6d 245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents: 208
diff changeset
   915
c10719939c6d 245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents: 208
diff changeset
   916
                        if auth["prefix"] in self.catalogs:
c10719939c6d 245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents: 208
diff changeset
   917
                                cat = self.catalogs[auth["prefix"]]
c10719939c6d 245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents: 208
diff changeset
   918
                                ts = cat.last_modified()
c10719939c6d 245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents: 208
diff changeset
   919
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   920
                                # Although we may have a catalog with a
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   921
                                # timestamp, the user may have changed the
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   922
                                # origin URL for the authority.  If this has
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   923
                                # occurred, we need to perform a full refresh.
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   924
                                if cat.origin() != auth["origin"]:
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   925
                                        full_refresh = True
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   926
215
c10719939c6d 245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents: 208
diff changeset
   927
                        if ts and not full_refresh:
c10719939c6d 245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents: 208
diff changeset
   928
                                hdr = {'If-Modified-Since': ts}
c10719939c6d 245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents: 208
diff changeset
   929
                        else:
c10719939c6d 245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents: 208
diff changeset
   930
                                hdr = {}
c10719939c6d 245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents: 208
diff changeset
   931
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   932
                        ssl_tuple = self.get_ssl_credentials(auth["prefix"])
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   933
116
9c9942a52984 (image flag day) remove pkg catalog, improve pkg status, localize pkg(1), use
Stephen Hahn <sch@Sun.COM>
parents: 111
diff changeset
   934
                        # 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
   935
                        try:
201
63e78f600aa7 185 traceback on pkg refresh when hostname lookup fails
Danek Duvall <danek.duvall@sun.com>
parents: 195
diff changeset
   936
                                c, v = versioned_urlopen(auth["origin"],
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   937
                                    "catalog", [0], ssl_creds = ssl_tuple,
319
39b8b5c538bf 1104 want custom user-agent string
Danek Duvall <danek.duvall@sun.com>
parents: 316
diff changeset
   938
                                    headers = hdr, imgtype = self.type)
215
c10719939c6d 245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents: 208
diff changeset
   939
                        except urllib2.HTTPError, e:
260
a1b77322abb2 255 Symbolic HTTP response codes should be used
Shawn Walker <swalker@opensolaris.org>
parents: 259
diff changeset
   940
                                # 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
   941
                                # to date
a1b77322abb2 255 Symbolic HTTP response codes should be used
Shawn Walker <swalker@opensolaris.org>
parents: 259
diff changeset
   942
                                if e.code == httplib.NOT_MODIFIED:
215
c10719939c6d 245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents: 208
diff changeset
   943
                                        succeeded += 1
c10719939c6d 245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents: 208
diff changeset
   944
                                else:
c10719939c6d 245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents: 208
diff changeset
   945
                                        failed.append((auth, e))
c10719939c6d 245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents: 208
diff changeset
   946
                                continue
c10719939c6d 245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents: 208
diff changeset
   947
201
63e78f600aa7 185 traceback on pkg refresh when hostname lookup fails
Danek Duvall <danek.duvall@sun.com>
parents: 195
diff changeset
   948
                        except urllib2.URLError, e:
63e78f600aa7 185 traceback on pkg refresh when hostname lookup fails
Danek Duvall <danek.duvall@sun.com>
parents: 195
diff changeset
   949
                                failed.append((auth, e))
63e78f600aa7 185 traceback on pkg refresh when hostname lookup fails
Danek Duvall <danek.duvall@sun.com>
parents: 195
diff changeset
   950
                                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
   951
                        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
   952
                                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
   953
                                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
   954
157
504b9e6d213c Catalog should be on-disk instead of in memory
johansen <johansen@sun.com>
parents: 146
diff changeset
   955
                        # root for this catalog
504b9e6d213c Catalog should be on-disk instead of in memory
johansen <johansen@sun.com>
parents: 146
diff changeset
   956
                        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
   957
201
63e78f600aa7 185 traceback on pkg refresh when hostname lookup fails
Danek Duvall <danek.duvall@sun.com>
parents: 195
diff changeset
   958
                        try:
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   959
                                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
   960
                        except IOError, e:
63e78f600aa7 185 traceback on pkg refresh when hostname lookup fails
Danek Duvall <danek.duvall@sun.com>
parents: 195
diff changeset
   961
                                failed.append((auth, e))
388
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
   962
                        except socket.timeout, e:
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
   963
                                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
   964
                        else:
63e78f600aa7 185 traceback on pkg refresh when hostname lookup fails
Danek Duvall <danek.duvall@sun.com>
parents: 195
diff changeset
   965
                                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
   966
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
   967
                self.cache_catalogs()
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
   968
201
63e78f600aa7 185 traceback on pkg refresh when hostname lookup fails
Danek Duvall <danek.duvall@sun.com>
parents: 195
diff changeset
   969
                if failed:
63e78f600aa7 185 traceback on pkg refresh when hostname lookup fails
Danek Duvall <danek.duvall@sun.com>
parents: 195
diff changeset
   970
                        raise RuntimeError, (failed, total, 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
   971
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
   972
        CATALOG_CACHE_VERSION = 1
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
   973
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
   974
        def cache_catalogs(self):
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
   975
                """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
   976
                cache = {}
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
   977
                for auth in self.gen_authorities():
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
   978
                        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
   979
                        # 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
   980
                        # not using it anymore?
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
   981
                        try:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
   982
                                catalog.Catalog.read_catalog(cache,
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
   983
                                    croot, auth = auth["prefix"])
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
   984
                        except EnvironmentError, e:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
   985
                                # 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
   986
                                # 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
   987
                                # knows about it.
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
   988
                                if e.errno == errno.ENOENT:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
   989
                                        pass
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
   990
                                else:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
   991
                                        raise
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
   992
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
   993
                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
   994
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
   995
                try:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
   996
                        pf = file(pickle_file, "wb")
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
   997
                        # Version the dump file
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
   998
                        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
   999
                            protocol = cPickle.HIGHEST_PROTOCOL)
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1000
                        pf.close()
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1001
                except (cPickle.PickleError, EnvironmentError):
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1002
                        try:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1003
                                os.remove(pickle_file)
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1004
                        except EnvironmentError:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1005
                                pass
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1006
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1007
                self._catalog = cache
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1008
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1009
        def load_catalog_cache(self):
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1010
                """Read in the cached catalog data."""
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1011
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1012
                self.__load_pkg_states()
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1013
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1014
                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
  1015
                try:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1016
                        version, self._catalog = cPickle.load(file(cache_file))
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1017
                except (cPickle.PickleError, EnvironmentError):
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1018
                        raise RuntimeError
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1019
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1020
                # 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
  1021
                if version != self.CATALOG_CACHE_VERSION:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1022
                        raise RuntimeError
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1023
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1024
                # 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
  1025
                # 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
  1026
                # them to the user?
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1027
                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
  1028
                        if state != PKG_STATE_INSTALLED:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1029
                                continue
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1030
                        auth, name, vers = f.tuple()
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1031
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1032
                        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
  1033
                            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
  1034
                                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
  1035
                                    f.get_authority())
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1036
235
61994d15c39b 373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents: 226
diff changeset
  1037
        def load_catalogs(self, progresstracker):
157
504b9e6d213c Catalog should be on-disk instead of in memory
johansen <johansen@sun.com>
parents: 146
diff changeset
  1038
                for auth in self.gen_authorities():
504b9e6d213c Catalog should be on-disk instead of in memory
johansen <johansen@sun.com>
parents: 146
diff changeset
  1039
                        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
  1040
                        progresstracker.catalog_start(auth["prefix"])
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1041
                        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
  1042
                                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
  1043
                                    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
  1044
                                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
  1045
                                    authority=authpfx)
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1046
                        else:
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1047
                                c = catalog.Catalog(croot,
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1048
                                    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
  1049
                        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
  1050
                        progresstracker.catalog_done()
59
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
  1051
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1052
                # 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
  1053
                # 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
  1054
                # 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
  1055
                # 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
  1056
                try:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1057
                        self.load_catalog_cache()
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1058
                except RuntimeError:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1059
                        self.cache_catalogs()
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1060
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1061
        def fmri_is_same_pkg(self, cfmri, pfmri):
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1062
                """Determine whether fmri and pfmri share the same package
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1063
                name, even if they're not equivalent versions.  This
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1064
                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
  1065
                the same because of a rename operation."""
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1066
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1067
                # 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
  1068
                # 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
  1069
                # rename.
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1070
                if cfmri.is_same_pkg(pfmri):
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1071
                        return True
329
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
  1072
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
  1073
                # Get the catalog for the correct authority
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
  1074
                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
  1075
                return cat.rename_is_same_pkg(cfmri, pfmri)
329
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
  1076
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1077
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1078
        def fmri_is_successor(self, cfmri, pfmri):
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1079
                """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
  1080
                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
  1081
                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
  1082
                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
  1083
                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
  1084
                routine from the catalog.  Otherwise, this runs the standard
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1085
                fmri.is_successor() code."""
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1086
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1087
                # Get the catalog for the correct authority
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1088
                cat = self.get_catalog(cfmri)
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1089
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1090
                # 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
  1091
                # 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
  1092
                # rename.
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1093
                if cfmri.is_successor(pfmri):
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1094
                        return True
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1095
                else:
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1096
                        return cat.rename_is_successor(cfmri, pfmri)
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1097
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1098
        # 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
  1099
        # 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
  1100
        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
  1101
                """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
  1102
                self.__load_pkg_states()
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1103
                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
  1104
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1105
        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
  1106
                """Build up the package state dictionary.
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
  1107
                
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
  1108
                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
  1109
                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
  1110
                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
  1111
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
  1112
                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
  1113
                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
  1114
                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
  1115
                """
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1116
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1117
                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
  1118
                        return
418
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
  1119
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
  1120
                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
  1121
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1122
                self.pkg_states = {}
418
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
  1123
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1124
                # 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
  1125
                # 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
  1126
                # 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
  1127
                # 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
  1128
                # 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
  1129
                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
  1130
                        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
  1131
                                fmristr = urllib.unquote(pl)
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
  1132
                                path = "%s/%s" % (installed_state_dir, pl)
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
  1133
                                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
  1134
                                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
  1135
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1136
                                self.pkg_states[fmristr] = \
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1137
                                    (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
  1138
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
  1139
                        return
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
  1140
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
  1141
                # 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
  1142
                # 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
  1143
                proot = "%s/pkg" % self.imgdir
195
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
  1144
                for pd in sorted(os.listdir(proot)):
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
  1145
                        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
  1146
                                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
  1147
                                if not os.path.exists(path):
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
  1148
                                        continue
226
8939051a496c 376 image must use default authority when none specified
johansen <johansen@sun.com>
parents: 222
diff changeset
  1149
331
4f332d6b4036 1266 Client loses track of authority preference, chaos ensues
johansen <johansen@sun.com>
parents: 329
diff changeset
  1150
                                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
  1151
                                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
  1152
                                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
  1153
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1154
                                self.pkg_states[fmristr] = \
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1155
                                    (PKG_STATE_INSTALLED, f)
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1156
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1157
        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
  1158
                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
  1159
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1160
        def update_optional_dependency(self, inputfmri):
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1161
                """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
  1162
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1163
                myfmri = inputfmri
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1164
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1165
                if isinstance(myfmri, str):
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1166
                        name = pkg.fmri.extract_pkg_name(myfmri)
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1167
                        myfmri = self.strtofmri(myfmri)
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1168
                else:
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1169
                        name = myfmri.get_name()
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1170
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
  1171
                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
  1172
                        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
  1173
                            matcher = pkg.fmri.exact_name_match).next()[0]
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
  1174
                except RuntimeError:
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
  1175
                        # 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
  1176
                        # 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
  1177
                        # 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
  1178
                        # 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
  1179
                        # 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
  1180
                        # 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
  1181
                        # 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
  1182
                        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
  1183
                        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
  1184
                        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
  1185
                            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
  1186
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1187
                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
  1188
                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
  1189
                        self.optional_dependencies[name] = myfmri
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1190
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1191
        def apply_optional_dependencies(self, myfmri):
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1192
                """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
  1193
                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
  1194
                unversioned fmris are returned upgraded"""
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1195
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1196
                if isinstance(myfmri, str):
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1197
                        name = pkg.fmri.extract_pkg_name(myfmri)
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1198
                        myfmri = self.strtofmri(myfmri)
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1199
                else:
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1200
                        name = myfmri.get_name()
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1201
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1202
                minfmri = self.optional_dependencies.get(name, None)
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1203
                if not minfmri:
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1204
                        return myfmri
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1205
316
d6ba58c63264 1039 circular dependency in packages is detected at install-time
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 315
diff changeset
  1206
                if self.fmri_is_successor(minfmri, myfmri):
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1207
                        return minfmri
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1208
                return myfmri
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1209
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1210
        def load_optional_dependencies(self):
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1211
                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
  1212
                        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
  1213
5e1f4d8429bf 669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents: 341
diff changeset
  1214
                        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
  1215
                                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
  1216
                                if required == False:
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1217
                                        self.update_optional_dependency(min_fmri)
195
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
  1218
289
c2e63370fb2b 160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents: 285
diff changeset
  1219
        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
  1220
                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
  1221
                    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
  1222
339
d8e57580599b 1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  1223
        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
  1224
                # 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
  1225
                try:
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
  1226
                        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
  1227
                            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
  1228
                except KeyError:
d8e57580599b 1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  1229
                        if returnuid:
d8e57580599b 1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  1230
                                return uid
d8e57580599b 1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  1231
                        else:
d8e57580599b 1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  1232
                                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
  1233
289
c2e63370fb2b 160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents: 285
diff changeset
  1234
        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
  1235
                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
  1236
                    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
  1237
339
d8e57580599b 1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  1238
        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
  1239
                try:
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
  1240
                        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
  1241
                            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
  1242
                except KeyError:
d8e57580599b 1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  1243
                        if returngid:
d8e57580599b 1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  1244
                                return gid
d8e57580599b 1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  1245
                        else:
d8e57580599b 1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  1246
                                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
  1247
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1248
        @staticmethod
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1249
        def __multimatch(name, patterns, matcher):
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1250
                """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
  1251
                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
  1252
                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
  1253
                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
  1254
                string."""
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1255
                return [
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1256
                    (i, pat, pat.tuple()[2],
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1257
                        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
  1258
                    for i, pat in enumerate(patterns)
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1259
                    if matcher(name, pat.tuple()[1])
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1260
                ]
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1261
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1262
        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
  1263
            constraint = pkg.version.CONSTRAINT_AUTO):
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1264
                """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
  1265
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1266
                if not matcher:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1267
                        matcher = pkg.fmri.fmri_match
59
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
  1268
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1269
                if not patterns:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1270
                        patterns = []
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1271
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1272
                # 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
  1273
                # 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
  1274
                # messages.
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1275
                opatterns = patterns[:]
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1276
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1277
                for i, pat in enumerate(patterns):
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1278
                        if not isinstance(pat, pkg.fmri.PkgFmri):
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1279
                                if "*" in pat or "?" in pat:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1280
                                        matcher = pkg.fmri.glob_match
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1281
                                patterns[i] = pkg.fmri.PkgFmri(pat, "5.11")
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1282
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1283
                pauth = self.cfg_cache.preferred_authority
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1284
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1285
                # 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
  1286
                # 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
  1287
                # 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
  1288
                # 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
  1289
                # 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
  1290
                matchingpats = set()
59
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
  1291
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1292
                # 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
  1293
                # memory?
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1294
                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
  1295
                        # 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
  1296
                        # 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
  1297
                        # 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
  1298
                        matches = self.__multimatch(name, patterns, matcher)
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1299
                        if patterns and not matches:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1300
                                continue
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1301
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1302
                        newest = self._catalog[name]["versions"][-1]
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1303
                        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
  1304
                                # 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
  1305
                                # 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
  1306
                                # the pattern for removal from consideration.
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1307
                                nomatch = []
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1308
                                for i, match in enumerate(matches):
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1309
                                        if match[2] and \
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1310
                                            not ver.is_successor(match[2],
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1311
                                                constraint):
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1312
                                                nomatch.append(i)
221
e1dbb27a23b5 52 catalog can leave inventory behind, making pkg(1) blind
Stephen Hahn <sch@Sun.COM>
parents: 219
diff changeset
  1313
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1314
                                # 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
  1315
                                # 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
  1316
                                # 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
  1317
                                # "matches" for each new version.
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1318
                                vmatches = [
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1319
                                    matches[i]
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1320
                                    for i, match in enumerate(matches)
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1321
                                    if i not in nomatch
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1322
                                ]
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1323
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1324
                                # 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
  1325
                                # 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
  1326
                                if matches and not vmatches:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1327
                                        continue
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1328
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1329
                                # 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
  1330
                                # for authorities.
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1331
                                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
  1332
                                nomatch = []
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1333
                                for i, match in enumerate(vmatches):
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1334
                                        if match[3] and \
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1335
                                            match[3] not in authlist:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1336
                                                nomatch.append(i)
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1337
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1338
                                amatches = [
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1339
                                    vmatches[i]
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1340
                                    for i, match in enumerate(vmatches)
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1341
                                    if i not in nomatch
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1342
                                ]
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1343
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1344
                                if vmatches and not amatches:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1345
                                        continue
104
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
  1346
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1347
                                # 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
  1348
                                # matching pattern specified no authority, we
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1349
                                # 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
  1350
                                # 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
  1351
                                # and the auths in the patterns.
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1352
                                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
  1353
                                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
  1354
                                        authlist = set(
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1355
                                            m[3:5]
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1356
                                            for m in amatches
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1357
                                            if m[3] in authlist
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1358
                                        )
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1359
                                else:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1360
                                        authlist = zip(authlist, authlist)
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1361
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1362
                                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
  1363
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1364
                                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
  1365
                                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
  1366
                                state = {
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1367
                                    "upgradable": ver != newest,
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1368
                                    "frozen": False,
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1369
                                    "incorporated": False,
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1370
                                    "excludes": False
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1371
                                }
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1372
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1373
                                # 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
  1374
                                # 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
  1375
                                # 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
  1376
                                # 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
  1377
                                # 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
  1378
                                # too.
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1379
                                yielded = False
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1380
                                if all_known:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1381
                                        for auth, rauth in authlist:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1382
                                                nfmri = pfmri.copy()
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1383
                                                nfmri.set_authority(rauth,
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1384
                                                    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
  1385
                                                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
  1386
                                                        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
  1387
                                                            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
  1388
                                                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
  1389
                                                        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
  1390
                                                            PKG_STATE_KNOWN
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1391
                                                yield nfmri, state
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1392
                                                yielded = True
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1393
                                elif inst_state == PKG_STATE_INSTALLED:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1394
                                        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
  1395
                                        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
  1396
                                            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
  1397
                                        state["state"] = inst_state
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1398
                                        yield nfmri, state
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1399
                                        yielded = True
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1400
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1401
                                if yielded:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1402
                                        matchingpats |= set(i[:2] for i in amatches)
329
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
  1403
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1404
                nonmatchingpats = [
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1405
                    opatterns[i]
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1406
                    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
  1407
                ]
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1408
                if nonmatchingpats:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1409
                        raise RuntimeError, nonmatchingpats
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1410
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1411
        def inventory(self, *args, **kwargs):
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1412
                """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
  1413
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1414
                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
  1415
                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
  1416
                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
  1417
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1418
                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
  1419
                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
  1420
                enumerated.
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1421
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1422
                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
  1423
                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
  1424
                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
  1425
                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
  1426
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1427
                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
  1428
                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
  1429
                "subsetting" constraint is used."""
161
e0322fe7842c Simplify and correct the package matching code.
Danek Duvall <danek.duvall@sun.com>
parents: 157
diff changeset
  1430
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1431
                # "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
  1432
                # 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
  1433
                # 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
  1434
                # 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
  1435
                # 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
  1436
                # 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
  1437
                # 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
  1438
                # 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
  1439
                preferred = kwargs.pop("preferred", False)
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1440
                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
  1441
                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
  1442
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1443
                if not preferred:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1444
                        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
  1445
                                yield f
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1446
                else:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1447
                        nplist = []
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1448
                        firstnp = None
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1449
                        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
  1450
                                if f[0].get_authority() == pauth:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1451
                                        yield f
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1452
                                        if first_only:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1453
                                                return
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1454
                                else:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1455
                                        if first_only:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1456
                                                if not firstnp:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1457
                                                        firstnp = f
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1458
                                        else:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1459
                                                nplist.append(f)
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1460
                        if first_only:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1461
                                yield firstnp
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1462
                                return
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1463
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1464
                        for f in nplist:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1465
                                yield f
59
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
  1466
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
  1467
        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
  1468
                """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
  1469
                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
  1470
                index directory.
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
  1471
                """
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
  1472
                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
  1473
204
8f650d596aec 72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents: 201
diff changeset
  1474
        def local_search(self, args):
144
ce619e0b453f Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents: 139
diff changeset
  1475
                """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
  1476
                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
  1477
                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
  1478
                qe = query_e.ClientQueryEngine(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
  1479
                query = query_e.Query(args[0])
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
  1480
                return qe.search(query)
144
ce619e0b453f Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents: 139
diff changeset
  1481
204
8f650d596aec 72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents: 201
diff changeset
  1482
        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
  1483
                """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
  1484
                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
  1485
                failed = []
8f650d596aec 72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents: 201
diff changeset
  1486
8f650d596aec 72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents: 201
diff changeset
  1487
                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
  1488
                        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
  1489
8f650d596aec 72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents: 201
diff changeset
  1490
                for auth in servers:
322
e1b078577730 1101 pkg search -s <server> returns a traceback
Danek Duvall <danek.duvall@sun.com>
parents: 319
diff changeset
  1491
                        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
  1492
                            authority = auth.get("prefix", None),
e1b078577730 1101 pkg search -s <server> returns a traceback
Danek Duvall <danek.duvall@sun.com>
parents: 319
diff changeset
  1493
                            origin = auth["origin"])
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
  1494
204
8f650d596aec 72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents: 201
diff changeset
  1495
                        try:
8f650d596aec 72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents: 201
diff changeset
  1496
                                res, v = versioned_urlopen(auth["origin"],
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
  1497
                                    "search", [0], urllib.quote(args[0], ""),
319
39b8b5c538bf 1104 want custom user-agent string
Danek Duvall <danek.duvall@sun.com>
parents: 316
diff changeset
  1498
                                     ssl_creds = ssl_tuple, imgtype = self.type)
204
8f650d596aec 72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents: 201
diff changeset
  1499
                        except urllib2.HTTPError, e:
260
a1b77322abb2 255 Symbolic HTTP response codes should be used
Shawn Walker <swalker@opensolaris.org>
parents: 259
diff changeset
  1500
                                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
  1501
                                        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
  1502
                                continue
8f650d596aec 72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents: 201
diff changeset
  1503
                        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
  1504
                                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
  1505
                                continue
8f650d596aec 72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents: 201
diff changeset
  1506
388
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  1507
                        try:
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  1508
                                for l in res.read().splitlines():
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  1509
                                        fields = l.split()
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  1510
                                        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
  1511
                                                yield fields[:2] + [ "", "" ]
388
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  1512
                                        else:
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
  1513
                                                yield fields[:4]
388
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  1514
                        except socket.timeout, e:
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  1515
                                failed.append((auth, e))
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  1516
                                continue
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  1517
204
8f650d596aec 72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents: 201
diff changeset
  1518
                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
  1519
                        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
  1520
388
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  1521
        def incoming_download_dir(self):
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  1522
                """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
  1523
                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
  1524
                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
  1525
                directory."""
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  1526
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  1527
                return os.path.normpath(os.path.join(self.imgdir, "download",
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  1528
                    "incoming-%d" % os.getpid()))
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  1529
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  1530
        def cached_download_dir(self):
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  1531
                """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
  1532
                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
  1533
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  1534
                return os.path.normpath(os.path.join(self.imgdir, "download"))
251
6c3d70b74865 470 pkg image-update can fail under some conditions
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 243
diff changeset
  1535
6c3d70b74865 470 pkg image-update can fail under some conditions
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 243
diff changeset
  1536
        def cleanup_downloads(self):
388
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  1537
                """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
  1538
                did not successfully finish."""
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  1539
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  1540
                shutil.rmtree(self.incoming_download_dir(), True)
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  1541
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  1542
        def cleanup_cached_content(self):
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  1543
                """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
  1544
                downloaded content.  This may take a while for a large
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  1545
                directory hierarchy."""
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  1546
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  1547
                if self.cfg_cache.flush_content_cache:
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  1548
                        msg("Deleting content cache")
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  1549
                        shutil.rmtree(self.cached_download_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
  1550
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1551
        def salvagedir(self, path):
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1552
                """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
  1553
                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
  1554
                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
  1555
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1556
                salvagedir = os.path.normpath(
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1557
                    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
  1558
                    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
  1559
405
16824ed83efe 2209 license install failure on Windows if license file already exists
Tom Mueller <Tom.Mueller@sun.com>
parents: 399
diff changeset
  1560
                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
  1561
                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
  1562
                        os.makedirs(parent)
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1563
                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
  1564
                # 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
  1565
                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
  1566
                        "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
  1567
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1568
        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
  1569
                """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
  1570
                all components"""
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1571
                out = set()
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1572
                for d in dirs:
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1573
                        p = d
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1574
                        while p != "":
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1575
                                out.add(p)
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1576
                                p = os.path.dirname(p)
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1577
                return out
329
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
  1578
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
  1579
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
  1580
        def make_install_plan(self, pkg_list, progress, filters = [],
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1581
            verbose = False, noexecute = False):
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1582
                """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
  1583
                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
  1584
                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
  1585
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1586
                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
  1587
                however, it defaults to choosing the preferred authority
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1588
                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
  1589
                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
  1590
                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
  1591
                to name the package."""
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1592
172
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  1593
                error = 0
235
61994d15c39b 373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents: 226
diff changeset
  1594
                ip = imageplan.ImagePlan(self, progress, filters = filters)
172
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  1595
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1596
                self.load_optional_dependencies()
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1597
172
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  1598
                for p in pkg_list:
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  1599
                        try:
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1600
                                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
  1601
                                matches = list(self.inventory([ conp ],
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1602
                                    all_known = True))
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1603
                        except RuntimeError:
172
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  1604
                                # XXX Module directly printing.
384
9d4746e5dd3e 115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents: 383
diff changeset
  1605
                                msg(_("""\
172
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  1606
pkg: no package matching '%s' could be found in current catalog
384
9d4746e5dd3e 115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents: 383
diff changeset
  1607
     suggest relaxing pattern, refreshing and/or examining catalogs""") % p)
172
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  1608
                                error = 1
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  1609
                                continue
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  1610
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  1611
                        pnames = {}
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1612
                        pmatch = []
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1613
                        npnames = {}
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1614
                        npmatch = []
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1615
                        for m, state in matches:
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1616
                                if m.preferred_authority():
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1617
                                        pnames[m.get_pkg_stem()] = 1
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1618
                                        pmatch.append(m)
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1619
                                else:
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1620
                                        npnames[m.get_pkg_stem()] = 1
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1621
                                        npmatch.append(m)
172
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  1622
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  1623
                        if len(pnames.keys()) > 1:
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  1624
                                # XXX Module directly printing.
384
9d4746e5dd3e 115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents: 383
diff changeset
  1625
                                msg(_("pkg: '%s' matches multiple packages") % \
9d4746e5dd3e 115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents: 383
diff changeset
  1626
                                    p)
172
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  1627
                                for k in pnames.keys():
384
9d4746e5dd3e 115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents: 383
diff changeset
  1628
                                        msg("\t%s" % k)
172
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  1629
                                error = 1
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  1630
                                continue
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1631
                        elif len(pnames.keys()) < 1 and len(npnames.keys()) > 1:
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1632
                                # XXX Module directly printing.
384
9d4746e5dd3e 115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents: 383
diff changeset
  1633
                                msg(_("pkg: '%s' matches multiple packages") % \
9d4746e5dd3e 115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents: 383
diff changeset
  1634
                                    p)
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1635
                                for k in npnames.keys():
384
9d4746e5dd3e 115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents: 383
diff changeset
  1636
                                        msg("\t%s" % k)
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1637
                                error = 1
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1638
                                continue
172
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  1639
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  1640
                        # 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
  1641
                        # the first; i.e., the latest.
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1642
                        if len(pmatch) > 0:
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1643
                                ip.propose_fmri(pmatch[0])
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1644
                        else:
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
  1645
                                ip.propose_fmri(npmatch[0])
172
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  1646
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  1647
                if error != 0:
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  1648
                        raise RuntimeError, "Unable to assemble image plan"
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  1649
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  1650
                if verbose:
384
9d4746e5dd3e 115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents: 383
diff changeset
  1651
                        msg(_("Before evaluation:"))
9d4746e5dd3e 115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents: 383
diff changeset
  1652
                        msg(ip)
172
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  1653
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  1654
                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
  1655
                self.imageplan = ip
172
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  1656
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  1657
                if verbose:
384
9d4746e5dd3e 115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents: 383
diff changeset
  1658
                        msg(_("After evaluation:"))
9d4746e5dd3e 115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents: 383
diff changeset
  1659
                        msg(ip.display())
45
8a3f00dea14f catalog refresh; basic catalog listing; precise manifest pulls
Stephen Hahn <sch@sun.com>
parents: 39
diff changeset
  1660
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
  1661
        def rebuild_search_index(self, progtracker):
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
  1662
                """Rebuilds the search indexes.  Removes all 
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
  1663
                existing indexes and replaces them from scratch rather than 
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
  1664
                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
  1665
                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
  1666
                if not os.path.isdir(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
  1667
                        img.mkdirs()
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
  1668
                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
  1669
                    CLIENT_DEFAULT_MEM_USE_KB, progtracker)
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
  1670
                ind.check_index(self.get_fmri_manifest_pairs(),
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
  1671
                    force_rebuild = True)
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
  1672
50
bfcb1661f019 basic image and package plans
Stephen Hahn <sch@sun.com>
parents: 45
diff changeset
  1673
if __name__ == "__main__":
bfcb1661f019 basic image and package plans
Stephen Hahn <sch@sun.com>
parents: 45
diff changeset
  1674
        pass