src/modules/client/image.py
author Bart Smaalders <Bart.Smaalders@Sun.COM>
Thu, 17 Apr 2008 17:04:00 -0700
changeset 340 5367cc80f90d
parent 339 d8e57580599b
child 341 42383445191b
permissions -rw-r--r--
1287 pkg install needs to be told where to find non-default pkgs 1288 studio package depends on non-redistributable pkg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
19
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
     1
#!/usr/bin/python
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
45
8a3f00dea14f catalog refresh; basic catalog listing; precise manifest pulls
Stephen Hahn <sch@sun.com>
parents: 39
diff changeset
    29
import urllib
201
63e78f600aa7 185 traceback on pkg refresh when hostname lookup fails
Danek Duvall <danek.duvall@sun.com>
parents: 195
diff changeset
    30
import urllib2
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
    31
import httplib
251
6c3d70b74865 470 pkg image-update can fail under some conditions
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 243
diff changeset
    32
import shutil
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
    33
import sys
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
    34
import time
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
    35
import types
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
    36
 
104
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
    37
# 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
    38
8b9613402116 refactor catalog and package to be common; improve bump-server
Stephen Hahn <sch@sun.com>
parents: 33
diff changeset
    39
import pkg.catalog as catalog
215
c10719939c6d 245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents: 208
diff changeset
    40
import pkg.updatelog as updatelog
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
    41
import pkg.fmri
50
bfcb1661f019 basic image and package plans
Stephen Hahn <sch@sun.com>
parents: 45
diff changeset
    42
import pkg.manifest as manifest
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
    43
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
    44
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
    45
import pkg.client.imageconfig as imageconfig
172
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
    46
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
    47
import pkg.client.retrieve as retrieve
251
6c3d70b74865 470 pkg image-update can fail under some conditions
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 243
diff changeset
    48
import pkg.client.filelist as filelist
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
104
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
    50
145
08bee7fd13f6 Add versioning to the protocols
Danek Duvall <danek.duvall@sun.com>
parents: 144
diff changeset
    51
from pkg.misc import versioned_urlopen
319
39b8b5c538bf 1104 want custom user-agent string
Danek Duvall <danek.duvall@sun.com>
parents: 316
diff changeset
    52
from pkg.client.imagetypes import *
19
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    53
26
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
    54
img_user_prefix = ".org.opensolaris,pkg"
30
f06ad6cb4b3f stop using flavour terminology
Stephen Hahn <sch@sun.com>
parents: 29
diff changeset
    55
img_root_prefix = "var/pkg"
26
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
    56
19
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    57
class Image(object):
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    58
        """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
    59
        of a self-consistent graph of Packages.
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    60
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    61
        An Image has a root path.
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    62
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    63
        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
    64
        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
    65
        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
    66
        Image (IMG_PARTIAL for zones, for instance).
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
        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
    69
        partial Image must be an entire Image.
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    70
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    71
        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
    72
        ".org.opensolaris,pkg".
19
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    73
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    74
        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
    75
        self.root + "/var/pkg".
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    76
26
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
    77
        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
    78
        system's root Image.
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
    79
29
f621f1df0849 fix install target; correct imports for module renames
"Stephen Hahn <sch@sun.com>"
parents: 26
diff changeset
    80
        Directory layout
f621f1df0849 fix install target; correct imports for module renames
"Stephen Hahn <sch@sun.com>"
parents: 26
diff changeset
    81
f621f1df0849 fix install target; correct imports for module renames
"Stephen Hahn <sch@sun.com>"
parents: 26
diff changeset
    82
          $IROOT/catalog
f621f1df0849 fix install target; correct imports for module renames
"Stephen Hahn <sch@sun.com>"
parents: 26
diff changeset
    83
               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
    84
               the escaped URI of the catalog.
f621f1df0849 fix install target; correct imports for module renames
"Stephen Hahn <sch@sun.com>"
parents: 26
diff changeset
    85
30
f06ad6cb4b3f stop using flavour terminology
Stephen Hahn <sch@sun.com>
parents: 29
diff changeset
    86
          $IROOT/file
f06ad6cb4b3f stop using flavour terminology
Stephen Hahn <sch@sun.com>
parents: 29
diff changeset
    87
               Directory containing file hashes of installed packages.
f06ad6cb4b3f stop using flavour terminology
Stephen Hahn <sch@sun.com>
parents: 29
diff changeset
    88
f06ad6cb4b3f stop using flavour terminology
Stephen Hahn <sch@sun.com>
parents: 29
diff changeset
    89
          $IROOT/pkg
f06ad6cb4b3f stop using flavour terminology
Stephen Hahn <sch@sun.com>
parents: 29
diff changeset
    90
               Directory containing manifests and states of installed packages.
f06ad6cb4b3f stop using flavour terminology
Stephen Hahn <sch@sun.com>
parents: 29
diff changeset
    91
60
6bd5cd83cfb1 Reverse index database and searching support.
Danek Duvall <danek.duvall@sun.com>
parents: 59
diff changeset
    92
          $IROOT/index
6bd5cd83cfb1 Reverse index database and searching support.
Danek Duvall <danek.duvall@sun.com>
parents: 59
diff changeset
    93
               Directory containing reverse-index databases.
6bd5cd83cfb1 Reverse index database and searching support.
Danek Duvall <danek.duvall@sun.com>
parents: 59
diff changeset
    94
104
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
    95
          $IROOT/cfg_cache
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
    96
               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
    97
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
    98
          $IROOT/state
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
    99
               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
   100
19
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
   101
        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
   102
        reuse Image contents.
26
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   103
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   104
        XXX Image file format?  Image file manipulation API?"""
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   105
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   106
        def __init__(self):
104
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   107
                self.cfg_cache = None
26
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   108
                self.type = None
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   109
                self.root = None
30
f06ad6cb4b3f stop using flavour terminology
Stephen Hahn <sch@sun.com>
parents: 29
diff changeset
   110
                self.imgdir = None
271
ec8a7669bff2 659 package that delivers existing automounter mountpoint fails installation
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 268
diff changeset
   111
                self.img_prefix = None
26
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   112
                self.repo_uris = []
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   113
                self.filter_tags = {}
32
c26788b7217c begin client install; sequences are now timestamps; skeleton ELF module
Stephen Hahn <sch@sun.com>
parents: 30
diff changeset
   114
                self.catalogs = {}
c26788b7217c begin client install; sequences are now timestamps; skeleton ELF module
Stephen Hahn <sch@sun.com>
parents: 30
diff changeset
   115
50
bfcb1661f019 basic image and package plans
Stephen Hahn <sch@sun.com>
parents: 45
diff changeset
   116
                self.attrs = {}
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   117
                self.link_actions = None
315
989c801f050b 1076 action __cmp__, action __str__ and manifest loading could all be faster
Dan Price <dp@eng.sun.com>
parents: 313
diff changeset
   118
                self.installed_pkg_cache = None
50
bfcb1661f019 basic image and package plans
Stephen Hahn <sch@sun.com>
parents: 45
diff changeset
   119
bfcb1661f019 basic image and package plans
Stephen Hahn <sch@sun.com>
parents: 45
diff changeset
   120
                self.attrs["Policy-Require-Optional"] = False
bfcb1661f019 basic image and package plans
Stephen Hahn <sch@sun.com>
parents: 45
diff changeset
   121
                self.attrs["Policy-Pursue-Latest"] = True
bfcb1661f019 basic image and package plans
Stephen Hahn <sch@sun.com>
parents: 45
diff changeset
   122
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   123
                self.imageplan = None # valid after evaluation succceds
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   124
                
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   125
                # 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
   126
                # frmi.XXX  Needs rewrite using graph follower
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   127
                self.optional_dependencies = {}
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   128
104
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   129
        def find_root(self, d):
289
c2e63370fb2b 160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents: 285
diff changeset
   130
                # Ascend from the given directory d to find first
26
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   131
                # 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
   132
                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
   133
                # 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
   134
                d = os.path.realpath(d)
26
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   135
                while 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
   136
                        if os.path.isdir(os.path.join(d, img_user_prefix)):
26
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   137
                                # XXX Look at image file to determine filter
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   138
                                # tags and repo URIs.
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   139
                                self.type = IMG_USER
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   140
                                self.root = d
271
ec8a7669bff2 659 package that delivers existing automounter mountpoint fails installation
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 268
diff changeset
   141
                                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
   142
                                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
   143
                                self.attrs["Build-Release"] = "5.11"
26
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   144
                                return
289
c2e63370fb2b 160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents: 285
diff changeset
   145
                        elif os.path.isdir(os.path.join(d, img_root_prefix)):
26
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   146
                                # XXX Look at image file to determine filter
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   147
                                # tags and repo URIs.
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   148
                                # XXX Look at image file to determine if this
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   149
                                # image is a partial image.
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   150
                                self.type = IMG_ENTIRE
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   151
                                self.root = d
271
ec8a7669bff2 659 package that delivers existing automounter mountpoint fails installation
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 268
diff changeset
   152
                                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
   153
                                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
   154
                                self.attrs["Build-Release"] = "5.11"
26
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   155
                                return
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   156
289
c2e63370fb2b 160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents: 285
diff changeset
   157
                        # 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
   158
                        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
   159
                        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
   160
289
c2e63370fb2b 160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents: 285
diff changeset
   161
                        # 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
   162
                        # 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
   163
                        #
c2e63370fb2b 160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents: 285
diff changeset
   164
                        # (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
   165
                        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
   166
                                raise ValueError, "directory %s not contained within an image" % startd
26
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   167
104
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   168
        def load_config(self):
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   169
                """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
   170
                location."""
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   171
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   172
                # 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
   173
                # configuration.
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   174
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   175
                if self.root == None:
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   176
                        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
   177
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   178
                ic = imageconfig.ImageConfig()
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   179
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   180
                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
   181
                        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
   182
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   183
                self.cfg_cache = ic
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   184
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   185
        # 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
   186
        # operation.
29
f621f1df0849 fix install target; correct imports for module renames
"Stephen Hahn <sch@sun.com>"
parents: 26
diff changeset
   187
        def mkdirs(self):
30
f06ad6cb4b3f stop using flavour terminology
Stephen Hahn <sch@sun.com>
parents: 29
diff changeset
   188
                if not os.path.isdir(self.imgdir + "/catalog"):
f06ad6cb4b3f stop using flavour terminology
Stephen Hahn <sch@sun.com>
parents: 29
diff changeset
   189
                        os.makedirs(self.imgdir + "/catalog")
f06ad6cb4b3f stop using flavour terminology
Stephen Hahn <sch@sun.com>
parents: 29
diff changeset
   190
                if not os.path.isdir(self.imgdir + "/file"):
f06ad6cb4b3f stop using flavour terminology
Stephen Hahn <sch@sun.com>
parents: 29
diff changeset
   191
                        os.makedirs(self.imgdir + "/file")
f06ad6cb4b3f stop using flavour terminology
Stephen Hahn <sch@sun.com>
parents: 29
diff changeset
   192
                if not os.path.isdir(self.imgdir + "/pkg"):
f06ad6cb4b3f stop using flavour terminology
Stephen Hahn <sch@sun.com>
parents: 29
diff changeset
   193
                        os.makedirs(self.imgdir + "/pkg")
60
6bd5cd83cfb1 Reverse index database and searching support.
Danek Duvall <danek.duvall@sun.com>
parents: 59
diff changeset
   194
                if not os.path.isdir(self.imgdir + "/index"):
6bd5cd83cfb1 Reverse index database and searching support.
Danek Duvall <danek.duvall@sun.com>
parents: 59
diff changeset
   195
                        os.makedirs(self.imgdir + "/index")
29
f621f1df0849 fix install target; correct imports for module renames
"Stephen Hahn <sch@sun.com>"
parents: 26
diff changeset
   196
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   197
        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
   198
            ssl_key = None, ssl_cert = None):
19
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
   199
                self.type = type
22
379f0f6809ff pkgsend open, pkgsend add file, pkgsend close; Transaction object
"Stephen Hahn <sch@sun.com>"
parents: 19
diff changeset
   200
                self.root = root
379f0f6809ff pkgsend open, pkgsend add file, pkgsend close; Transaction object
"Stephen Hahn <sch@sun.com>"
parents: 19
diff changeset
   201
                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
   202
                        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
   203
                else:
271
ec8a7669bff2 659 package that delivers existing automounter mountpoint fails installation
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 268
diff changeset
   204
                        self.img_prefix = img_root_prefix
ec8a7669bff2 659 package that delivers existing automounter mountpoint fails installation
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 268
diff changeset
   205
                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
   206
                self.mkdirs()
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   207
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   208
                self.cfg_cache = imageconfig.ImageConfig()
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   209
111
647c91609117 Client-side filtering.
Danek Duvall <danek.duvall@sun.com>
parents: 107
diff changeset
   210
                if is_zone:
647c91609117 Client-side filtering.
Danek Duvall <danek.duvall@sun.com>
parents: 107
diff changeset
   211
                        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
   212
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   213
                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
   214
                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
   215
                self.cfg_cache.authorities[auth_name]["origin"] = \
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   216
                    misc.url_affix_trailing_slash(auth_url)
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   217
                self.cfg_cache.authorities[auth_name]["mirrors"] = []
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   218
                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
   219
                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
   220
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   221
                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
   222
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   223
                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
   224
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   225
        def is_liveroot(self):
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   226
                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
   227
29
f621f1df0849 fix install target; correct imports for module renames
"Stephen Hahn <sch@sun.com>"
parents: 26
diff changeset
   228
        def get_root(self):
f621f1df0849 fix install target; correct imports for module renames
"Stephen Hahn <sch@sun.com>"
parents: 26
diff changeset
   229
                return self.root
f621f1df0849 fix install target; correct imports for module renames
"Stephen Hahn <sch@sun.com>"
parents: 26
diff changeset
   230
104
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   231
        def gen_authorities(self):
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   232
                if not self.cfg_cache:
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   233
                        raise RuntimeError, "empty ImageConfig"
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   234
                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
   235
                        raise RuntimeError, "no defined authorities"
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   236
                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
   237
                        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
   238
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   239
        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
   240
                """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
   241
                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
   242
                preferred authority."""
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   243
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   244
                # 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
   245
                # 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
   246
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   247
                if authority == None:
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   248
                        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
   249
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   250
                try:
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   251
                        o = self.cfg_cache.authorities[authority]["origin"]
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   252
                except KeyError:
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   253
                        # 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
   254
                        # exists, fall back to preferred authority.
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   255
                        authority = self.cfg_cache.preferred_authority
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   256
                        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
   257
146
9b9fcd56b8b2 Reduce use of the re module, for performance.
Danek Duvall <danek.duvall@sun.com>
parents: 145
diff changeset
   258
                return o.rstrip("/")
104
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   259
322
e1b078577730 1101 pkg search -s <server> returns a traceback
Danek Duvall <danek.duvall@sun.com>
parents: 319
diff changeset
   260
        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
   261
                """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
   262
                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
   263
                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
   264
                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
   265
                """
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   266
322
e1b078577730 1101 pkg search -s <server> returns a traceback
Danek Duvall <danek.duvall@sun.com>
parents: 319
diff changeset
   267
                if authority is None:
e1b078577730 1101 pkg search -s <server> returns a traceback
Danek Duvall <danek.duvall@sun.com>
parents: 319
diff changeset
   268
                        if origin is None:
e1b078577730 1101 pkg search -s <server> returns a traceback
Danek Duvall <danek.duvall@sun.com>
parents: 319
diff changeset
   269
                                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
   270
                        else:
e1b078577730 1101 pkg search -s <server> returns a traceback
Danek Duvall <danek.duvall@sun.com>
parents: 319
diff changeset
   271
                                auths = self.cfg_cache.authorities
e1b078577730 1101 pkg search -s <server> returns a traceback
Danek Duvall <danek.duvall@sun.com>
parents: 319
diff changeset
   272
                                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
   273
                                        if auth["origin"] == origin:
e1b078577730 1101 pkg search -s <server> returns a traceback
Danek Duvall <danek.duvall@sun.com>
parents: 319
diff changeset
   274
                                                authority = pfx
e1b078577730 1101 pkg search -s <server> returns a traceback
Danek Duvall <danek.duvall@sun.com>
parents: 319
diff changeset
   275
                                                break
e1b078577730 1101 pkg search -s <server> returns a traceback
Danek Duvall <danek.duvall@sun.com>
parents: 319
diff changeset
   276
                                else:
e1b078577730 1101 pkg search -s <server> returns a traceback
Danek Duvall <danek.duvall@sun.com>
parents: 319
diff changeset
   277
                                        return None
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   278
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   279
                try:
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   280
                        authent = self.cfg_cache.authorities[authority]
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   281
                except KeyError:
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   282
                        authority = self.cfg_cache.preferred_authority
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   283
                        authent = self.cfg_cache.authorities[authority]
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   284
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   285
                return (authent["ssl_key"], authent["ssl_cert"])
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   286
104
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   287
        def get_default_authority(self):
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   288
                return self.cfg_cache.preferred_authority
19
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
   289
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   290
        def has_authority(self, auth_name):
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   291
                return auth_name in self.cfg_cache.authorities
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   292
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   293
        def delete_authority(self, auth_name):
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   294
                if not self.has_authority(auth_name):
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   295
                        raise KeyError, "no such authority '%s'" % auth_name
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   296
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   297
                self.cfg_cache.delete_authority(auth_name)
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   298
                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
   299
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   300
        def get_authority(self, auth_name):
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   301
                if not self.has_authority(auth_name):
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   302
                        raise KeyError, "no such authority '%s'" % auth_name
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   303
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   304
                return self.cfg_cache.authorities[auth_name]
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   305
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   306
        def split_authority(self, auth):
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   307
                prefix = auth["prefix"]
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   308
                update_dt = None
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   309
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   310
                try:
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   311
                        cat = self.catalogs[prefix]
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   312
                except KeyError:
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   313
                        cat = None
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   314
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   315
                if cat:
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   316
                        update_dt = cat.last_modified()
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   317
                        if update_dt:
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   318
                                update_dt = catalog.ts_to_datetime(update_dt)
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   319
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   320
                return (prefix, auth["origin"], auth["ssl_key"],
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   321
                    auth["ssl_cert"], update_dt)
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   322
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   323
        def set_preferred_authority(self, auth_name):
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   324
                if not self.has_authority(auth_name):
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   325
                        raise KeyError, "no such authority '%s'" % auth_name
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   326
                self.cfg_cache.preferred_authority = auth_name
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   327
                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
   328
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   329
        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
   330
            ssl_cert = None, mirrors = []):
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   331
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   332
                auths = self.cfg_cache.authorities
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   333
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   334
                if auth_name in auths:
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   335
                        # If authority already exists, only update non-NULL
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   336
                        # values passed to set_authority
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   337
                        if origin_url:
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   338
                                auths[auth_name]["origin"] = \
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   339
                                    misc.url_affix_trailing_slash(origin_url)
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   340
                        if ssl_key:
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   341
                                auths[auth_name]["ssl_key"] = ssl_key
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   342
                        if ssl_cert:
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   343
                                auths[auth_name]["ssl_cert"] = ssl_cert
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   344
                        if mirrors:
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   345
                                auths[auth_name]["mirrors"] = mirrors
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
                else:
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   348
                        auths[auth_name] = {}
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   349
                        auths[auth_name]["prefix"] = auth_name
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   350
                        auths[auth_name]["origin"] = \
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   351
                            misc.url_affix_trailing_slash(origin_url)
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   352
                        auths[auth_name]["mirrors"] = mirrors
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   353
                        auths[auth_name]["ssl_key"] = ssl_key
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   354
                        auths[auth_name]["ssl_cert"] = ssl_cert
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
                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
   357
161
e0322fe7842c Simplify and correct the package matching code.
Danek Duvall <danek.duvall@sun.com>
parents: 157
diff changeset
   358
        def get_matching_fmris(self, patterns, matcher = None,
e0322fe7842c Simplify and correct the package matching code.
Danek Duvall <danek.duvall@sun.com>
parents: 157
diff changeset
   359
            constraint = None, counthash = None):
e0322fe7842c Simplify and correct the package matching code.
Danek Duvall <danek.duvall@sun.com>
parents: 157
diff changeset
   360
                """Iterate through all catalogs, looking for packages matching
e0322fe7842c Simplify and correct the package matching code.
Danek Duvall <danek.duvall@sun.com>
parents: 157
diff changeset
   361
                'pattern', based on the function in 'matcher' and the versioning
e0322fe7842c Simplify and correct the package matching code.
Danek Duvall <danek.duvall@sun.com>
parents: 157
diff changeset
   362
                constraint described by 'constraint'.  If 'matcher' is None,
e0322fe7842c Simplify and correct the package matching code.
Danek Duvall <danek.duvall@sun.com>
parents: 157
diff changeset
   363
                uses fmri subset matching as the default.  Returns a list of
e0322fe7842c Simplify and correct the package matching code.
Danek Duvall <danek.duvall@sun.com>
parents: 157
diff changeset
   364
                (catalog, fmri) pairs.  If 'counthash' is a dictionary, instead
e0322fe7842c Simplify and correct the package matching code.
Danek Duvall <danek.duvall@sun.com>
parents: 157
diff changeset
   365
                store the number of matched fmris for each package name which
e0322fe7842c Simplify and correct the package matching code.
Danek Duvall <danek.duvall@sun.com>
parents: 157
diff changeset
   366
                was matched."""
e0322fe7842c Simplify and correct the package matching code.
Danek Duvall <danek.duvall@sun.com>
parents: 157
diff changeset
   367
e0322fe7842c Simplify and correct the package matching code.
Danek Duvall <danek.duvall@sun.com>
parents: 157
diff changeset
   368
                # XXX Do we want to recognize regex (some) metacharacters and
e0322fe7842c Simplify and correct the package matching code.
Danek Duvall <danek.duvall@sun.com>
parents: 157
diff changeset
   369
                # switch automatically to the regex matcher?
221
e1dbb27a23b5 52 catalog can leave inventory behind, making pkg(1) blind
Stephen Hahn <sch@Sun.COM>
parents: 219
diff changeset
   370
195
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   371
                # XXX If the patterns contain an authority, we could reduce the
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   372
                # number of catalogs searched by only looking at catalogs whose
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   373
                # authorities match FMRIs in the pattern.
34
8b9613402116 refactor catalog and package to be common; improve bump-server
Stephen Hahn <sch@sun.com>
parents: 33
diff changeset
   374
195
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   375
                # Check preferred authority first, if package isn't found here,
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   376
                # then check all authorities.
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   377
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   378
                cat = self.catalogs[self.cfg_cache.preferred_authority]
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   379
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   380
                m = cat.get_matching_fmris(patterns, matcher,
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   381
                    constraint, counthash)
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   382
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   383
                for k, c in self.catalogs.items():
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   384
                        if k == self.cfg_cache.preferred_authority:
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   385
                                continue
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   386
                        m.extend(c.get_matching_fmris(patterns, matcher,
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   387
                            constraint, counthash))
69
9eeb33eab728 Gracefully exit when trying to install packages on an image without a catalog.
Danek Duvall <danek.duvall@sun.com>
parents: 67
diff changeset
   388
221
e1dbb27a23b5 52 catalog can leave inventory behind, making pkg(1) blind
Stephen Hahn <sch@Sun.COM>
parents: 219
diff changeset
   389
                ips = [ ip for ip in self.gen_installed_pkgs() if ip not in m ]
e1dbb27a23b5 52 catalog can leave inventory behind, making pkg(1) blind
Stephen Hahn <sch@Sun.COM>
parents: 219
diff changeset
   390
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   391
                m.extend(catalog.extract_matching_fmris(ips, patterns,
221
e1dbb27a23b5 52 catalog can leave inventory behind, making pkg(1) blind
Stephen Hahn <sch@Sun.COM>
parents: 219
diff changeset
   392
                    matcher, constraint, counthash))
e1dbb27a23b5 52 catalog can leave inventory behind, making pkg(1) blind
Stephen Hahn <sch@Sun.COM>
parents: 219
diff changeset
   393
69
9eeb33eab728 Gracefully exit when trying to install packages on an image without a catalog.
Danek Duvall <danek.duvall@sun.com>
parents: 67
diff changeset
   394
                if not m:
221
e1dbb27a23b5 52 catalog can leave inventory behind, making pkg(1) blind
Stephen Hahn <sch@Sun.COM>
parents: 219
diff changeset
   395
                        raise KeyError, "packages matching '%s' not found in catalog or image" \
161
e0322fe7842c Simplify and correct the package matching code.
Danek Duvall <danek.duvall@sun.com>
parents: 157
diff changeset
   396
                            % patterns
45
8a3f00dea14f catalog refresh; basic catalog listing; precise manifest pulls
Stephen Hahn <sch@sun.com>
parents: 39
diff changeset
   397
50
bfcb1661f019 basic image and package plans
Stephen Hahn <sch@sun.com>
parents: 45
diff changeset
   398
                return m
45
8a3f00dea14f catalog refresh; basic catalog listing; precise manifest pulls
Stephen Hahn <sch@sun.com>
parents: 39
diff changeset
   399
235
61994d15c39b 373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents: 226
diff changeset
   400
        def verify(self, fmri, progresstracker, **args):
61994d15c39b 373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents: 226
diff changeset
   401
                """ generator that returns any errors in installed pkgs
61994d15c39b 373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents: 226
diff changeset
   402
                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
   403
235
61994d15c39b 373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents: 226
diff changeset
   404
                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
   405
                        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
   406
                        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
   407
                        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
   408
                        if errors:
61994d15c39b 373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents: 226
diff changeset
   409
                                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
   410
                                    errors)
61994d15c39b 373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents: 226
diff changeset
   411
                                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
   412
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
   413
        def gen_installed_actions(self):
6ece196588cb 348 files that move from pkg to pkg can cause problems during upgrade
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 235
diff changeset
   414
                """ generates actions in installed image """
6ece196588cb 348 files that move from pkg to pkg can cause problems during upgrade
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 235
diff changeset
   415
6ece196588cb 348 files that move from pkg to pkg can cause problems during upgrade
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 235
diff changeset
   416
                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
   417
                        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
   418
                                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
   419
6ece196588cb 348 files that move from pkg to pkg can cause problems during upgrade
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 235
diff changeset
   420
        def get_link_actions(self):
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
   421
                """ 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
   422
                target """
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   423
                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
   424
                        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
   425
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
   426
                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
   427
                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
   428
                        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
   429
                                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
   430
                                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
   431
                                        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
   432
                                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
   433
                                        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
   434
                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
   435
                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
   436
50
bfcb1661f019 basic image and package plans
Stephen Hahn <sch@sun.com>
parents: 45
diff changeset
   437
        def has_manifest(self, fmri):
45
8a3f00dea14f catalog refresh; basic catalog listing; precise manifest pulls
Stephen Hahn <sch@sun.com>
parents: 39
diff changeset
   438
                mpath = fmri.get_dir_path()
8a3f00dea14f catalog refresh; basic catalog listing; precise manifest pulls
Stephen Hahn <sch@sun.com>
parents: 39
diff changeset
   439
8a3f00dea14f catalog refresh; basic catalog listing; precise manifest pulls
Stephen Hahn <sch@sun.com>
parents: 39
diff changeset
   440
                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
   441
8a3f00dea14f catalog refresh; basic catalog listing; precise manifest pulls
Stephen Hahn <sch@sun.com>
parents: 39
diff changeset
   442
                if (os.path.exists(local_mpath)):
50
bfcb1661f019 basic image and package plans
Stephen Hahn <sch@sun.com>
parents: 45
diff changeset
   443
                        return True
bfcb1661f019 basic image and package plans
Stephen Hahn <sch@sun.com>
parents: 45
diff changeset
   444
bfcb1661f019 basic image and package plans
Stephen Hahn <sch@sun.com>
parents: 45
diff changeset
   445
                return False
45
8a3f00dea14f catalog refresh; basic catalog listing; precise manifest pulls
Stephen Hahn <sch@sun.com>
parents: 39
diff changeset
   446
329
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
   447
        def _fetch_manifest(self, fmri):
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   448
                """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
   449
                and write resulting contents to disk.  Helper routine for
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
   450
                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
   451
                that.  """
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   452
50
bfcb1661f019 basic image and package plans
Stephen Hahn <sch@sun.com>
parents: 45
diff changeset
   453
                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
   454
                m.set_fmri(self, fmri)
72
9deed41412b3 Support for proper package upgrade.
Danek Duvall <danek.duvall@sun.com>
parents: 69
diff changeset
   455
144
ce619e0b453f Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents: 139
diff changeset
   456
                fmri_dir_path = os.path.join(self.imgdir, "pkg",
ce619e0b453f Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents: 139
diff changeset
   457
                    fmri.get_dir_path())
ce619e0b453f Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents: 139
diff changeset
   458
                mpath = os.path.join(fmri_dir_path, "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
   459
                ipath = os.path.join(fmri_dir_path, "index")
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   460
315
989c801f050b 1076 action __cmp__, action __str__ and manifest loading could all be faster
Dan Price <dp@eng.sun.com>
parents: 313
diff changeset
   461
                # 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
   462
                # 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
   463
                # representation to disk.
989c801f050b 1076 action __cmp__, action __str__ and manifest loading could all be faster
Dan Price <dp@eng.sun.com>
parents: 313
diff changeset
   464
                mcontent = retrieve.get_manifest(self, fmri)
50
bfcb1661f019 basic image and package plans
Stephen Hahn <sch@sun.com>
parents: 45
diff changeset
   465
                m.set_content(mcontent)
144
ce619e0b453f Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents: 139
diff changeset
   466
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   467
                # Write the originating authority into the manifest.
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   468
                # 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
   469
                # 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
   470
                # from the depot.
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   471
                if not fmri.has_authority():
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   472
                        m["authority"] = self.get_default_authority()
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   473
                else:
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   474
                        m["authority"] = fmri.get_authority()
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   475
315
989c801f050b 1076 action __cmp__, action __str__ and manifest loading could all be faster
Dan Price <dp@eng.sun.com>
parents: 313
diff changeset
   476
                m.store(mpath, ipath)
144
ce619e0b453f Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents: 139
diff changeset
   477
50
bfcb1661f019 basic image and package plans
Stephen Hahn <sch@sun.com>
parents: 45
diff changeset
   478
                return m
45
8a3f00dea14f catalog refresh; basic catalog listing; precise manifest pulls
Stephen Hahn <sch@sun.com>
parents: 39
diff changeset
   479
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   480
        def _valid_manifest(self, fmri, manifest):
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   481
                """Check authority attached to manifest.  Make sure
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   482
                it matches authority specified in FMRI."""
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   483
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   484
                authority = fmri.get_authority()
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   485
                if not authority:
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   486
                        authority = self.get_default_authority()
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   487
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   488
                if not "authority" in manifest:
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   489
                        return False
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   490
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   491
                if manifest["authority"] != authority:
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   492
                        return False
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   493
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   494
                return True
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   495
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   496
        def get_manifest(self, fmri, filtered = False):
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   497
                """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
   498
                object, applying appropriate filters as needed."""
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   499
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   500
                m = manifest.Manifest()
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   501
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   502
                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
   503
                    fmri.get_dir_path())
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   504
                mpath = os.path.join(fmri_dir_path, "manifest")
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   505
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   506
                # If the manifest isn't there, download.
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   507
                if not os.path.exists(mpath):
329
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
   508
                        m = self._fetch_manifest(fmri)
296
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
                        mcontent = file(mpath).read()
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   511
                        m.set_fmri(self, fmri)
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   512
                        m.set_content(mcontent)
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   513
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   514
                # 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
   515
                # 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
   516
                if not self._valid_manifest(fmri, m):
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   517
                        try:
329
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
   518
                                m = self._fetch_manifest(fmri)
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   519
                        except NameError:
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   520
                                # In thise case, the client has failed to
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   521
                                # download a new manifest with the same name.
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   522
                                # 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
   523
                                # 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
   524
                                # 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
   525
                                pass
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   526
329
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
   527
		# XXX perhaps all of the below should live in Manifest.filter()?
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
   528
                if filtered:
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
   529
			filters = []
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
   530
			try:
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
   531
				f = file("%s/filters" % fmri_dir_path, "r")
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
   532
			except IOError, e:
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
   533
				if e.errno != errno.ENOENT:
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
   534
					raise
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
   535
			else:
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
   536
				filters = [
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
   537
				    (l.strip(), compile(
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
   538
					l.strip(), "<filter string>", "eval"))
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
   539
				    for l in f.readlines()
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
   540
				]
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
   541
			m.filter(filters)
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
   542
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   543
                return m
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   544
331
4f332d6b4036 1266 Client loses track of authority preference, chaos ensues
johansen <johansen@sun.com>
parents: 329
diff changeset
   545
        def installed_file_authority(self, filepath):
195
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   546
                """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
   547
                Return the authority that installed this package."""
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   548
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   549
                read_only = False
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   550
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   551
                try:
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   552
                        f = file(filepath, "r+")
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   553
                except IOError, e:
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   554
                        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
   555
                                read_only = True
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   556
                        else:
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   557
                                raise
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   558
                if read_only:
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   559
                        f = file(filepath, "r")
296
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
                flines = f.readlines()
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   562
                newauth = None
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   563
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   564
                try:
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   565
                        version, auth = flines
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   566
                except ValueError:
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   567
                        # 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
   568
                        # 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
   569
                        # 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
   570
                        # to assume that the package was installed from
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   571
                        # the preferred authority.  Here, we set up
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   572
                        # the authority to record that.
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   573
                        auth = flines[0]
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   574
                        auth = auth.strip()
313
c4d18a029dfd 761 'import timedanek' in subprocess_method.py's __main__
Danek Duvall <danek.duvall@sun.com>
parents: 310
diff changeset
   575
                        newauth = "%s_%s" % (pkg.fmri.PREF_AUTH_PFX, auth)
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   576
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   577
                if newauth and not read_only:
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   578
                        # This is where we actually update the installed
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   579
                        # file with the new authority.
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   580
                        f.seek(0)
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   581
                        f.writelines(["VERSION_1\n", newauth])
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   582
                        auth = newauth
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   583
195
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   584
                f.close()
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   585
331
4f332d6b4036 1266 Client loses track of authority preference, chaos ensues
johansen <johansen@sun.com>
parents: 329
diff changeset
   586
                if not auth:
4f332d6b4036 1266 Client loses track of authority preference, chaos ensues
johansen <johansen@sun.com>
parents: 329
diff changeset
   587
                        auth = "%s_%s" % (pkg.fmri.PREF_AUTH_PFX,
4f332d6b4036 1266 Client loses track of authority preference, chaos ensues
johansen <johansen@sun.com>
parents: 329
diff changeset
   588
                            self.get_default_authority())
4f332d6b4036 1266 Client loses track of authority preference, chaos ensues
johansen <johansen@sun.com>
parents: 329
diff changeset
   589
195
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   590
                return auth
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   591
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   592
        def install_file_present(self, fmri):
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   593
                """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
   594
                on the system.  Otherwise, returns false."""
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   595
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   596
                return os.path.exists("%s/pkg/%s/installed" % (self.imgdir,
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   597
                    fmri.get_dir_path()))
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   598
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   599
        def add_install_file(self, fmri):
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   600
                """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
   601
                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
   602
                installed."""
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   603
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   604
                f = file("%s/pkg/%s/installed" % (self.imgdir,
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   605
                    fmri.get_dir_path()), "w")
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   606
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   607
                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
   608
                f.close()
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   609
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   610
        def remove_install_file(self, fmri):
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   611
                """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
   612
                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
   613
                installed."""
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   614
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   615
                os.unlink("%s/pkg/%s/installed" % (self.imgdir,
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   616
                    fmri.get_dir_path()))
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   617
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   618
        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
   619
                pd = pfmri.get_pkg_stem()
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
   620
                pdir = "%s/pkg/%s" % (self.imgdir,
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
   621
                    pfmri.get_dir_path(stemonly = True))
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
   622
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
   623
                try:
195
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   624
                        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
   625
                            "%s/%s/installed" % (pdir, vd))
59
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
   626
                            for vd in os.listdir(pdir)
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
   627
                            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
   628
                except OSError:
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   629
                        return None
59
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
   630
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
   631
                if len(pkgs_inst) == 0:
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   632
                        return None
59
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
   633
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
   634
                assert len(pkgs_inst) <= 1
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
   635
195
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   636
                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
   637
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   638
                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
   639
104
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   640
        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
   641
                """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
   642
195
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   643
                if self.install_file_present(pfmri):
104
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   644
                        return "installed"
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   645
106
ed11fcd45545 pkg status -a; allow trailing / in URL; don't write 404 into manifest;
"Stephen Hahn <sch@sun.com>"
parents: 104
diff changeset
   646
                return "known"
104
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   647
195
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   648
        def fmri_set_default_authority(self, fmri):
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   649
                """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
   650
                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
   651
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   652
                if fmri.has_authority():
195
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   653
                        return
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   654
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   655
                fmri.set_authority(self.get_default_authority(), True)
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   656
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   657
        def get_catalog(self, fmri, exception = False):
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   658
                """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
   659
                correct catalog for this image."""
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   660
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   661
                # 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
   662
                # then return the catalog for the preferred authority
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   663
                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
   664
                        cat = self.catalogs[self.get_default_authority()]
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   665
                else:
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   666
                        try:
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   667
                                cat = self.catalogs[fmri.get_authority()]
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   668
                        except KeyError:
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   669
                                # If the authority that installed this package
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   670
                                # has vanished, pick the default authority
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   671
                                # instead.
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   672
                                if exception:
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   673
                                        raise
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   674
                                else:
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   675
                                        cat = self.catalogs[\
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   676
                                            self.get_default_authority()]
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   677
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   678
                return cat
195
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   679
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
   680
        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
   681
                """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
   682
                installed in the current image."""
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   683
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   684
                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
   685
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   686
                if v and not fmri.has_authority():
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   687
                        fmri.set_authority(v.get_authority_str())
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   688
                elif not fmri.has_authority():
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   689
                        fmri.set_authority(self.get_default_authority(), True)
266
5e5bff6fedce 582 Importing packages seemingly misrecords dependencies
johansen <johansen@sun.com>
parents: 260
diff changeset
   690
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   691
                if v and self.fmri_is_successor(v, fmri):
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   692
                        return True
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   693
                else:
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   694
                        try:
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   695
                                cat = self.get_catalog(fmri, exception = True)
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   696
                        except KeyError:
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   697
                                return False
59
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
   698
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   699
                        # 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
   700
                        # packages that are equivalent to fmri.
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   701
                        rpkgs = cat.rename_newer_pkgs(fmri)
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   702
                        for f in rpkgs:
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   703
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   704
                                v = self._get_version_installed(f)
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   705
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   706
                                if v and self.fmri_is_successor(v, fmri):
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   707
                                        return True
59
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
   708
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
   709
                return False
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
   710
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   711
        def older_version_installed(self, fmri):
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   712
                """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
   713
                older version of the package is installed.  This takes
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   714
                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
   715
                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
   716
                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
   717
                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
   718
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   719
                v = self._get_version_installed(fmri)
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   720
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   721
                assert fmri.has_authority()
268
3d53da66d4a4 582 Importing packages seemingly misrecords dependencies
johansen <johansen@sun.com>
parents: 266
diff changeset
   722
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   723
                if v:
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   724
                        return v
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   725
                else:
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   726
                        cat = self.get_catalog(fmri)
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   727
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   728
                        rpkgs = cat.rename_older_pkgs(fmri)
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   729
                        for f in rpkgs:
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   730
                                v = self._get_version_installed(f)
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   731
                                if v and self.fmri_is_successor(fmri, v):
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   732
                                        return v
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   733
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   734
                return None
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   735
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
   736
        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
   737
                """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
   738
                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
   739
195
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   740
                # 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
   741
                assert fmri.has_authority()
195
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   742
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   743
                v = self._get_version_installed(fmri)
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   744
                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
   745
                        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
   746
a1e20e9a9845 add CLI test suite, correct bugs found by test suite, ration out CLI options
Stephen Hahn <sch@Sun.COM>
parents: 116
diff changeset
   747
                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
   748
67
62c897652bbc Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents: 63
diff changeset
   749
        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
   750
                """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
   751
                FMRI."""
67
62c897652bbc Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents: 63
diff changeset
   752
62c897652bbc Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents: 63
diff changeset
   753
                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
   754
                    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
   755
62c897652bbc Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents: 63
diff changeset
   756
                if not os.path.isdir(thedir):
62c897652bbc Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents: 63
diff changeset
   757
                        return []
62c897652bbc Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents: 63
diff changeset
   758
62c897652bbc Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents: 63
diff changeset
   759
                for v in os.listdir(thedir):
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   760
                        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
   761
                            self.attrs["Build-Release"])
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   762
                        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
   763
                                dependents = [
62c897652bbc Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents: 63
diff changeset
   764
                                    urllib.unquote(d)
62c897652bbc Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents: 63
diff changeset
   765
                                    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
   766
                                    if os.path.exists(
1861fdf62519 on uninstall, don't complain about uninstalled dependents
Danek Duvall <danek.duvall@sun.com>
parents: 135
diff changeset
   767
                                        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
   768
                                ]
62c897652bbc Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents: 63
diff changeset
   769
62c897652bbc Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents: 63
diff changeset
   770
                return dependents
62c897652bbc Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents: 63
diff changeset
   771
215
c10719939c6d 245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents: 208
diff changeset
   772
        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
   773
                failed = []
63e78f600aa7 185 traceback on pkg refresh when hostname lookup fails
Danek Duvall <danek.duvall@sun.com>
parents: 195
diff changeset
   774
                total = 0
63e78f600aa7 185 traceback on pkg refresh when hostname lookup fails
Danek Duvall <danek.duvall@sun.com>
parents: 195
diff changeset
   775
                succeeded = 0
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   776
                cat = None
215
c10719939c6d 245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents: 208
diff changeset
   777
                ts = 0
201
63e78f600aa7 185 traceback on pkg refresh when hostname lookup fails
Danek Duvall <danek.duvall@sun.com>
parents: 195
diff changeset
   778
116
9c9942a52984 (image flag day) remove pkg catalog, improve pkg status, localize pkg(1), use
Stephen Hahn <sch@Sun.COM>
parents: 111
diff changeset
   779
                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
   780
                        total += 1
215
c10719939c6d 245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents: 208
diff changeset
   781
c10719939c6d 245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents: 208
diff changeset
   782
                        if auth["prefix"] in self.catalogs:
c10719939c6d 245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents: 208
diff changeset
   783
                                cat = self.catalogs[auth["prefix"]]
c10719939c6d 245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents: 208
diff changeset
   784
                                ts = cat.last_modified()
c10719939c6d 245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents: 208
diff changeset
   785
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   786
                                # Although we may have a catalog with a
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   787
                                # timestamp, the user may have changed the
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   788
                                # origin URL for the authority.  If this has
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   789
                                # occurred, we need to perform a full refresh.
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   790
                                if cat.origin() != auth["origin"]:
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   791
                                        full_refresh = True
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   792
215
c10719939c6d 245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents: 208
diff changeset
   793
                        if ts and not full_refresh:
c10719939c6d 245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents: 208
diff changeset
   794
                                hdr = {'If-Modified-Since': ts}
c10719939c6d 245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents: 208
diff changeset
   795
                        else:
c10719939c6d 245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents: 208
diff changeset
   796
                                hdr = {}
c10719939c6d 245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents: 208
diff changeset
   797
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   798
                        ssl_tuple = self.get_ssl_credentials(auth["prefix"])
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   799
116
9c9942a52984 (image flag day) remove pkg catalog, improve pkg status, localize pkg(1), use
Stephen Hahn <sch@Sun.COM>
parents: 111
diff changeset
   800
                        # 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
   801
                        try:
201
63e78f600aa7 185 traceback on pkg refresh when hostname lookup fails
Danek Duvall <danek.duvall@sun.com>
parents: 195
diff changeset
   802
                                c, v = versioned_urlopen(auth["origin"],
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   803
                                    "catalog", [0], ssl_creds = ssl_tuple,
319
39b8b5c538bf 1104 want custom user-agent string
Danek Duvall <danek.duvall@sun.com>
parents: 316
diff changeset
   804
                                    headers = hdr, imgtype = self.type)
215
c10719939c6d 245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents: 208
diff changeset
   805
                        except urllib2.HTTPError, e:
260
a1b77322abb2 255 Symbolic HTTP response codes should be used
Shawn Walker <swalker@opensolaris.org>
parents: 259
diff changeset
   806
                                # 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
   807
                                # to date
a1b77322abb2 255 Symbolic HTTP response codes should be used
Shawn Walker <swalker@opensolaris.org>
parents: 259
diff changeset
   808
                                if e.code == httplib.NOT_MODIFIED:
215
c10719939c6d 245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents: 208
diff changeset
   809
                                        succeeded += 1
c10719939c6d 245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents: 208
diff changeset
   810
                                else:
c10719939c6d 245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents: 208
diff changeset
   811
                                        failed.append((auth, e))
c10719939c6d 245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents: 208
diff changeset
   812
                                continue
c10719939c6d 245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents: 208
diff changeset
   813
201
63e78f600aa7 185 traceback on pkg refresh when hostname lookup fails
Danek Duvall <danek.duvall@sun.com>
parents: 195
diff changeset
   814
                        except urllib2.URLError, e:
63e78f600aa7 185 traceback on pkg refresh when hostname lookup fails
Danek Duvall <danek.duvall@sun.com>
parents: 195
diff changeset
   815
                                failed.append((auth, e))
63e78f600aa7 185 traceback on pkg refresh when hostname lookup fails
Danek Duvall <danek.duvall@sun.com>
parents: 195
diff changeset
   816
                                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
   817
                        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
   818
                                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
   819
                                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
   820
157
504b9e6d213c Catalog should be on-disk instead of in memory
johansen <johansen@sun.com>
parents: 146
diff changeset
   821
                        # root for this catalog
504b9e6d213c Catalog should be on-disk instead of in memory
johansen <johansen@sun.com>
parents: 146
diff changeset
   822
                        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
   823
201
63e78f600aa7 185 traceback on pkg refresh when hostname lookup fails
Danek Duvall <danek.duvall@sun.com>
parents: 195
diff changeset
   824
                        try:
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   825
                                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
   826
                        except IOError, e:
63e78f600aa7 185 traceback on pkg refresh when hostname lookup fails
Danek Duvall <danek.duvall@sun.com>
parents: 195
diff changeset
   827
                                failed.append((auth, e))
63e78f600aa7 185 traceback on pkg refresh when hostname lookup fails
Danek Duvall <danek.duvall@sun.com>
parents: 195
diff changeset
   828
                        else:
63e78f600aa7 185 traceback on pkg refresh when hostname lookup fails
Danek Duvall <danek.duvall@sun.com>
parents: 195
diff changeset
   829
                                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
   830
201
63e78f600aa7 185 traceback on pkg refresh when hostname lookup fails
Danek Duvall <danek.duvall@sun.com>
parents: 195
diff changeset
   831
                if failed:
63e78f600aa7 185 traceback on pkg refresh when hostname lookup fails
Danek Duvall <danek.duvall@sun.com>
parents: 195
diff changeset
   832
                        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
   833
235
61994d15c39b 373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents: 226
diff changeset
   834
        def load_catalogs(self, progresstracker):
157
504b9e6d213c Catalog should be on-disk instead of in memory
johansen <johansen@sun.com>
parents: 146
diff changeset
   835
                for auth in self.gen_authorities():
504b9e6d213c Catalog should be on-disk instead of in memory
johansen <johansen@sun.com>
parents: 146
diff changeset
   836
                        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
   837
                        progresstracker.catalog_start(auth["prefix"])
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   838
                        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
   839
                                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
   840
                                    auth["prefix"])
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   841
                                c = catalog.Catalog(croot, authority = authpfx)
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   842
                        else:
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   843
                                c = catalog.Catalog(croot,
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   844
                                    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
   845
                        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
   846
                        progresstracker.catalog_done()
59
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
   847
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   848
        def fmri_is_same_pkg(self, cfmri, pfmri):
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   849
                """Determine whether fmri and pfmri share the same package
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   850
                name, even if they're not equivalent versions.  This
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   851
                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
   852
                the same because of a rename operation."""
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   853
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   854
                # If authorities don't match, this can't be a successor
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   855
                if not pkg.fmri.is_same_authority(cfmri.authority, pfmri.authority):
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   856
                        return False
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   857
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   858
                # 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
   859
                # 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
   860
                # rename.
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   861
                if cfmri.is_same_pkg(pfmri):
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   862
                        return True
329
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
   863
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
   864
                # Get the catalog for the correct authority
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
   865
                cat = self.get_catalog(cfmri)
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
   866
		return cat.rename_is_same_pkg(cfmri, pfmri)
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
   867
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   868
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   869
        def fmri_is_successor(self, cfmri, pfmri):
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   870
                """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
   871
                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
   872
                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
   873
                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
   874
                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
   875
                routine from the catalog.  Otherwise, this runs the standard
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   876
                fmri.is_successor() code."""
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   877
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   878
                # If authorities don't match, this can't be a successor
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   879
                if not pkg.fmri.is_same_authority(cfmri.authority, pfmri.authority):
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   880
                        return False
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   881
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   882
                # Get the catalog for the correct authority
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   883
                cat = self.get_catalog(cfmri)
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   884
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   885
                # 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
   886
                # 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
   887
                # rename.
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   888
                if cfmri.is_successor(pfmri):
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   889
                        return True
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   890
                else:
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   891
                        return cat.rename_is_successor(cfmri, pfmri)
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   892
157
504b9e6d213c Catalog should be on-disk instead of in memory
johansen <johansen@sun.com>
parents: 146
diff changeset
   893
        def gen_known_package_fmris(self):
221
e1dbb27a23b5 52 catalog can leave inventory behind, making pkg(1) blind
Stephen Hahn <sch@Sun.COM>
parents: 219
diff changeset
   894
                """Generate the list of known packages, being the union of the
e1dbb27a23b5 52 catalog can leave inventory behind, making pkg(1) blind
Stephen Hahn <sch@Sun.COM>
parents: 219
diff changeset
   895
                   catalogs and the installed image."""
e1dbb27a23b5 52 catalog can leave inventory behind, making pkg(1) blind
Stephen Hahn <sch@Sun.COM>
parents: 219
diff changeset
   896
e1dbb27a23b5 52 catalog can leave inventory behind, making pkg(1) blind
Stephen Hahn <sch@Sun.COM>
parents: 219
diff changeset
   897
                li = [ x for x in self.gen_installed_pkgs() ]
e1dbb27a23b5 52 catalog can leave inventory behind, making pkg(1) blind
Stephen Hahn <sch@Sun.COM>
parents: 219
diff changeset
   898
e1dbb27a23b5 52 catalog can leave inventory behind, making pkg(1) blind
Stephen Hahn <sch@Sun.COM>
parents: 219
diff changeset
   899
                # Generate those packages in the set of catalogs.
59
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
   900
                for c in self.catalogs.values():
157
504b9e6d213c Catalog should be on-disk instead of in memory
johansen <johansen@sun.com>
parents: 146
diff changeset
   901
                        for pf in c.fmris():
221
e1dbb27a23b5 52 catalog can leave inventory behind, making pkg(1) blind
Stephen Hahn <sch@Sun.COM>
parents: 219
diff changeset
   902
                                if pf in li:
e1dbb27a23b5 52 catalog can leave inventory behind, making pkg(1) blind
Stephen Hahn <sch@Sun.COM>
parents: 219
diff changeset
   903
                                        li.remove(pf)
106
ed11fcd45545 pkg status -a; allow trailing / in URL; don't write 404 into manifest;
"Stephen Hahn <sch@sun.com>"
parents: 104
diff changeset
   904
                                yield pf
59
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
   905
221
e1dbb27a23b5 52 catalog can leave inventory behind, making pkg(1) blind
Stephen Hahn <sch@Sun.COM>
parents: 219
diff changeset
   906
        def gen_installed_pkgs(self):
315
989c801f050b 1076 action __cmp__, action __str__ and manifest loading could all be faster
Dan Price <dp@eng.sun.com>
parents: 313
diff changeset
   907
                if self.installed_pkg_cache is not None:
989c801f050b 1076 action __cmp__, action __str__ and manifest loading could all be faster
Dan Price <dp@eng.sun.com>
parents: 313
diff changeset
   908
                        return iter(self.installed_pkg_cache)
989c801f050b 1076 action __cmp__, action __str__ and manifest loading could all be faster
Dan Price <dp@eng.sun.com>
parents: 313
diff changeset
   909
                else:
989c801f050b 1076 action __cmp__, action __str__ and manifest loading could all be faster
Dan Price <dp@eng.sun.com>
parents: 313
diff changeset
   910
                        return self.gen_installed_pkgs_forreal()
989c801f050b 1076 action __cmp__, action __str__ and manifest loading could all be faster
Dan Price <dp@eng.sun.com>
parents: 313
diff changeset
   911
989c801f050b 1076 action __cmp__, action __str__ and manifest loading could all be faster
Dan Price <dp@eng.sun.com>
parents: 313
diff changeset
   912
        def gen_installed_pkgs_forreal(self):
195
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   913
                proot = "%s/pkg" % self.imgdir
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   914
315
989c801f050b 1076 action __cmp__, action __str__ and manifest loading could all be faster
Dan Price <dp@eng.sun.com>
parents: 313
diff changeset
   915
                self.installed_pkg_cache = []
195
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   916
                for pd in sorted(os.listdir(proot)):
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   917
                        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
   918
                                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
   919
                                if not os.path.exists(path):
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   920
                                        continue
226
8939051a496c 376 image must use default authority when none specified
johansen <johansen@sun.com>
parents: 222
diff changeset
   921
331
4f332d6b4036 1266 Client loses track of authority preference, chaos ensues
johansen <johansen@sun.com>
parents: 329
diff changeset
   922
                                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
   923
                                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
   924
                                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
   925
315
989c801f050b 1076 action __cmp__, action __str__ and manifest loading could all be faster
Dan Price <dp@eng.sun.com>
parents: 313
diff changeset
   926
                                self.installed_pkg_cache.append(f)
989c801f050b 1076 action __cmp__, action __str__ and manifest loading could all be faster
Dan Price <dp@eng.sun.com>
parents: 313
diff changeset
   927
                                yield f
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   928
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   929
        def strtofmri(self, myfmri):
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   930
                ret = pkg.fmri.PkgFmri(myfmri, 
331
4f332d6b4036 1266 Client loses track of authority preference, chaos ensues
johansen <johansen@sun.com>
parents: 329
diff changeset
   931
                    self.attrs["Build-Release"])
4f332d6b4036 1266 Client loses track of authority preference, chaos ensues
johansen <johansen@sun.com>
parents: 329
diff changeset
   932
                    
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   933
                return ret
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   934
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   935
        def update_optional_dependency(self, inputfmri):
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   936
                """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
   937
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   938
                myfmri = inputfmri
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   939
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   940
                if isinstance(myfmri, str):
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   941
                        name = pkg.fmri.extract_pkg_name(myfmri)
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   942
                        myfmri = self.strtofmri(myfmri)
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   943
                else:
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   944
                        name = myfmri.get_name()
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   945
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   946
                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
   947
                if not ofmri or self.fmri_is_successor(myfmri, ofmri):
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   948
                               self.optional_dependencies[name] = myfmri
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   949
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   950
        def apply_optional_dependencies(self, myfmri):
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   951
                """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
   952
                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
   953
                unversioned fmris are returned upgraded"""
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   954
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   955
                if isinstance(myfmri, str):
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   956
                        name = pkg.fmri.extract_pkg_name(myfmri)
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   957
                        myfmri = self.strtofmri(myfmri)
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   958
                else:
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   959
                        name = myfmri.get_name()
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   960
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   961
                minfmri = self.optional_dependencies.get(name, None)
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   962
                if not minfmri:
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   963
                        return myfmri
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   964
316
d6ba58c63264 1039 circular dependency in packages is detected at install-time
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 315
diff changeset
   965
                if self.fmri_is_successor(minfmri, myfmri):
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   966
                        return minfmri
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   967
                return myfmri
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   968
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   969
        def load_optional_dependencies(self):
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   970
                for fmri in self.gen_installed_pkgs():
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   971
                        deps = self.get_manifest(fmri, filtered = True).get_dependencies()
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   972
                        for required, min_fmri, max_fmri in deps:
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   973
                                if required == False:
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   974
                                        self.update_optional_dependency(min_fmri)
195
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   975
289
c2e63370fb2b 160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents: 285
diff changeset
   976
        def get_user_by_name(self, name):
c2e63370fb2b 160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents: 285
diff changeset
   977
                return portable.get_user_by_name(name, self.root, 
c2e63370fb2b 160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents: 285
diff changeset
   978
                                                 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
   979
339
d8e57580599b 1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
   980
        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
   981
                # 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
   982
                try:
d8e57580599b 1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
   983
                        return portable.get_name_by_uid(uid, self.root, 
d8e57580599b 1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
   984
                            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
   985
                except KeyError:
d8e57580599b 1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
   986
                        if returnuid:
d8e57580599b 1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
   987
                                return uid
d8e57580599b 1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
   988
                        else:
d8e57580599b 1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
   989
                                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
   990
289
c2e63370fb2b 160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents: 285
diff changeset
   991
        def get_group_by_name(self, name):
c2e63370fb2b 160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents: 285
diff changeset
   992
                return portable.get_group_by_name(name, self.root, 
c2e63370fb2b 160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents: 285
diff changeset
   993
                                                  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
   994
339
d8e57580599b 1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
   995
        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
   996
                try:
d8e57580599b 1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
   997
                        return portable.get_name_by_gid(gid, self.root, 
d8e57580599b 1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
   998
                            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
   999
                except KeyError:
d8e57580599b 1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  1000
                        if returngid:
d8e57580599b 1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  1001
                                return gid
d8e57580599b 1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  1002
                        else:
d8e57580599b 1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  1003
                                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
  1004
219
f303ff108edd 60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents: 215
diff changeset
  1005
        def gen_inventory(self, patterns, all_known=False):
f303ff108edd 60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents: 215
diff changeset
  1006
                """Iterating the package inventory, yielding per-package info.
59
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
  1007
219
f303ff108edd 60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents: 215
diff changeset
  1008
                Yielded data are of the form package,dict, where dict is:
f303ff108edd 60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents: 215
diff changeset
  1009
                  state  : package installation state
f303ff108edd 60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents: 215
diff changeset
  1010
                  frozen,
f303ff108edd 60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents: 215
diff changeset
  1011
                  incorporated,
f303ff108edd 60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents: 215
diff changeset
  1012
                  excludes,
f303ff108edd 60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents: 215
diff changeset
  1013
                  upgradable : Booleans indicating the aforementioned flags.
f303ff108edd 60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents: 215
diff changeset
  1014
                """
f303ff108edd 60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents: 215
diff changeset
  1015
                pkgs_known = []
f303ff108edd 60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents: 215
diff changeset
  1016
                badpats = []
59
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
  1017
219
f303ff108edd 60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents: 215
diff changeset
  1018
                if patterns:
f303ff108edd 60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents: 215
diff changeset
  1019
                        for p in patterns:
f303ff108edd 60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents: 215
diff changeset
  1020
                                try:
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1021
                                        # XXX dp: not sure if this is
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1022
                                        # right with respect to the code
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1023
                                        # 6 or 7 lines further below.
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1024
                                        for m in self.get_matching_fmris(p):
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1025
                                                if all_known or self.is_installed(m):
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1026
                                                        pkgs_known.extend([ m ])
219
f303ff108edd 60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents: 215
diff changeset
  1027
                                except KeyError:
f303ff108edd 60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents: 215
diff changeset
  1028
                                        badpats.append(p)
221
e1dbb27a23b5 52 catalog can leave inventory behind, making pkg(1) blind
Stephen Hahn <sch@Sun.COM>
parents: 219
diff changeset
  1029
e1dbb27a23b5 52 catalog can leave inventory behind, making pkg(1) blind
Stephen Hahn <sch@Sun.COM>
parents: 219
diff changeset
  1030
                        pkgs_known.extend(
e1dbb27a23b5 52 catalog can leave inventory behind, making pkg(1) blind
Stephen Hahn <sch@Sun.COM>
parents: 219
diff changeset
  1031
                                [ x for x in self.gen_installed_pkgs()
e1dbb27a23b5 52 catalog can leave inventory behind, making pkg(1) blind
Stephen Hahn <sch@Sun.COM>
parents: 219
diff changeset
  1032
                                for p in patterns
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1033
                                if pkg.fmri.fmri_match(x.get_pkg_stem(), p)
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
  1034
                                and not x in pkgs_known ] )
104
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
  1035
                else:
221
e1dbb27a23b5 52 catalog can leave inventory behind, making pkg(1) blind
Stephen Hahn <sch@Sun.COM>
parents: 219
diff changeset
  1036
                        pkgs_known = sorted(self.gen_installed_pkgs())
104
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
  1037
329
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
  1038
		counthash = {}
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
  1039
		if pkgs_known:
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
  1040
			#
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
  1041
			# Walk the installed packages looking for those
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
  1042
			# which have upgrades available.
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
  1043
			#
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
  1044
			self.get_matching_fmris(pkgs_known,
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
  1045
			    counthash = counthash)
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
  1046
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
  1047
		#
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
  1048
		# If needed, merge in the rest of the known packages; we don't	
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
  1049
		# compute upgradability for those, since it's very expensive.
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
  1050
		#
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
  1051
		if all_known and not patterns:
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
  1052
                        pkgs_all_known = [ pf for pf in
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
  1053
                            self.gen_known_package_fmris() ]
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
  1054
			pkgs_known += pkgs_all_known
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
  1055
			pkgs_known = sorted(set(pkgs_known))
161
e0322fe7842c Simplify and correct the package matching code.
Danek Duvall <danek.duvall@sun.com>
parents: 157
diff changeset
  1056
104
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
  1057
                for p in pkgs_known:
329
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
  1058
                        if counthash.get(p, 0) > 1:
219
f303ff108edd 60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents: 215
diff changeset
  1059
                                upgradable = True
f303ff108edd 60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents: 215
diff changeset
  1060
                        else:
f303ff108edd 60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents: 215
diff changeset
  1061
                                upgradable = False
f303ff108edd 60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents: 215
diff changeset
  1062
                        inventory = {
f303ff108edd 60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents: 215
diff changeset
  1063
                                "state": self.get_pkg_state_by_fmri(p),
f303ff108edd 60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents: 215
diff changeset
  1064
                                "frozen": False,
f303ff108edd 60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents: 215
diff changeset
  1065
                                "incorporated": False,
f303ff108edd 60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents: 215
diff changeset
  1066
                                "excludes": False,
f303ff108edd 60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents: 215
diff changeset
  1067
                                "upgradable": upgradable}
f303ff108edd 60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents: 215
diff changeset
  1068
                        yield p, inventory
59
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
  1069
219
f303ff108edd 60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents: 215
diff changeset
  1070
                if badpats:
f303ff108edd 60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents: 215
diff changeset
  1071
                        raise RuntimeError, badpats
59
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
  1072
204
8f650d596aec 72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents: 201
diff changeset
  1073
        def local_search(self, args):
144
ce619e0b453f Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents: 139
diff changeset
  1074
                """Search the image for the token in args[0]."""
ce619e0b453f Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents: 139
diff changeset
  1075
                idxdir = os.path.join(self.imgdir, "pkg")
ce619e0b453f Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents: 139
diff changeset
  1076
ce619e0b453f Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents: 139
diff changeset
  1077
                # Convert a full directory path to the FMRI it represents.
ce619e0b453f Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents: 139
diff changeset
  1078
                def idx_to_fmri(index):
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1079
                        return pkg.fmri.PkgFmri(urllib.unquote(os.path.dirname(
190
ca8aa1e0e90d 53 pkg search separates package name from version with "/", not "@"
Danek Duvall <danek.duvall@sun.com>
parents: 183
diff changeset
  1080
                            index[len(idxdir) + 1:]).replace("/", "@")), None)
144
ce619e0b453f Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents: 139
diff changeset
  1081
ce619e0b453f Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents: 139
diff changeset
  1082
                indices = (
ce619e0b453f Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents: 139
diff changeset
  1083
                    (os.path.join(dir, "index"), os.path.join(dir, "manifest"))
ce619e0b453f Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents: 139
diff changeset
  1084
                    for dir, dirnames, filenames in os.walk(idxdir)
163
eeacdf67f937 search only installed packages, and don't complain about unwriteable indices
Danek Duvall <danek.duvall@sun.com>
parents: 161
diff changeset
  1085
                    if "manifest" in filenames and "installed" in filenames
144
ce619e0b453f Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents: 139
diff changeset
  1086
                )
ce619e0b453f Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents: 139
diff changeset
  1087
ce619e0b453f Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents: 139
diff changeset
  1088
                for index, mfst in indices:
ce619e0b453f Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents: 139
diff changeset
  1089
                        # Try loading the index; if that fails, try parsing the
ce619e0b453f Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents: 139
diff changeset
  1090
                        # manifest.
ce619e0b453f Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents: 139
diff changeset
  1091
                        try:
ce619e0b453f Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents: 139
diff changeset
  1092
                                d = cPickle.load(file(index))
ce619e0b453f Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents: 139
diff changeset
  1093
                        except:
ce619e0b453f Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents: 139
diff changeset
  1094
                                m = manifest.Manifest()
ce619e0b453f Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents: 139
diff changeset
  1095
                                try:
ce619e0b453f Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents: 139
diff changeset
  1096
                                        mcontent = file(mfst).read()
ce619e0b453f Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents: 139
diff changeset
  1097
                                except:
ce619e0b453f Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents: 139
diff changeset
  1098
                                        # XXX log something?
ce619e0b453f Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents: 139
diff changeset
  1099
                                        continue
ce619e0b453f Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents: 139
diff changeset
  1100
                                m.set_content(mcontent)
ce619e0b453f Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents: 139
diff changeset
  1101
                                try:
ce619e0b453f Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents: 139
diff changeset
  1102
                                        m.pickle(file(index, "wb"))
ce619e0b453f Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents: 139
diff changeset
  1103
                                except:
ce619e0b453f Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents: 139
diff changeset
  1104
                                        pass
ce619e0b453f Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents: 139
diff changeset
  1105
                                d = m.search_dict()
ce619e0b453f Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents: 139
diff changeset
  1106
ce619e0b453f Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents: 139
diff changeset
  1107
                        for k, v in d.items():
ce619e0b453f Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents: 139
diff changeset
  1108
                                if args[0] in v:
302
a5268194080e 981 pkg search could have more useful output
Danek Duvall <danek.duvall@sun.com>
parents: 301
diff changeset
  1109
                                        # Yield the index name (such as
a5268194080e 981 pkg search could have more useful output
Danek Duvall <danek.duvall@sun.com>
parents: 301
diff changeset
  1110
                                        # "basename", the fmri, and then
a5268194080e 981 pkg search could have more useful output
Danek Duvall <danek.duvall@sun.com>
parents: 301
diff changeset
  1111
                                        # the "match results" which
a5268194080e 981 pkg search could have more useful output
Danek Duvall <danek.duvall@sun.com>
parents: 301
diff changeset
  1112
                                        # include the action name and
a5268194080e 981 pkg search could have more useful output
Danek Duvall <danek.duvall@sun.com>
parents: 301
diff changeset
  1113
                                        # the value of the key attribute
a5268194080e 981 pkg search could have more useful output
Danek Duvall <danek.duvall@sun.com>
parents: 301
diff changeset
  1114
                                        try:
a5268194080e 981 pkg search could have more useful output
Danek Duvall <danek.duvall@sun.com>
parents: 301
diff changeset
  1115
                                                yield k, idx_to_fmri(index), \
a5268194080e 981 pkg search could have more useful output
Danek Duvall <danek.duvall@sun.com>
parents: 301
diff changeset
  1116
                                                    v[args[0]][0], v[args[0]][1]
a5268194080e 981 pkg search could have more useful output
Danek Duvall <danek.duvall@sun.com>
parents: 301
diff changeset
  1117
                                        except TypeError:
a5268194080e 981 pkg search could have more useful output
Danek Duvall <danek.duvall@sun.com>
parents: 301
diff changeset
  1118
                                                yield k, idx_to_fmri(index), \
a5268194080e 981 pkg search could have more useful output
Danek Duvall <danek.duvall@sun.com>
parents: 301
diff changeset
  1119
                                                    "", ""
144
ce619e0b453f Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents: 139
diff changeset
  1120
204
8f650d596aec 72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents: 201
diff changeset
  1121
        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
  1122
                """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
  1123
                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
  1124
                failed = []
8f650d596aec 72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents: 201
diff changeset
  1125
8f650d596aec 72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents: 201
diff changeset
  1126
                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
  1127
                        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
  1128
8f650d596aec 72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents: 201
diff changeset
  1129
                for auth in servers:
322
e1b078577730 1101 pkg search -s <server> returns a traceback
Danek Duvall <danek.duvall@sun.com>
parents: 319
diff changeset
  1130
                        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
  1131
                            authority = auth.get("prefix", None),
e1b078577730 1101 pkg search -s <server> returns a traceback
Danek Duvall <danek.duvall@sun.com>
parents: 319
diff changeset
  1132
                            origin = auth["origin"])
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
  1133
204
8f650d596aec 72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents: 201
diff changeset
  1134
                        try:
8f650d596aec 72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents: 201
diff changeset
  1135
                                res, v = versioned_urlopen(auth["origin"],
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
  1136
                                    "search", [0], urllib.quote(args[0], ""),
319
39b8b5c538bf 1104 want custom user-agent string
Danek Duvall <danek.duvall@sun.com>
parents: 316
diff changeset
  1137
                                     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
  1138
                        except urllib2.HTTPError, e:
260
a1b77322abb2 255 Symbolic HTTP response codes should be used
Shawn Walker <swalker@opensolaris.org>
parents: 259
diff changeset
  1139
                                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
  1140
                                        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
  1141
                                continue
8f650d596aec 72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents: 201
diff changeset
  1142
                        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
  1143
                                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
  1144
                                continue
8f650d596aec 72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents: 201
diff changeset
  1145
8f650d596aec 72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents: 201
diff changeset
  1146
                        for l in res.read().splitlines():
302
a5268194080e 981 pkg search could have more useful output
Danek Duvall <danek.duvall@sun.com>
parents: 301
diff changeset
  1147
                                fields = l.split()
a5268194080e 981 pkg search could have more useful output
Danek Duvall <danek.duvall@sun.com>
parents: 301
diff changeset
  1148
                                if len(fields) < 4:
a5268194080e 981 pkg search could have more useful output
Danek Duvall <danek.duvall@sun.com>
parents: 301
diff changeset
  1149
                                       yield fields[:2] + [ "", "" ]
a5268194080e 981 pkg search could have more useful output
Danek Duvall <danek.duvall@sun.com>
parents: 301
diff changeset
  1150
                                else:
a5268194080e 981 pkg search could have more useful output
Danek Duvall <danek.duvall@sun.com>
parents: 301
diff changeset
  1151
                                       yield fields[:4]
204
8f650d596aec 72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents: 201
diff changeset
  1152
                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
  1153
                        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
  1154
251
6c3d70b74865 470 pkg image-update can fail under some conditions
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 243
diff changeset
  1155
        def get_download_dir(self):
6c3d70b74865 470 pkg image-update can fail under some conditions
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 243
diff changeset
  1156
                return os.path.normpath(os.path.join(
6c3d70b74865 470 pkg image-update can fail under some conditions
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 243
diff changeset
  1157
                                self.imgdir,
271
ec8a7669bff2 659 package that delivers existing automounter mountpoint fails installation
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 268
diff changeset
  1158
                                "download",
251
6c3d70b74865 470 pkg image-update can fail under some conditions
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 243
diff changeset
  1159
                                str(os.getpid())))
6c3d70b74865 470 pkg image-update can fail under some conditions
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 243
diff changeset
  1160
6c3d70b74865 470 pkg image-update can fail under some conditions
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 243
diff changeset
  1161
        def cleanup_downloads(self):
6c3d70b74865 470 pkg image-update can fail under some conditions
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 243
diff changeset
  1162
                shutil.rmtree(self.get_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
  1163
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1164
        def salvagedir(self, path):
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1165
                """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
  1166
                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
  1167
                passback mechanism. Path is rooted in /...."""
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1168
                
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1169
                salvagedir = os.path.normpath(
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1170
                    os.path.join(self.imgdir, "lost+found",
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1171
                                 path + "-" + time.strftime("%Y-%m-%d+%H:%M:%S")))        
289
c2e63370fb2b 160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents: 285
diff changeset
  1172
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1173
                os.makedirs(salvagedir)
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1174
                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
  1175
                # XXX need a better way to do this.
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1176
                print >> sys.stderr, \
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1177
                    "\nWarning - directory %s not empty - contents preserved in %s" % \
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1178
                    (path, salvagedir)
251
6c3d70b74865 470 pkg image-update can fail under some conditions
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 243
diff changeset
  1179
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1180
        def expanddirs(self, dirs):
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1181
                """ given a set of directories, return expanded set that includes 
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1182
                all components"""
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1183
                out = set()
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1184
                for d in dirs:
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1185
                        p = d
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1186
                        while p != "":
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1187
                                out.add(p)
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1188
                                p = os.path.dirname(p)
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1189
                return out
329
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
  1190
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
  1191
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
  1192
        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
  1193
            verbose = False, noexecute = False):
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1194
                """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
  1195
                to assemble an appropriate image plan.  This is a helper
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
  1196
		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
  1197
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1198
                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
  1199
                however, it defaults to choosing the preferred authority
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1200
                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
  1201
                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
  1202
                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
  1203
                to name the package."""
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1204
172
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  1205
                error = 0
235
61994d15c39b 373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents: 226
diff changeset
  1206
                ip = imageplan.ImagePlan(self, progress, filters = filters)
172
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  1207
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1208
                self.load_optional_dependencies()
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1209
172
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  1210
                for p in pkg_list:
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  1211
                        try:
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1212
                                conp = self.apply_optional_dependencies(p)
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1213
                                matches = self.get_matching_fmris(conp,
175
8d591677690b 22 Specifying a version on the "pkg install" commandline makes no difference
Danek Duvall <danek.duvall@sun.com>
parents: 173
diff changeset
  1214
                                    constraint = version.CONSTRAINT_AUTO)
172
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  1215
                        except KeyError:
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  1216
                                # XXX Module directly printing.
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  1217
                                print _("""\
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  1218
pkg: no package matching '%s' could be found in current catalog
175
8d591677690b 22 Specifying a version on the "pkg install" commandline makes no difference
Danek Duvall <danek.duvall@sun.com>
parents: 173
diff changeset
  1219
     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
  1220
                                error = 1
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  1221
                                continue
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  1222
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  1223
                        pnames = {}
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1224
                        pmatch = []
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1225
                        npnames = {}
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1226
                        npmatch = []
172
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  1227
                        for m in matches:
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1228
                                if m.preferred_authority():
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1229
                                        pnames[m.get_pkg_stem()] = 1
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1230
                                        pmatch.append(m)
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1231
                                else:
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1232
                                        npnames[m.get_pkg_stem()] = 1
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1233
                                        npmatch.append(m)
172
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  1234
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  1235
                        if len(pnames.keys()) > 1:
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  1236
                                # XXX Module directly printing.
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  1237
                                print \
175
8d591677690b 22 Specifying a version on the "pkg install" commandline makes no difference
Danek Duvall <danek.duvall@sun.com>
parents: 173
diff changeset
  1238
                                    _("pkg: '%s' matches multiple packages") % p
172
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  1239
                                for k in pnames.keys():
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  1240
                                        print "\t%s" % k
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  1241
                                error = 1
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  1242
                                continue
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1243
                        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
  1244
                                # XXX Module directly printing.
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1245
                                print \
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1246
                                    _("pkg: '%s' matches multiple packages") % p
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1247
                                for k in npnames.keys():
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1248
                                        print "\t%s" % k
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1249
                                error = 1
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1250
                                continue
172
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  1251
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  1252
                        # 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
  1253
                        # the first; i.e., the latest.
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1254
                        if len(pmatch) > 0:
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1255
                                ip.propose_fmri(pmatch[0])
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1256
                        else:
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1257
                                ip.propose_fmri(npmatch[0]) 
172
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  1258
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  1259
                if error != 0:
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  1260
                        raise RuntimeError, "Unable to assemble image plan"
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  1261
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  1262
                if verbose:
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  1263
                        print _("Before evaluation:")
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  1264
                        print ip
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  1265
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  1266
                ip.evaluate()
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1267
                self.imageplan = ip 
172
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  1268
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  1269
                if verbose:
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  1270
                        print _("After evaluation:")
329
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
  1271
                        print ip.display()
45
8a3f00dea14f catalog refresh; basic catalog listing; precise manifest pulls
Stephen Hahn <sch@sun.com>
parents: 39
diff changeset
  1272
50
bfcb1661f019 basic image and package plans
Stephen Hahn <sch@sun.com>
parents: 45
diff changeset
  1273
if __name__ == "__main__":
bfcb1661f019 basic image and package plans
Stephen Hahn <sch@sun.com>
parents: 45
diff changeset
  1274
        pass