src/modules/client/image.py
author Danek Duvall <danek.duvall@sun.com>
Thu, 17 Apr 2008 19:03:51 -0700
changeset 341 42383445191b
parent 340 5367cc80f90d
child 342 5e1f4d8429bf
permissions -rw-r--r--
1144 "pkg list -as" fails when unable to write to the pkg directory
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
341
42383445191b 1144 "pkg list -as" fails when unable to write to the pkg directory
Danek Duvall <danek.duvall@sun.com>
parents: 340
diff changeset
   476
                try:
42383445191b 1144 "pkg list -as" fails when unable to write to the pkg directory
Danek Duvall <danek.duvall@sun.com>
parents: 340
diff changeset
   477
                        m.store(mpath, ipath)
42383445191b 1144 "pkg list -as" fails when unable to write to the pkg directory
Danek Duvall <danek.duvall@sun.com>
parents: 340
diff changeset
   478
                except OSError, e:
42383445191b 1144 "pkg list -as" fails when unable to write to the pkg directory
Danek Duvall <danek.duvall@sun.com>
parents: 340
diff changeset
   479
                        if e.errno not in (errno.EROFS, errno.EACCES):
42383445191b 1144 "pkg list -as" fails when unable to write to the pkg directory
Danek Duvall <danek.duvall@sun.com>
parents: 340
diff changeset
   480
                                raise
144
ce619e0b453f Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents: 139
diff changeset
   481
50
bfcb1661f019 basic image and package plans
Stephen Hahn <sch@sun.com>
parents: 45
diff changeset
   482
                return m
45
8a3f00dea14f catalog refresh; basic catalog listing; precise manifest pulls
Stephen Hahn <sch@sun.com>
parents: 39
diff changeset
   483
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   484
        def _valid_manifest(self, fmri, manifest):
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   485
                """Check authority attached to manifest.  Make sure
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   486
                it matches authority specified in FMRI."""
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
                authority = fmri.get_authority()
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   489
                if not authority:
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   490
                        authority = self.get_default_authority()
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   491
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   492
                if not "authority" in manifest:
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   493
                        return False
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   494
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   495
                if manifest["authority"] != authority:
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   496
                        return False
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   497
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   498
                return True
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
        def get_manifest(self, fmri, filtered = False):
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   501
                """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
   502
                object, applying appropriate filters as needed."""
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   503
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   504
                m = manifest.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
                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
   507
                    fmri.get_dir_path())
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   508
                mpath = os.path.join(fmri_dir_path, "manifest")
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   509
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   510
                # If the manifest isn't there, download.
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   511
                if not os.path.exists(mpath):
329
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
   512
                        m = self._fetch_manifest(fmri)
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   513
                else:
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   514
                        mcontent = file(mpath).read()
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   515
                        m.set_fmri(self, fmri)
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   516
                        m.set_content(mcontent)
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   517
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   518
                # 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
   519
                # 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
   520
                if not self._valid_manifest(fmri, m):
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   521
                        try:
329
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
   522
                                m = self._fetch_manifest(fmri)
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   523
                        except NameError:
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   524
                                # In thise case, the client has failed to
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   525
                                # download a new manifest with the same name.
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   526
                                # 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
   527
                                # 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
   528
                                # 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
   529
                                pass
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   530
329
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
   531
		# 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
   532
                if filtered:
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
   533
			filters = []
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
   534
			try:
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
   535
				f = file("%s/filters" % fmri_dir_path, "r")
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
   536
			except IOError, e:
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
   537
				if e.errno != errno.ENOENT:
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
   538
					raise
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
   539
			else:
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
   540
				filters = [
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
   541
				    (l.strip(), compile(
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
   542
					l.strip(), "<filter string>", "eval"))
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
   543
				    for l in f.readlines()
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
   544
				]
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
   545
			m.filter(filters)
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
   546
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   547
                return m
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   548
331
4f332d6b4036 1266 Client loses track of authority preference, chaos ensues
johansen <johansen@sun.com>
parents: 329
diff changeset
   549
        def installed_file_authority(self, filepath):
195
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   550
                """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
   551
                Return the authority that installed this package."""
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   552
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   553
                read_only = False
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   554
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   555
                try:
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   556
                        f = file(filepath, "r+")
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   557
                except IOError, e:
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   558
                        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
   559
                                read_only = True
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   560
                        else:
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   561
                                raise
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   562
                if read_only:
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   563
                        f = file(filepath, "r")
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   564
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   565
                flines = f.readlines()
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   566
                newauth = None
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   567
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   568
                try:
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   569
                        version, auth = flines
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   570
                except ValueError:
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   571
                        # 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
   572
                        # 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
   573
                        # 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
   574
                        # to assume that the package was installed from
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   575
                        # the preferred authority.  Here, we set up
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   576
                        # the authority to record that.
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   577
                        auth = flines[0]
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   578
                        auth = auth.strip()
313
c4d18a029dfd 761 'import timedanek' in subprocess_method.py's __main__
Danek Duvall <danek.duvall@sun.com>
parents: 310
diff changeset
   579
                        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
   580
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   581
                if newauth and not read_only:
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   582
                        # This is where we actually update the installed
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   583
                        # file with the new authority.
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   584
                        f.seek(0)
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   585
                        f.writelines(["VERSION_1\n", newauth])
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   586
                        auth = newauth
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   587
195
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   588
                f.close()
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   589
331
4f332d6b4036 1266 Client loses track of authority preference, chaos ensues
johansen <johansen@sun.com>
parents: 329
diff changeset
   590
                if not auth:
4f332d6b4036 1266 Client loses track of authority preference, chaos ensues
johansen <johansen@sun.com>
parents: 329
diff changeset
   591
                        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
   592
                            self.get_default_authority())
4f332d6b4036 1266 Client loses track of authority preference, chaos ensues
johansen <johansen@sun.com>
parents: 329
diff changeset
   593
195
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   594
                return auth
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
        def install_file_present(self, fmri):
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   597
                """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
   598
                on the system.  Otherwise, returns false."""
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   599
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   600
                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
   601
                    fmri.get_dir_path()))
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   602
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   603
        def add_install_file(self, fmri):
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   604
                """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
   605
                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
   606
                installed."""
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   607
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   608
                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
   609
                    fmri.get_dir_path()), "w")
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   610
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   611
                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
   612
                f.close()
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   613
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   614
        def remove_install_file(self, fmri):
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   615
                """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
   616
                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
   617
                installed."""
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   618
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   619
                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
   620
                    fmri.get_dir_path()))
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   621
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   622
        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
   623
                pd = pfmri.get_pkg_stem()
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
   624
                pdir = "%s/pkg/%s" % (self.imgdir,
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
   625
                    pfmri.get_dir_path(stemonly = True))
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
   626
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
   627
                try:
195
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   628
                        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
   629
                            "%s/%s/installed" % (pdir, vd))
59
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
   630
                            for vd in os.listdir(pdir)
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
   631
                            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
   632
                except OSError:
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   633
                        return None
59
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
   634
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
   635
                if len(pkgs_inst) == 0:
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   636
                        return None
59
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
   637
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
   638
                assert len(pkgs_inst) <= 1
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
   639
195
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   640
                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
   641
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   642
                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
   643
104
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   644
        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
   645
                """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
   646
195
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   647
                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
   648
                        return "installed"
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   649
106
ed11fcd45545 pkg status -a; allow trailing / in URL; don't write 404 into manifest;
"Stephen Hahn <sch@sun.com>"
parents: 104
diff changeset
   650
                return "known"
104
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   651
195
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   652
        def fmri_set_default_authority(self, fmri):
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   653
                """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
   654
                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
   655
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   656
                if fmri.has_authority():
195
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   657
                        return
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   658
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   659
                fmri.set_authority(self.get_default_authority(), True)
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
        def get_catalog(self, fmri, exception = False):
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   662
                """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
   663
                correct catalog for this image."""
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   664
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   665
                # 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
   666
                # then return the catalog for the preferred authority
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   667
                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
   668
                        cat = self.catalogs[self.get_default_authority()]
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   669
                else:
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   670
                        try:
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   671
                                cat = self.catalogs[fmri.get_authority()]
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   672
                        except KeyError:
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   673
                                # If the authority that installed this package
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   674
                                # has vanished, pick the default authority
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   675
                                # instead.
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   676
                                if exception:
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   677
                                        raise
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   678
                                else:
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   679
                                        cat = self.catalogs[\
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   680
                                            self.get_default_authority()]
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   681
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   682
                return cat
195
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   683
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
   684
        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
   685
                """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
   686
                installed in the current image."""
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   687
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   688
                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
   689
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   690
                if v and not fmri.has_authority():
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   691
                        fmri.set_authority(v.get_authority_str())
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   692
                elif not fmri.has_authority():
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   693
                        fmri.set_authority(self.get_default_authority(), True)
266
5e5bff6fedce 582 Importing packages seemingly misrecords dependencies
johansen <johansen@sun.com>
parents: 260
diff changeset
   694
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   695
                if v and self.fmri_is_successor(v, fmri):
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   696
                        return True
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   697
                else:
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   698
                        try:
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   699
                                cat = self.get_catalog(fmri, exception = True)
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   700
                        except KeyError:
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   701
                                return False
59
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
   702
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   703
                        # 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
   704
                        # packages that are equivalent to fmri.
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   705
                        rpkgs = cat.rename_newer_pkgs(fmri)
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   706
                        for f in rpkgs:
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   707
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   708
                                v = self._get_version_installed(f)
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   709
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   710
                                if v and self.fmri_is_successor(v, fmri):
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   711
                                        return True
59
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
   712
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
   713
                return False
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
   714
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   715
        def older_version_installed(self, fmri):
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   716
                """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
   717
                older version of the package is installed.  This takes
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   718
                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
   719
                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
   720
                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
   721
                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
   722
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   723
                v = self._get_version_installed(fmri)
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   724
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   725
                assert fmri.has_authority()
268
3d53da66d4a4 582 Importing packages seemingly misrecords dependencies
johansen <johansen@sun.com>
parents: 266
diff changeset
   726
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   727
                if v:
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   728
                        return v
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   729
                else:
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   730
                        cat = self.get_catalog(fmri)
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   731
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   732
                        rpkgs = cat.rename_older_pkgs(fmri)
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   733
                        for f in rpkgs:
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   734
                                v = self._get_version_installed(f)
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   735
                                if v and self.fmri_is_successor(fmri, v):
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   736
                                        return v
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   737
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   738
                return None
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   739
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
   740
        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
   741
                """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
   742
                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
   743
195
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   744
                # 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
   745
                assert fmri.has_authority()
195
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   746
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   747
                v = self._get_version_installed(fmri)
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   748
                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
   749
                        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
   750
a1e20e9a9845 add CLI test suite, correct bugs found by test suite, ration out CLI options
Stephen Hahn <sch@Sun.COM>
parents: 116
diff changeset
   751
                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
   752
67
62c897652bbc Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents: 63
diff changeset
   753
        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
   754
                """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
   755
                FMRI."""
67
62c897652bbc Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents: 63
diff changeset
   756
62c897652bbc Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents: 63
diff changeset
   757
                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
   758
                    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
   759
62c897652bbc Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents: 63
diff changeset
   760
                if not os.path.isdir(thedir):
62c897652bbc Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents: 63
diff changeset
   761
                        return []
62c897652bbc Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents: 63
diff changeset
   762
62c897652bbc Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents: 63
diff changeset
   763
                for v in os.listdir(thedir):
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   764
                        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
   765
                            self.attrs["Build-Release"])
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   766
                        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
   767
                                dependents = [
62c897652bbc Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents: 63
diff changeset
   768
                                    urllib.unquote(d)
62c897652bbc Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents: 63
diff changeset
   769
                                    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
   770
                                    if os.path.exists(
1861fdf62519 on uninstall, don't complain about uninstalled dependents
Danek Duvall <danek.duvall@sun.com>
parents: 135
diff changeset
   771
                                        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
   772
                                ]
62c897652bbc Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents: 63
diff changeset
   773
62c897652bbc Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents: 63
diff changeset
   774
                return dependents
62c897652bbc Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents: 63
diff changeset
   775
215
c10719939c6d 245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents: 208
diff changeset
   776
        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
   777
                failed = []
63e78f600aa7 185 traceback on pkg refresh when hostname lookup fails
Danek Duvall <danek.duvall@sun.com>
parents: 195
diff changeset
   778
                total = 0
63e78f600aa7 185 traceback on pkg refresh when hostname lookup fails
Danek Duvall <danek.duvall@sun.com>
parents: 195
diff changeset
   779
                succeeded = 0
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   780
                cat = None
215
c10719939c6d 245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents: 208
diff changeset
   781
                ts = 0
201
63e78f600aa7 185 traceback on pkg refresh when hostname lookup fails
Danek Duvall <danek.duvall@sun.com>
parents: 195
diff changeset
   782
116
9c9942a52984 (image flag day) remove pkg catalog, improve pkg status, localize pkg(1), use
Stephen Hahn <sch@Sun.COM>
parents: 111
diff changeset
   783
                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
   784
                        total += 1
215
c10719939c6d 245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents: 208
diff changeset
   785
c10719939c6d 245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents: 208
diff changeset
   786
                        if auth["prefix"] in self.catalogs:
c10719939c6d 245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents: 208
diff changeset
   787
                                cat = self.catalogs[auth["prefix"]]
c10719939c6d 245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents: 208
diff changeset
   788
                                ts = cat.last_modified()
c10719939c6d 245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents: 208
diff changeset
   789
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   790
                                # Although we may have a catalog with a
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   791
                                # timestamp, the user may have changed the
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   792
                                # origin URL for the authority.  If this has
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   793
                                # occurred, we need to perform a full refresh.
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   794
                                if cat.origin() != auth["origin"]:
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   795
                                        full_refresh = True
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   796
215
c10719939c6d 245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents: 208
diff changeset
   797
                        if ts and not full_refresh:
c10719939c6d 245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents: 208
diff changeset
   798
                                hdr = {'If-Modified-Since': ts}
c10719939c6d 245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents: 208
diff changeset
   799
                        else:
c10719939c6d 245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents: 208
diff changeset
   800
                                hdr = {}
c10719939c6d 245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents: 208
diff changeset
   801
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   802
                        ssl_tuple = self.get_ssl_credentials(auth["prefix"])
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   803
116
9c9942a52984 (image flag day) remove pkg catalog, improve pkg status, localize pkg(1), use
Stephen Hahn <sch@Sun.COM>
parents: 111
diff changeset
   804
                        # 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
   805
                        try:
201
63e78f600aa7 185 traceback on pkg refresh when hostname lookup fails
Danek Duvall <danek.duvall@sun.com>
parents: 195
diff changeset
   806
                                c, v = versioned_urlopen(auth["origin"],
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   807
                                    "catalog", [0], ssl_creds = ssl_tuple,
319
39b8b5c538bf 1104 want custom user-agent string
Danek Duvall <danek.duvall@sun.com>
parents: 316
diff changeset
   808
                                    headers = hdr, imgtype = self.type)
215
c10719939c6d 245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents: 208
diff changeset
   809
                        except urllib2.HTTPError, e:
260
a1b77322abb2 255 Symbolic HTTP response codes should be used
Shawn Walker <swalker@opensolaris.org>
parents: 259
diff changeset
   810
                                # 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
   811
                                # to date
a1b77322abb2 255 Symbolic HTTP response codes should be used
Shawn Walker <swalker@opensolaris.org>
parents: 259
diff changeset
   812
                                if e.code == httplib.NOT_MODIFIED:
215
c10719939c6d 245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents: 208
diff changeset
   813
                                        succeeded += 1
c10719939c6d 245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents: 208
diff changeset
   814
                                else:
c10719939c6d 245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents: 208
diff changeset
   815
                                        failed.append((auth, e))
c10719939c6d 245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents: 208
diff changeset
   816
                                continue
c10719939c6d 245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents: 208
diff changeset
   817
201
63e78f600aa7 185 traceback on pkg refresh when hostname lookup fails
Danek Duvall <danek.duvall@sun.com>
parents: 195
diff changeset
   818
                        except urllib2.URLError, e:
63e78f600aa7 185 traceback on pkg refresh when hostname lookup fails
Danek Duvall <danek.duvall@sun.com>
parents: 195
diff changeset
   819
                                failed.append((auth, e))
63e78f600aa7 185 traceback on pkg refresh when hostname lookup fails
Danek Duvall <danek.duvall@sun.com>
parents: 195
diff changeset
   820
                                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
   821
                        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
   822
                                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
   823
                                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
   824
157
504b9e6d213c Catalog should be on-disk instead of in memory
johansen <johansen@sun.com>
parents: 146
diff changeset
   825
                        # root for this catalog
504b9e6d213c Catalog should be on-disk instead of in memory
johansen <johansen@sun.com>
parents: 146
diff changeset
   826
                        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
   827
201
63e78f600aa7 185 traceback on pkg refresh when hostname lookup fails
Danek Duvall <danek.duvall@sun.com>
parents: 195
diff changeset
   828
                        try:
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   829
                                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
   830
                        except IOError, e:
63e78f600aa7 185 traceback on pkg refresh when hostname lookup fails
Danek Duvall <danek.duvall@sun.com>
parents: 195
diff changeset
   831
                                failed.append((auth, e))
63e78f600aa7 185 traceback on pkg refresh when hostname lookup fails
Danek Duvall <danek.duvall@sun.com>
parents: 195
diff changeset
   832
                        else:
63e78f600aa7 185 traceback on pkg refresh when hostname lookup fails
Danek Duvall <danek.duvall@sun.com>
parents: 195
diff changeset
   833
                                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
   834
201
63e78f600aa7 185 traceback on pkg refresh when hostname lookup fails
Danek Duvall <danek.duvall@sun.com>
parents: 195
diff changeset
   835
                if failed:
63e78f600aa7 185 traceback on pkg refresh when hostname lookup fails
Danek Duvall <danek.duvall@sun.com>
parents: 195
diff changeset
   836
                        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
   837
235
61994d15c39b 373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents: 226
diff changeset
   838
        def load_catalogs(self, progresstracker):
157
504b9e6d213c Catalog should be on-disk instead of in memory
johansen <johansen@sun.com>
parents: 146
diff changeset
   839
                for auth in self.gen_authorities():
504b9e6d213c Catalog should be on-disk instead of in memory
johansen <johansen@sun.com>
parents: 146
diff changeset
   840
                        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
   841
                        progresstracker.catalog_start(auth["prefix"])
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   842
                        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
   843
                                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
   844
                                    auth["prefix"])
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   845
                                c = catalog.Catalog(croot, authority = authpfx)
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   846
                        else:
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   847
                                c = catalog.Catalog(croot,
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   848
                                    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
   849
                        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
   850
                        progresstracker.catalog_done()
59
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
   851
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   852
        def fmri_is_same_pkg(self, cfmri, pfmri):
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   853
                """Determine whether fmri and pfmri share the same package
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   854
                name, even if they're not equivalent versions.  This
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   855
                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
   856
                the same because of a rename operation."""
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 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
   859
                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
   860
                        return False
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   861
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   862
                # 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
   863
                # 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
   864
                # rename.
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   865
                if cfmri.is_same_pkg(pfmri):
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   866
                        return True
329
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
   867
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
   868
                # Get the catalog for the correct authority
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
   869
                cat = self.get_catalog(cfmri)
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
   870
		return cat.rename_is_same_pkg(cfmri, pfmri)
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
   871
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   872
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   873
        def fmri_is_successor(self, cfmri, pfmri):
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   874
                """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
   875
                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
   876
                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
   877
                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
   878
                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
   879
                routine from the catalog.  Otherwise, this runs the standard
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   880
                fmri.is_successor() code."""
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
                # 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
   883
                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
   884
                        return False
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   885
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   886
                # Get the catalog for the correct authority
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   887
                cat = self.get_catalog(cfmri)
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   888
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   889
                # 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
   890
                # 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
   891
                # rename.
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   892
                if cfmri.is_successor(pfmri):
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   893
                        return True
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   894
                else:
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   895
                        return cat.rename_is_successor(cfmri, pfmri)
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
   896
157
504b9e6d213c Catalog should be on-disk instead of in memory
johansen <johansen@sun.com>
parents: 146
diff changeset
   897
        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
   898
                """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
   899
                   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
   900
e1dbb27a23b5 52 catalog can leave inventory behind, making pkg(1) blind
Stephen Hahn <sch@Sun.COM>
parents: 219
diff changeset
   901
                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
   902
e1dbb27a23b5 52 catalog can leave inventory behind, making pkg(1) blind
Stephen Hahn <sch@Sun.COM>
parents: 219
diff changeset
   903
                # 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
   904
                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
   905
                        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
   906
                                if pf in li:
e1dbb27a23b5 52 catalog can leave inventory behind, making pkg(1) blind
Stephen Hahn <sch@Sun.COM>
parents: 219
diff changeset
   907
                                        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
   908
                                yield pf
59
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
   909
221
e1dbb27a23b5 52 catalog can leave inventory behind, making pkg(1) blind
Stephen Hahn <sch@Sun.COM>
parents: 219
diff changeset
   910
        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
   911
                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
   912
                        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
   913
                else:
989c801f050b 1076 action __cmp__, action __str__ and manifest loading could all be faster
Dan Price <dp@eng.sun.com>
parents: 313
diff changeset
   914
                        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
   915
989c801f050b 1076 action __cmp__, action __str__ and manifest loading could all be faster
Dan Price <dp@eng.sun.com>
parents: 313
diff changeset
   916
        def gen_installed_pkgs_forreal(self):
195
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   917
                proot = "%s/pkg" % self.imgdir
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   918
315
989c801f050b 1076 action __cmp__, action __str__ and manifest loading could all be faster
Dan Price <dp@eng.sun.com>
parents: 313
diff changeset
   919
                self.installed_pkg_cache = []
195
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   920
                for pd in sorted(os.listdir(proot)):
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   921
                        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
   922
                                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
   923
                                if not os.path.exists(path):
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   924
                                        continue
226
8939051a496c 376 image must use default authority when none specified
johansen <johansen@sun.com>
parents: 222
diff changeset
   925
331
4f332d6b4036 1266 Client loses track of authority preference, chaos ensues
johansen <johansen@sun.com>
parents: 329
diff changeset
   926
                                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
   927
                                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
   928
                                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
   929
315
989c801f050b 1076 action __cmp__, action __str__ and manifest loading could all be faster
Dan Price <dp@eng.sun.com>
parents: 313
diff changeset
   930
                                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
   931
                                yield f
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   932
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   933
        def strtofmri(self, myfmri):
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   934
                ret = pkg.fmri.PkgFmri(myfmri, 
331
4f332d6b4036 1266 Client loses track of authority preference, chaos ensues
johansen <johansen@sun.com>
parents: 329
diff changeset
   935
                    self.attrs["Build-Release"])
4f332d6b4036 1266 Client loses track of authority preference, chaos ensues
johansen <johansen@sun.com>
parents: 329
diff changeset
   936
                    
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   937
                return ret
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   938
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   939
        def update_optional_dependency(self, inputfmri):
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   940
                """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
   941
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   942
                myfmri = inputfmri
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   943
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   944
                if isinstance(myfmri, str):
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   945
                        name = pkg.fmri.extract_pkg_name(myfmri)
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   946
                        myfmri = self.strtofmri(myfmri)
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   947
                else:
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   948
                        name = myfmri.get_name()
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
                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
   951
                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
   952
                               self.optional_dependencies[name] = myfmri
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   953
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   954
        def apply_optional_dependencies(self, myfmri):
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   955
                """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
   956
                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
   957
                unversioned fmris are returned upgraded"""
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   958
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   959
                if isinstance(myfmri, str):
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   960
                        name = pkg.fmri.extract_pkg_name(myfmri)
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   961
                        myfmri = self.strtofmri(myfmri)
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   962
                else:
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   963
                        name = myfmri.get_name()
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   964
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   965
                minfmri = self.optional_dependencies.get(name, None)
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   966
                if not 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
316
d6ba58c63264 1039 circular dependency in packages is detected at install-time
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 315
diff changeset
   969
                if self.fmri_is_successor(minfmri, myfmri):
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   970
                        return minfmri
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   971
                return myfmri
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   972
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   973
        def load_optional_dependencies(self):
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   974
                for fmri in self.gen_installed_pkgs():
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   975
                        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
   976
                        for required, min_fmri, max_fmri in deps:
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   977
                                if required == False:
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   978
                                        self.update_optional_dependency(min_fmri)
195
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
   979
289
c2e63370fb2b 160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents: 285
diff changeset
   980
        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
   981
                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
   982
                                                 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
   983
339
d8e57580599b 1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
   984
        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
   985
                # 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
   986
                try:
d8e57580599b 1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
   987
                        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
   988
                            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
   989
                except KeyError:
d8e57580599b 1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
   990
                        if returnuid:
d8e57580599b 1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
   991
                                return uid
d8e57580599b 1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
   992
                        else:
d8e57580599b 1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
   993
                                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
   994
289
c2e63370fb2b 160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents: 285
diff changeset
   995
        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
   996
                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
   997
                                                  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
   998
339
d8e57580599b 1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
   999
        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
  1000
                try:
d8e57580599b 1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  1001
                        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
  1002
                            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
  1003
                except KeyError:
d8e57580599b 1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  1004
                        if returngid:
d8e57580599b 1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  1005
                                return gid
d8e57580599b 1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  1006
                        else:
d8e57580599b 1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  1007
                                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
  1008
219
f303ff108edd 60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents: 215
diff changeset
  1009
        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
  1010
                """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
  1011
219
f303ff108edd 60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents: 215
diff changeset
  1012
                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
  1013
                  state  : package installation state
f303ff108edd 60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents: 215
diff changeset
  1014
                  frozen,
f303ff108edd 60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents: 215
diff changeset
  1015
                  incorporated,
f303ff108edd 60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents: 215
diff changeset
  1016
                  excludes,
f303ff108edd 60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents: 215
diff changeset
  1017
                  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
  1018
                """
f303ff108edd 60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents: 215
diff changeset
  1019
                pkgs_known = []
f303ff108edd 60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents: 215
diff changeset
  1020
                badpats = []
59
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
  1021
219
f303ff108edd 60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents: 215
diff changeset
  1022
                if patterns:
f303ff108edd 60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents: 215
diff changeset
  1023
                        for p in patterns:
f303ff108edd 60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents: 215
diff changeset
  1024
                                try:
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1025
                                        # XXX dp: not sure if this is
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1026
                                        # right with respect to the code
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1027
                                        # 6 or 7 lines further below.
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1028
                                        for m in self.get_matching_fmris(p):
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1029
                                                if all_known or self.is_installed(m):
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1030
                                                        pkgs_known.extend([ m ])
219
f303ff108edd 60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents: 215
diff changeset
  1031
                                except KeyError:
f303ff108edd 60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents: 215
diff changeset
  1032
                                        badpats.append(p)
221
e1dbb27a23b5 52 catalog can leave inventory behind, making pkg(1) blind
Stephen Hahn <sch@Sun.COM>
parents: 219
diff changeset
  1033
e1dbb27a23b5 52 catalog can leave inventory behind, making pkg(1) blind
Stephen Hahn <sch@Sun.COM>
parents: 219
diff changeset
  1034
                        pkgs_known.extend(
e1dbb27a23b5 52 catalog can leave inventory behind, making pkg(1) blind
Stephen Hahn <sch@Sun.COM>
parents: 219
diff changeset
  1035
                                [ 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
  1036
                                for p in patterns
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1037
                                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
  1038
                                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
  1039
                else:
221
e1dbb27a23b5 52 catalog can leave inventory behind, making pkg(1) blind
Stephen Hahn <sch@Sun.COM>
parents: 219
diff changeset
  1040
                        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
  1041
329
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
  1042
		counthash = {}
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
  1043
		if pkgs_known:
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
  1044
			#
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
  1045
			# Walk the installed packages looking for those
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
  1046
			# which have upgrades available.
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
			self.get_matching_fmris(pkgs_known,
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
  1049
			    counthash = counthash)
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
		#
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
  1052
		# 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
  1053
		# compute upgradability for those, since it's very expensive.
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
  1054
		#
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
  1055
		if all_known and not patterns:
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
  1056
                        pkgs_all_known = [ pf for pf in
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
  1057
                            self.gen_known_package_fmris() ]
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
  1058
			pkgs_known += pkgs_all_known
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
  1059
			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
  1060
104
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
  1061
                for p in pkgs_known:
329
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
  1062
                        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
  1063
                                upgradable = True
f303ff108edd 60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents: 215
diff changeset
  1064
                        else:
f303ff108edd 60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents: 215
diff changeset
  1065
                                upgradable = False
f303ff108edd 60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents: 215
diff changeset
  1066
                        inventory = {
f303ff108edd 60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents: 215
diff changeset
  1067
                                "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
  1068
                                "frozen": False,
f303ff108edd 60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents: 215
diff changeset
  1069
                                "incorporated": False,
f303ff108edd 60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents: 215
diff changeset
  1070
                                "excludes": False,
f303ff108edd 60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents: 215
diff changeset
  1071
                                "upgradable": upgradable}
f303ff108edd 60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents: 215
diff changeset
  1072
                        yield p, inventory
59
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
  1073
219
f303ff108edd 60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents: 215
diff changeset
  1074
                if badpats:
f303ff108edd 60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents: 215
diff changeset
  1075
                        raise RuntimeError, badpats
59
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
  1076
204
8f650d596aec 72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents: 201
diff changeset
  1077
        def local_search(self, args):
144
ce619e0b453f Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents: 139
diff changeset
  1078
                """Search the image for the token in args[0]."""
ce619e0b453f Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents: 139
diff changeset
  1079
                idxdir = os.path.join(self.imgdir, "pkg")
ce619e0b453f Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents: 139
diff changeset
  1080
ce619e0b453f Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents: 139
diff changeset
  1081
                # 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
  1082
                def idx_to_fmri(index):
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1083
                        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
  1084
                            index[len(idxdir) + 1:]).replace("/", "@")), None)
144
ce619e0b453f Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents: 139
diff changeset
  1085
ce619e0b453f Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents: 139
diff changeset
  1086
                indices = (
ce619e0b453f Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents: 139
diff changeset
  1087
                    (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
  1088
                    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
  1089
                    if "manifest" in filenames and "installed" in filenames
144
ce619e0b453f Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents: 139
diff changeset
  1090
                )
ce619e0b453f Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents: 139
diff changeset
  1091
ce619e0b453f Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents: 139
diff changeset
  1092
                for index, mfst in indices:
ce619e0b453f Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents: 139
diff changeset
  1093
                        # 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
  1094
                        # 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
                                d = cPickle.load(file(index))
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
                                m = manifest.Manifest()
ce619e0b453f Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents: 139
diff changeset
  1099
                                try:
ce619e0b453f Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents: 139
diff changeset
  1100
                                        mcontent = file(mfst).read()
ce619e0b453f Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents: 139
diff changeset
  1101
                                except:
ce619e0b453f Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents: 139
diff changeset
  1102
                                        # XXX log something?
ce619e0b453f Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents: 139
diff changeset
  1103
                                        continue
ce619e0b453f Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents: 139
diff changeset
  1104
                                m.set_content(mcontent)
ce619e0b453f Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents: 139
diff changeset
  1105
                                try:
ce619e0b453f Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents: 139
diff changeset
  1106
                                        m.pickle(file(index, "wb"))
ce619e0b453f Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents: 139
diff changeset
  1107
                                except:
ce619e0b453f Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents: 139
diff changeset
  1108
                                        pass
ce619e0b453f Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents: 139
diff changeset
  1109
                                d = m.search_dict()
ce619e0b453f Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents: 139
diff changeset
  1110
ce619e0b453f Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents: 139
diff changeset
  1111
                        for k, v in d.items():
ce619e0b453f Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents: 139
diff changeset
  1112
                                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
  1113
                                        # 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
  1114
                                        # "basename", the fmri, and then
a5268194080e 981 pkg search could have more useful output
Danek Duvall <danek.duvall@sun.com>
parents: 301
diff changeset
  1115
                                        # the "match results" which
a5268194080e 981 pkg search could have more useful output
Danek Duvall <danek.duvall@sun.com>
parents: 301
diff changeset
  1116
                                        # include the action name and
a5268194080e 981 pkg search could have more useful output
Danek Duvall <danek.duvall@sun.com>
parents: 301
diff changeset
  1117
                                        # 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
  1118
                                        try:
a5268194080e 981 pkg search could have more useful output
Danek Duvall <danek.duvall@sun.com>
parents: 301
diff changeset
  1119
                                                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
  1120
                                                    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
  1121
                                        except TypeError:
a5268194080e 981 pkg search could have more useful output
Danek Duvall <danek.duvall@sun.com>
parents: 301
diff changeset
  1122
                                                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
  1123
                                                    "", ""
144
ce619e0b453f Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents: 139
diff changeset
  1124
204
8f650d596aec 72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents: 201
diff changeset
  1125
        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
  1126
                """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
  1127
                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
  1128
                failed = []
8f650d596aec 72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents: 201
diff changeset
  1129
8f650d596aec 72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents: 201
diff changeset
  1130
                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
  1131
                        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
  1132
8f650d596aec 72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents: 201
diff changeset
  1133
                for auth in servers:
322
e1b078577730 1101 pkg search -s <server> returns a traceback
Danek Duvall <danek.duvall@sun.com>
parents: 319
diff changeset
  1134
                        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
  1135
                            authority = auth.get("prefix", None),
e1b078577730 1101 pkg search -s <server> returns a traceback
Danek Duvall <danek.duvall@sun.com>
parents: 319
diff changeset
  1136
                            origin = auth["origin"])
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
  1137
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
                        try:
8f650d596aec 72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents: 201
diff changeset
  1139
                                res, v = versioned_urlopen(auth["origin"],
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
  1140
                                    "search", [0], urllib.quote(args[0], ""),
319
39b8b5c538bf 1104 want custom user-agent string
Danek Duvall <danek.duvall@sun.com>
parents: 316
diff changeset
  1141
                                     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
  1142
                        except urllib2.HTTPError, e:
260
a1b77322abb2 255 Symbolic HTTP response codes should be used
Shawn Walker <swalker@opensolaris.org>
parents: 259
diff changeset
  1143
                                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
  1144
                                        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
  1145
                                continue
8f650d596aec 72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents: 201
diff changeset
  1146
                        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
  1147
                                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
  1148
                                continue
8f650d596aec 72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents: 201
diff changeset
  1149
8f650d596aec 72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents: 201
diff changeset
  1150
                        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
  1151
                                fields = l.split()
a5268194080e 981 pkg search could have more useful output
Danek Duvall <danek.duvall@sun.com>
parents: 301
diff changeset
  1152
                                if len(fields) < 4:
a5268194080e 981 pkg search could have more useful output
Danek Duvall <danek.duvall@sun.com>
parents: 301
diff changeset
  1153
                                       yield fields[:2] + [ "", "" ]
a5268194080e 981 pkg search could have more useful output
Danek Duvall <danek.duvall@sun.com>
parents: 301
diff changeset
  1154
                                else:
a5268194080e 981 pkg search could have more useful output
Danek Duvall <danek.duvall@sun.com>
parents: 301
diff changeset
  1155
                                       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
  1156
                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
  1157
                        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
  1158
251
6c3d70b74865 470 pkg image-update can fail under some conditions
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 243
diff changeset
  1159
        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
  1160
                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
  1161
                                self.imgdir,
271
ec8a7669bff2 659 package that delivers existing automounter mountpoint fails installation
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 268
diff changeset
  1162
                                "download",
251
6c3d70b74865 470 pkg image-update can fail under some conditions
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 243
diff changeset
  1163
                                str(os.getpid())))
6c3d70b74865 470 pkg image-update can fail under some conditions
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 243
diff changeset
  1164
6c3d70b74865 470 pkg image-update can fail under some conditions
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 243
diff changeset
  1165
        def cleanup_downloads(self):
6c3d70b74865 470 pkg image-update can fail under some conditions
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 243
diff changeset
  1166
                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
  1167
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1168
        def salvagedir(self, path):
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1169
                """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
  1170
                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
  1171
                passback mechanism. Path is rooted in /...."""
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1172
                
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1173
                salvagedir = os.path.normpath(
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1174
                    os.path.join(self.imgdir, "lost+found",
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1175
                                 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
  1176
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1177
                os.makedirs(salvagedir)
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1178
                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
  1179
                # XXX need a better way to do this.
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1180
                print >> sys.stderr, \
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1181
                    "\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
  1182
                    (path, salvagedir)
251
6c3d70b74865 470 pkg image-update can fail under some conditions
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 243
diff changeset
  1183
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1184
        def expanddirs(self, dirs):
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1185
                """ 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
  1186
                all components"""
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1187
                out = set()
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1188
                for d in dirs:
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1189
                        p = d
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1190
                        while p != "":
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1191
                                out.add(p)
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1192
                                p = os.path.dirname(p)
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1193
                return out
329
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
  1194
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
  1195
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
  1196
        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
  1197
            verbose = False, noexecute = False):
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1198
                """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
  1199
                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
  1200
		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
  1201
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1202
                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
  1203
                however, it defaults to choosing the preferred authority
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1204
                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
  1205
                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
  1206
                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
  1207
                to name the package."""
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1208
172
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  1209
                error = 0
235
61994d15c39b 373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents: 226
diff changeset
  1210
                ip = imageplan.ImagePlan(self, progress, filters = filters)
172
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  1211
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1212
                self.load_optional_dependencies()
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1213
172
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  1214
                for p in pkg_list:
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  1215
                        try:
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1216
                                conp = self.apply_optional_dependencies(p)
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1217
                                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
  1218
                                    constraint = version.CONSTRAINT_AUTO)
172
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  1219
                        except KeyError:
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  1220
                                # XXX Module directly printing.
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  1221
                                print _("""\
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  1222
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
  1223
     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
  1224
                                error = 1
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  1225
                                continue
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  1226
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  1227
                        pnames = {}
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1228
                        pmatch = []
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1229
                        npnames = {}
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1230
                        npmatch = []
172
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  1231
                        for m in matches:
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1232
                                if m.preferred_authority():
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1233
                                        pnames[m.get_pkg_stem()] = 1
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1234
                                        pmatch.append(m)
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1235
                                else:
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1236
                                        npnames[m.get_pkg_stem()] = 1
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1237
                                        npmatch.append(m)
172
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  1238
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  1239
                        if len(pnames.keys()) > 1:
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  1240
                                # XXX Module directly printing.
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  1241
                                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
  1242
                                    _("pkg: '%s' matches multiple packages") % p
172
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  1243
                                for k in pnames.keys():
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  1244
                                        print "\t%s" % k
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  1245
                                error = 1
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  1246
                                continue
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1247
                        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
  1248
                                # XXX Module directly printing.
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1249
                                print \
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1250
                                    _("pkg: '%s' matches multiple packages") % p
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1251
                                for k in npnames.keys():
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1252
                                        print "\t%s" % k
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1253
                                error = 1
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1254
                                continue
172
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  1255
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  1256
                        # 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
  1257
                        # the first; i.e., the latest.
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1258
                        if len(pmatch) > 0:
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1259
                                ip.propose_fmri(pmatch[0])
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1260
                        else:
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1261
                                ip.propose_fmri(npmatch[0]) 
172
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  1262
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  1263
                if error != 0:
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  1264
                        raise RuntimeError, "Unable to assemble image plan"
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
                if verbose:
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  1267
                        print _("Before evaluation:")
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  1268
                        print ip
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  1269
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  1270
                ip.evaluate()
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1271
                self.imageplan = ip 
172
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  1272
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  1273
                if verbose:
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  1274
                        print _("After evaluation:")
329
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
  1275
                        print ip.display()
45
8a3f00dea14f catalog refresh; basic catalog listing; precise manifest pulls
Stephen Hahn <sch@sun.com>
parents: 39
diff changeset
  1276
50
bfcb1661f019 basic image and package plans
Stephen Hahn <sch@sun.com>
parents: 45
diff changeset
  1277
if __name__ == "__main__":
bfcb1661f019 basic image and package plans
Stephen Hahn <sch@sun.com>
parents: 45
diff changeset
  1278
        pass