src/modules/client/image.py
author Tom Mueller <Tom.Mueller@sun.com>
Sun, 03 May 2009 16:01:10 -0500
changeset 1107 d2cc5edc2593
parent 1102 5ea5cdb4360d
child 1111 26c3e2407c53
permissions -rw-r--r--
8600 incompatibility due to newline following publisher in installed file
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
409
713e20963dc2 2314 shebang lines should use minimum python version
Shawn Walker <swalker@opensolaris.org>
parents: 405
diff changeset
     1
#!/usr/bin/python2.4
19
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
     2
#
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
     3
# CDDL HEADER START
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
     4
#
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
     5
# The contents of this file are subject to the terms of the
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
     6
# Common Development and Distribution License (the "License").
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
     7
# You may not use this file except in compliance with the License.
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
     8
#
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
     9
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    10
# or http://www.opensolaris.org/os/licensing.
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    11
# See the License for the specific language governing permissions
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    12
# and limitations under the License.
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    13
#
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    14
# When distributing Covered Code, include this CDDL HEADER in each
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    15
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    16
# If applicable, add the following below this CDDL HEADER, with the
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    17
# fields enclosed by brackets "[]" replaced with your own identifying
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    18
# information: Portions Copyright [yyyy] [name of copyright owner]
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    19
#
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    20
# CDDL HEADER END
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    21
#
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    22
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
    23
#
835
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
    24
# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
19
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    25
# Use is subject to license terms.
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
    26
#
19
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    27
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
    28
import datetime as dt
161
e0322fe7842c Simplify and correct the package matching code.
Danek Duvall <danek.duvall@sun.com>
parents: 157
diff changeset
    29
import errno
26
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
    30
import os
838
aafbe4737188 3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 835
diff changeset
    31
import platform
aafbe4737188 3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 835
diff changeset
    32
import shutil
aafbe4737188 3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 835
diff changeset
    33
import tempfile
aafbe4737188 3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 835
diff changeset
    34
import time
45
8a3f00dea14f catalog refresh; basic catalog listing; precise manifest pulls
Stephen Hahn <sch@sun.com>
parents: 39
diff changeset
    35
import urllib
479
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
    36
655
6eef82185057 2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 648
diff changeset
    37
import pkg.Uuid25
6eef82185057 2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 648
diff changeset
    38
import pkg.catalog             as catalog
6eef82185057 2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 648
diff changeset
    39
import pkg.client.api_errors   as api_errors
6eef82185057 2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 648
diff changeset
    40
import pkg.client.constraint   as constraint
6eef82185057 2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 648
diff changeset
    41
import pkg.client.history      as history
6eef82185057 2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 648
diff changeset
    42
import pkg.client.imageconfig  as imageconfig
6eef82185057 2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 648
diff changeset
    43
import pkg.client.imageplan    as imageplan
6eef82185057 2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 648
diff changeset
    44
import pkg.client.imagestate   as imagestate
6eef82185057 2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 648
diff changeset
    45
import pkg.client.pkgplan      as pkgplan
6eef82185057 2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 648
diff changeset
    46
import pkg.client.progress     as progress
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 931
diff changeset
    47
import pkg.client.publisher    as publisher
655
6eef82185057 2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 648
diff changeset
    48
import pkg.client.retrieve     as retrieve
877
b23f809e8abd 6653 we should elide alternate architectures from in-memory manifests
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 855
diff changeset
    49
import pkg.client.variant      as variant
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
    50
import pkg.fmri
655
6eef82185057 2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 648
diff changeset
    51
import pkg.manifest            as manifest
6eef82185057 2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 648
diff changeset
    52
import pkg.misc                as misc
6eef82185057 2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 648
diff changeset
    53
import pkg.portable            as portable
539
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
    54
import pkg.version
104
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
    55
835
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
    56
from pkg.actions import MalformedActionError
576
6ee6de304041 3777 PKG_TIMEOUT_MAX is a placebo setting
Dan Price <dp@eng.sun.com>
parents: 573
diff changeset
    57
from pkg.client import global_settings
835
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
    58
from pkg.client.api_errors import InvalidDepotResponseException
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
    59
from pkg.client.imagetypes import IMG_USER, IMG_ENTIRE
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
    60
from pkg.misc import CfgCacheError
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
    61
from pkg.misc import EmptyI, EmptyDict
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
    62
from pkg.misc import msg, emsg
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
    63
from pkg.misc import TransportException
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
    64
from pkg.misc import TransportFailures
19
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    65
1068
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
    66
CATALOG_CACHE_FILE = "catalog_cache"
26
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
    67
img_user_prefix = ".org.opensolaris,pkg"
30
f06ad6cb4b3f stop using flavour terminology
Stephen Hahn <sch@sun.com>
parents: 29
diff changeset
    68
img_root_prefix = "var/pkg"
26
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
    69
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
    70
PKG_STATE_INSTALLED = "installed"
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
    71
PKG_STATE_KNOWN = "known"
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
    72
19
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    73
class Image(object):
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    74
        """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
    75
        of a self-consistent graph of Packages.
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    76
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    77
        An Image has a root path.
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    78
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    79
        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
    80
        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
    81
        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
    82
        Image (IMG_PARTIAL for zones, for instance).
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    83
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    84
        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
    85
        partial Image must be an entire Image.
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    86
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    87
        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
    88
        ".org.opensolaris,pkg".
19
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    89
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    90
        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
    91
        self.root + "/var/pkg".
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    92
26
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
    93
        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
    94
        system's root Image.
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
    95
29
f621f1df0849 fix install target; correct imports for module renames
"Stephen Hahn <sch@sun.com>"
parents: 26
diff changeset
    96
        Directory layout
f621f1df0849 fix install target; correct imports for module renames
"Stephen Hahn <sch@sun.com>"
parents: 26
diff changeset
    97
f621f1df0849 fix install target; correct imports for module renames
"Stephen Hahn <sch@sun.com>"
parents: 26
diff changeset
    98
          $IROOT/catalog
f621f1df0849 fix install target; correct imports for module renames
"Stephen Hahn <sch@sun.com>"
parents: 26
diff changeset
    99
               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
   100
               the escaped URI of the catalog.
f621f1df0849 fix install target; correct imports for module renames
"Stephen Hahn <sch@sun.com>"
parents: 26
diff changeset
   101
30
f06ad6cb4b3f stop using flavour terminology
Stephen Hahn <sch@sun.com>
parents: 29
diff changeset
   102
          $IROOT/file
f06ad6cb4b3f stop using flavour terminology
Stephen Hahn <sch@sun.com>
parents: 29
diff changeset
   103
               Directory containing file hashes of installed packages.
f06ad6cb4b3f stop using flavour terminology
Stephen Hahn <sch@sun.com>
parents: 29
diff changeset
   104
f06ad6cb4b3f stop using flavour terminology
Stephen Hahn <sch@sun.com>
parents: 29
diff changeset
   105
          $IROOT/pkg
f06ad6cb4b3f stop using flavour terminology
Stephen Hahn <sch@sun.com>
parents: 29
diff changeset
   106
               Directory containing manifests and states of installed packages.
f06ad6cb4b3f stop using flavour terminology
Stephen Hahn <sch@sun.com>
parents: 29
diff changeset
   107
60
6bd5cd83cfb1 Reverse index database and searching support.
Danek Duvall <danek.duvall@sun.com>
parents: 59
diff changeset
   108
          $IROOT/index
6bd5cd83cfb1 Reverse index database and searching support.
Danek Duvall <danek.duvall@sun.com>
parents: 59
diff changeset
   109
               Directory containing reverse-index databases.
6bd5cd83cfb1 Reverse index database and searching support.
Danek Duvall <danek.duvall@sun.com>
parents: 59
diff changeset
   110
104
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   111
          $IROOT/cfg_cache
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   112
               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
   113
418
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
   114
          $IROOT/opaque
104
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   115
               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
   116
418
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
   117
          $IROOT/state/installed
434
48c05c66cdd2 2595 List speedup changes don't work on Windows
Tom Mueller <Tom.Mueller@sun.com>
parents: 432
diff changeset
   118
               Directory containing files whose names identify the installed
48c05c66cdd2 2595 List speedup changes don't work on Windows
Tom Mueller <Tom.Mueller@sun.com>
parents: 432
diff changeset
   119
               packages.
418
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
   120
397
617be57c5f2b 777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents: 394
diff changeset
   121
        All of these directories and files other than state are considered
617be57c5f2b 777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents: 394
diff changeset
   122
        essential for any image to be complete. To add a new essential file or
617be57c5f2b 777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents: 394
diff changeset
   123
        subdirectory, the following steps should be done.
617be57c5f2b 777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents: 394
diff changeset
   124
617be57c5f2b 777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents: 394
diff changeset
   125
        If it's a directory, add it to the image_subdirs list below and it will
617be57c5f2b 777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents: 394
diff changeset
   126
        be created automatically. The programmer must fill the directory as
617be57c5f2b 777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents: 394
diff changeset
   127
        needed. If a file is added, the programmer is responsible for creating
617be57c5f2b 777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents: 394
diff changeset
   128
        that file during image creation at an appropriate place and time.
617be57c5f2b 777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents: 394
diff changeset
   129
418
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
   130
        If a directory is required to be present in order for an image to be
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
   131
        identifiable as such, it should go into required_subdirs instead.
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
   132
        However, upgrade issues abound; this list should probably not change.
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
   133
397
617be57c5f2b 777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents: 394
diff changeset
   134
        Once those steps have been carried out, the change should be added
617be57c5f2b 777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents: 394
diff changeset
   135
        to the test suite for image corruption (t_pkg_install_corrupt_image.py).
617be57c5f2b 777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents: 394
diff changeset
   136
        This will likely also involve a change to
617be57c5f2b 777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents: 394
diff changeset
   137
        SingleDepotTestCaseCorruptImage in testutils.py. Each of these files
617be57c5f2b 777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents: 394
diff changeset
   138
        outline what must be updated.
617be57c5f2b 777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents: 394
diff changeset
   139
19
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
   140
        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
   141
        reuse Image contents.
26
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   142
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   143
        XXX Image file format?  Image file manipulation API?"""
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   144
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
   145
        required_subdirs = [ "catalog", "file", "pkg" ]
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
   146
        image_subdirs = required_subdirs + [ "index", "state/installed" ]
397
617be57c5f2b 777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents: 394
diff changeset
   147
26
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   148
        def __init__(self):
104
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   149
                self.cfg_cache = None
26
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   150
                self.type = None
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   151
                self.root = None
539
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
   152
                self.history = history.History()
30
f06ad6cb4b3f stop using flavour terminology
Stephen Hahn <sch@sun.com>
parents: 29
diff changeset
   153
                self.imgdir = None
1037
56ff5f4fab83 8050 image-update fails from b110 to b111 at SUNWgnome-system-monitor manifest
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 999
diff changeset
   154
                self.pkgdir = None
271
ec8a7669bff2 659 package that delivers existing automounter mountpoint fails installation
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 268
diff changeset
   155
                self.img_prefix = None
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
   156
                self.index_dir = None
26
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   157
                self.repo_uris = []
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   158
                self.filter_tags = {}
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
   159
                self.__catalogs = {}
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
   160
                self._catalog = {}
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
   161
                self.__pkg_states = None
554
fe196874250d 3508 zone install should utilize/populate global zone d/l cache
Dan Price <dp@eng.sun.com>
parents: 552
diff changeset
   162
                self.dl_cache_dir = None
fe196874250d 3508 zone install should utilize/populate global zone d/l cache
Dan Price <dp@eng.sun.com>
parents: 552
diff changeset
   163
                self.dl_cache_incoming = None
fe196874250d 3508 zone install should utilize/populate global zone d/l cache
Dan Price <dp@eng.sun.com>
parents: 552
diff changeset
   164
                self.is_user_cache_dir = False
556
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   165
                self.state = imagestate.ImageState()
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   166
                self.attrs = {
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   167
                    "Policy-Require-Optional": False,
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   168
                    "Policy-Pursue-Latest": True
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   169
                }
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
   170
                self.__catalog_cache_mod_time = None
32
c26788b7217c begin client install; sequences are now timestamps; skeleton ELF module
Stephen Hahn <sch@sun.com>
parents: 30
diff changeset
   171
556
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   172
                self.imageplan = None # valid after evaluation succeeds
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
   173
655
6eef82185057 2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 648
diff changeset
   174
                self.constraints = constraint.ConstraintSet()
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   175
462
910600c14093 45 "move" action for files that are renamed, but must be preserved
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 461
diff changeset
   176
                # a place to keep info about saved_files; needed by file action
910600c14093 45 "move" action for files that are renamed, but must be preserved
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 461
diff changeset
   177
                self.saved_files = {}
556
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   178
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   179
                # A place to keep track of which manifests (based on fmri and
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   180
                # operation) have already provided intent information.
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   181
                self.__touched_manifests = {}
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   182
567
ea1d96e269a4 3505 client action and manifest creation are wasteful
johansen <johansen@sun.com>
parents: 565
diff changeset
   183
                self.__manifest_cache = {}
ea1d96e269a4 3505 client action and manifest creation are wasteful
johansen <johansen@sun.com>
parents: 565
diff changeset
   184
674
e740c8c3bed1 166 os.makedirs() does not set directory mode
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 664
diff changeset
   185
                # right now we don't explicitly set dir/file modes everywhere;
e740c8c3bed1 166 os.makedirs() does not set directory mode
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 664
diff changeset
   186
                # set umask to proper value to prevent problems w/ overly
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   187
                # locked down umask.
674
e740c8c3bed1 166 os.makedirs() does not set directory mode
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 664
diff changeset
   188
                os.umask(0022)
e740c8c3bed1 166 os.makedirs() does not set directory mode
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 664
diff changeset
   189
582
303fa3b78f93 3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents: 577
diff changeset
   190
        def _check_subdirs(self, sub_d, prefix):
303fa3b78f93 3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents: 577
diff changeset
   191
                for n in self.required_subdirs:
303fa3b78f93 3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents: 577
diff changeset
   192
                        if not os.path.isdir(os.path.join(sub_d, prefix, n)):
303fa3b78f93 3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents: 577
diff changeset
   193
                                return False
303fa3b78f93 3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents: 577
diff changeset
   194
                return True
397
617be57c5f2b 777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents: 394
diff changeset
   195
582
303fa3b78f93 3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents: 577
diff changeset
   196
        def image_type(self, d):
303fa3b78f93 3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents: 577
diff changeset
   197
                """Returns the type of image at directory: d; or None"""
303fa3b78f93 3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents: 577
diff changeset
   198
                rv = None
303fa3b78f93 3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents: 577
diff changeset
   199
                if os.path.isdir(os.path.join(d, img_user_prefix)) and \
303fa3b78f93 3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents: 577
diff changeset
   200
                        os.path.isfile(os.path.join(d, img_user_prefix,
786
a400f8c4d1c0 2340 support authority enable and disable
Tom Mueller <Tom.Mueller@sun.com>
parents: 756
diff changeset
   201
                            imageconfig.CFG_FILE)) and \
582
303fa3b78f93 3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents: 577
diff changeset
   202
                            self._check_subdirs(d, img_user_prefix):
303fa3b78f93 3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents: 577
diff changeset
   203
                        rv = IMG_USER
303fa3b78f93 3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents: 577
diff changeset
   204
                elif os.path.isdir(os.path.join(d, img_root_prefix)) \
303fa3b78f93 3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents: 577
diff changeset
   205
                         and os.path.isfile(os.path.join(d,
786
a400f8c4d1c0 2340 support authority enable and disable
Tom Mueller <Tom.Mueller@sun.com>
parents: 756
diff changeset
   206
                             img_root_prefix, imageconfig.CFG_FILE)) and \
582
303fa3b78f93 3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents: 577
diff changeset
   207
                             self._check_subdirs(d, img_root_prefix):
303fa3b78f93 3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents: 577
diff changeset
   208
                        rv = IMG_ENTIRE
303fa3b78f93 3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents: 577
diff changeset
   209
                return rv
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   210
582
303fa3b78f93 3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents: 577
diff changeset
   211
        def find_root(self, d, exact_match=False):
289
c2e63370fb2b 160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents: 285
diff changeset
   212
                # Ascend from the given directory d to find first
561
be1ad23e7704 1651 pkg treats -R <bogus-dir> as "use the image at /"
Brock Pytlik <bpytlik@sun.com>
parents: 560
diff changeset
   213
                # encountered image. If exact_match is true, if the
be1ad23e7704 1651 pkg treats -R <bogus-dir> as "use the image at /"
Brock Pytlik <bpytlik@sun.com>
parents: 560
diff changeset
   214
                # image found doesn't match startd, raise an
be1ad23e7704 1651 pkg treats -R <bogus-dir> as "use the image at /"
Brock Pytlik <bpytlik@sun.com>
parents: 560
diff changeset
   215
                # ImageNotFoundException.
289
c2e63370fb2b 160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents: 285
diff changeset
   216
                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
   217
                # 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
   218
                d = os.path.realpath(d)
26
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   219
                while True:
582
303fa3b78f93 3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents: 577
diff changeset
   220
                        imgtype = self.image_type(d)
303fa3b78f93 3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents: 577
diff changeset
   221
                        if imgtype == IMG_USER:
26
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   222
                                # XXX Look at image file to determine filter
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   223
                                # tags and repo URIs.
561
be1ad23e7704 1651 pkg treats -R <bogus-dir> as "use the image at /"
Brock Pytlik <bpytlik@sun.com>
parents: 560
diff changeset
   224
                                if exact_match and \
be1ad23e7704 1651 pkg treats -R <bogus-dir> as "use the image at /"
Brock Pytlik <bpytlik@sun.com>
parents: 560
diff changeset
   225
                                    os.path.realpath(startd) != \
be1ad23e7704 1651 pkg treats -R <bogus-dir> as "use the image at /"
Brock Pytlik <bpytlik@sun.com>
parents: 560
diff changeset
   226
                                    os.path.realpath(d):
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   227
                                        raise api_errors.ImageNotFoundException(
561
be1ad23e7704 1651 pkg treats -R <bogus-dir> as "use the image at /"
Brock Pytlik <bpytlik@sun.com>
parents: 560
diff changeset
   228
                                            exact_match, startd, d)
582
303fa3b78f93 3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents: 577
diff changeset
   229
                                self.__set_dirs(imgtype=imgtype, root=d)
59
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
   230
                                self.attrs["Build-Release"] = "5.11"
26
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   231
                                return
582
303fa3b78f93 3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents: 577
diff changeset
   232
                        elif imgtype == IMG_ENTIRE:
26
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   233
                                # XXX Look at image file to determine filter
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   234
                                # tags and repo URIs.
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   235
                                # XXX Look at image file to determine if this
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   236
                                # image is a partial image.
561
be1ad23e7704 1651 pkg treats -R <bogus-dir> as "use the image at /"
Brock Pytlik <bpytlik@sun.com>
parents: 560
diff changeset
   237
                                if exact_match and \
be1ad23e7704 1651 pkg treats -R <bogus-dir> as "use the image at /"
Brock Pytlik <bpytlik@sun.com>
parents: 560
diff changeset
   238
                                    os.path.realpath(startd) != \
be1ad23e7704 1651 pkg treats -R <bogus-dir> as "use the image at /"
Brock Pytlik <bpytlik@sun.com>
parents: 560
diff changeset
   239
                                    os.path.realpath(d):
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   240
                                        raise api_errors.ImageNotFoundException(
561
be1ad23e7704 1651 pkg treats -R <bogus-dir> as "use the image at /"
Brock Pytlik <bpytlik@sun.com>
parents: 560
diff changeset
   241
                                            exact_match, startd, d)
582
303fa3b78f93 3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents: 577
diff changeset
   242
                                self.__set_dirs(imgtype=imgtype, root=d)
59
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
   243
                                self.attrs["Build-Release"] = "5.11"
26
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   244
                                return
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   245
289
c2e63370fb2b 160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents: 285
diff changeset
   246
                        # 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
   247
                        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
   248
                        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
   249
289
c2e63370fb2b 160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents: 285
diff changeset
   250
                        # 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
   251
                        # 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
   252
                        #
c2e63370fb2b 160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents: 285
diff changeset
   253
                        # (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
   254
                        if d == oldpath:
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   255
                                raise api_errors.ImageNotFoundException(
596
f4519e2a99bc 3704 InventoryException raised if optional dependencies not in catalog
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 583
diff changeset
   256
                                    exact_match, startd, d)
26
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   257
104
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   258
        def load_config(self):
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   259
                """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
   260
                location."""
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   261
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   262
                # 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
   263
                # configuration.
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   264
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   265
                if self.root == None:
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   266
                        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
   267
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   268
                ic = imageconfig.ImageConfig()
786
a400f8c4d1c0 2340 support authority enable and disable
Tom Mueller <Tom.Mueller@sun.com>
parents: 756
diff changeset
   269
                ic.read(self.imgdir)
104
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   270
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   271
                self.cfg_cache = ic
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   272
838
aafbe4737188 3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 835
diff changeset
   273
                # make sure we define architecture variant; upgrade config
aafbe4737188 3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 835
diff changeset
   274
                # file if possible.
aafbe4737188 3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 835
diff changeset
   275
                if "variant.arch" not in self.cfg_cache.variants:
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   276
                        self.cfg_cache.variants["variant.arch"] = \
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   277
                            platform.processor()
838
aafbe4737188 3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 835
diff changeset
   278
                        try:
aafbe4737188 3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 835
diff changeset
   279
                                self.save_config()
aafbe4737188 3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 835
diff changeset
   280
                        except api_errors.PermissionsException:
aafbe4737188 3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 835
diff changeset
   281
                                pass
aafbe4737188 3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 835
diff changeset
   282
                # make sure we define zone variant; upgrade config if possible
aafbe4737188 3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 835
diff changeset
   283
                if "variant.opensolaris.zone" not in self.cfg_cache.variants:
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   284
                        zone = self.cfg_cache.filters.get("opensolaris.zone",
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   285
                            "")
838
aafbe4737188 3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 835
diff changeset
   286
                        if zone == "nonglobal":
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   287
                                self.cfg_cache.variants[
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   288
                                    "variant.opensolaris.zone"] = "nonglobal"
838
aafbe4737188 3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 835
diff changeset
   289
                        else:
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   290
                                self.cfg_cache.variants[
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   291
                                    "variant.opensolaris.zone"] = "global"
838
aafbe4737188 3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 835
diff changeset
   292
                        try:
aafbe4737188 3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 835
diff changeset
   293
                                self.save_config()
aafbe4737188 3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 835
diff changeset
   294
                        except api_errors.PermissionsException:
aafbe4737188 3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 835
diff changeset
   295
                                pass
aafbe4737188 3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 835
diff changeset
   296
551
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
   297
        def save_config(self):
786
a400f8c4d1c0 2340 support authority enable and disable
Tom Mueller <Tom.Mueller@sun.com>
parents: 756
diff changeset
   298
                self.cfg_cache.write(self.imgdir)
551
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
   299
104
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   300
        # 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
   301
        # operation.
29
f621f1df0849 fix install target; correct imports for module renames
"Stephen Hahn <sch@sun.com>"
parents: 26
diff changeset
   302
        def mkdirs(self):
397
617be57c5f2b 777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents: 394
diff changeset
   303
                for sd in self.image_subdirs:
617be57c5f2b 777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents: 394
diff changeset
   304
                        if not os.path.isdir(os.path.join(self.imgdir, sd)):
617be57c5f2b 777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents: 394
diff changeset
   305
                                os.makedirs(os.path.join(self.imgdir, sd))
29
f621f1df0849 fix install target; correct imports for module renames
"Stephen Hahn <sch@sun.com>"
parents: 26
diff changeset
   306
554
fe196874250d 3508 zone install should utilize/populate global zone d/l cache
Dan Price <dp@eng.sun.com>
parents: 552
diff changeset
   307
        def __set_dirs(self, imgtype, root):
fe196874250d 3508 zone install should utilize/populate global zone d/l cache
Dan Price <dp@eng.sun.com>
parents: 552
diff changeset
   308
                self.type = imgtype
22
379f0f6809ff pkgsend open, pkgsend add file, pkgsend close; Transaction object
"Stephen Hahn <sch@sun.com>"
parents: 19
diff changeset
   309
                self.root = root
379f0f6809ff pkgsend open, pkgsend add file, pkgsend close; Transaction object
"Stephen Hahn <sch@sun.com>"
parents: 19
diff changeset
   310
                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
   311
                        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
   312
                else:
271
ec8a7669bff2 659 package that delivers existing automounter mountpoint fails installation
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 268
diff changeset
   313
                        self.img_prefix = img_root_prefix
993
7cfbab7739c3 588 directory remove of cwd fails due to EPERM or EINVAL
Danek Duvall <danek.duvall@sun.com>
parents: 988
diff changeset
   314
7cfbab7739c3 588 directory remove of cwd fails due to EPERM or EINVAL
Danek Duvall <danek.duvall@sun.com>
parents: 988
diff changeset
   315
                # Change directory to the root of the image so that we can
7cfbab7739c3 588 directory remove of cwd fails due to EPERM or EINVAL
Danek Duvall <danek.duvall@sun.com>
parents: 988
diff changeset
   316
                # remove any directories beneath us.  If we're changing the
7cfbab7739c3 588 directory remove of cwd fails due to EPERM or EINVAL
Danek Duvall <danek.duvall@sun.com>
parents: 988
diff changeset
   317
                # image, don't chdir, as we're likely changing to a new BE
7cfbab7739c3 588 directory remove of cwd fails due to EPERM or EINVAL
Danek Duvall <danek.duvall@sun.com>
parents: 988
diff changeset
   318
                # and want to be able to unmount it later.
999
04c29b9c97a0 7811 pkg image-create no longer creates image path if it doesn't exist
Danek Duvall <danek.duvall@sun.com>
parents: 996
diff changeset
   319
                if not self.imgdir and os.path.isdir(root):
993
7cfbab7739c3 588 directory remove of cwd fails due to EPERM or EINVAL
Danek Duvall <danek.duvall@sun.com>
parents: 988
diff changeset
   320
                        os.chdir(root)
7cfbab7739c3 588 directory remove of cwd fails due to EPERM or EINVAL
Danek Duvall <danek.duvall@sun.com>
parents: 988
diff changeset
   321
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
   322
                self.imgdir = os.path.join(self.root, self.img_prefix)
1037
56ff5f4fab83 8050 image-update fails from b110 to b111 at SUNWgnome-system-monitor manifest
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 999
diff changeset
   323
                self.pkgdir = os.path.join(self.imgdir, "pkg")
539
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
   324
                self.history.root_dir = self.imgdir
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
   325
554
fe196874250d 3508 zone install should utilize/populate global zone d/l cache
Dan Price <dp@eng.sun.com>
parents: 552
diff changeset
   326
                if "PKG_CACHEDIR" in os.environ:
fe196874250d 3508 zone install should utilize/populate global zone d/l cache
Dan Price <dp@eng.sun.com>
parents: 552
diff changeset
   327
                        self.dl_cache_dir = os.path.normpath( \
fe196874250d 3508 zone install should utilize/populate global zone d/l cache
Dan Price <dp@eng.sun.com>
parents: 552
diff changeset
   328
                            os.environ["PKG_CACHEDIR"])
fe196874250d 3508 zone install should utilize/populate global zone d/l cache
Dan Price <dp@eng.sun.com>
parents: 552
diff changeset
   329
                        self.is_user_cache_dir = True
fe196874250d 3508 zone install should utilize/populate global zone d/l cache
Dan Price <dp@eng.sun.com>
parents: 552
diff changeset
   330
                else:
fe196874250d 3508 zone install should utilize/populate global zone d/l cache
Dan Price <dp@eng.sun.com>
parents: 552
diff changeset
   331
                        self.dl_cache_dir = os.path.normpath( \
fe196874250d 3508 zone install should utilize/populate global zone d/l cache
Dan Price <dp@eng.sun.com>
parents: 552
diff changeset
   332
                            os.path.join(self.imgdir, "download"))
fe196874250d 3508 zone install should utilize/populate global zone d/l cache
Dan Price <dp@eng.sun.com>
parents: 552
diff changeset
   333
                self.dl_cache_incoming = os.path.normpath(os.path.join(
fe196874250d 3508 zone install should utilize/populate global zone d/l cache
Dan Price <dp@eng.sun.com>
parents: 552
diff changeset
   334
                    self.dl_cache_dir, "incoming-%d" % os.getpid()))
fe196874250d 3508 zone install should utilize/populate global zone d/l cache
Dan Price <dp@eng.sun.com>
parents: 552
diff changeset
   335
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   336
        def set_attrs(self, imgtype, root, is_zone, prefix, pub_url,
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   337
            ssl_key=None, ssl_cert=None, variants=EmptyDict,
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
   338
            refresh_allowed=True, progtrack=None):
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   339
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   340
                self.__set_dirs(imgtype=imgtype, root=root)
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   341
1086
16500d7bf1ca 8321 image_create should not validate publisher uri
Shawn Walker <srw@sun.com>
parents: 1085
diff changeset
   342
                # Create the publisher object before creating the image...
16500d7bf1ca 8321 image_create should not validate publisher uri
Shawn Walker <srw@sun.com>
parents: 1085
diff changeset
   343
                repo = publisher.Repository()
16500d7bf1ca 8321 image_create should not validate publisher uri
Shawn Walker <srw@sun.com>
parents: 1085
diff changeset
   344
                repo.add_origin(pub_url, ssl_cert=ssl_cert, ssl_key=ssl_key)
16500d7bf1ca 8321 image_create should not validate publisher uri
Shawn Walker <srw@sun.com>
parents: 1085
diff changeset
   345
                newpub = publisher.Publisher(prefix,
16500d7bf1ca 8321 image_create should not validate publisher uri
Shawn Walker <srw@sun.com>
parents: 1085
diff changeset
   346
                    meta_root=self._get_publisher_meta_root(prefix),
16500d7bf1ca 8321 image_create should not validate publisher uri
Shawn Walker <srw@sun.com>
parents: 1085
diff changeset
   347
                    repositories=[repo])
16500d7bf1ca 8321 image_create should not validate publisher uri
Shawn Walker <srw@sun.com>
parents: 1085
diff changeset
   348
1102
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
   349
                # Initialize and store the configuration object.
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
   350
                self.cfg_cache = imageconfig.ImageConfig()
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
   351
1086
16500d7bf1ca 8321 image_create should not validate publisher uri
Shawn Walker <srw@sun.com>
parents: 1085
diff changeset
   352
                # ...so that if creation of the Publisher object fails, an
16500d7bf1ca 8321 image_create should not validate publisher uri
Shawn Walker <srw@sun.com>
parents: 1085
diff changeset
   353
                # empty, useless image won't be left behind.
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   354
                if not os.path.exists(os.path.join(self.imgdir,
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   355
                    imageconfig.CFG_FILE)):
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
   356
                        self.history.log_operation_start("image-create")
539
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
   357
                else:
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
   358
                        self.history.log_operation_start("image-set-attributes")
539
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
   359
1102
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
   360
                # Determine and add the default variants for the image.
111
647c91609117 Client-side filtering.
Danek Duvall <danek.duvall@sun.com>
parents: 107
diff changeset
   361
                if is_zone:
647c91609117 Client-side filtering.
Danek Duvall <danek.duvall@sun.com>
parents: 107
diff changeset
   362
                        self.cfg_cache.filters["opensolaris.zone"] = "nonglobal"
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   363
                        self.cfg_cache.variants[
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   364
                            "variant.opensolaris.zone"] = "nonglobal"
838
aafbe4737188 3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 835
diff changeset
   365
                else:
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   366
                        self.cfg_cache.variants[
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   367
                            "variant.opensolaris.zone"] = "global"
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   368
838
aafbe4737188 3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 835
diff changeset
   369
                self.cfg_cache.variants["variant.arch"] = \
aafbe4737188 3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 835
diff changeset
   370
                    variants.get("variant.arch", platform.processor())
1102
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
   371
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
   372
                # After setting up the default variants, add any overrides or
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
   373
                # additional variants specified.
838
aafbe4737188 3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 835
diff changeset
   374
                self.cfg_cache.variants.update(variants)
aafbe4737188 3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 835
diff changeset
   375
1102
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
   376
                # Now everything is ready for publisher configuration.
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
   377
                self.cfg_cache.preferred_publisher = newpub.prefix
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
   378
                self.add_publisher(newpub, refresh_allowed=refresh_allowed,
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
   379
                    progtrack=progtrack)
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
   380
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
   381
                # Next, create the image directories if they haven't been
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
   382
                # (add_publisher will normally do this if it needs to write
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
   383
                # something to disk).  Waiting until after add_publisher is
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
   384
                # called avoids leaving an empty, useless set of directories
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
   385
                # for the image if the add fails.
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
   386
                self.mkdirs()
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
   387
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
   388
                # Finally, since all operations were successful, save the image
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
   389
                # configuration.
551
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
   390
                self.save_config()
1102
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
   391
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
   392
                self.history.log_operation_end()
104
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   393
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   394
        def is_liveroot(self):
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   395
                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
   396
344
4c887185d780 528 pkg list -u gives confusing output
Dan Price <dp@eng.sun.com>
parents: 342
diff changeset
   397
        def is_zone(self):
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   398
                return self.cfg_cache.variants[
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   399
                    "variant.opensolaris.zone"] == "nonglobal"
838
aafbe4737188 3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 835
diff changeset
   400
aafbe4737188 3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 835
diff changeset
   401
        def get_arch(self):
aafbe4737188 3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 835
diff changeset
   402
                return self.cfg_cache.variants["variant.arch"]
344
4c887185d780 528 pkg list -u gives confusing output
Dan Price <dp@eng.sun.com>
parents: 342
diff changeset
   403
29
f621f1df0849 fix install target; correct imports for module renames
"Stephen Hahn <sch@sun.com>"
parents: 26
diff changeset
   404
        def get_root(self):
f621f1df0849 fix install target; correct imports for module renames
"Stephen Hahn <sch@sun.com>"
parents: 26
diff changeset
   405
                return self.root
f621f1df0849 fix install target; correct imports for module renames
"Stephen Hahn <sch@sun.com>"
parents: 26
diff changeset
   406
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   407
        def gen_publishers(self, inc_disabled=False):
104
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   408
                if not self.cfg_cache:
835
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
   409
                        raise CfgCacheError, "empty ImageConfig"
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   410
                for p in self.cfg_cache.publishers:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   411
                        pub = self.cfg_cache.publishers[p]
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   412
                        if inc_disabled or not pub.disabled:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   413
                                yield self.cfg_cache.publishers[p]
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   414
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   415
        def get_url_by_publisher(self, prefix=None):
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   416
                """Return the URL prefix associated with the given prefix.
104
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   417
                For the undefined case, represented by None, return the
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   418
                preferred publisher."""
104
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   419
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   420
                # 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
   421
                # 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
   422
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   423
                if prefix is None:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   424
                        prefix = self.cfg_cache.preferred_publisher
104
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   425
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   426
                try:
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   427
                        o = self.cfg_cache.publishers[prefix]["origin"]
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
   428
                except KeyError:
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   429
                        # If the publisher that we're trying to get no longer
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   430
                        # exists, fall back to preferred publisher.
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   431
                        prefix = self.cfg_cache.preferred_publisher
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   432
                        o = self.cfg_cache.publishers[prefix]["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
   433
146
9b9fcd56b8b2 Reduce use of the re module, for performance.
Danek Duvall <danek.duvall@sun.com>
parents: 145
diff changeset
   434
                return o.rstrip("/")
104
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   435
648
9f1f457e78b2 3803 Mirror selection should avoid authority origin
johansen <johansen@sun.com>
parents: 644
diff changeset
   436
        def gen_depot_status(self):
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   437
                """Walk all publishers and return all depot status
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   438
                objects for both mirrors and primary publishers."""
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   439
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   440
                pubs = self.cfg_cache.publishers
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   441
                # return depot status objects in publisher order
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   442
                for pub in pubs.keys():
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   443
                        # first yield publisher origin
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   444
                        yield self.cfg_cache.publisher_status[pub]
648
9f1f457e78b2 3803 Mirror selection should avoid authority origin
johansen <johansen@sun.com>
parents: 644
diff changeset
   445
                        # then return mirrors
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   446
                        for ds in self.cfg_cache.mirror_status[pub]:
648
9f1f457e78b2 3803 Mirror selection should avoid authority origin
johansen <johansen@sun.com>
parents: 644
diff changeset
   447
                                yield ds
9f1f457e78b2 3803 Mirror selection should avoid authority origin
johansen <johansen@sun.com>
parents: 644
diff changeset
   448
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   449
        def num_mirrors(self, pub):
648
9f1f457e78b2 3803 Mirror selection should avoid authority origin
johansen <johansen@sun.com>
parents: 644
diff changeset
   450
                """Return the number of mirrors configured for the
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   451
                given publisher."""
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   452
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   453
                if pub == None:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   454
                        pub = self.cfg_cache.preferred_publisher
648
9f1f457e78b2 3803 Mirror selection should avoid authority origin
johansen <johansen@sun.com>
parents: 644
diff changeset
   455
835
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
   456
                try:
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   457
                        num = len(self.cfg_cache.mirror_status[pub])
835
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
   458
                except KeyError:
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   459
                        # pub isn't in the list of mirrors, return 0
835
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
   460
                        num = 0
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
   461
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
   462
                return num
648
9f1f457e78b2 3803 Mirror selection should avoid authority origin
johansen <johansen@sun.com>
parents: 644
diff changeset
   463
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   464
        def select_mirror(self, pub = None, chosen_set = None):
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   465
                """For the given publisher, look through the status of
461
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   466
                the mirrors.  Pick the best one.  This method returns
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   467
                a DepotStatus object or None.  The chosen_set argument
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   468
                contains a set object that lists the mirrors that were
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   469
                previously chosen.  This allows us to choose both
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   470
                by depot status statistics and ensures we don't
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   471
                always pick the same depot."""
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   472
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   473
                if pub == None:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   474
                        pub = self.cfg_cache.preferred_publisher
461
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   475
                try:
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   476
                        slst = self.cfg_cache.mirror_status[pub]
461
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   477
                except KeyError:
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   478
                        # If the publisher that we're trying to get no longer
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   479
                        # exists, fall back to preferred publisher.
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   480
                        pub = self.cfg_cache.preferred_publisher
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   481
                        slst = self.cfg_cache.mirror_status[pub]
461
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   482
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   483
                if len(slst) == 0:
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   484
                        if pub in self.cfg_cache.publisher_status:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   485
                                return self.cfg_cache.publisher_status[pub]
461
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   486
                        else:
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   487
                                return None
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   488
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   489
                # Choose mirror with fewest errors.
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   490
                # If mirrors have same number of errors, choose mirror
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   491
                # with smaller number of good transactions.  Assume it's
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   492
                # being underused, not high-latency.
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   493
                #
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   494
                # XXX Will need to revisit the above assumption.
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   495
                def cmp_depotstatus(a, b):
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   496
                        res = cmp(a.errors, b.errors)
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   497
                        if res == 0:
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   498
                                return cmp(a.good_tx, b.good_tx)
556
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   499
                        return res
461
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   500
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   501
                slst.sort(cmp = cmp_depotstatus)
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   502
648
9f1f457e78b2 3803 Mirror selection should avoid authority origin
johansen <johansen@sun.com>
parents: 644
diff changeset
   503
                # All mirrors in the chosen_set have already been
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   504
                # selected.  Try the publisher origin instead.
648
9f1f457e78b2 3803 Mirror selection should avoid authority origin
johansen <johansen@sun.com>
parents: 644
diff changeset
   505
                # Empty chosen_set, next time we start over.
461
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   506
                if chosen_set and len(chosen_set) == len(slst):
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   507
                        chosen_set.clear()
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   508
                        return self.cfg_cache.publisher_status[pub]
461
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   509
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   510
                if chosen_set and slst[0] in chosen_set:
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   511
                        for ds in slst:
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   512
                                if ds not in chosen_set:
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   513
                                        return ds
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   514
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   515
                return slst[0]
37cf3ac75e37 1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents: 453
diff changeset
   516
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   517
        def get_ssl_credentials(self, prefix=None, origin=None,
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   518
            pubent=None):
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   519
                """Deprecated; this function will be removed in a future
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   520
                release.  This information should be retrieved directly from a
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   521
                repository origin or mirror object.
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   522
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   523
                Return a tuple containing (ssl_key, ssl_cert) for the
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   524
                specified publisher prefix.  If the publisher isn't specified,
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   525
                attempt to determine the publisher by the given origin.  If
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   526
                neither is specified, use the preferred publisher.  pubent
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   527
                is a dictionary argument that contains the publisher
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   528
                information."""
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   529
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   530
                if not pubent and prefix is None:
322
e1b078577730 1101 pkg search -s <server> returns a traceback
Danek Duvall <danek.duvall@sun.com>
parents: 319
diff changeset
   531
                        if origin is None:
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   532
                                prefix = self.cfg_cache.preferred_publisher
322
e1b078577730 1101 pkg search -s <server> returns a traceback
Danek Duvall <danek.duvall@sun.com>
parents: 319
diff changeset
   533
                        else:
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   534
                                pubs = self.cfg_cache.publishers
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   535
                                for pfx, pub in pubs.iteritems():
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   536
                                        repo = pub.selected_repository
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   537
                                        if repo.has_origin(origin):
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   538
                                                prefix = pfx
322
e1b078577730 1101 pkg search -s <server> returns a traceback
Danek Duvall <danek.duvall@sun.com>
parents: 319
diff changeset
   539
                                                break
e1b078577730 1101 pkg search -s <server> returns a traceback
Danek Duvall <danek.duvall@sun.com>
parents: 319
diff changeset
   540
                                else:
e1b078577730 1101 pkg search -s <server> returns a traceback
Danek Duvall <danek.duvall@sun.com>
parents: 319
diff changeset
   541
                                        return None
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   542
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   543
                # One of these should be defined at this point unless the
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   544
                # caller didn't provide anything.
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   545
                assert prefix or origin or pubent
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   546
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   547
                if not pubent:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   548
                        try:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   549
                                pubent = self.cfg_cache.publishers[prefix]
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   550
                        except KeyError:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   551
                                prefix = self.cfg_cache.preferred_publisher
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   552
                                pubent = self.cfg_cache.publishers[prefix]
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   553
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   554
                repo = pubent.selected_repository
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   555
                origin = repo.origins[0]
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   556
                return (origin.ssl_key, origin.ssl_cert)
479
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
   557
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
   558
        def check_cert_validity(self):
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   559
                """Look through the publishers defined for the image.  Print
479
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
   560
                a message and exit with an error if one of the certificates
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
   561
                has expired.  If certificates are getting close to expiration,
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
   562
                print a warning instead."""
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
   563
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   564
                for p in self.gen_publishers():
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   565
                        for r in p.repositories:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   566
                                for uri in r.origins:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   567
                                        if uri.ssl_cert:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   568
                                                misc.validate_ssl_cert(
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   569
                                                    uri.ssl_cert,
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   570
                                                    prefix=p.prefix, uri=uri)
479
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
   571
                return True
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
   572
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   573
        def get_uuid(self, prefix):
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   574
                """Deprecated; this function will be removed in a future
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   575
                release.  This information should be retrieved directly from a
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   576
                publisher object.
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   577
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   578
                Return the UUID for the specified publisher prefix.  If the
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   579
                policy for sending the UUID is set to false, return None."""
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   580
551
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
   581
                if not self.cfg_cache.get_policy(imageconfig.SEND_UUID):
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
   582
                        return None
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
   583
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
   584
                try:
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   585
                        return self.cfg_cache.publishers[prefix].client_uuid
551
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
   586
                except KeyError:
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
   587
                        return None
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   588
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   589
        def has_publisher(self, prefix=None, alias=None):
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   590
                for pub in self.gen_publishers():
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   591
                        if prefix == pub.prefix or (alias and
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   592
                            alias == pub.alias):
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   593
                                return True
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   594
                return False
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   595
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
   596
        def remove_publisher(self, prefix=None, alias=None, progtrack=None):
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
   597
                if not progtrack:
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
   598
                        progtrack = progress.QuietProgressTracker()
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
   599
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   600
                self.history.log_operation_start("remove-publisher")
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   601
                try:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   602
                        pub = self.get_publisher(prefix=prefix,
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   603
                            alias=alias)
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   604
                except api_errors.ApiException, e:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   605
                        self.history.log_operation_end(e)
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   606
                        raise e
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   607
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   608
                if pub.prefix == self.cfg_cache.preferred_publisher:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   609
                        e = api_errors.RemovePreferredPublisher()
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   610
                        self.history.log_operation_end(error=e)
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   611
                        raise e
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   612
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   613
                self.cfg_cache.remove_publisher(prefix)
551
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
   614
                self.save_config()
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
   615
                self.remove_publisher_metadata(pub)
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
   616
                self.load_catalogs(progtrack, force=True)
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   617
                self.history.log_operation_end()
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   618
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   619
        def get_publishers(self):
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   620
                return self.cfg_cache.publishers
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   621
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   622
        def get_publisher(self, prefix=None, alias=None, origin=None):
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
   623
                publishers = [p for p in self.get_publishers().values()]
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
   624
                for pub in publishers:
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   625
                        if prefix and prefix == pub.prefix:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   626
                                return pub
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   627
                        elif alias and alias == pub.alias:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   628
                                return pub
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   629
                        elif origin and \
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   630
                            pub.selected_repository.has_origin(origin):
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   631
                                return pub
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   632
                raise api_errors.UnknownPublisher(max(prefix, alias, origin))
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   633
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   634
        def get_publisher_last_update_time(self, prefix, cached=True):
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   635
                """Returns a datetime object (or 'None') representing the last
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   636
                time the catalog for a publisher was updated.
988
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
   637
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   638
                If the catalog has already been loaded, this reflects the
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   639
                in-memory state of the catalog.
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   640
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   641
                If the catalog has not already been loaded or 'cached' is False,
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   642
                then the catalog will be temporarily loaded and the most recent
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   643
                information returned."""
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   644
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   645
                if not cached:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   646
                        try:
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
   647
                                cat = self.__catalogs[prefix]
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   648
                        except KeyError:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   649
                                pass
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   650
                        else:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   651
                                update_dt = cat.last_modified()
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   652
                                if update_dt:
988
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
   653
                                        update_dt = catalog.ts_to_datetime(
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
   654
                                            update_dt)
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   655
                                return update_dt
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   656
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   657
                # Temporarily retrieve the catalog object, but don't
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   658
                # cache it as that would interfere with load_catalogs.
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   659
                try:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   660
                        croot = "%s/catalog/%s" % (self.imgdir, prefix)
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   661
                        cat = catalog.Catalog(croot, publisher=prefix)
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   662
                except (EnvironmentError, catalog.CatalogException):
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   663
                        cat = None
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   664
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   665
                update_dt = None
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   666
                if cat:
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   667
                        update_dt = cat.last_modified()
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   668
                        if update_dt:
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
   669
                                update_dt = catalog.ts_to_datetime(update_dt)
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   670
                return update_dt
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   671
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   672
        def get_preferred_publisher(self):
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   673
                """Returns the prefix of the preferred publisher."""
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   674
                return self.cfg_cache.preferred_publisher
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   675
1102
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
   676
        def set_preferred_publisher(self, prefix=None, alias=None, pub=None):
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
   677
                """Sets the preferred publisher for packaging operations.
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
   678
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
   679
                'prefix' is an optional string value specifying the name of
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
   680
                a publisher; ignored if 'pub' is provided.
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
   681
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
   682
                'alias' is an optional string value specifying the alias of
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
   683
                a publisher; ignored if 'pub' is provided.
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
   684
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
   685
                'pub' is an optional Publisher object identifying the
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
   686
                publisher to set as the preferred publisher.
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
   687
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
   688
                One of the above parameters must be provided."""
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
   689
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   690
                self.history.log_operation_start("set-preferred-publisher")
1102
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
   691
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
   692
                if not pub:
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
   693
                        try:
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
   694
                                pub = self.get_publisher(prefix=prefix,
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
   695
                                    alias=alias)
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
   696
                        except api_errors.UnknownPublisher, e:
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
   697
                                self.history.log_operation_end(error=e)
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
   698
                                raise e
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   699
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   700
                if pub.disabled:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   701
                        e = api_errors.SetPreferredPublisherDisabled(pub)
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   702
                        self.history.log_operation_end(error=e)
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   703
                        raise e
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   704
                self.cfg_cache.preferred_publisher = pub.prefix
551
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
   705
                self.save_config()
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   706
                self.history.log_operation_end()
539
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
   707
551
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
   708
        def set_property(self, prop_name, prop_value):
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   709
                assert prop_name != "preferred-publisher"
551
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
   710
                self.cfg_cache.properties[prop_name] = prop_value
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
   711
                self.save_config()
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
   712
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
   713
        def get_property(self, prop_name):
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
   714
                return self.cfg_cache.properties[prop_name]
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
   715
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
   716
        def has_property(self, prop_name):
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
   717
                return prop_name in self.cfg_cache.properties
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
   718
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
   719
        def delete_property(self, prop_name):
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   720
                assert prop_name != "preferred-publisher"
551
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
   721
                del self.cfg_cache.properties[prop_name]
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
   722
                self.save_config()
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
   723
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
   724
        def properties(self):
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
   725
                for p in self.cfg_cache.properties:
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
   726
                        yield p
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
   727
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
   728
        def add_publisher(self, pub, refresh_allowed=True, progtrack=None):
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   729
                """Adds the provided publisher object to the image
1102
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
   730
                configuration.
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
   731
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
   732
                'refresh_allowed' is an optional, boolean value indicating
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
   733
                whether the publisher's metadata should be retrieved when adding
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
   734
                it to the image's configuration.
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
   735
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
   736
                'progtrack' is an optional ProgressTracker object."""
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   737
                self.history.log_operation_start("add-publisher")
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   738
                for p in self.cfg_cache.publishers.values():
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   739
                        if pub == p or (pub.alias and pub.alias == p.alias):
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   740
                                error = api_errors.DuplicatePublisher(pub)
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   741
                                self.history.log_operation_end(error=error)
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   742
                                raise error
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   743
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
   744
                # Must assign this first before performing any more operations.
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
   745
                pub.meta_root = self._get_publisher_meta_root(pub.prefix)
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
   746
                self.cfg_cache.publishers[pub.prefix] = pub
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
   747
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
   748
                # This ensures that if data is leftover from a publisher
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
   749
                # with the same prefix as this one that it gets purged
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
   750
                # first to prevent usage of stale data.
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
   751
                self.remove_publisher_metadata(pub)
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
   752
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   753
                if refresh_allowed:
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
   754
                        try:
1102
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
   755
                                # First, verify that the publisher has a valid
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
   756
                                # pkg(5) repository.
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
   757
                                self.valid_publisher_test(pub)
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
   758
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
   759
                                self.__retrieve_catalogs(full_refresh=True,
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
   760
                                    pubs=[pub], progtrack=progtrack)
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
   761
                        except Exception, e:
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
   762
                                # Remove the newly added publisher since the
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
   763
                                # retrieval failed.
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
   764
                                del self.cfg_cache.publishers[pub.prefix]
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
   765
                                self.history.log_operation_end(error=e)
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
   766
                                raise
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
   767
                        except:
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
   768
                                # Remove the newly added publisher since the
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
   769
                                # retrieval failed.
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
   770
                                del self.cfg_cache.publishers[pub.prefix]
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
   771
                                self.history.log_operation_end(
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
   772
                                    result=history.RESULT_FAILED_UNKNOWN)
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
   773
                                raise
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
   774
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
   775
                # Only after success should the configuration be saved.
551
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
   776
                self.save_config()
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   777
                self.history.log_operation_end()
539
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
   778
235
61994d15c39b 373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents: 226
diff changeset
   779
        def verify(self, fmri, progresstracker, **args):
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
   780
                """generator that returns any errors in installed pkgs
235
61994d15c39b 373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents: 226
diff changeset
   781
                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
   782
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   783
                for act in self.get_manifest(fmri).gen_actions(
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   784
                    self.list_excludes()):
235
61994d15c39b 373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents: 226
diff changeset
   785
                        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
   786
                        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
   787
                        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
   788
                        if errors:
61994d15c39b 373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents: 226
diff changeset
   789
                                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
   790
                                    errors)
583
fc856572d86e 388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents: 582
diff changeset
   791
                                yield (act, errors)
fc856572d86e 388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents: 582
diff changeset
   792
fc856572d86e 388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents: 582
diff changeset
   793
        def repair(self, repairs, progtrack):
fc856572d86e 388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents: 582
diff changeset
   794
                """Repair any actions in the fmri that failed a verify."""
687
3d7060f40501 4450 pkg fix passes bogus cancellation point to pkgplan/imageplan
Brad Hall <bhall@eng.sun.com>
parents: 685
diff changeset
   795
                # XXX: This (lambda x: False) is temporary until we move pkg fix
3d7060f40501 4450 pkg fix passes bogus cancellation point to pkgplan/imageplan
Brad Hall <bhall@eng.sun.com>
parents: 685
diff changeset
   796
                # into the api and can actually use the
3d7060f40501 4450 pkg fix passes bogus cancellation point to pkgplan/imageplan
Brad Hall <bhall@eng.sun.com>
parents: 685
diff changeset
   797
                # api::__check_cancelation() function.
583
fc856572d86e 388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents: 582
diff changeset
   798
                pps = []
fc856572d86e 388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents: 582
diff changeset
   799
                for fmri, actions in repairs:
fc856572d86e 388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents: 582
diff changeset
   800
                        msg("Repairing: %-50s" % fmri.get_pkg_stem())
838
aafbe4737188 3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 835
diff changeset
   801
                        m = self.get_manifest(fmri)
692
ccf4f4e9da34 4818 pkg fix traceback
Brad Hall <bhall@eng.sun.com>
parents: 687
diff changeset
   802
                        pp = pkgplan.PkgPlan(self, progtrack, lambda: False)
583
fc856572d86e 388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents: 582
diff changeset
   803
                        pp.propose_repair(fmri, m, actions)
838
aafbe4737188 3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 835
diff changeset
   804
                        pp.evaluate(self.list_excludes(), self.list_excludes())
583
fc856572d86e 388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents: 582
diff changeset
   805
                        pps.append(pp)
fc856572d86e 388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents: 582
diff changeset
   806
692
ccf4f4e9da34 4818 pkg fix traceback
Brad Hall <bhall@eng.sun.com>
parents: 687
diff changeset
   807
                ip = imageplan.ImagePlan(self, progtrack, lambda: False)
625
e46b345645d6 3799 need to start progress tracker going early on
Brock Pytlik <bpytlik@sun.com>
parents: 621
diff changeset
   808
                progtrack.evaluate_start()
583
fc856572d86e 388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents: 582
diff changeset
   809
                ip.pkg_plans = pps
687
3d7060f40501 4450 pkg fix passes bogus cancellation point to pkgplan/imageplan
Brad Hall <bhall@eng.sun.com>
parents: 685
diff changeset
   810
3d7060f40501 4450 pkg fix passes bogus cancellation point to pkgplan/imageplan
Brad Hall <bhall@eng.sun.com>
parents: 685
diff changeset
   811
                ip.evaluate()
3d7060f40501 4450 pkg fix passes bogus cancellation point to pkgplan/imageplan
Brad Hall <bhall@eng.sun.com>
parents: 685
diff changeset
   812
                ip.preexecute()
3d7060f40501 4450 pkg fix passes bogus cancellation point to pkgplan/imageplan
Brad Hall <bhall@eng.sun.com>
parents: 685
diff changeset
   813
                ip.execute()
583
fc856572d86e 388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents: 582
diff changeset
   814
fc856572d86e 388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents: 582
diff changeset
   815
                return True
222
12006bf2a260 4 We need to be able to verify that package(s) is/are correctly installed
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 221
diff changeset
   816
50
bfcb1661f019 basic image and package plans
Stephen Hahn <sch@sun.com>
parents: 45
diff changeset
   817
        def has_manifest(self, fmri):
45
8a3f00dea14f catalog refresh; basic catalog listing; precise manifest pulls
Stephen Hahn <sch@sun.com>
parents: 39
diff changeset
   818
                mpath = fmri.get_dir_path()
8a3f00dea14f catalog refresh; basic catalog listing; precise manifest pulls
Stephen Hahn <sch@sun.com>
parents: 39
diff changeset
   819
8a3f00dea14f catalog refresh; basic catalog listing; precise manifest pulls
Stephen Hahn <sch@sun.com>
parents: 39
diff changeset
   820
                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
   821
8a3f00dea14f catalog refresh; basic catalog listing; precise manifest pulls
Stephen Hahn <sch@sun.com>
parents: 39
diff changeset
   822
                if (os.path.exists(local_mpath)):
50
bfcb1661f019 basic image and package plans
Stephen Hahn <sch@sun.com>
parents: 45
diff changeset
   823
                        return True
bfcb1661f019 basic image and package plans
Stephen Hahn <sch@sun.com>
parents: 45
diff changeset
   824
bfcb1661f019 basic image and package plans
Stephen Hahn <sch@sun.com>
parents: 45
diff changeset
   825
                return False
45
8a3f00dea14f catalog refresh; basic catalog listing; precise manifest pulls
Stephen Hahn <sch@sun.com>
parents: 39
diff changeset
   826
877
b23f809e8abd 6653 we should elide alternate architectures from in-memory manifests
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 855
diff changeset
   827
        def __fetch_manifest_with_retries(self, fmri, excludes=EmptyI):
956
adf6bdfdb3b5 6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 941
diff changeset
   828
                """go get the manifest we want - retry if needed"""
adf6bdfdb3b5 6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 941
diff changeset
   829
576
6ee6de304041 3777 PKG_TIMEOUT_MAX is a placebo setting
Dan Price <dp@eng.sun.com>
parents: 573
diff changeset
   830
                retry_count = global_settings.PKG_TIMEOUT_MAX
6ee6de304041 3777 PKG_TIMEOUT_MAX is a placebo setting
Dan Price <dp@eng.sun.com>
parents: 573
diff changeset
   831
                failures = TransportFailures()
388
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
   832
956
adf6bdfdb3b5 6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 941
diff changeset
   833
                while retry_count > 0:
388
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
   834
                        try:
956
adf6bdfdb3b5 6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 941
diff changeset
   835
                                mcontent = retrieve.get_manifest(self, fmri)
1068
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
   836
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
   837
                                m = manifest.CachedManifest(fmri, self.pkgdir,
1037
56ff5f4fab83 8050 image-update fails from b110 to b111 at SUNWgnome-system-monitor manifest
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 999
diff changeset
   838
                                    self.cfg_cache.preferred_publisher,
56ff5f4fab83 8050 image-update fails from b110 to b111 at SUNWgnome-system-monitor manifest
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 999
diff changeset
   839
                                    excludes, mcontent)
956
adf6bdfdb3b5 6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 941
diff changeset
   840
adf6bdfdb3b5 6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 941
diff changeset
   841
                                # What is the client currently processing?
adf6bdfdb3b5 6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 941
diff changeset
   842
                                targets = self.state.get_targets()
988
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
   843
956
adf6bdfdb3b5 6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 941
diff changeset
   844
                                intent = None
adf6bdfdb3b5 6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 941
diff changeset
   845
                                for entry in targets:
adf6bdfdb3b5 6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 941
diff changeset
   846
                                        target, reason = entry
adf6bdfdb3b5 6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 941
diff changeset
   847
adf6bdfdb3b5 6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 941
diff changeset
   848
                                        # Ignore the publisher for comparison.
988
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
   849
                                        np_target = target.get_fmri(
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
   850
                                            anarchy=True)
956
adf6bdfdb3b5 6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 941
diff changeset
   851
                                        np_fmri = fmri.get_fmri(anarchy=True)
adf6bdfdb3b5 6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 941
diff changeset
   852
                                        if np_target == np_fmri:
adf6bdfdb3b5 6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 941
diff changeset
   853
                                                intent = reason
adf6bdfdb3b5 6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 941
diff changeset
   854
988
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
   855
                                # If no intent could be found, assume
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
   856
                                # INTENT_INFO.
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
   857
                                self.__set_touched_manifest(fmri,
956
adf6bdfdb3b5 6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 941
diff changeset
   858
                                    max(intent, imagestate.INTENT_INFO))
adf6bdfdb3b5 6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 941
diff changeset
   859
adf6bdfdb3b5 6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 941
diff changeset
   860
                                return m
adf6bdfdb3b5 6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 941
diff changeset
   861
576
6ee6de304041 3777 PKG_TIMEOUT_MAX is a placebo setting
Dan Price <dp@eng.sun.com>
parents: 573
diff changeset
   862
                        except TransportException, e:
399
e594d9c5bd60 2295 pkg forgets to raise TransferTimedOutException
johansen <johansen@sun.com>
parents: 397
diff changeset
   863
                                retry_count -= 1
576
6ee6de304041 3777 PKG_TIMEOUT_MAX is a placebo setting
Dan Price <dp@eng.sun.com>
parents: 573
diff changeset
   864
                                failures.append(e)
399
e594d9c5bd60 2295 pkg forgets to raise TransferTimedOutException
johansen <johansen@sun.com>
parents: 397
diff changeset
   865
835
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
   866
                        except MalformedActionError, e:
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
   867
                                retry_count -= 1
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   868
                                pub = fmri.get_publisher()
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   869
                                url = self.cfg_cache.publishers[pub]["origin"]
835
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
   870
                                te = misc.TransferContentException(url=url,
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
   871
                                    reason=str(e))
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
   872
                                failures.append(te)
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
   873
956
adf6bdfdb3b5 6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 941
diff changeset
   874
                raise failures
388
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
   875
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   876
        def __get_touched_manifest(self, fmri, intent):
556
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   877
                """Returns whether intent information has been provided for the
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   878
                given fmri."""
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   879
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   880
                op = self.history.operation_name
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   881
                if not op:
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   882
                        # The client may not have provided the name of the
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   883
                        # operation it is performing.
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   884
                        op = "unknown"
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   885
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   886
                if op not in self.__touched_manifests:
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   887
                        # No intent information has been provided for fmris
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   888
                        # for the current operation.
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   889
                        return False
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   890
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   891
                f = str(fmri)
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   892
                if f not in self.__touched_manifests[op]:
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   893
                        # No intent information has been provided for this
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   894
                        # fmri for the current operation.
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   895
                        return False
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   896
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   897
                if intent not in self.__touched_manifests[op][f]:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   898
                        # No intent information has been provided for this
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   899
                        # fmri for the current operation and reason.
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   900
                        return False
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   901
556
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   902
                return True
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   903
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   904
        def __set_touched_manifest(self, fmri, intent):
556
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   905
                """Records that intent information has been provided for the
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   906
                given fmri's manifest."""
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   907
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   908
                op = self.history.operation_name
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   909
                if not op:
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   910
                        # The client may not have provided the name of the
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   911
                        # operation it is performing.
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   912
                        op = "unknown"
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   913
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   914
                if op not in self.__touched_manifests:
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   915
                        # No intent information has yet been provided for fmris
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   916
                        # for the current operation.
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   917
                        self.__touched_manifests[op] = {}
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   918
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   919
                f = str(fmri)
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   920
                if f not in self.__touched_manifests[op]:
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   921
                        # No intent information has yet been provided for this
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   922
                        # fmri for the current operation.
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   923
                        self.__touched_manifests[op][f] = { intent: None }
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   924
                else:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   925
                        # No intent information has yet been provided for this
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   926
                        # fmri for the current operation and reason.
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   927
                        self.__touched_manifests[op][f][intent] = None
556
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   928
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   929
        def __touch_manifest(self, fmri):
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   930
                """Perform steps necessary to 'touch' a manifest to provide
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   931
                intent information.  Ignores most exceptions as this operation
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   932
                is only for informational purposes."""
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   933
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   934
                # What is the client currently processing?
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   935
                target, intent = self.state.get_target()
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   936
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   937
                # Ignore dry-runs of operations or operations which do not have
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   938
                # a set target.
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   939
                if not target or intent == imagestate.INTENT_EVALUATE:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   940
                        return
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   941
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   942
                if not self.__get_touched_manifest(fmri, intent):
556
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   943
                        # If the manifest for this fmri hasn't been "seen"
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   944
                        # before, determine if intent information needs to be
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   945
                        # provided.
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   946
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   947
                        # Ignore the publisher for comparison.
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   948
                        np_target = target.get_fmri(anarchy=True)
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   949
                        np_fmri = fmri.get_fmri(anarchy=True)
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   950
                        if np_target == np_fmri:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   951
                                # If the client is currently processing
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   952
                                # the given fmri (for an install, etc.)
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   953
                                # then intent information is needed.
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   954
                                retrieve.touch_manifest(self, fmri)
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   955
                                self.__set_touched_manifest(fmri, intent)
556
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   956
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
   957
        def get_manifest_path(self, fmri):
956
adf6bdfdb3b5 6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 941
diff changeset
   958
                """Return path to on-disk manifest"""
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
   959
                mpath = os.path.join(self.imgdir, "pkg",
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
   960
                    fmri.get_dir_path(), "manifest")
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
   961
                return mpath
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
   962
877
b23f809e8abd 6653 we should elide alternate architectures from in-memory manifests
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 855
diff changeset
   963
        def __get_manifest(self, fmri, excludes=EmptyI):
556
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   964
                """Find on-disk manifest and create in-memory Manifest
956
adf6bdfdb3b5 6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 941
diff changeset
   965
                object.... grab from server if needed"""
556
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   966
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   967
                try:
1068
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
   968
                        return manifest.CachedManifest(fmri, self.pkgdir,
1037
56ff5f4fab83 8050 image-update fails from b110 to b111 at SUNWgnome-system-monitor manifest
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 999
diff changeset
   969
                            self.cfg_cache.preferred_publisher,
56ff5f4fab83 8050 image-update fails from b110 to b111 at SUNWgnome-system-monitor manifest
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 999
diff changeset
   970
                            excludes)
956
adf6bdfdb3b5 6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 941
diff changeset
   971
                except KeyError:
adf6bdfdb3b5 6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 941
diff changeset
   972
                        return self.__fetch_manifest_with_retries(fmri,
adf6bdfdb3b5 6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 941
diff changeset
   973
                            excludes)
adf6bdfdb3b5 6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 941
diff changeset
   974
adf6bdfdb3b5 6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 941
diff changeset
   975
        def get_manifest(self, fmri, add_to_cache=True, all_arch=False):
adf6bdfdb3b5 6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 941
diff changeset
   976
                """return manifest; uses cached version if available.
adf6bdfdb3b5 6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 941
diff changeset
   977
                all_arch controls whether manifest contains actions
adf6bdfdb3b5 6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 941
diff changeset
   978
                for all architectures"""
adf6bdfdb3b5 6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 941
diff changeset
   979
adf6bdfdb3b5 6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 941
diff changeset
   980
                # Normally elide other arch variants
adf6bdfdb3b5 6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 941
diff changeset
   981
                if all_arch:
988
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
   982
                        add_to_cache = False
956
adf6bdfdb3b5 6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 941
diff changeset
   983
                        v = EmptyI
adf6bdfdb3b5 6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 941
diff changeset
   984
                else:
adf6bdfdb3b5 6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 941
diff changeset
   985
                        arch = {"variant.arch": self.get_arch()}
adf6bdfdb3b5 6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 941
diff changeset
   986
                        v = [variant.Variants(arch).allow_action]
877
b23f809e8abd 6653 we should elide alternate architectures from in-memory manifests
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 855
diff changeset
   987
634
44055bedbebd 4263 manifest caching should only be done for pkg(1) for now
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 625
diff changeset
   988
                # XXX This is a temporary workaround so that GUI api consumsers
44055bedbebd 4263 manifest caching should only be done for pkg(1) for now
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 625
diff changeset
   989
                # are not negatively impacted by manifest caching.  This should
44055bedbebd 4263 manifest caching should only be done for pkg(1) for now
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 625
diff changeset
   990
                # be removed by bug 4231 whenever a better way to handle caching
44055bedbebd 4263 manifest caching should only be done for pkg(1) for now
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 625
diff changeset
   991
                # is found.
956
adf6bdfdb3b5 6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 941
diff changeset
   992
                if global_settings.client_name == "pkg" and not all_arch:
634
44055bedbebd 4263 manifest caching should only be done for pkg(1) for now
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 625
diff changeset
   993
                        if fmri in self.__manifest_cache:
44055bedbebd 4263 manifest caching should only be done for pkg(1) for now
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 625
diff changeset
   994
                                m = self.__manifest_cache[fmri]
44055bedbebd 4263 manifest caching should only be done for pkg(1) for now
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 625
diff changeset
   995
                        else:
956
adf6bdfdb3b5 6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 941
diff changeset
   996
                                m = self.__get_manifest(fmri, v)
886
8f40fc0ee8f9 6712 search shouldn't index actions for other variants of an image
Brock Pytlik <bpytlik@sun.com>
parents: 877
diff changeset
   997
                                if add_to_cache:
8f40fc0ee8f9 6712 search shouldn't index actions for other variants of an image
Brock Pytlik <bpytlik@sun.com>
parents: 877
diff changeset
   998
                                        self.__manifest_cache[fmri] = m
567
ea1d96e269a4 3505 client action and manifest creation are wasteful
johansen <johansen@sun.com>
parents: 565
diff changeset
   999
                else:
956
adf6bdfdb3b5 6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 941
diff changeset
  1000
                        m = self.__get_manifest(fmri, v)
567
ea1d96e269a4 3505 client action and manifest creation are wasteful
johansen <johansen@sun.com>
parents: 565
diff changeset
  1001
556
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
  1002
                self.__touch_manifest(fmri)
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1003
                return m
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1004
964
a6b1ee94f115 7547 Some working set reductions possible for image-update
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 956
diff changeset
  1005
        def uncache_manifest(self, fmri):
a6b1ee94f115 7547 Some working set reductions possible for image-update
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 956
diff changeset
  1006
                """Remove specified FMRI from manifest cache."""
a6b1ee94f115 7547 Some working set reductions possible for image-update
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 956
diff changeset
  1007
a6b1ee94f115 7547 Some working set reductions possible for image-update
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 956
diff changeset
  1008
                if fmri in self.__manifest_cache:
a6b1ee94f115 7547 Some working set reductions possible for image-update
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 956
diff changeset
  1009
                        del self.__manifest_cache[fmri]
a6b1ee94f115 7547 Some working set reductions possible for image-update
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 956
diff changeset
  1010
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1011
        def installed_file_publisher(self, filepath):
195
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
  1012
                """Find the pkg's installed file named by filepath.
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1013
                Return the publisher that installed this package."""
195
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
  1014
956
adf6bdfdb3b5 6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 941
diff changeset
  1015
                f = file(filepath)
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
  1016
                try:
956
adf6bdfdb3b5 6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 941
diff changeset
  1017
                        flines = f.readlines()
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1018
                        version, pub = flines
918
6a14979b842a 1164 "installed" metadata files don't end in newlines
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 891
diff changeset
  1019
                        version = version.strip()
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1020
                        pub = pub.strip()
956
adf6bdfdb3b5 6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 941
diff changeset
  1021
                        f.close()
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1022
                except ValueError:
956
adf6bdfdb3b5 6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 941
diff changeset
  1023
                        # If we get a ValueError, we've encountered an
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
  1024
                        # 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
  1025
                        # 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
  1026
                        # to assume that the package was installed from
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1027
                        # the preferred publisher.  Here, we set up
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1028
                        # the publisher to record that.
356
672e0af33ea8 1536 empty installed files generate tracebacks
johansen <johansen@sun.com>
parents: 347
diff changeset
  1029
                        if flines:
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1030
                                pub = flines[0]
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1031
                                pub = pub.strip()
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1032
                                newpub = "%s_%s" % (pkg.fmri.PREF_PUB_PFX,
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1033
                                    pub)
356
672e0af33ea8 1536 empty installed files generate tracebacks
johansen <johansen@sun.com>
parents: 347
diff changeset
  1034
                        else:
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1035
                                newpub = "%s_%s" % (pkg.fmri.PREF_PUB_PFX,
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1036
                                    self.get_preferred_publisher())
356
672e0af33ea8 1536 empty installed files generate tracebacks
johansen <johansen@sun.com>
parents: 347
diff changeset
  1037
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1038
                        pub = newpub
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1039
956
adf6bdfdb3b5 6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 941
diff changeset
  1040
                        try:
adf6bdfdb3b5 6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 941
diff changeset
  1041
                                f = file(filepath, "w")
1107
d2cc5edc2593 8600 incompatibility due to newline following publisher in installed file
Tom Mueller <Tom.Mueller@sun.com>
parents: 1102
diff changeset
  1042
                                f.writelines(["VERSION_1\n", newpub])
956
adf6bdfdb3b5 6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 941
diff changeset
  1043
                                f.close()
adf6bdfdb3b5 6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 941
diff changeset
  1044
                        except IOError, e:
988
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  1045
                                if e.errno not in (errno.EACCES, errno.EROFS):
956
adf6bdfdb3b5 6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 941
diff changeset
  1046
                                        raise
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1047
                assert pub
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1048
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1049
                return pub
195
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
  1050
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1051
        def _install_file(self, fmri):
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1052
                """Returns the path to the "installed" file for a given fmri."""
956
adf6bdfdb3b5 6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 941
diff changeset
  1053
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1054
                return "%s/pkg/%s/installed" % (self.imgdir,
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1055
                    fmri.get_dir_path())
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1056
195
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
  1057
        def install_file_present(self, fmri):
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
  1058
                """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
  1059
                on the system.  Otherwise, returns false."""
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
  1060
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1061
                return os.path.exists(self._install_file(fmri))
195
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
  1062
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
  1063
        def add_install_file(self, fmri):
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
  1064
                """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
  1065
                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
  1066
                installed."""
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
  1067
418
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
  1068
                # XXX This can be removed at some point in the future once we
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
  1069
                # think this link is available on all systems
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
  1070
                if not os.path.isdir("%s/state/installed" % self.imgdir):
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1071
                        self.__update_installed_pkgs()
418
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
  1072
717
c40259b4ce98 4569 pkg uninstall tracesback when lacking permissions
Brock Pytlik <bpytlik@sun.com>
parents: 715
diff changeset
  1073
                try:
c40259b4ce98 4569 pkg uninstall tracesback when lacking permissions
Brock Pytlik <bpytlik@sun.com>
parents: 715
diff changeset
  1074
                        f = file(self._install_file(fmri), "w")
c40259b4ce98 4569 pkg uninstall tracesback when lacking permissions
Brock Pytlik <bpytlik@sun.com>
parents: 715
diff changeset
  1075
                except EnvironmentError:
c40259b4ce98 4569 pkg uninstall tracesback when lacking permissions
Brock Pytlik <bpytlik@sun.com>
parents: 715
diff changeset
  1076
                        try:
c40259b4ce98 4569 pkg uninstall tracesback when lacking permissions
Brock Pytlik <bpytlik@sun.com>
parents: 715
diff changeset
  1077
                                os.makedirs(os.path.dirname(
c40259b4ce98 4569 pkg uninstall tracesback when lacking permissions
Brock Pytlik <bpytlik@sun.com>
parents: 715
diff changeset
  1078
                                    self._install_file(fmri)))
c40259b4ce98 4569 pkg uninstall tracesback when lacking permissions
Brock Pytlik <bpytlik@sun.com>
parents: 715
diff changeset
  1079
                        except EnvironmentError, e:
c40259b4ce98 4569 pkg uninstall tracesback when lacking permissions
Brock Pytlik <bpytlik@sun.com>
parents: 715
diff changeset
  1080
                                if e.errno == errno.EACCES:
c40259b4ce98 4569 pkg uninstall tracesback when lacking permissions
Brock Pytlik <bpytlik@sun.com>
parents: 715
diff changeset
  1081
                                        raise api_errors.PermissionsException(
c40259b4ce98 4569 pkg uninstall tracesback when lacking permissions
Brock Pytlik <bpytlik@sun.com>
parents: 715
diff changeset
  1082
                                            e.filename)
1075
2c935307c8ab 7593 stack trace on reinstallation of package with insufficient permissions
Rich Burridge <rich.burridge@sun.com>
parents: 1068
diff changeset
  1083
                                if e.errno != errno.EEXIST and \
2c935307c8ab 7593 stack trace on reinstallation of package with insufficient permissions
Rich Burridge <rich.burridge@sun.com>
parents: 1068
diff changeset
  1084
                                    not os.path.isdir(e.filename):
2c935307c8ab 7593 stack trace on reinstallation of package with insufficient permissions
Rich Burridge <rich.burridge@sun.com>
parents: 1068
diff changeset
  1085
                                        raise
2c935307c8ab 7593 stack trace on reinstallation of package with insufficient permissions
Rich Burridge <rich.burridge@sun.com>
parents: 1068
diff changeset
  1086
717
c40259b4ce98 4569 pkg uninstall tracesback when lacking permissions
Brock Pytlik <bpytlik@sun.com>
parents: 715
diff changeset
  1087
                        f = file(self._install_file(fmri), "w")
195
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
  1088
1107
d2cc5edc2593 8600 incompatibility due to newline following publisher in installed file
Tom Mueller <Tom.Mueller@sun.com>
parents: 1102
diff changeset
  1089
                f.writelines(["VERSION_1\n", fmri.get_publisher_str()])
195
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
  1090
                f.close()
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
  1091
434
48c05c66cdd2 2595 List speedup changes don't work on Windows
Tom Mueller <Tom.Mueller@sun.com>
parents: 432
diff changeset
  1092
                fi = file("%s/state/installed/%s" % (self.imgdir,
48c05c66cdd2 2595 List speedup changes don't work on Windows
Tom Mueller <Tom.Mueller@sun.com>
parents: 432
diff changeset
  1093
                    fmri.get_link_path()), "w")
48c05c66cdd2 2595 List speedup changes don't work on Windows
Tom Mueller <Tom.Mueller@sun.com>
parents: 432
diff changeset
  1094
                fi.close()
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1095
                self.__pkg_states[urllib.unquote(fmri.get_link_path())] = \
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1096
                    (PKG_STATE_INSTALLED, fmri)
418
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
  1097
195
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
  1098
        def remove_install_file(self, fmri):
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
  1099
                """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
  1100
                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
  1101
                installed."""
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
  1102
418
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
  1103
                # XXX This can be removed at some point in the future once we
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
  1104
                # think this link is available on all systems
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
  1105
                if not os.path.isdir("%s/state/installed" % self.imgdir):
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1106
                        self.__update_installed_pkgs()
418
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
  1107
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1108
                os.unlink(self._install_file(fmri))
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1109
                try:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1110
                        os.unlink("%s/state/installed/%s" % (self.imgdir,
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1111
                            fmri.get_link_path()))
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1112
                except EnvironmentError, e:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1113
                        if e.errno != errno.ENOENT:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1114
                                raise
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1115
                self.__pkg_states[urllib.unquote(fmri.get_link_path())] = \
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1116
                    (PKG_STATE_KNOWN, fmri)
418
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
  1117
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1118
        def __update_installed_pkgs(self):
418
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
  1119
                """Take the image's record of installed packages from the
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
  1120
                prototype layout, with an installed file in each
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
  1121
                $META/pkg/stem/version directory, to the $META/state/installed
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
  1122
                summary directory form."""
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
  1123
658
e470d4688084 4412 pkg refresh can strand one w/o packages after upgrade from 86
Danek Duvall <danek.duvall@sun.com>
parents: 655
diff changeset
  1124
                # If the directory is empty or it doesn't exist, we should
e470d4688084 4412 pkg refresh can strand one w/o packages after upgrade from 86
Danek Duvall <danek.duvall@sun.com>
parents: 655
diff changeset
  1125
                # populate it.  The easy test is to try to remove the directory,
e470d4688084 4412 pkg refresh can strand one w/o packages after upgrade from 86
Danek Duvall <danek.duvall@sun.com>
parents: 655
diff changeset
  1126
                # which will fail if it's already got entries in it, or doesn't
e470d4688084 4412 pkg refresh can strand one w/o packages after upgrade from 86
Danek Duvall <danek.duvall@sun.com>
parents: 655
diff changeset
  1127
                # exist.  Other errors are beyond our capability to handle.
834
f8b3396500b3 4883 import failure for non-sunos platforms due to missing pspawn
Tom Mueller <Tom.Mueller@sun.com>
parents: 792
diff changeset
  1128
                statedir = os.path.join(self.imgdir, "state", "installed")
658
e470d4688084 4412 pkg refresh can strand one w/o packages after upgrade from 86
Danek Duvall <danek.duvall@sun.com>
parents: 655
diff changeset
  1129
                try:
834
f8b3396500b3 4883 import failure for non-sunos platforms due to missing pspawn
Tom Mueller <Tom.Mueller@sun.com>
parents: 792
diff changeset
  1130
                        os.rmdir(statedir)
658
e470d4688084 4412 pkg refresh can strand one w/o packages after upgrade from 86
Danek Duvall <danek.duvall@sun.com>
parents: 655
diff changeset
  1131
                except EnvironmentError, e:
834
f8b3396500b3 4883 import failure for non-sunos platforms due to missing pspawn
Tom Mueller <Tom.Mueller@sun.com>
parents: 792
diff changeset
  1132
                        if e.errno in (errno.EEXIST, errno.ENOTEMPTY):
658
e470d4688084 4412 pkg refresh can strand one w/o packages after upgrade from 86
Danek Duvall <danek.duvall@sun.com>
parents: 655
diff changeset
  1133
                                return
685
6f53483db920 1469 image-update by unprivileged user should give better error message
Brock Pytlik <bpytlik@sun.com>
parents: 674
diff changeset
  1134
                        elif e.errno == errno.EACCES:
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1135
                                # The directory may exist and be non-empty
834
f8b3396500b3 4883 import failure for non-sunos platforms due to missing pspawn
Tom Mueller <Tom.Mueller@sun.com>
parents: 792
diff changeset
  1136
                                # even though we got EACCES.  Try
f8b3396500b3 4883 import failure for non-sunos platforms due to missing pspawn
Tom Mueller <Tom.Mueller@sun.com>
parents: 792
diff changeset
  1137
                                # to determine its emptiness another way.
f8b3396500b3 4883 import failure for non-sunos platforms due to missing pspawn
Tom Mueller <Tom.Mueller@sun.com>
parents: 792
diff changeset
  1138
                                try:
f8b3396500b3 4883 import failure for non-sunos platforms due to missing pspawn
Tom Mueller <Tom.Mueller@sun.com>
parents: 792
diff changeset
  1139
                                        if os.path.isdir(statedir) and \
f8b3396500b3 4883 import failure for non-sunos platforms due to missing pspawn
Tom Mueller <Tom.Mueller@sun.com>
parents: 792
diff changeset
  1140
                                            len(os.listdir(statedir)) > 0:
f8b3396500b3 4883 import failure for non-sunos platforms due to missing pspawn
Tom Mueller <Tom.Mueller@sun.com>
parents: 792
diff changeset
  1141
                                                return
f8b3396500b3 4883 import failure for non-sunos platforms due to missing pspawn
Tom Mueller <Tom.Mueller@sun.com>
parents: 792
diff changeset
  1142
                                except EnvironmentError:
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1143
                                        # ignore this error, pass on the
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1144
                                        # original access error
834
f8b3396500b3 4883 import failure for non-sunos platforms due to missing pspawn
Tom Mueller <Tom.Mueller@sun.com>
parents: 792
diff changeset
  1145
                                        pass
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1146
                                raise api_errors.PermissionsException(
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1147
                                    e.filename)
658
e470d4688084 4412 pkg refresh can strand one w/o packages after upgrade from 86
Danek Duvall <danek.duvall@sun.com>
parents: 655
diff changeset
  1148
                        elif e.errno != errno.ENOENT:
e470d4688084 4412 pkg refresh can strand one w/o packages after upgrade from 86
Danek Duvall <danek.duvall@sun.com>
parents: 655
diff changeset
  1149
                                raise
e470d4688084 4412 pkg refresh can strand one w/o packages after upgrade from 86
Danek Duvall <danek.duvall@sun.com>
parents: 655
diff changeset
  1150
834
f8b3396500b3 4883 import failure for non-sunos platforms due to missing pspawn
Tom Mueller <Tom.Mueller@sun.com>
parents: 792
diff changeset
  1151
                tmpdir = os.path.join(self.imgdir, "state", "installed.build")
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1152
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1153
                # Create the link forest in a temporary directory.  We should
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1154
                # only execute this method once (if ever) in the lifetime of an
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1155
                # image, but if the path already exists and makedirs() blows up,
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1156
                # just be quiet if it's already a directory.  If it's not a
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1157
                # directory or something else weird happens, re-raise.
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1158
                try:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1159
                        os.makedirs(tmpdir)
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1160
                except OSError, e:
834
f8b3396500b3 4883 import failure for non-sunos platforms due to missing pspawn
Tom Mueller <Tom.Mueller@sun.com>
parents: 792
diff changeset
  1161
                        if e.errno == errno.EACCES:
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1162
                                raise api_errors.PermissionsException(
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1163
                                    e.filename)
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1164
                        if e.errno != errno.EEXIST or \
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1165
                            not os.path.isdir(tmpdir):
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1166
                                raise
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1167
                        return
418
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
  1168
834
f8b3396500b3 4883 import failure for non-sunos platforms due to missing pspawn
Tom Mueller <Tom.Mueller@sun.com>
parents: 792
diff changeset
  1169
                proot = os.path.join(self.imgdir, "pkg")
418
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
  1170
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1171
                for pd, vd in (
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1172
                    (p, v)
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1173
                    for p in sorted(os.listdir(proot))
834
f8b3396500b3 4883 import failure for non-sunos platforms due to missing pspawn
Tom Mueller <Tom.Mueller@sun.com>
parents: 792
diff changeset
  1174
                    for v in sorted(os.listdir(os.path.join(proot, p)))
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1175
                    ):
834
f8b3396500b3 4883 import failure for non-sunos platforms due to missing pspawn
Tom Mueller <Tom.Mueller@sun.com>
parents: 792
diff changeset
  1176
                        path = os.path.join(proot, pd, vd, "installed")
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1177
                        if not os.path.exists(path):
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1178
                                continue
418
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
  1179
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1180
                        fmristr = urllib.unquote("%s@%s" % (pd, vd))
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1181
                        pub = self.installed_file_publisher(path)
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1182
                        f = pkg.fmri.PkgFmri(fmristr, publisher = pub)
834
f8b3396500b3 4883 import failure for non-sunos platforms due to missing pspawn
Tom Mueller <Tom.Mueller@sun.com>
parents: 792
diff changeset
  1183
                        fi = file(os.path.join(tmpdir, f.get_link_path()), "w")
434
48c05c66cdd2 2595 List speedup changes don't work on Windows
Tom Mueller <Tom.Mueller@sun.com>
parents: 432
diff changeset
  1184
                        fi.close()
418
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
  1185
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1186
                # Someone may have already created this directory.  Junk the
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1187
                # directory we just populated if that's the case.
418
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
  1188
                try:
834
f8b3396500b3 4883 import failure for non-sunos platforms due to missing pspawn
Tom Mueller <Tom.Mueller@sun.com>
parents: 792
diff changeset
  1189
                        portable.rename(tmpdir, statedir)
418
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
  1190
                except EnvironmentError, e:
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
  1191
                        if e.errno != errno.EEXIST:
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
  1192
                                raise
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1193
                        shutil.rmtree(tmpdir)
418
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
  1194
556
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
  1195
        def get_version_installed(self, pfmri):
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
  1196
                """Returns an fmri of the installed package matching the
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
  1197
                package stem of the given fmri or None if no match is found."""
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1198
556
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
  1199
                for f in self.gen_installed_pkgs():
568
52eea0be5030 3714 cannot uninstall package after authority removal
Danek Duvall <danek.duvall@sun.com>
parents: 567
diff changeset
  1200
                        if self.fmri_is_same_pkg(f, pfmri):
556
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
  1201
                                return f
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
  1202
                return None
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
  1203
104
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
  1204
        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
  1205
                """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
  1206
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1207
                return self.__pkg_states.get(pfmri.get_fmri(anarchy = True)[5:],
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1208
                    (PKG_STATE_KNOWN, None))[0]
104
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
  1209
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1210
        def get_pkg_pub_by_fmri(self, pfmri):
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1211
                """Return the publisher from which 'pfmri' was installed."""
423
5c756997bf67 2253 With the latest build of the pkg repo, can't install packages from additional authorities
Danek Duvall <danek.duvall@sun.com>
parents: 419
diff changeset
  1212
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1213
                f = self.__pkg_states.get(pfmri.get_fmri(anarchy = True)[5:],
423
5c756997bf67 2253 With the latest build of the pkg repo, can't install packages from additional authorities
Danek Duvall <danek.duvall@sun.com>
parents: 419
diff changeset
  1214
                    (PKG_STATE_KNOWN, None))[1]
5c756997bf67 2253 With the latest build of the pkg repo, can't install packages from additional authorities
Danek Duvall <danek.duvall@sun.com>
parents: 419
diff changeset
  1215
                if f:
5c756997bf67 2253 With the latest build of the pkg repo, can't install packages from additional authorities
Danek Duvall <danek.duvall@sun.com>
parents: 419
diff changeset
  1216
                        # Return the non-preferred-prefixed name
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1217
                        return f.get_publisher()
423
5c756997bf67 2253 With the latest build of the pkg repo, can't install packages from additional authorities
Danek Duvall <danek.duvall@sun.com>
parents: 419
diff changeset
  1218
                return None
5c756997bf67 2253 With the latest build of the pkg repo, can't install packages from additional authorities
Danek Duvall <danek.duvall@sun.com>
parents: 419
diff changeset
  1219
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1220
        def fmri_set_default_publisher(self, fmri):
195
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
  1221
                """If the FMRI supplied as an argument does not have
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1222
                a publisher, set it to the image's preferred publisher."""
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1223
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1224
                if fmri.has_publisher():
195
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
  1225
                        return
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
  1226
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1227
                fmri.set_publisher(self.get_preferred_publisher(), True)
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1228
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1229
        def get_catalog(self, fmri, exception = False):
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1230
                """Given a FMRI, look at the publisher and return the
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1231
                correct catalog for this image."""
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1232
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1233
                # If FMRI has no publisher, or is default publisher,
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1234
                # then return the catalog for the preferred publisher
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1235
                if not fmri.has_publisher() or fmri.preferred_publisher():
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1236
                        cat = self.__catalogs[self.get_preferred_publisher()]
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1237
                else:
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1238
                        try:
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1239
                                cat = self.__catalogs[fmri.get_publisher()]
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1240
                        except KeyError:
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1241
                                # If the publisher that installed this package
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1242
                                # has vanished, pick the default publisher
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1243
                                # instead.
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1244
                                if exception:
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1245
                                        raise
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1246
                                else:
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1247
                                        cat = self.__catalogs[\
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1248
                                            self.get_preferred_publisher()]
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1249
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1250
                return cat
195
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
  1251
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
  1252
        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
  1253
                """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
  1254
                installed in the current image."""
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1255
560
4c8d82d58131 3569 pkg state code obviates use of _get_version_installed
Shawn Walker <shawn.walker@sun.com>
parents: 556
diff changeset
  1256
                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
  1257
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1258
                if v and not fmri.has_publisher():
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1259
                        fmri.set_publisher(v.get_publisher_str())
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1260
                elif not fmri.has_publisher():
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1261
                        fmri.set_publisher(self.get_preferred_publisher(), True)
266
5e5bff6fedce 582 Importing packages seemingly misrecords dependencies
johansen <johansen@sun.com>
parents: 260
diff changeset
  1262
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1263
                if v and self.fmri_is_successor(v, fmri):
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1264
                        return True
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1265
                else:
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1266
                        try:
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1267
                                cat = self.get_catalog(fmri, exception = True)
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1268
                        except KeyError:
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1269
                                return False
59
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
  1270
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1271
                        # 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
  1272
                        # packages that are equivalent to fmri.
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1273
                        rpkgs = cat.rename_newer_pkgs(fmri)
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1274
                        for f in rpkgs:
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1275
560
4c8d82d58131 3569 pkg state code obviates use of _get_version_installed
Shawn Walker <shawn.walker@sun.com>
parents: 556
diff changeset
  1276
                                v = self.get_version_installed(f)
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1277
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1278
                                if v and self.fmri_is_successor(v, fmri):
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1279
                                        return True
59
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
  1280
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
  1281
                return False
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
  1282
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1283
        def older_version_installed(self, fmri):
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1284
                """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
  1285
                older version of the package is installed.  This takes
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1286
                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
  1287
                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
  1288
                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
  1289
                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
  1290
560
4c8d82d58131 3569 pkg state code obviates use of _get_version_installed
Shawn Walker <shawn.walker@sun.com>
parents: 556
diff changeset
  1291
                v = self.get_version_installed(fmri)
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1292
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1293
                assert fmri.has_publisher()
268
3d53da66d4a4 582 Importing packages seemingly misrecords dependencies
johansen <johansen@sun.com>
parents: 266
diff changeset
  1294
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1295
                if v:
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1296
                        return v
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1297
                else:
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1298
                        cat = self.get_catalog(fmri)
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1299
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1300
                        rpkgs = cat.rename_older_pkgs(fmri)
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1301
                        for f in rpkgs:
560
4c8d82d58131 3569 pkg state code obviates use of _get_version_installed
Shawn Walker <shawn.walker@sun.com>
parents: 556
diff changeset
  1302
                                v = self.get_version_installed(f)
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1303
                                if v and self.fmri_is_successor(fmri, v):
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1304
                                        return v
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1305
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1306
                return None
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1307
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
  1308
        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
  1309
                """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
  1310
                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
  1311
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1312
                # All FMRIs passed to is_installed shall have a publisher
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1313
                assert fmri.has_publisher()
195
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
  1314
560
4c8d82d58131 3569 pkg state code obviates use of _get_version_installed
Shawn Walker <shawn.walker@sun.com>
parents: 556
diff changeset
  1315
                v = self.get_version_installed(fmri)
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1316
                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
  1317
                        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
  1318
a1e20e9a9845 add CLI test suite, correct bugs found by test suite, ration out CLI options
Stephen Hahn <sch@Sun.COM>
parents: 116
diff changeset
  1319
                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
  1320
838
aafbe4737188 3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 835
diff changeset
  1321
        def list_excludes(self, new_variants=None):
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1322
                """Generate a list of callables that each return True if an
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1323
                action is to be included in the image using the currently
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1324
                defined variants for the image, or an updated set if
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1325
                new_variants are specified.  The callables take a single action
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1326
                argument.  Variants, facets and filters will be handled in
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1327
                this fashion."""
956
adf6bdfdb3b5 6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 941
diff changeset
  1328
838
aafbe4737188 3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 835
diff changeset
  1329
                # XXX simple for now; facets and filters need impl.
aafbe4737188 3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 835
diff changeset
  1330
                if new_variants:
aafbe4737188 3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 835
diff changeset
  1331
                        new_vars = self.cfg_cache.variants.copy()
aafbe4737188 3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 835
diff changeset
  1332
                        new_vars.update(new_variants)
aafbe4737188 3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 835
diff changeset
  1333
                        return [new_vars.allow_action]
aafbe4737188 3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 835
diff changeset
  1334
                else:
aafbe4737188 3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 835
diff changeset
  1335
                        return [self.cfg_cache.variants.allow_action]
aafbe4737188 3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 835
diff changeset
  1336
432
578875da6e04 48 Removing a dependency is not flagged, and recovery is not obvious
Danek Duvall <danek.duvall@sun.com>
parents: 429
diff changeset
  1337
        def __build_dependents(self, progtrack):
578875da6e04 48 Removing a dependency is not flagged, and recovery is not obvious
Danek Duvall <danek.duvall@sun.com>
parents: 429
diff changeset
  1338
                """Build a dictionary mapping packages to the list of packages
578875da6e04 48 Removing a dependency is not flagged, and recovery is not obvious
Danek Duvall <danek.duvall@sun.com>
parents: 429
diff changeset
  1339
                that have required dependencies on them."""
956
adf6bdfdb3b5 6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 941
diff changeset
  1340
432
578875da6e04 48 Removing a dependency is not flagged, and recovery is not obvious
Danek Duvall <danek.duvall@sun.com>
parents: 429
diff changeset
  1341
                self.__req_dependents = {}
578875da6e04 48 Removing a dependency is not flagged, and recovery is not obvious
Danek Duvall <danek.duvall@sun.com>
parents: 429
diff changeset
  1342
578875da6e04 48 Removing a dependency is not flagged, and recovery is not obvious
Danek Duvall <danek.duvall@sun.com>
parents: 429
diff changeset
  1343
                for fmri in self.gen_installed_pkgs():
577
cd4e8df4322b 873 Text is wrong in the General Info tab
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 576
diff changeset
  1344
                        progtrack.evaluate_progress(fmri)
838
aafbe4737188 3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 835
diff changeset
  1345
                        mfst = self.get_manifest(fmri)
aafbe4737188 3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 835
diff changeset
  1346
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1347
                        for dep in mfst.gen_actions_by_type("depend",
838
aafbe4737188 3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 835
diff changeset
  1348
                            self.list_excludes()):
432
578875da6e04 48 Removing a dependency is not flagged, and recovery is not obvious
Danek Duvall <danek.duvall@sun.com>
parents: 429
diff changeset
  1349
                                if dep.attrs["type"] != "require":
578875da6e04 48 Removing a dependency is not flagged, and recovery is not obvious
Danek Duvall <danek.duvall@sun.com>
parents: 429
diff changeset
  1350
                                        continue
578875da6e04 48 Removing a dependency is not flagged, and recovery is not obvious
Danek Duvall <danek.duvall@sun.com>
parents: 429
diff changeset
  1351
                                dfmri = self.strtofmri(dep.attrs["fmri"])
578875da6e04 48 Removing a dependency is not flagged, and recovery is not obvious
Danek Duvall <danek.duvall@sun.com>
parents: 429
diff changeset
  1352
                                if dfmri not in self.__req_dependents:
578875da6e04 48 Removing a dependency is not flagged, and recovery is not obvious
Danek Duvall <danek.duvall@sun.com>
parents: 429
diff changeset
  1353
                                        self.__req_dependents[dfmri] = []
578875da6e04 48 Removing a dependency is not flagged, and recovery is not obvious
Danek Duvall <danek.duvall@sun.com>
parents: 429
diff changeset
  1354
                                self.__req_dependents[dfmri].append(fmri)
578875da6e04 48 Removing a dependency is not flagged, and recovery is not obvious
Danek Duvall <danek.duvall@sun.com>
parents: 429
diff changeset
  1355
578875da6e04 48 Removing a dependency is not flagged, and recovery is not obvious
Danek Duvall <danek.duvall@sun.com>
parents: 429
diff changeset
  1356
        def get_dependents(self, pfmri, progtrack):
104
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
  1357
                """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
  1358
                FMRI."""
67
62c897652bbc Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents: 63
diff changeset
  1359
432
578875da6e04 48 Removing a dependency is not flagged, and recovery is not obvious
Danek Duvall <danek.duvall@sun.com>
parents: 429
diff changeset
  1360
                if not hasattr(self, "_Image__req_dependents"):
578875da6e04 48 Removing a dependency is not flagged, and recovery is not obvious
Danek Duvall <danek.duvall@sun.com>
parents: 429
diff changeset
  1361
                        self.__build_dependents(progtrack)
67
62c897652bbc Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents: 63
diff changeset
  1362
432
578875da6e04 48 Removing a dependency is not flagged, and recovery is not obvious
Danek Duvall <danek.duvall@sun.com>
parents: 429
diff changeset
  1363
                dependents = []
578875da6e04 48 Removing a dependency is not flagged, and recovery is not obvious
Danek Duvall <danek.duvall@sun.com>
parents: 429
diff changeset
  1364
                # We run through all the keys, in case a package is depended
578875da6e04 48 Removing a dependency is not flagged, and recovery is not obvious
Danek Duvall <danek.duvall@sun.com>
parents: 429
diff changeset
  1365
                # upon under multiple versions.  That is, if pkgA depends on
578875da6e04 48 Removing a dependency is not flagged, and recovery is not obvious
Danek Duvall <danek.duvall@sun.com>
parents: 429
diff changeset
  1366
                # libc@1 and pkgB depends on libc@2, we need to return both pkgA
578875da6e04 48 Removing a dependency is not flagged, and recovery is not obvious
Danek Duvall <danek.duvall@sun.com>
parents: 429
diff changeset
  1367
                # and pkgB.  If we used package names as keys, this would be
578875da6e04 48 Removing a dependency is not flagged, and recovery is not obvious
Danek Duvall <danek.duvall@sun.com>
parents: 429
diff changeset
  1368
                # simpler, but it wouldn't handle package rename.
578875da6e04 48 Removing a dependency is not flagged, and recovery is not obvious
Danek Duvall <danek.duvall@sun.com>
parents: 429
diff changeset
  1369
                for f in self.__req_dependents.iterkeys():
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1370
                        if self.fmri_is_successor(pfmri, f):
432
578875da6e04 48 Removing a dependency is not flagged, and recovery is not obvious
Danek Duvall <danek.duvall@sun.com>
parents: 429
diff changeset
  1371
                                dependents.extend(self.__req_dependents[f])
67
62c897652bbc Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents: 63
diff changeset
  1372
                return dependents
62c897652bbc Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents: 63
diff changeset
  1373
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1374
        def __do_get_versions(self, pub):
835
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
  1375
                """An internal method that is a wrapper around get_catalog.
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
  1376
                This handles retryable exceptions and timeouts."""
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
  1377
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
  1378
                retry_count = global_settings.PKG_TIMEOUT_MAX
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
  1379
                failures = TransportFailures()
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
  1380
                versdict = None
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1381
835
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
  1382
                while not versdict:
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
  1383
                        try:
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1384
                                versdict = retrieve.get_versions(self, pub)
835
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
  1385
                        except TransportException, e:
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
  1386
                                retry_count -= 1
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
  1387
                                failures.append(e)
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
  1388
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
  1389
                                if retry_count <= 0:
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
  1390
                                        raise failures
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
  1391
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
  1392
                return versdict
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
  1393
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1394
        def valid_publisher_test(self, pub):
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1395
                """Test that the publisher supplied in pub actually
835
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
  1396
                points to a valid packaging server."""
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
  1397
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
  1398
                try:
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1399
                        vd = self.__do_get_versions(pub)
835
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
  1400
                except (retrieve.VersionRetrievalError,
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
  1401
                    TransportFailures), e:
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
  1402
                        # Failure when contacting server.  Report
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
  1403
                        # this as an error.
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1404
                        raise InvalidDepotResponseException(pub["origin"],
835
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
  1405
                            "Transport errors encountered when trying to "
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
  1406
                            "contact depot server.  Reported the following "
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
  1407
                            "errors:\n%s" % e)
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
  1408
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
  1409
                if not self._valid_versions_test(vd):
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1410
                        raise InvalidDepotResponseException(pub["origin"],
835
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
  1411
                            "Invalid or unparseable version information.")
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
  1412
1102
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
  1413
        def captive_portal_test(self, pubs=None):
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
  1414
                """A captive portal forces a HTTP client on a network to see a
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
  1415
                special web page, usually for pubentication purposes
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
  1416
                (http://en.wikipedia.org/wiki/Captive_portal).
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
  1417
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
  1418
                'pubs' is an optional list of publisher objects to be used for
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
  1419
                the check.  If not provided, any publishers available for
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
  1420
                packaging operations will be used for the test instead."""
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
  1421
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
  1422
                if not pubs:
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
  1423
                        pubs = list(self.gen_publishers())
835
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
  1424
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
  1425
                vd = None
1102
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
  1426
                for pub in pubs:
835
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
  1427
                        try:
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1428
                                vd = self.__do_get_versions(pub)
835
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
  1429
                        except (retrieve.VersionRetrievalError,
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
  1430
                            TransportFailures):
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
  1431
                                # Encountered a transport error while
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1432
                                # trying to contact this publisher.
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1433
                                # Pick another publisher instead.
835
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
  1434
                                continue
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
  1435
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
  1436
                        if self._valid_versions_test(vd):
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
  1437
                                return
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
  1438
                        else:
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1439
                                raise InvalidDepotResponseException(
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1440
                                    pub["origin"], _("This server is not a "
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1441
                                    "valid package depot."))
835
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
  1442
                if not vd:
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1443
                        # We got all the way through the list of puborites but
835
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
  1444
                        # encountered transport errors in every case.  This is
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
  1445
                        # likely a network configuration problem.  Report our
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
  1446
                        # inability to contact a server.
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
  1447
                        raise InvalidDepotResponseException(None,
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1448
                            "Unable to contact any configured publishers. "
835
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
  1449
                            "This is likely a network configuration problem.")
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
  1450
1068
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1451
        @staticmethod
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1452
        def _valid_versions_test(versdict):
835
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
  1453
                """Check that the versions information contained in
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
  1454
                versdict contains valid version specifications.
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
  1455
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1456
                In order to test for this condition, pick a publisher
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1457
                from the list of active publishers.  Check to see if
835
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
  1458
                we can connect to it.  If so, test to see if it supports
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
  1459
                the versions/0 operations.  If versions/0 is not found,
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
  1460
                we get an unparseable response, or the response does
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
  1461
                not contain pkg-server, or versions 0 then we're not
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
  1462
                talking to a depot.  Return an error in these cases."""
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
  1463
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
  1464
                if "pkg-server" in versdict:
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
  1465
                        # success!
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
  1466
                        return True
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
  1467
                elif "versions" in versdict:
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
  1468
                        try:
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
  1469
                                versids = [
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
  1470
                                    int(v)
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
  1471
                                    for v in versdict["versions"].split()
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
  1472
                                ]
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
  1473
                        except ValueError:
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
  1474
                                # Unable to determine version number.  Fail.
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
  1475
                                return False
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
  1476
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
  1477
                        if 0 not in versids:
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
  1478
                                # Paranoia.  versions 0 should be in the
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
  1479
                                # output for versions/0.  If we're here,
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
  1480
                                # something has gone very wrong.  EPIC FAIL!
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
  1481
                                return False
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
  1482
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
  1483
                        # found versions/0, success!
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
  1484
                        return True
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
  1485
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
  1486
                # Some other error encountered. Fail
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
  1487
                return False
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
  1488
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1489
        def _do_get_catalog(self, pub, hdr, ts):
621
6c144915eed1 551 IPS should handle socket errors
johansen <johansen@sun.com>
parents: 616
diff changeset
  1490
                """An internal method that is a wrapper around get_catalog.
6c144915eed1 551 IPS should handle socket errors
johansen <johansen@sun.com>
parents: 616
diff changeset
  1491
                This handles retryable exceptions and timeouts."""
6c144915eed1 551 IPS should handle socket errors
johansen <johansen@sun.com>
parents: 616
diff changeset
  1492
6c144915eed1 551 IPS should handle socket errors
johansen <johansen@sun.com>
parents: 616
diff changeset
  1493
                retry_count = global_settings.PKG_TIMEOUT_MAX
6c144915eed1 551 IPS should handle socket errors
johansen <johansen@sun.com>
parents: 616
diff changeset
  1494
                failures = TransportFailures()
6c144915eed1 551 IPS should handle socket errors
johansen <johansen@sun.com>
parents: 616
diff changeset
  1495
                success = False
6c144915eed1 551 IPS should handle socket errors
johansen <johansen@sun.com>
parents: 616
diff changeset
  1496
6c144915eed1 551 IPS should handle socket errors
johansen <johansen@sun.com>
parents: 616
diff changeset
  1497
                while not success:
6c144915eed1 551 IPS should handle socket errors
johansen <johansen@sun.com>
parents: 616
diff changeset
  1498
                        try:
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1499
                                success = retrieve.get_catalog(self, pub,
621
6c144915eed1 551 IPS should handle socket errors
johansen <johansen@sun.com>
parents: 616
diff changeset
  1500
                                    hdr, ts)
6c144915eed1 551 IPS should handle socket errors
johansen <johansen@sun.com>
parents: 616
diff changeset
  1501
                        except TransportException, e:
6c144915eed1 551 IPS should handle socket errors
johansen <johansen@sun.com>
parents: 616
diff changeset
  1502
                                retry_count -= 1
6c144915eed1 551 IPS should handle socket errors
johansen <johansen@sun.com>
parents: 616
diff changeset
  1503
                                failures.append(e)
6c144915eed1 551 IPS should handle socket errors
johansen <johansen@sun.com>
parents: 616
diff changeset
  1504
6c144915eed1 551 IPS should handle socket errors
johansen <johansen@sun.com>
parents: 616
diff changeset
  1505
                                if retry_count <= 0:
6c144915eed1 551 IPS should handle socket errors
johansen <johansen@sun.com>
parents: 616
diff changeset
  1506
                                        raise failures
6c144915eed1 551 IPS should handle socket errors
johansen <johansen@sun.com>
parents: 616
diff changeset
  1507
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1508
        def refresh_publishers(self, full_refresh=False, immediate=False,
1102
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
  1509
            pubs=None, progtrack=None, validate=True):
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1510
                """Refreshes the metadata (e.g. catalog) for one or more
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1511
                publishers.
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1512
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1513
                'full_refresh' is an optional boolean value indicating whether
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1514
                a full retrieval of publisher metadata (e.g. catalogs) or only
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1515
                an update to the existing metadata should be performed.  When
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1516
                True, 'immediate' is also set to True.
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1517
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1518
                'immediate' is an optional boolean value indicating whether the
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1519
                a refresh should occur now.  If False, a publisher's selected
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1520
                repository will only be checked for updates if the update
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1521
                interval period recorded in the image configuration has been
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1522
                exceeded; ignored when 'full_refresh' is True.
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1523
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1524
                'pubs' is a list of publisher prefixes or publisher objects
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1525
                to refresh.  Passing an empty list or using the default value
1102
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
  1526
                implies all publishers.
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
  1527
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
  1528
                'validate' is an optional, boolean value indicating whether a
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
  1529
                connectivity test should be performed before attempting to
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
  1530
                retrieve publisher metadata."""
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1531
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1532
                if full_refresh:
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1533
                        immediate = True
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1534
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1535
                if not progtrack:
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1536
                        progtrack = progress.QuietProgressTracker()
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1537
1102
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
  1538
                self.history.log_operation_start("refresh-publishers")
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1539
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1540
                # Verify validity of certificates before attempting network
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1541
                # operations.
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1542
                try:
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1543
                        self.check_cert_validity()
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1544
                except api_errors.ExpiringCertificate, e:
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1545
                        # XXX need client messaging framework
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1546
                        misc.emsg(e)
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1547
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1548
                pubs_to_refresh = []
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1549
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1550
                if not pubs:
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1551
                        # Omit disabled publishers.
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1552
                        pubs = [p for p in self.gen_publishers()]
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1553
                for pub in pubs:
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1554
                        p = pub
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1555
                        if not isinstance(p, publisher.Publisher):
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1556
                                p = self.get_publisher(prefix=p)
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1557
                        if p.disabled:
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1558
                                e = api_errors.DisabledPublisher(p)
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1559
                                self.history.log_operation_end(error=e)
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1560
                                raise e
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1561
                        if immediate or p.needs_refresh:
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1562
                                pubs_to_refresh.append(p)
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1563
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1564
                if not pubs_to_refresh:
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1565
                        # Trigger a load of the catalogs if they haven't been
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1566
                        # loaded yet for the sake of our caller.
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1567
                        self.load_catalogs(progtrack)
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1568
                        self.history.log_operation_end()
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1569
                        return
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1570
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1571
                try:
1102
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
  1572
                        if validate:
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
  1573
                                # Before an attempt is made to retrieve catalogs
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
  1574
                                # from the publisher repositories, a check needs
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
  1575
                                # to be done to ensure that the client isn't
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
  1576
                                # stuck behind a captive portal.
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
  1577
                                self.captive_portal_test()
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
  1578
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1579
                        self.__retrieve_catalogs(full_refresh=full_refresh,
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1580
                            pubs=pubs_to_refresh, progtrack=progtrack)
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1581
                except (api_errors.ApiException, catalog.CatalogException), e:
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1582
                        # Reload catalogs; this picks up any updates and
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1583
                        # ensures the catalog is loaded for callers.
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1584
                        self.load_catalogs(progtrack, force=True)
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1585
                        self.history.log_operation_end(error=e)
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1586
                        raise
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1587
                self.history.log_operation_end()
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1588
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1589
        def __retrieve_catalogs(self, full_refresh=False, pubs=None,
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1590
            progtrack=None):
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1591
                """Retrieves the catalogs for the specified publishers
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1592
                performing full or incremental updates as needed or indicated.
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1593
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1594
                'full_refresh' is a boolean value indicating whether a full
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1595
                update should be forced for the specified publishers.
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1596
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1597
                'pubs' is an optional list of publisher objects to refresh the
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1598
                metadata for.  If not provided or 'None', all publishers will be
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1599
                refreshed.  Disabled publishers are always ignored regardless of
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1600
                whether this list is provided.
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1601
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1602
                'progtrack' is an optional ProgressTracker object."""
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1603
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1604
                if not progtrack:
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1605
                        progtrack = progress.QuietProgressTracker()
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1606
201
63e78f600aa7 185 traceback on pkg refresh when hostname lookup fails
Danek Duvall <danek.duvall@sun.com>
parents: 195
diff changeset
  1607
                failed = []
63e78f600aa7 185 traceback on pkg refresh when hostname lookup fails
Danek Duvall <danek.duvall@sun.com>
parents: 195
diff changeset
  1608
                total = 0
63e78f600aa7 185 traceback on pkg refresh when hostname lookup fails
Danek Duvall <danek.duvall@sun.com>
parents: 195
diff changeset
  1609
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1610
                if not pubs:
1102
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
  1611
                        pubs = list(self.gen_publishers())
625
e46b345645d6 3799 need to start progress tracker going early on
Brock Pytlik <bpytlik@sun.com>
parents: 621
diff changeset
  1612
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1613
                try:
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1614
                        # Ensure Image directory structure is valid.
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1615
                        self.mkdirs()
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1616
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1617
                        # Load the catalogs, if they haven't been already, so
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1618
                        # incremental updates can be performed.
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1619
                        self.load_catalogs(progtrack)
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1620
                except EnvironmentError, e:
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1621
                        self.history.log_operation_end(error=e)
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1622
                        raise
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1623
1102
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
  1624
                progtrack.refresh_start(len(pubs))
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1625
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1626
                def catalog_changed(prefix, old_ts, old_size):
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1627
                        if not old_ts or not old_size:
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1628
                                # It didn't exist before.
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1629
                                return True
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1630
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1631
                        croot = "%s/catalog/%s" % (self.imgdir, prefix)
1102
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
  1632
                        c = catalog.Catalog(croot, publisher=prefix)
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1633
                        if c.last_modified() != old_ts:
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1634
                                return True
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1635
                        if c.size() != old_size:
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1636
                                return True
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1637
                        return False
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1638
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1639
                updated = 0
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1640
                succeeded = 0
1102
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
  1641
                for pub in pubs:
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1642
                        if pub.disabled:
786
a400f8c4d1c0 2340 support authority enable and disable
Tom Mueller <Tom.Mueller@sun.com>
parents: 756
diff changeset
  1643
                                continue
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1644
201
63e78f600aa7 185 traceback on pkg refresh when hostname lookup fails
Danek Duvall <danek.duvall@sun.com>
parents: 195
diff changeset
  1645
                        total += 1
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1646
                        progtrack.refresh_progress(pub.prefix)
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1647
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1648
                        full_refresh_this_pub = False
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1649
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1650
                        cat = None
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1651
                        ts = 0
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1652
                        size = 0
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1653
                        if pub.prefix in self.__catalogs:
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1654
                                cat = self.__catalogs[pub.prefix]
215
c10719939c6d 245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents: 208
diff changeset
  1655
                                ts = cat.last_modified()
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1656
                                size = cat.size()
215
c10719939c6d 245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents: 208
diff changeset
  1657
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
  1658
                                # Although we may have a catalog with a
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
  1659
                                # timestamp, the user may have changed the
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1660
                                # origin URL for the publisher.  If this has
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
  1661
                                # occurred, we need to perform a full refresh.
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1662
                                repo = pub.selected_repository
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1663
                                if cat.origin() not in repo.origins:
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1664
                                        full_refresh_this_pub = True
310
8fa744df663a 975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents: 307
diff changeset
  1665
496
d36d6700c011 2917 pkg refresh should allow refreshing specific repository(ies)
Brock Pytlik <bpytlik@sun.com>
parents: 479
diff changeset
  1666
                        if ts and not full_refresh and \
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1667
                            not full_refresh_this_pub:
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1668
                                hdr = {"If-Modified-Since": ts}
215
c10719939c6d 245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents: 208
diff changeset
  1669
                        else:
c10719939c6d 245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents: 208
diff changeset
  1670
                                hdr = {}
c10719939c6d 245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents: 208
diff changeset
  1671
235
61994d15c39b 373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents: 226
diff changeset
  1672
                        try:
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1673
                                self._do_get_catalog(pub, hdr, ts)
621
6c144915eed1 551 IPS should handle socket errors
johansen <johansen@sun.com>
parents: 616
diff changeset
  1674
                        except retrieve.CatalogRetrievalError, e:
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1675
                                failed.append((pub, e))
621
6c144915eed1 551 IPS should handle socket errors
johansen <johansen@sun.com>
parents: 616
diff changeset
  1676
                        except TransportFailures, e:
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1677
                                failed.append((pub, e))
201
63e78f600aa7 185 traceback on pkg refresh when hostname lookup fails
Danek Duvall <danek.duvall@sun.com>
parents: 195
diff changeset
  1678
                        else:
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1679
                                if catalog_changed(pub.prefix, ts, size):
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1680
                                        updated += 1
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1681
                                pub.last_refreshed = dt.datetime.utcnow()
201
63e78f600aa7 185 traceback on pkg refresh when hostname lookup fails
Danek Duvall <danek.duvall@sun.com>
parents: 195
diff changeset
  1682
                                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
  1683
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1684
                if updated > 0:
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1685
                        # If any publisher metadata was changed, then destroy
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1686
                        # the catalog cache, update the installed package list,
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1687
                        # and force a reload of all catalog data.
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1688
                        self.__destroy_catalog_cache()
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1689
                        self.__update_installed_pkgs()
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1690
                        self.load_catalogs(progtrack, force=True)
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1691
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1692
                progtrack.refresh_done()
625
e46b345645d6 3799 need to start progress tracker going early on
Brock Pytlik <bpytlik@sun.com>
parents: 621
diff changeset
  1693
201
63e78f600aa7 185 traceback on pkg refresh when hostname lookup fails
Danek Duvall <danek.duvall@sun.com>
parents: 195
diff changeset
  1694
                if failed:
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  1695
                        raise api_errors.CatalogRefreshException(failed, total,
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  1696
                            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
  1697
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1698
                return updated > 0
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1699
1068
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1700
        CATALOG_CACHE_VERSION = 4
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1701
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1702
        def __cache_catalogs(self, progtrack, pubs=None):
1068
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1703
                """Read in all the catalogs and cache the data.
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1704
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1705
                'pubs' is a list of publisher objects to include when caching
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1706
                the image's configured publisher metadata.
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1707
                """
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1708
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1709
                progtrack.cache_catalogs_start()
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1710
                cache = {}
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1711
                publist = []
835
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
  1712
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
  1713
                try:
1068
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1714
                        publist = dict(
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1715
                            (p.prefix, p) for p in self.gen_publishers()
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1716
                        )
835
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
  1717
                except CfgCacheError:
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1718
                        # No publishers defined.  If the caller hasn't
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1719
                        # supplied publishers to cache, raise the error
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1720
                        if not pubs:
835
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
  1721
                                raise
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
  1722
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1723
                if pubs:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1724
                        # If caller passed publishers, include this in
1068
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1725
                        # the list of publishers to cache.  These might
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1726
                        # be publisher objects that haven't been added
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1727
                        # to the image configuration yet.
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1728
                        for p in pubs:
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1729
                                publist[p.prefix] = p
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1730
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1731
                for pub in publist.itervalues():
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1732
                        try:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1733
                                catalog.Catalog.read_catalog(cache,
1068
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1734
                                    pub.meta_root, pub=pub.prefix)
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1735
                        except EnvironmentError, e:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1736
                                # If a catalog file is just missing, ignore it.
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1737
                                # If there's a worse error, make sure the user
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1738
                                # knows about it.
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1739
                                if e.errno == errno.ENOENT:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1740
                                        pass
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1741
                                else:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1742
                                        raise
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1743
723
35192419888d 4447 A corrupt(?) catalog.pkl renders pkg(5) unusable.
Danek Duvall <danek.duvall@sun.com>
parents: 717
diff changeset
  1744
                self._catalog = cache
35192419888d 4447 A corrupt(?) catalog.pkl renders pkg(5) unusable.
Danek Duvall <danek.duvall@sun.com>
parents: 717
diff changeset
  1745
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1746
                # Use the current time until the actual file timestamp can be
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1747
                # retrieved at the end.  That way, if an exception is raised
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1748
                # or an early return occurs, it will still be set.
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1749
                self.__catalog_cache_mod_time = int(time.time())
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1750
1068
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1751
                # Remove old catalog cache files.
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1752
                croot = os.path.join(self.imgdir, "catalog")
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1753
                for fname in ("pkg_names.pkl", "catalog.pkl"):
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1754
                        fpath = os.path.join(croot, fname)
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1755
                        try:
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1756
                                portable.remove(fpath)
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1757
                        except KeyboardInterrupt:
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1758
                                raise
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1759
                        except:
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1760
                                # If for any reason, the file can't be removed,
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1761
                                # it doesn't matter.
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1762
                                pass
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1763
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1764
                try:
1068
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1765
                        cfd, ctmp = tempfile.mkstemp(dir=croot)
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1766
                        cf = os.fdopen(cfd, "wb")
723
35192419888d 4447 A corrupt(?) catalog.pkl renders pkg(5) unusable.
Danek Duvall <danek.duvall@sun.com>
parents: 717
diff changeset
  1767
                except EnvironmentError:
1068
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1768
                        # If the cache can't be written, it doesn't matter.
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1769
                        progtrack.cache_catalogs_done()
723
35192419888d 4447 A corrupt(?) catalog.pkl renders pkg(5) unusable.
Danek Duvall <danek.duvall@sun.com>
parents: 717
diff changeset
  1770
                        return
35192419888d 4447 A corrupt(?) catalog.pkl renders pkg(5) unusable.
Danek Duvall <danek.duvall@sun.com>
parents: 717
diff changeset
  1771
1068
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1772
                def cleanup():
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1773
                        try:
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1774
                                if cf:
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1775
                                        cf.close()
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1776
                        except EnvironmentError:
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1777
                                pass
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1778
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1779
                        try:
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1780
                                portable.remove(ctmp)
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1781
                        except EnvironmentError:
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1782
                                pass
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1783
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1784
                # First, the list of all publishers is built assigning each
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1785
                # one a sequentially incremented integer as they are discovered.
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1786
                # This number is used as a mapping code for publishers to reduce
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1787
                # the size of the catalog cache.
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1788
                pubs = {}
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1789
                for pkg_name in cache:
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1790
                        vers = cache[pkg_name]
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1791
                        for k, v in vers.iteritems():
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1792
                                if k == "versions":
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1793
                                        continue
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1794
                                for p in v[1]:
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1795
                                        if p not in pubs:
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1796
                                                pubs[p] = str(len(pubs))
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1797
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1798
                # '|' is used to separate fields of information (such
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1799
                # as fmri name and each version).
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1800
                # '!' is used to separate items within a field (such as
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1801
                # information about a version).
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1802
                # '^' is used to separate item values (such as a publisher and
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1803
                # its index number).
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1804
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1805
                # First line of file is the version of the catalog cache.
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1806
                try:
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1807
                        cf.write("%s\n" % self.CATALOG_CACHE_VERSION)
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1808
                except EnvironmentError:
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1809
                        # If the cache can't be written, it doesn't matter.
1068
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1810
                        cleanup()
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1811
                        progtrack.cache_catalogs_done()
1068
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1812
                        return
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1813
                except:
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1814
                        cleanup()
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1815
                        raise
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1816
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1817
                # Second line of the file is the list of publisher prefixes
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1818
                # and their index number used to decode the fmri entries.
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1819
                publine = "!".join([
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1820
                    "^".join((p, pubs[p])) for p in pubs
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1821
                ])
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1822
723
35192419888d 4447 A corrupt(?) catalog.pkl renders pkg(5) unusable.
Danek Duvall <danek.duvall@sun.com>
parents: 717
diff changeset
  1823
                try:
1068
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1824
                        cf.write("%s\n" % publine)
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1825
                except EnvironmentError:
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1826
                        # If the cache can't be written, it doesn't matter.
1068
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1827
                        cleanup()
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1828
                        progtrack.cache_catalogs_done()
1068
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1829
                        return
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1830
                except:
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1831
                        cleanup()
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1832
                        raise
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1833
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1834
                # All lines after the first two are made up of a package's
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1835
                # version-specific fmri and the list of publishers that have
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1836
                # it in their catalog, or where it was installed from.
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1837
                for pkg_name in sorted(cache.keys()):
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1838
                        vers = cache[pkg_name]
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1839
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1840
                        # Iteration has to be performed over versions to retain
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1841
                        # sort order.
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1842
                        first = True
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1843
                        release = None
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1844
                        build_release = None
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1845
                        branch = None
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1846
                        for v in vers["versions"]:
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1847
                                f, fpubs = vers[str(v)]
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1848
                                known = "^".join(
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1849
                                    pubs[p] for p in fpubs
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1850
                                    if fpubs[p]
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1851
                                )
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1852
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1853
                                unknown = "^".join(
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1854
                                    pubs[p] for p in fpubs
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1855
                                    if not fpubs[p]
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1856
                                )
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1857
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1858
                                if first:
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1859
                                        # When writing the first entry for a
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1860
                                        # package, write its full fmri.
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1861
                                        first = False
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1862
                                        release = f.version.release
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1863
                                        build_release = f.version.build_release
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1864
                                        branch = f.version.branch
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1865
                                        sfmri = f.get_fmri(anarchy=True,
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1866
                                            include_scheme=False)
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1867
                                else:
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1868
                                        # For successive entries, write only
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1869
                                        # what is not shared by the previous
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1870
                                        # entry.
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1871
                                        rmatch = f.version.release == release
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1872
                                        brmatch = f.version.build_release == \
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1873
                                            build_release
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1874
                                        bmatch = f.version.branch == branch
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1875
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1876
                                        sver = str(f.version)
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1877
                                        if rmatch and brmatch and bmatch:
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1878
                                                # If release, build_release, and
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1879
                                                # branch match the last entry,
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1880
                                                # they can be omitted.
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1881
                                                sfmri = ":" + sver.split(":")[1]
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1882
                                        elif rmatch and brmatch:
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1883
                                                # If release and build_release
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1884
                                                # match the last entry, they can
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1885
                                                # be omitted.
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1886
                                                sfmri = "-" + sver.split("-")[1]
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1887
                                        elif rmatch:
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1888
                                                # If release matches the last
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1889
                                                # entry, it can be omitted.
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1890
                                                sfmri = "," + sver.split(",")[1]
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1891
                                        else:
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1892
                                                # Nothing matched the previous
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1893
                                                # entry except the name, so the
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1894
                                                # full version must be written.
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1895
                                                sfmri = "@" + sver
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1896
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1897
                                        release = f.version.release
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1898
                                        build_release = f.version.build_release
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1899
                                        branch = f.version.branch
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1900
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1901
                                line = sfmri + "|" + known + "!" + unknown
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1902
                                try:
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1903
                                        cf.write(line + "\n")
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1904
                                except EnvironmentError:
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1905
                                        # If the cache can't be written, it
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1906
                                        # doesn't matter.
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1907
                                        progtrack.cache_catalogs_done()
1068
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1908
                                        cleanup()
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1909
                                        return
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1910
                                except:
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1911
                                        cleanup()
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1912
                                        raise
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1913
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1914
                cfpath = os.path.join(croot, CATALOG_CACHE_FILE)
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1915
                try:
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1916
                        cf.close()
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1917
                        cf = None
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1918
                        os.chmod(ctmp, 0644)
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1919
                        portable.rename(ctmp, cfpath)
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1920
                except EnvironmentError:
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1921
                        # If the cache can't be written, it doesn't matter.
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1922
                        progtrack.cache_catalogs_done()
1068
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1923
                        cleanup()
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1924
                        return
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1925
                except:
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1926
                        cleanup()
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1927
                        raise
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1928
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1929
                # Update the mod time with the actual timestamp from the file.
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1930
                self.__catalog_cache_mod_time = \
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1931
                    self.__get_catalog_cache_mod_time()
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1932
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1933
                progtrack.cache_catalogs_done()
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1934
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1935
        def __get_catalog_cache_mod_time(self):
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1936
                """Internal helper function used to obtain last modification
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1937
                time of the on-disk catalog cache."""
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1938
1068
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1939
                croot = os.path.join(self.imgdir, "catalog")
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1940
                cache_file = os.path.join(croot, CATALOG_CACHE_FILE)
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1941
                try:
715
5620652f5927 4886 api.info shouldn't be reloading the catalog from disk needlessly
Brock Pytlik <bpytlik@sun.com>
parents: 703
diff changeset
  1942
                        mod_time = os.stat(cache_file).st_mtime
5620652f5927 4886 api.info shouldn't be reloading the catalog from disk needlessly
Brock Pytlik <bpytlik@sun.com>
parents: 703
diff changeset
  1943
                except EnvironmentError, e:
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1944
                        if e.errno == errno.EACCES:
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1945
                                raise api_errors.PermissionsException(
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1946
                                    e.filename)
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1947
                        if e.errno != errno.ENOENT:
715
5620652f5927 4886 api.info shouldn't be reloading the catalog from disk needlessly
Brock Pytlik <bpytlik@sun.com>
parents: 703
diff changeset
  1948
                                raise
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1949
                        mod_time = None
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1950
                return mod_time
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1951
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1952
        def __load_catalog_cache(self, progtrack):
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1953
                """Read in the cached catalog data."""
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1954
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1955
                progtrack.load_catalog_cache_start()
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1956
                croot = os.path.join(self.imgdir, "catalog")
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1957
                cache_file = os.path.join(croot, CATALOG_CACHE_FILE)
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1958
                mod_time = self.__get_catalog_cache_mod_time()
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1959
                if self._catalog:
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1960
                        if mod_time == self.__catalog_cache_mod_time:
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1961
                                # Cache already loaded and up to date.
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1962
                                progtrack.load_catalog_cache_done()
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1963
                                return
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1964
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1965
                try:
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1966
                        cf = file(cache_file, "rb")
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1967
                except EnvironmentError, e:
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1968
                        self._catalog = {}
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1969
                        self.__catalog_cache_mod_time = None
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1970
                        if e.errno == errno.EACCES:
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1971
                                raise api_errors.PermissionsException(
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1972
                                    e.filename)
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1973
                        if e.errno == errno.ENOENT:
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1974
                                raise api_errors.CatalogCacheMissing()
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1975
                        raise
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1976
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1977
                # First line should be version.
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1978
                try:
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1979
                        ver = cf.readline().strip()
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1980
                        ver = int(ver)
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1981
                except ValueError:
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1982
                        ver = None
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1983
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1984
                # If we don't recognize the version, complain.
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1985
                if ver != self.CATALOG_CACHE_VERSION:
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1986
                        raise api_errors.CatalogCacheBadVersion(
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1987
                            ver, expected=self.CATALOG_CACHE_VERSION)
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1988
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1989
                # Second line should be the list of publishers.
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1990
                publine = cf.readline().strip()
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1991
                if not publine:
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1992
                        publine = ""
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1993
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1994
                pubidx = {}
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1995
                for e in publine.split("!"):
1068
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1996
                        try:
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1997
                                p, idx = e.split("^")
1068
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1998
                        except ValueError:
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1999
                                raise api_errors.CatalogCacheInvalid(
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  2000
                                    publine, line_number=2)
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2001
                        pubidx[idx] = p
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2002
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2003
                if not pubidx:
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2004
                        raise api_errors.CatalogCacheInvalid(
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2005
                            publine, line_number=2)
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2006
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2007
                self._catalog = {}
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2008
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2009
                # Read until EOF.
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2010
                pkg_name = None
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2011
                sver = None
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2012
                for lnum, line in ((i + 3, l.strip())
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2013
                    for i, l in enumerate(cf)):
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2014
                        # The first of these line for each package is of
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2015
                        # the format:
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2016
                        # fmri|pub1_known^pub2...!pub1_unknown^pub2...
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2017
                        #
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2018
                        # Successive versions of the same package are of
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2019
                        # the format:
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2020
                        # @ver|pub1_known^pub2...!pub1_unknown^pub2...
1068
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  2021
                        try:
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2022
                                sfmri, spubs = line.split("|", 1)
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2023
                                sfmri = sfmri.strip()
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2024
                        except (AttributeError, ValueError):
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2025
                                raise api_errors.CatalogCacheInvalid(
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2026
                                    line, line_number=lnum)
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2027
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2028
                        if sfmri[0] in (":", "-", ",", "@") and \
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2029
                            not pkg_name:
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2030
                                # The previous line should have been a
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2031
                                # full fmri or provided enough info
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2032
                                # to construct one for this entry.
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2033
                                raise api_errors.CatalogCacheInvalid(
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2034
                                    line, line_number=lnum)
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2035
                        elif sfmri[0] == ":":
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2036
                                # Everything but the timestamp is the
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2037
                                # same as the previous entry.
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2038
                                sfmri = "%s@%s%s" % (pkg_name,
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2039
                                    sver.split(":")[0], sfmri)
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2040
                        elif sfmri[0] == "-":
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2041
                                # Everything but the branch is the same
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2042
                                # as the previous entry.
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2043
                                sfmri = "%s@%s%s" % (pkg_name,
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2044
                                    sver.split("-")[0], sfmri)
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2045
                        elif sfmri[0] == ",":
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2046
                                # Everything but the release is the same
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2047
                                # as the previous entry.
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2048
                                sfmri = "%s@%s%s" % (pkg_name,
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2049
                                    sver.split(",")[0], sfmri)
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2050
                        elif sfmri[0] == "@":
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2051
                                # If the entry starts with this, then
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2052
                                # only the package name is shared.
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2053
                                sfmri = pkg_name + sfmri
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2054
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2055
                        known, unknown = spubs.split("!")
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2056
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2057
                        # Transform the publisher index numbers into
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2058
                        # their equivalent prefixes.
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2059
                        pubs = {}
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2060
                        for k in known.split("^"):
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2061
                                if k in pubidx:
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2062
                                        pubs[pubidx[k]] = True
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2063
                        for u in unknown.split("^"):
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2064
                                if u in pubidx:
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2065
                                        pubs[pubidx[u]] = False
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2066
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2067
                        if not pubs:
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2068
                                raise api_errors.CatalogCacheInvalid(
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2069
                                    line, line_number=lnum)
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2070
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2071
                        # Build the FMRI from the provided string and
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2072
                        # cache the result using the publisher info.
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2073
                        try:
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2074
                                pfmri = pkg.fmri.PkgFmri(sfmri)
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2075
                                pkg_name = pfmri.pkg_name
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2076
                                sver = sfmri.split("@", 1)[1]
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2077
                        except (pkg.fmri.FmriError, IndexError), e:
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2078
                                raise api_errors.CatalogCacheInvalid(
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2079
                                    line, line_number=lnum)
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2080
                        catalog.Catalog.fast_cache_fmri(self._catalog,
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2081
                            pfmri, sver, pubs)
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2082
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2083
                try:
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2084
                        cf.close()
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2085
                except EnvironmentError:
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2086
                        # All of the data was retrieved, so this error
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2087
                        # doesn't matter.
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2088
                        pass
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2089
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2090
                # Now that all of the data has been loaded, set the
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2091
                # modification time.
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2092
                self.__catalog_cache_mod_time = mod_time
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2093
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2094
                progtrack.load_catalog_cache_done()
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2095
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2096
        def load_catalogs(self, progtrack, force=False):
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2097
                """Load publisher catalog data.
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2098
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2099
                'progtrack' should be a ProgressTracker object that will be used
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2100
                to provide progress information to clients.
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2101
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2102
                'force' is an optional, boolean value that, when 'True', will
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2103
                cause the publisher catalog data to be loaded again even if it
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2104
                has been already.  It defaults to 'False', which will cause the
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2105
                catalog data to only be loaded when not already loaded or when
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2106
                the catalog cache has been modified (which should only happen in
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2107
                the case of another process modifying it)."""
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2108
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2109
                if not force and self.__catalogs and \
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2110
                    self.__pkg_states is not None:
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2111
                        last_mod_time = self.__catalog_cache_mod_time
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2112
                        if last_mod_time:
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2113
                                mod_time = self.__get_catalog_cache_mod_time()
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2114
                                if mod_time == last_mod_time:
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2115
                                        # Don't load the catalogs as they are
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2116
                                        # already loaded and state information
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2117
                                        # is up to date.
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2118
                                        return
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2119
                                elif not mod_time:
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2120
                                        # Don't load the catalogs since no cache
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2121
                                        # exists on-disk but an in-memory one
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2122
                                        # does.  This can happen for
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2123
                                        # unprivileged users, or in a readonly
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2124
                                        # environment such as a Live CD where
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2125
                                        # the cache does not exist for space
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2126
                                        # or other reasons.
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2127
                                        return
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2128
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2129
                assert progtrack
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2130
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2131
                # Flush existing catalog data.
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2132
                self.__catalogs = {}
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  2133
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2134
                for pub in self.gen_publishers():
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2135
                        croot = "%s/catalog/%s" % (self.imgdir, pub.prefix)
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2136
                        progtrack.catalog_start(pub.prefix)
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2137
                        if pub.prefix == self.cfg_cache.preferred_publisher:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2138
                                pubpfx = "%s_%s" % (pkg.fmri.PREF_PUB_PFX,
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2139
                                    pub.prefix)
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
  2140
                                c = catalog.Catalog(croot,
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2141
                                    publisher=pubpfx)
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  2142
                        else:
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  2143
                                c = catalog.Catalog(croot,
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2144
                                    publisher=pub.prefix)
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2145
                        self.__catalogs[pub.prefix] = c
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2146
                        progtrack.catalog_done()
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2147
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2148
                # Load package state information as this will be used during
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2149
                # catalog cache generation.
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2150
                self.__load_pkg_states()
59
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
  2151
1068
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  2152
                # Try to load the catalog cache file.  If that fails, call
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  2153
                # cache_catalogs so that the data from the canonical text copies
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  2154
                # of the catalogs from each publisher will be loaded and the
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  2155
                # data cached.
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  2156
                #
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2157
                # XXX Given that this is a read operation, should we be writing?
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2158
                try:
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2159
                        self.__load_catalog_cache(progtrack)
1068
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  2160
                except api_errors.CatalogCacheError:
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  2161
                        # If the load failed because of a bad version,
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  2162
                        # corruption, or because it was missing, just try to
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  2163
                        # rebuild it automatically.
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2164
                        self.__cache_catalogs(progtrack)
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2165
715
5620652f5927 4886 api.info shouldn't be reloading the catalog from disk needlessly
Brock Pytlik <bpytlik@sun.com>
parents: 703
diff changeset
  2166
                # Add the packages which are installed, but not in the catalog.
5620652f5927 4886 api.info shouldn't be reloading the catalog from disk needlessly
Brock Pytlik <bpytlik@sun.com>
parents: 703
diff changeset
  2167
                # XXX Should we have a different state for these, so we can flag
5620652f5927 4886 api.info shouldn't be reloading the catalog from disk needlessly
Brock Pytlik <bpytlik@sun.com>
parents: 703
diff changeset
  2168
                # them to the user?
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2169
                for state, f in self.__pkg_states.values():
715
5620652f5927 4886 api.info shouldn't be reloading the catalog from disk needlessly
Brock Pytlik <bpytlik@sun.com>
parents: 703
diff changeset
  2170
                        if state != PKG_STATE_INSTALLED:
5620652f5927 4886 api.info shouldn't be reloading the catalog from disk needlessly
Brock Pytlik <bpytlik@sun.com>
parents: 703
diff changeset
  2171
                                continue
988
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2172
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2173
                        # cache_fmri will automatically determine whether the
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2174
                        # fmri is in the catalog and then cache if needed.  The
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2175
                        # fmri (or its version or publisher information) could
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2176
                        # be missing for a number of reasons:
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2177
                        #   * the package's publisher was removed, and no other
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2178
                        #     publisher has a matching catalog entry
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2179
                        #   * the fmri does not exist in the catalogs of any
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2180
                        #     existing publisher, even though the publisher
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2181
                        #     of the installed package has a catalog
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2182
                        #   * the package's publisher was removed or does not
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2183
                        #     exist in the installed package publisher's
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2184
                        #     catalog, but another publisher has a matching
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2185
                        #     catalog entry, so the fmri has been cached with
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2186
                        #     the other publisher's information, and the
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2187
                        #     installed publisher's information is missing
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2188
                        #
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2189
                        # The state of the package itself may be installed, but
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2190
                        # the package is unknown to the publisher (not in its
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2191
                        # catalog).
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2192
                        catalog.Catalog.cache_fmri(self._catalog, f,
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2193
                            f.get_publisher(), known=False)
715
5620652f5927 4886 api.info shouldn't be reloading the catalog from disk needlessly
Brock Pytlik <bpytlik@sun.com>
parents: 703
diff changeset
  2194
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2195
        def __destroy_catalog_cache(self):
1068
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  2196
                croot = os.path.join(self.imgdir, "catalog")
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  2197
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  2198
                # Remove catalog cache files (including old ones).
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  2199
                croot = os.path.join(self.imgdir, "catalog")
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  2200
                for fname in ("pkg_names.pkl", "catalog.pkl", "catalog_cache"):
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  2201
                        fpath = os.path.join(croot, fname)
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  2202
                        try:
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  2203
                                portable.remove(fpath)
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  2204
                        except KeyboardInterrupt:
537
3dc9fc9b5fee 1540 changes to authorities should include refresh
Brock Pytlik <bpytlik@sun.com>
parents: 526
diff changeset
  2205
                                raise
1068
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  2206
                        except:
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  2207
                                # If for any reason, the file can't be removed,
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  2208
                                # it doesn't matter as it will be overwritten.
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  2209
                                pass
556
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
  2210
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2211
                # Reset the in-memory cache.
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2212
                self._catalog = {}
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2213
                self.__catalog_cache_mod_time = None
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2214
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  2215
        def _get_publisher_meta_root(self, prefix):
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  2216
                return os.path.join(self.imgdir, "catalog", prefix)
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  2217
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2218
        def has_catalog(self, prefix):
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  2219
                return os.path.exists(os.path.join(
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  2220
                    self._get_publisher_meta_root(prefix), "catalog"))
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2221
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2222
        def remove_publisher_metadata(self, pub):
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2223
                """Removes the metadata for the specified publisher object."""
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2224
537
3dc9fc9b5fee 1540 changes to authorities should include refresh
Brock Pytlik <bpytlik@sun.com>
parents: 526
diff changeset
  2225
                try:
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2226
                        del self.__catalogs[pub.prefix]
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2227
                except KeyError:
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2228
                        # May not have been loaded yet.
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2229
                        pass
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2230
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2231
                pub.remove_meta_root()
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2232
                self.__destroy_catalog_cache()
537
3dc9fc9b5fee 1540 changes to authorities should include refresh
Brock Pytlik <bpytlik@sun.com>
parents: 526
diff changeset
  2233
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  2234
        def fmri_is_same_pkg(self, cfmri, pfmri):
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  2235
                """Determine whether fmri and pfmri share the same package
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  2236
                name, even if they're not equivalent versions.  This
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  2237
                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
  2238
                the same because of a rename operation."""
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  2239
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  2240
                # 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
  2241
                # 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
  2242
                # rename.
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  2243
                if cfmri.is_same_pkg(pfmri):
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  2244
                        return True
329
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
  2245
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2246
                # Get the catalog for the correct publisher
329
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
  2247
                cat = self.get_catalog(cfmri)
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
  2248
                return cat.rename_is_same_pkg(cfmri, pfmri)
329
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
  2249
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  2250
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  2251
        def fmri_is_successor(self, cfmri, pfmri):
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  2252
                """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
  2253
                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
  2254
                package is a successor.  This routine takes two FMRIs, and
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2255
                if they have the same publisher, checks if they've been
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  2256
                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
  2257
                routine from the catalog.  Otherwise, this runs the standard
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  2258
                fmri.is_successor() code."""
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  2259
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2260
                # Get the catalog for the correct publisher
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  2261
                cat = self.get_catalog(cfmri)
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  2262
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  2263
                # 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
  2264
                # 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
  2265
                # rename.
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  2266
                if cfmri.is_successor(pfmri):
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  2267
                        return True
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  2268
                else:
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  2269
                        return cat.rename_is_successor(cfmri, pfmri)
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  2270
516
53da6297fb65 3039 Install and Image-update should check index consistency with installed packages
Brock Pytlik <bpytlik@sun.com>
parents: 499
diff changeset
  2271
        def gen_installed_pkg_names(self):
53da6297fb65 3039 Install and Image-update should check index consistency with installed packages
Brock Pytlik <bpytlik@sun.com>
parents: 499
diff changeset
  2272
                """Generate the string representation of all installed
53da6297fb65 3039 Install and Image-update should check index consistency with installed packages
Brock Pytlik <bpytlik@sun.com>
parents: 499
diff changeset
  2273
                packages. This is faster than going through gen_installed_pkgs
53da6297fb65 3039 Install and Image-update should check index consistency with installed packages
Brock Pytlik <bpytlik@sun.com>
parents: 499
diff changeset
  2274
                when all that will be done is to extract the strings from
53da6297fb65 3039 Install and Image-update should check index consistency with installed packages
Brock Pytlik <bpytlik@sun.com>
parents: 499
diff changeset
  2275
                the result.
53da6297fb65 3039 Install and Image-update should check index consistency with installed packages
Brock Pytlik <bpytlik@sun.com>
parents: 499
diff changeset
  2276
                """
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2277
                if self.__pkg_states is not None:
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2278
                        for i in self.__pkg_states.values():
516
53da6297fb65 3039 Install and Image-update should check index consistency with installed packages
Brock Pytlik <bpytlik@sun.com>
parents: 499
diff changeset
  2279
                                yield i[1].get_fmri(anarchy=True)
53da6297fb65 3039 Install and Image-update should check index consistency with installed packages
Brock Pytlik <bpytlik@sun.com>
parents: 499
diff changeset
  2280
                else:
53da6297fb65 3039 Install and Image-update should check index consistency with installed packages
Brock Pytlik <bpytlik@sun.com>
parents: 499
diff changeset
  2281
                        installed_state_dir = "%s/state/installed" % \
53da6297fb65 3039 Install and Image-update should check index consistency with installed packages
Brock Pytlik <bpytlik@sun.com>
parents: 499
diff changeset
  2282
                            self.imgdir
53da6297fb65 3039 Install and Image-update should check index consistency with installed packages
Brock Pytlik <bpytlik@sun.com>
parents: 499
diff changeset
  2283
                        if os.path.isdir(installed_state_dir):
53da6297fb65 3039 Install and Image-update should check index consistency with installed packages
Brock Pytlik <bpytlik@sun.com>
parents: 499
diff changeset
  2284
                                for pl in os.listdir(installed_state_dir):
53da6297fb65 3039 Install and Image-update should check index consistency with installed packages
Brock Pytlik <bpytlik@sun.com>
parents: 499
diff changeset
  2285
                                        yield "pkg:/" + urllib.unquote(pl)
53da6297fb65 3039 Install and Image-update should check index consistency with installed packages
Brock Pytlik <bpytlik@sun.com>
parents: 499
diff changeset
  2286
                        else:
53da6297fb65 3039 Install and Image-update should check index consistency with installed packages
Brock Pytlik <bpytlik@sun.com>
parents: 499
diff changeset
  2287
                                proot = "%s/pkg" % self.imgdir
53da6297fb65 3039 Install and Image-update should check index consistency with installed packages
Brock Pytlik <bpytlik@sun.com>
parents: 499
diff changeset
  2288
                                for pd in sorted(os.listdir(proot)):
53da6297fb65 3039 Install and Image-update should check index consistency with installed packages
Brock Pytlik <bpytlik@sun.com>
parents: 499
diff changeset
  2289
                                        for vd in \
53da6297fb65 3039 Install and Image-update should check index consistency with installed packages
Brock Pytlik <bpytlik@sun.com>
parents: 499
diff changeset
  2290
                                            sorted(os.listdir("%s/%s" %
53da6297fb65 3039 Install and Image-update should check index consistency with installed packages
Brock Pytlik <bpytlik@sun.com>
parents: 499
diff changeset
  2291
                                            (proot, pd))):
53da6297fb65 3039 Install and Image-update should check index consistency with installed packages
Brock Pytlik <bpytlik@sun.com>
parents: 499
diff changeset
  2292
                                                path = "%s/%s/%s/installed" % \
53da6297fb65 3039 Install and Image-update should check index consistency with installed packages
Brock Pytlik <bpytlik@sun.com>
parents: 499
diff changeset
  2293
                                                    (proot, pd, vd)
53da6297fb65 3039 Install and Image-update should check index consistency with installed packages
Brock Pytlik <bpytlik@sun.com>
parents: 499
diff changeset
  2294
                                                if not os.path.exists(path):
53da6297fb65 3039 Install and Image-update should check index consistency with installed packages
Brock Pytlik <bpytlik@sun.com>
parents: 499
diff changeset
  2295
                                                        continue
53da6297fb65 3039 Install and Image-update should check index consistency with installed packages
Brock Pytlik <bpytlik@sun.com>
parents: 499
diff changeset
  2296
53da6297fb65 3039 Install and Image-update should check index consistency with installed packages
Brock Pytlik <bpytlik@sun.com>
parents: 499
diff changeset
  2297
                                                yield urllib.unquote(
53da6297fb65 3039 Install and Image-update should check index consistency with installed packages
Brock Pytlik <bpytlik@sun.com>
parents: 499
diff changeset
  2298
                                                    "pkg:/%s@%s" % (pd, vd))
53da6297fb65 3039 Install and Image-update should check index consistency with installed packages
Brock Pytlik <bpytlik@sun.com>
parents: 499
diff changeset
  2299
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2300
        # This could simply call self.inventory() (or be replaced by inventory),
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2301
        # but it turns out to be about 20% slower.
221
e1dbb27a23b5 52 catalog can leave inventory behind, making pkg(1) blind
Stephen Hahn <sch@Sun.COM>
parents: 219
diff changeset
  2302
        def gen_installed_pkgs(self):
418
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
  2303
                """Return an iteration through the installed packages."""
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2304
                self.__load_pkg_states()
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2305
                return (i[1] for i in self.__pkg_states.values())
315
989c801f050b 1076 action __cmp__, action __str__ and manifest loading could all be faster
Dan Price <dp@eng.sun.com>
parents: 313
diff changeset
  2306
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2307
        def __load_pkg_states(self):
423
5c756997bf67 2253 With the latest build of the pkg repo, can't install packages from additional authorities
Danek Duvall <danek.duvall@sun.com>
parents: 419
diff changeset
  2308
                """Build up the package state dictionary.
526
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 518
diff changeset
  2309
423
5c756997bf67 2253 With the latest build of the pkg repo, can't install packages from additional authorities
Danek Duvall <danek.duvall@sun.com>
parents: 419
diff changeset
  2310
                This dictionary maps the full fmri string to a tuple of the
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2311
                state, the prefix of the publisher from which it's installed,
423
5c756997bf67 2253 With the latest build of the pkg repo, can't install packages from additional authorities
Danek Duvall <danek.duvall@sun.com>
parents: 419
diff changeset
  2312
                and the fmri object.
5c756997bf67 2253 With the latest build of the pkg repo, can't install packages from additional authorities
Danek Duvall <danek.duvall@sun.com>
parents: 419
diff changeset
  2313
5c756997bf67 2253 With the latest build of the pkg repo, can't install packages from additional authorities
Danek Duvall <danek.duvall@sun.com>
parents: 419
diff changeset
  2314
                Note that this dictionary only maps installed packages.  Use
5c756997bf67 2253 With the latest build of the pkg repo, can't install packages from additional authorities
Danek Duvall <danek.duvall@sun.com>
parents: 419
diff changeset
  2315
                get_pkg_state_by_fmri() to retrieve the state for arbitrary
5c756997bf67 2253 With the latest build of the pkg repo, can't install packages from additional authorities
Danek Duvall <danek.duvall@sun.com>
parents: 419
diff changeset
  2316
                packages.
5c756997bf67 2253 With the latest build of the pkg repo, can't install packages from additional authorities
Danek Duvall <danek.duvall@sun.com>
parents: 419
diff changeset
  2317
                """
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2318
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2319
                if self.__pkg_states is not None:
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2320
                        return
418
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
  2321
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
  2322
                installed_state_dir = "%s/state/installed" % self.imgdir
195
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
  2323
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2324
                self.__pkg_states = {}
418
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
  2325
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2326
                # If the state directory structure has already been created,
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2327
                # loading information from it is fast.  The directory is
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2328
                # populated with symlinks, named by their (url-encoded) FMRI,
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2329
                # which point to the "installed" file in the corresponding
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2330
                # directory under /var/pkg.
418
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
  2331
                if os.path.isdir(installed_state_dir):
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
  2332
                        for pl in sorted(os.listdir(installed_state_dir)):
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
  2333
                                fmristr = urllib.unquote(pl)
434
48c05c66cdd2 2595 List speedup changes don't work on Windows
Tom Mueller <Tom.Mueller@sun.com>
parents: 432
diff changeset
  2334
                                tmpf = pkg.fmri.PkgFmri(fmristr)
48c05c66cdd2 2595 List speedup changes don't work on Windows
Tom Mueller <Tom.Mueller@sun.com>
parents: 432
diff changeset
  2335
                                path = self._install_file(tmpf)
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2336
                                pub = self.installed_file_publisher(path)
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2337
                                f = pkg.fmri.PkgFmri(fmristr, publisher = pub)
418
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
  2338
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2339
                                self.__pkg_states[fmristr] = \
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2340
                                    (PKG_STATE_INSTALLED, f)
418
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
  2341
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
  2342
                        return
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
  2343
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
  2344
                # Otherwise, we must iterate through the earlier installed
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
  2345
                # state.  One day, this can be removed.
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
  2346
                proot = "%s/pkg" % self.imgdir
195
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
  2347
                for pd in sorted(os.listdir(proot)):
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
  2348
                        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
  2349
                                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
  2350
                                if not os.path.exists(path):
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
  2351
                                        continue
226
8939051a496c 376 image must use default authority when none specified
johansen <johansen@sun.com>
parents: 222
diff changeset
  2352
331
4f332d6b4036 1266 Client loses track of authority preference, chaos ensues
johansen <johansen@sun.com>
parents: 329
diff changeset
  2353
                                fmristr = urllib.unquote("%s@%s" % (pd, vd))
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2354
                                pub = self.installed_file_publisher(path)
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2355
                                f = pkg.fmri.PkgFmri(fmristr, publisher = pub)
226
8939051a496c 376 image must use default authority when none specified
johansen <johansen@sun.com>
parents: 222
diff changeset
  2356
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2357
                                self.__pkg_states[fmristr] = \
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2358
                                    (PKG_STATE_INSTALLED, f)
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  2359
516
53da6297fb65 3039 Install and Image-update should check index consistency with installed packages
Brock Pytlik <bpytlik@sun.com>
parents: 499
diff changeset
  2360
        def clear_pkg_state(self):
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2361
                self.__pkg_states = None
567
ea1d96e269a4 3505 client action and manifest creation are wasteful
johansen <johansen@sun.com>
parents: 565
diff changeset
  2362
                self.__manifest_cache = {}
516
53da6297fb65 3039 Install and Image-update should check index consistency with installed packages
Brock Pytlik <bpytlik@sun.com>
parents: 499
diff changeset
  2363
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  2364
        def strtofmri(self, myfmri):
423
5c756997bf67 2253 With the latest build of the pkg repo, can't install packages from additional authorities
Danek Duvall <danek.duvall@sun.com>
parents: 419
diff changeset
  2365
                return pkg.fmri.PkgFmri(myfmri, self.attrs["Build-Release"])
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  2366
526
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 518
diff changeset
  2367
        def strtomatchingfmri(self, myfmri):
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2368
                return pkg.fmri.MatchingPkgFmri(myfmri,
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2369
                    self.attrs["Build-Release"])
526
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 518
diff changeset
  2370
655
6eef82185057 2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 648
diff changeset
  2371
        def load_constraints(self, progtrack):
6eef82185057 2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 648
diff changeset
  2372
                """Load constraints for all install pkgs"""
6eef82185057 2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 648
diff changeset
  2373
                for fmri in self.gen_installed_pkgs():
6eef82185057 2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 648
diff changeset
  2374
                        # skip loading if already done
6eef82185057 2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 648
diff changeset
  2375
                        if self.constraints.start_loading(fmri):
838
aafbe4737188 3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 835
diff changeset
  2376
                                mfst = self.get_manifest(fmri)
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2377
                                for dep in mfst.gen_actions_by_type("depend",
838
aafbe4737188 3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 835
diff changeset
  2378
                                    self.list_excludes()):
655
6eef82185057 2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 648
diff changeset
  2379
                                        progtrack.evaluate_progress()
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2380
                                        f, con = dep.parse(self,
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2381
                                            fmri.get_name())
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2382
                                        self.constraints.update_constraints(con)
655
6eef82185057 2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 648
diff changeset
  2383
                                self.constraints.finish_loading(fmri)
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  2384
655
6eef82185057 2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 648
diff changeset
  2385
        def get_installed_unbound_inc_list(self):
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2386
                """Returns list of packages containing incorporation
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2387
                dependencies on which no other pkgs depend."""
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  2388
655
6eef82185057 2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 648
diff changeset
  2389
                inc_tuples = []
6eef82185057 2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 648
diff changeset
  2390
                dependents = set()
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  2391
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  2392
                for fmri in self.gen_installed_pkgs():
655
6eef82185057 2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 648
diff changeset
  2393
                        fmri_name = fmri.get_pkg_stem()
838
aafbe4737188 3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 835
diff changeset
  2394
                        mfst = self.get_manifest(fmri)
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2395
                        for dep in mfst.gen_actions_by_type("depend",
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2396
                            self.list_excludes()):
655
6eef82185057 2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 648
diff changeset
  2397
                                con_fmri = dep.get_constrained_fmri(self)
6eef82185057 2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 648
diff changeset
  2398
                                if con_fmri:
6eef82185057 2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 648
diff changeset
  2399
                                        con_name = con_fmri.get_pkg_stem()
6eef82185057 2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 648
diff changeset
  2400
                                        dependents.add(con_name)
6eef82185057 2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 648
diff changeset
  2401
                                        inc_tuples.append((fmri_name, con_name))
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2402
                # remove those incorporations which are depended on by other
655
6eef82185057 2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 648
diff changeset
  2403
                # incorporations.
6eef82185057 2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 648
diff changeset
  2404
                deletions = 0
6eef82185057 2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 648
diff changeset
  2405
                for i, a in enumerate(inc_tuples[:]):
6eef82185057 2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 648
diff changeset
  2406
                        if a[0] in dependents:
6eef82185057 2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 648
diff changeset
  2407
                                del inc_tuples[i - deletions]
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2408
655
6eef82185057 2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 648
diff changeset
  2409
                return list(set([ a[0] for a in inc_tuples ]))
195
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
  2410
289
c2e63370fb2b 160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents: 285
diff changeset
  2411
        def get_user_by_name(self, name):
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
  2412
                return portable.get_user_by_name(name, self.root,
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
  2413
                    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
  2414
339
d8e57580599b 1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  2415
        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
  2416
                # 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
  2417
                try:
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
  2418
                        return portable.get_name_by_uid(uid, self.root,
339
d8e57580599b 1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  2419
                            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
  2420
                except KeyError:
d8e57580599b 1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  2421
                        if returnuid:
d8e57580599b 1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  2422
                                return uid
d8e57580599b 1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  2423
                        else:
d8e57580599b 1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  2424
                                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
  2425
289
c2e63370fb2b 160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents: 285
diff changeset
  2426
        def get_group_by_name(self, name):
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
  2427
                return portable.get_group_by_name(name, self.root,
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
  2428
                    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
  2429
339
d8e57580599b 1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  2430
        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
  2431
                try:
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
  2432
                        return portable.get_name_by_gid(gid, self.root,
339
d8e57580599b 1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  2433
                            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
  2434
                except KeyError:
d8e57580599b 1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  2435
                        if returngid:
d8e57580599b 1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  2436
                                return gid
d8e57580599b 1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  2437
                        else:
d8e57580599b 1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  2438
                                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
  2439
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2440
        @staticmethod
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2441
        def __multimatch(name, patterns, matcher):
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2442
                """Applies a matcher to a name across a list of patterns.
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2443
                Returns all tuples of patterns which match the name.  Each tuple
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2444
                contains the index into the original list, the pattern itself,
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2445
                the package version, the publisher, and the raw publisher
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2446
                string."""
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2447
                return [
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2448
                    (i, pat, pat.tuple()[2],
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2449
                        pat.get_publisher(), pat.get_publisher_str())
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2450
                    for i, pat in enumerate(patterns)
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2451
                    if matcher(name, pat.tuple()[1])
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2452
                ]
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2453
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2454
        def __inventory(self, patterns=None, all_known=False, matcher=None,
1045
62656c214151 8135 plan creation could be faster for install and uninstall
Shawn Walker <srw@sun.com>
parents: 1037
diff changeset
  2455
            constraint=pkg.version.CONSTRAINT_AUTO, ordered=True):
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2456
                """Private method providing the back-end for inventory()."""
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2457
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2458
                if not matcher:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2459
                        matcher = pkg.fmri.fmri_match
59
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
  2460
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2461
                if not patterns:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2462
                        patterns = []
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2463
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2464
                # Store the original patterns before we possibly turn them into
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2465
                # PkgFmri objects, so we can give them back to the user in error
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2466
                # messages.
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2467
                opatterns = patterns[:]
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2468
526
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 518
diff changeset
  2469
                illegals = []
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2470
                for i, pat in enumerate(patterns):
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2471
                        if not isinstance(pat, pkg.fmri.PkgFmri):
526
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 518
diff changeset
  2472
                                try:
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 518
diff changeset
  2473
                                        if "*" in pat or "?" in pat:
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 518
diff changeset
  2474
                                                matcher = pkg.fmri.glob_match
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 518
diff changeset
  2475
                                                patterns[i] = \
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2476
                                                    pkg.fmri.MatchingPkgFmri(
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2477
                                                        pat, "5.11")
526
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 518
diff changeset
  2478
                                        else:
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 518
diff changeset
  2479
                                                patterns[i] = \
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 518
diff changeset
  2480
                                                    pkg.fmri.PkgFmri(pat,
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 518
diff changeset
  2481
                                                    "5.11")
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 518
diff changeset
  2482
                                except pkg.fmri.IllegalFmri, e:
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 518
diff changeset
  2483
                                        illegals.append(e)
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 518
diff changeset
  2484
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 518
diff changeset
  2485
                if illegals:
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2486
                        raise api_errors.InventoryException(illegal=illegals)
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2487
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2488
                ppub = self.cfg_cache.preferred_publisher
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2489
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2490
                # matchingpats is the set of all the patterns which matched a
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2491
                # package in the catalog.  This allows us to return partial
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2492
                # failure if some patterns match and some don't.
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2493
                # XXX It would be nice to keep track of why some patterns failed
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2494
                # to match -- based on name, version, or publisher.
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2495
                matchingpats = set()
59
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
  2496
1045
62656c214151 8135 plan creation could be faster for install and uninstall
Shawn Walker <srw@sun.com>
parents: 1037
diff changeset
  2497
                if ordered:
62656c214151 8135 plan creation could be faster for install and uninstall
Shawn Walker <srw@sun.com>
parents: 1037
diff changeset
  2498
                        entries = sorted(self._catalog.keys())
62656c214151 8135 plan creation could be faster for install and uninstall
Shawn Walker <srw@sun.com>
parents: 1037
diff changeset
  2499
                else:
62656c214151 8135 plan creation could be faster for install and uninstall
Shawn Walker <srw@sun.com>
parents: 1037
diff changeset
  2500
                        entries = self._catalog.keys()
62656c214151 8135 plan creation could be faster for install and uninstall
Shawn Walker <srw@sun.com>
parents: 1037
diff changeset
  2501
62656c214151 8135 plan creation could be faster for install and uninstall
Shawn Walker <srw@sun.com>
parents: 1037
diff changeset
  2502
                for name in entries:
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2503
                        # Eliminate all patterns not matching "name".  If there
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2504
                        # are no patterns left, go on to the next name, but only
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2505
                        # if there were any to start with.
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2506
                        matches = self.__multimatch(name, patterns, matcher)
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2507
                        if patterns and not matches:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2508
                                continue
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2509
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2510
                        newest = self._catalog[name]["versions"][-1]
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2511
                        for ver in reversed(self._catalog[name]["versions"]):
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2512
                                # If a pattern specified a version and that
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2513
                                # version isn't succeeded by "ver", then record
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2514
                                # the pattern for removal from consideration.
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2515
                                nomatch = []
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2516
                                for i, match in enumerate(matches):
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2517
                                        if match[2] and \
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2518
                                            not ver.is_successor(match[2],
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2519
                                                constraint):
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2520
                                                nomatch.append(i)
221
e1dbb27a23b5 52 catalog can leave inventory behind, making pkg(1) blind
Stephen Hahn <sch@Sun.COM>
parents: 219
diff changeset
  2521
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2522
                                # Eliminate the name matches that didn't match
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2523
                                # on versions.  We need to create a new list
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2524
                                # because we need to reuse the original
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2525
                                # "matches" for each new version.
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2526
                                vmatches = [
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2527
                                    matches[i]
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2528
                                    for i, match in enumerate(matches)
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2529
                                    if i not in nomatch
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2530
                                ]
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2531
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2532
                                # If we deleted all contenders (if we had any to
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2533
                                # begin with), go on to the next version.
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2534
                                if matches and not vmatches:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2535
                                        continue
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2536
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2537
                                # Like the version skipping above, do the same
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2538
                                # for publishers.
988
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2539
                                pubstate = self._catalog[name][str(ver)][1]
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2540
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2541
                                nomatch = []
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2542
                                for i, match in enumerate(vmatches):
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2543
                                        if match[3] and \
988
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2544
                                            match[3] not in pubstate:
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2545
                                                nomatch.append(i)
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2546
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2547
                                pmatches = [
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2548
                                    vmatches[i]
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2549
                                    for i, match in enumerate(vmatches)
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2550
                                    if i not in nomatch
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2551
                                ]
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2552
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2553
                                if vmatches and not pmatches:
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2554
                                        continue
104
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
  2555
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2556
                                # If no patterns were specified or any still-
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2557
                                # matching pattern specified no publisher, we
988
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2558
                                # use the entire list of publishers for this
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2559
                                # version.  Otherwise, we use the intersection
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2560
                                # of the list of publishers in pubstate, and
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2561
                                # the publishers in the patterns.
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2562
                                aset = set(i[3] for i in pmatches)
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2563
                                if aset and None not in aset:
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2564
                                        publist = set(
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2565
                                            m[3:5]
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2566
                                            for m in pmatches
988
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2567
                                            if m[3] in pubstate
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2568
                                        )
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2569
                                else:
988
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2570
                                        publist = zip(pubstate.keys(),
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2571
                                            pubstate.keys())
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2572
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2573
                                pfmri = self._catalog[name][str(ver)][0]
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2574
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2575
                                inst_state = self.get_pkg_state_by_fmri(pfmri)
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2576
                                inst_pub = self.get_pkg_pub_by_fmri(pfmri)
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2577
                                state = {
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2578
                                    "upgradable": ver != newest,
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2579
                                    "frozen": False,
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2580
                                    "incorporated": False,
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2581
                                    "excludes": False
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2582
                                }
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2583
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2584
                                # We yield copies of the fmri objects in the
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2585
                                # catalog because we add the publishers in, and
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2586
                                # don't want to mess up the canonical catalog.
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2587
                                # If a pattern had specified a publisher as
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2588
                                # preferred, be sure to emit an fmri that way,
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2589
                                # too.
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2590
                                yielded = False
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2591
                                if all_known:
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2592
                                        for pub, rpub in publist:
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2593
                                                nfmri = pfmri.copy()
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2594
                                                nfmri.set_publisher(rpub,
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2595
                                                    pub == ppub)
703
4cb0ea696976 3273 image.inventory yields same dictionary multiple times for packages in multiple authorities
Danek Duvall <danek.duvall@sun.com>
parents: 696
diff changeset
  2596
                                                st = state.copy()
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2597
                                                if pub == inst_pub:
703
4cb0ea696976 3273 image.inventory yields same dictionary multiple times for packages in multiple authorities
Danek Duvall <danek.duvall@sun.com>
parents: 696
diff changeset
  2598
                                                        st["state"] = \
423
5c756997bf67 2253 With the latest build of the pkg repo, can't install packages from additional authorities
Danek Duvall <danek.duvall@sun.com>
parents: 419
diff changeset
  2599
                                                            PKG_STATE_INSTALLED
5c756997bf67 2253 With the latest build of the pkg repo, can't install packages from additional authorities
Danek Duvall <danek.duvall@sun.com>
parents: 419
diff changeset
  2600
                                                else:
703
4cb0ea696976 3273 image.inventory yields same dictionary multiple times for packages in multiple authorities
Danek Duvall <danek.duvall@sun.com>
parents: 696
diff changeset
  2601
                                                        st["state"] = \
423
5c756997bf67 2253 With the latest build of the pkg repo, can't install packages from additional authorities
Danek Duvall <danek.duvall@sun.com>
parents: 419
diff changeset
  2602
                                                            PKG_STATE_KNOWN
988
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2603
                                                st["in_catalog"] = pubstate[pub]
703
4cb0ea696976 3273 image.inventory yields same dictionary multiple times for packages in multiple authorities
Danek Duvall <danek.duvall@sun.com>
parents: 696
diff changeset
  2604
                                                yield nfmri, st
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2605
                                                yielded = True
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2606
                                elif inst_state == PKG_STATE_INSTALLED:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2607
                                        nfmri = pfmri.copy()
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2608
                                        nfmri.set_publisher(inst_pub,
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2609
                                            inst_pub == ppub)
423
5c756997bf67 2253 With the latest build of the pkg repo, can't install packages from additional authorities
Danek Duvall <danek.duvall@sun.com>
parents: 419
diff changeset
  2610
                                        state["state"] = inst_state
988
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2611
                                        state["in_catalog"] = pubstate[inst_pub]
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2612
                                        yield nfmri, state
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2613
                                        yielded = True
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2614
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2615
                                if yielded:
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2616
                                        matchingpats |= set(
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2617
                                            i[:2] for i in pmatches)
329
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
  2618
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2619
                nonmatchingpats = [
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2620
                    opatterns[i]
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2621
                    for i, f in set(enumerate(patterns)) - matchingpats
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2622
                ]
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2623
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2624
                if nonmatchingpats:
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2625
                        raise api_errors.InventoryException(
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2626
                            notfound=nonmatchingpats)
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2627
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2628
        def inventory(self, *args, **kwargs):
988
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2629
                """Enumerate the package FMRIs in the image's catalog, yielding
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2630
                a list of tuples of the format (fmri, pkg state dict).
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2631
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2632
                If "patterns" is None (the default) or an empty sequence, all
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2633
                package names will match.  Otherwise, it is a list of patterns
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2634
                to match against FMRIs in the catalog.
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2635
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2636
                If "all_known" is False (the default), only installed packages
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2637
                will be enumerated.  If True, all known packages will be
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2638
                enumerated.
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2639
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2640
                The "matcher" parameter should specify a function taking two
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2641
                string arguments: a name and a pattern, returning True if the
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2642
                pattern matches the name, and False otherwise.  By default, the
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2643
                matcher will be pkg.fmri.fmri_match().
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2644
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2645
                The "constraint" parameter defines how a version specified in a
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2646
                pattern matches a version in the catalog.  By default, a natural
1045
62656c214151 8135 plan creation could be faster for install and uninstall
Shawn Walker <srw@sun.com>
parents: 1037
diff changeset
  2647
                "subsetting" constraint is used.
62656c214151 8135 plan creation could be faster for install and uninstall
Shawn Walker <srw@sun.com>
parents: 1037
diff changeset
  2648
62656c214151 8135 plan creation could be faster for install and uninstall
Shawn Walker <srw@sun.com>
parents: 1037
diff changeset
  2649
                The "ordered" parameter is a boolean value that indicates
62656c214151 8135 plan creation could be faster for install and uninstall
Shawn Walker <srw@sun.com>
parents: 1037
diff changeset
  2650
                whether the returned list should first be sorted by name before
62656c214151 8135 plan creation could be faster for install and uninstall
Shawn Walker <srw@sun.com>
parents: 1037
diff changeset
  2651
                being sorted by version (descending).  By default, this is True.
62656c214151 8135 plan creation could be faster for install and uninstall
Shawn Walker <srw@sun.com>
parents: 1037
diff changeset
  2652
                """
161
e0322fe7842c Simplify and correct the package matching code.
Danek Duvall <danek.duvall@sun.com>
parents: 157
diff changeset
  2653
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2654
                # "preferred" and "first_only" are private arguments that are
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2655
                # currently only used in evaluate_fmri(), but could be made more
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2656
                # generally useful.  "preferred" ensures that all potential
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2657
                # matches from the preferred publisher are generated before
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2658
                # those from non-preferred publishers.  In the current
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2659
                # implementation, this consumes more memory.  "first_only"
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2660
                # signals us to return only the first match, which allows us to
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2661
                # save all the memory that "preferred" currently eats up.
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2662
                preferred = kwargs.pop("preferred", False)
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2663
                first_only = kwargs.pop("first_only", False)
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2664
                ppub = self.cfg_cache.preferred_publisher
59
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
  2665
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2666
                if not preferred:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2667
                        for f in self.__inventory(*args, **kwargs):
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2668
                                yield f
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2669
                else:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2670
                        nplist = []
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2671
                        firstnp = None
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2672
                        for f in self.__inventory(*args, **kwargs):
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2673
                                if f[0].get_publisher() == ppub:
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2674
                                        yield f
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2675
                                        if first_only:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2676
                                                return
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2677
                                else:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2678
                                        if first_only:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2679
                                                if not firstnp:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2680
                                                        firstnp = f
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2681
                                        else:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2682
                                                nplist.append(f)
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2683
                        if first_only:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2684
                                yield firstnp
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2685
                                return
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2686
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2687
                        for f in nplist:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2688
                                yield f
59
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
  2689
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
  2690
        def update_index_dir(self, postfix="index"):
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
  2691
                """Since the index directory will not reliably be updated when
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
  2692
                the image root is, this should be called prior to using the
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
  2693
                index directory.
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
  2694
                """
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
  2695
                self.index_dir = os.path.join(self.imgdir, postfix)
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
  2696
388
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  2697
        def incoming_download_dir(self):
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  2698
                """Return the directory path for incoming downloads
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  2699
                that have yet to be completed.  Once a file has been
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  2700
                successfully downloaded, it is moved to the cached download
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  2701
                directory."""
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  2702
554
fe196874250d 3508 zone install should utilize/populate global zone d/l cache
Dan Price <dp@eng.sun.com>
parents: 552
diff changeset
  2703
                return self.dl_cache_incoming
388
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  2704
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  2705
        def cached_download_dir(self):
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  2706
                """Return the directory path for cached content.
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  2707
                Files that have been successfully downloaded live here."""
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  2708
554
fe196874250d 3508 zone install should utilize/populate global zone d/l cache
Dan Price <dp@eng.sun.com>
parents: 552
diff changeset
  2709
                return self.dl_cache_dir
251
6c3d70b74865 470 pkg image-update can fail under some conditions
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 243
diff changeset
  2710
6c3d70b74865 470 pkg image-update can fail under some conditions
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 243
diff changeset
  2711
        def cleanup_downloads(self):
388
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  2712
                """Clean up any downloads that were in progress but that
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  2713
                did not successfully finish."""
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  2714
554
fe196874250d 3508 zone install should utilize/populate global zone d/l cache
Dan Price <dp@eng.sun.com>
parents: 552
diff changeset
  2715
                shutil.rmtree(self.dl_cache_incoming, True)
388
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  2716
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  2717
        def cleanup_cached_content(self):
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  2718
                """Delete the directory that stores all of our cached
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  2719
                downloaded content.  This may take a while for a large
554
fe196874250d 3508 zone install should utilize/populate global zone d/l cache
Dan Price <dp@eng.sun.com>
parents: 552
diff changeset
  2720
                directory hierarchy.  Don't clean up caches if the
fe196874250d 3508 zone install should utilize/populate global zone d/l cache
Dan Price <dp@eng.sun.com>
parents: 552
diff changeset
  2721
                user overrode the underlying setting using PKG_CACHEDIR. """
388
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  2722
554
fe196874250d 3508 zone install should utilize/populate global zone d/l cache
Dan Price <dp@eng.sun.com>
parents: 552
diff changeset
  2723
                if not self.is_user_cache_dir and \
fe196874250d 3508 zone install should utilize/populate global zone d/l cache
Dan Price <dp@eng.sun.com>
parents: 552
diff changeset
  2724
                    self.cfg_cache.get_policy(imageconfig.FLUSH_CONTENT_CACHE):
388
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  2725
                        msg("Deleting content cache")
554
fe196874250d 3508 zone install should utilize/populate global zone d/l cache
Dan Price <dp@eng.sun.com>
parents: 552
diff changeset
  2726
                        shutil.rmtree(self.dl_cache_dir, True)
289
c2e63370fb2b 160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents: 285
diff changeset
  2727
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  2728
        def salvagedir(self, path):
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2729
                """Called when directory contains something and it's not
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2730
                supposed to because it's being deleted. XXX Need to work out a
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2731
                better error passback mechanism. Path is rooted in /...."""
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
  2732
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  2733
                salvagedir = os.path.normpath(
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  2734
                    os.path.join(self.imgdir, "lost+found",
384
9d4746e5dd3e 115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents: 383
diff changeset
  2735
                    path + "-" + time.strftime("%Y%m%dT%H%M%SZ")))
289
c2e63370fb2b 160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents: 285
diff changeset
  2736
405
16824ed83efe 2209 license install failure on Windows if license file already exists
Tom Mueller <Tom.Mueller@sun.com>
parents: 399
diff changeset
  2737
                parent = os.path.dirname(salvagedir)
16824ed83efe 2209 license install failure on Windows if license file already exists
Tom Mueller <Tom.Mueller@sun.com>
parents: 399
diff changeset
  2738
                if not os.path.exists(parent):
16824ed83efe 2209 license install failure on Windows if license file already exists
Tom Mueller <Tom.Mueller@sun.com>
parents: 399
diff changeset
  2739
                        os.makedirs(parent)
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2740
                shutil.move(os.path.normpath(os.path.join(self.root, path)),
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2741
                    salvagedir)
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  2742
                # XXX need a better way to do this.
384
9d4746e5dd3e 115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents: 383
diff changeset
  2743
                emsg("\nWarning - directory %s not empty - contents preserved "
9d4746e5dd3e 115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents: 383
diff changeset
  2744
                        "in %s" % (path, salvagedir))
251
6c3d70b74865 470 pkg image-update can fail under some conditions
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 243
diff changeset
  2745
462
910600c14093 45 "move" action for files that are renamed, but must be preserved
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 461
diff changeset
  2746
        def temporary_file(self):
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2747
                """create a temp file under image directory for various
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2748
                purposes"""
462
910600c14093 45 "move" action for files that are renamed, but must be preserved
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 461
diff changeset
  2749
                tempdir = os.path.normpath(os.path.join(self.imgdir, "tmp"))
910600c14093 45 "move" action for files that are renamed, but must be preserved
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 461
diff changeset
  2750
                if not os.path.exists(tempdir):
910600c14093 45 "move" action for files that are renamed, but must be preserved
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 461
diff changeset
  2751
                        os.makedirs(tempdir)
910600c14093 45 "move" action for files that are renamed, but must be preserved
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 461
diff changeset
  2752
                fd, name = tempfile.mkstemp(dir=tempdir)
910600c14093 45 "move" action for files that are renamed, but must be preserved
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 461
diff changeset
  2753
                os.close(fd)
910600c14093 45 "move" action for files that are renamed, but must be preserved
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 461
diff changeset
  2754
                return name
910600c14093 45 "move" action for files that are renamed, but must be preserved
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 461
diff changeset
  2755
988
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2756
        def __filter_install_matches(self, matches, names):
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2757
                """Attempts to eliminate redundant matches found during
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2758
                packaging operations:
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2759
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2760
                    * First, stems of installed packages for publishers that
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2761
                      are now unknown (no longer present in the image
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2762
                      configuration) are dropped.
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2763
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2764
                    * Second, if multiple matches are still present, stems of
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2765
                      of installed packages, that are not presently in the
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2766
                      corresponding publisher's catalog, are dropped.
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2767
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2768
                    * Finally, if multiple matches are still present, all
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2769
                      stems except for those in state PKG_STATE_INSTALLED are
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2770
                      dropped.
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2771
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2772
                Returns a list of the filtered matches, along with a dict of
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2773
                their unique names and a dict containing package state
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2774
                information."""
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2775
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2776
                olist = []
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2777
                onames = {}
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2778
                # First eliminate any duplicate matches that are for unknown
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2779
                # publishers (publishers which have been removed from the image
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2780
                # configuration).
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2781
                publist = [p.prefix for p in self.get_publishers().values()]
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2782
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2783
                for m in matches:
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2784
                        if m.get_publisher() in publist:
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2785
                                stem = m.get_pkg_stem()
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2786
                                onames[stem] = names[stem]
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2787
                                olist.append(m)
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2788
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2789
                # Next, if there are still multiple matches, eliminate fmris
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2790
                # belonging to publishers that no longer have the fmri in their
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2791
                # catalog.
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2792
                found_state = False
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2793
                if len(onames) > 1:
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2794
                        mlist = []
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2795
                        mnames = {}
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2796
                        for m in olist:
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2797
                                stem = m.get_pkg_stem()
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2798
                                st = onames[stem]
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2799
                                if st["in_catalog"]:
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2800
                                        if st["state"] == PKG_STATE_INSTALLED:
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2801
                                                found_state = True
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2802
                                        mnames[stem] = onames[stem]
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2803
                                        mlist.append(m)
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2804
                        olist = mlist
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2805
                        onames = mnames
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2806
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2807
                # Finally, if there are still multiple matches, and a known stem
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2808
                # has been found in the provided state, then eliminate any stems
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2809
                # that do not have the specified state.
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2810
                if found_state and len(onames) > 1:
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2811
                        mlist = []
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2812
                        mnames = {}
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2813
                        for m in olist:
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2814
                                stem = m.get_pkg_stem()
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2815
                                if onames[stem]["state"] == PKG_STATE_INSTALLED:
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2816
                                        mnames[stem] = onames[stem]
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2817
                                        mlist.append(m)
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2818
                        olist = mlist
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2819
                        onames = mnames
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2820
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2821
                return olist, onames
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2822
625
e46b345645d6 3799 need to start progress tracker going early on
Brock Pytlik <bpytlik@sun.com>
parents: 621
diff changeset
  2823
        def make_install_plan(self, pkg_list, progtrack, check_cancelation,
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2824
            noexecute, filters = None, verbose=False):
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  2825
                """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
  2826
                to assemble an appropriate image plan.  This is a helper
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
  2827
                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
  2828
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2829
                This method checks all publishers for a package match;
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2830
                however, it defaults to choosing the preferred publisher
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  2831
                when an ambiguous package name is specified.  If the user
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2832
                wishes to install a package from a non-preferred publisher,
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2833
                the full FMRI that contains a publisher should be used
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  2834
                to name the package."""
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  2835
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2836
                self.load_catalogs(progtrack)
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2837
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2838
                if filters is None:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2839
                        filters = []
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2840
172
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  2841
                error = 0
625
e46b345645d6 3799 need to start progress tracker going early on
Brock Pytlik <bpytlik@sun.com>
parents: 621
diff changeset
  2842
                ip = imageplan.ImagePlan(self, progtrack, check_cancelation,
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2843
                    filters=filters, noexecute=noexecute)
172
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  2844
625
e46b345645d6 3799 need to start progress tracker going early on
Brock Pytlik <bpytlik@sun.com>
parents: 621
diff changeset
  2845
                progtrack.evaluate_start()
655
6eef82185057 2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 648
diff changeset
  2846
                self.load_constraints(progtrack)
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  2847
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2848
                unfound_fmris = []
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2849
                multiple_matches = []
616
6d307b088d92 4056 make_uninstall_plan misreports trying to uninstall a known, but uninstalled package
Brock Pytlik <bpytlik@sun.com>
parents: 596
diff changeset
  2850
                illegal_fmris = []
655
6eef82185057 2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 648
diff changeset
  2851
                constraint_violations = []
6eef82185057 2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 648
diff changeset
  2852
6eef82185057 2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 648
diff changeset
  2853
                # order package list so that any unbound incorporations are
6eef82185057 2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 648
diff changeset
  2854
                # done first
6eef82185057 2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 648
diff changeset
  2855
6eef82185057 2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 648
diff changeset
  2856
                inc_list = self.get_installed_unbound_inc_list()
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2857
655
6eef82185057 2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 648
diff changeset
  2858
                head = []
6eef82185057 2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 648
diff changeset
  2859
                tail = []
6eef82185057 2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 648
diff changeset
  2860
6eef82185057 2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 648
diff changeset
  2861
6eef82185057 2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 648
diff changeset
  2862
                for p in pkg_list:
6eef82185057 2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 648
diff changeset
  2863
                        if p in inc_list:
6eef82185057 2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 648
diff changeset
  2864
                                head.append(p)
6eef82185057 2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 648
diff changeset
  2865
                        else:
6eef82185057 2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 648
diff changeset
  2866
                                tail.append(p)
6eef82185057 2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 648
diff changeset
  2867
                pkg_list = head + tail
6eef82185057 2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 648
diff changeset
  2868
6eef82185057 2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 648
diff changeset
  2869
                # This approach works only for cases w/ simple
6eef82185057 2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 648
diff changeset
  2870
                # incorporations; the apply_constraints_to_fmri
6eef82185057 2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 648
diff changeset
  2871
                # call below binds the version too quickly.  This
6eef82185057 2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 648
diff changeset
  2872
                # awaits a proper solver.
616
6d307b088d92 4056 make_uninstall_plan misreports trying to uninstall a known, but uninstalled package
Brock Pytlik <bpytlik@sun.com>
parents: 596
diff changeset
  2873
172
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  2874
                for p in pkg_list:
625
e46b345645d6 3799 need to start progress tracker going early on
Brock Pytlik <bpytlik@sun.com>
parents: 621
diff changeset
  2875
                        progtrack.evaluate_progress()
172
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  2876
                        try:
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2877
                                conp = pkg.fmri.PkgFmri(p,
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2878
                                    self.attrs["Build-Release"])
655
6eef82185057 2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 648
diff changeset
  2879
                        except pkg.fmri.IllegalFmri:
616
6d307b088d92 4056 make_uninstall_plan misreports trying to uninstall a known, but uninstalled package
Brock Pytlik <bpytlik@sun.com>
parents: 596
diff changeset
  2880
                                illegal_fmris.append(p)
655
6eef82185057 2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 648
diff changeset
  2881
                                error = 1
6eef82185057 2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 648
diff changeset
  2882
                                continue
6eef82185057 2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 648
diff changeset
  2883
                        try:
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2884
                                conp = \
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2885
                                    self.constraints.apply_constraints_to_fmri(
1085
aa3274c0fe55 8392 backpublishing variant-aware SUNWipkg to 101 will break zones on those builds
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1075
diff changeset
  2886
                                    conp, auto=True)
655
6eef82185057 2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 648
diff changeset
  2887
                        except constraint.ConstraintException, e:
6eef82185057 2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 648
diff changeset
  2888
                                error = 1
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2889
                                constraint_violations.extend(str(e).split("\n"))
616
6d307b088d92 4056 make_uninstall_plan misreports trying to uninstall a known, but uninstalled package
Brock Pytlik <bpytlik@sun.com>
parents: 596
diff changeset
  2890
                                continue
931
2c497b23356a 7200 package name matching too loose on upgrade
Danek Duvall <danek.duvall@sun.com>
parents: 926
diff changeset
  2891
2c497b23356a 7200 package name matching too loose on upgrade
Danek Duvall <danek.duvall@sun.com>
parents: 926
diff changeset
  2892
                        # If we were passed in an fmri object or a string that
2c497b23356a 7200 package name matching too loose on upgrade
Danek Duvall <danek.duvall@sun.com>
parents: 926
diff changeset
  2893
                        # anchors the package stem with the scheme, match on the
2c497b23356a 7200 package name matching too loose on upgrade
Danek Duvall <danek.duvall@sun.com>
parents: 926
diff changeset
  2894
                        # stem exactly as given.  Otherwise we can let the
2c497b23356a 7200 package name matching too loose on upgrade
Danek Duvall <danek.duvall@sun.com>
parents: 926
diff changeset
  2895
                        # default, looser matching mechanism be used.
2c497b23356a 7200 package name matching too loose on upgrade
Danek Duvall <danek.duvall@sun.com>
parents: 926
diff changeset
  2896
                        # inventory() will override if globbing characters are
2c497b23356a 7200 package name matching too loose on upgrade
Danek Duvall <danek.duvall@sun.com>
parents: 926
diff changeset
  2897
                        # used.
2c497b23356a 7200 package name matching too loose on upgrade
Danek Duvall <danek.duvall@sun.com>
parents: 926
diff changeset
  2898
                        matcher = None
988
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2899
                        if isinstance(p, pkg.fmri.PkgFmri) or \
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2900
                            p.startswith("pkg:/"):
931
2c497b23356a 7200 package name matching too loose on upgrade
Danek Duvall <danek.duvall@sun.com>
parents: 926
diff changeset
  2901
                                matcher = pkg.fmri.exact_name_match
2c497b23356a 7200 package name matching too loose on upgrade
Danek Duvall <danek.duvall@sun.com>
parents: 926
diff changeset
  2902
616
6d307b088d92 4056 make_uninstall_plan misreports trying to uninstall a known, but uninstalled package
Brock Pytlik <bpytlik@sun.com>
parents: 596
diff changeset
  2903
                        try:
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2904
                                matches = list(self.inventory([conp],
1045
62656c214151 8135 plan creation could be faster for install and uninstall
Shawn Walker <srw@sun.com>
parents: 1037
diff changeset
  2905
                                    all_known=True, matcher=matcher,
62656c214151 8135 plan creation could be faster for install and uninstall
Shawn Walker <srw@sun.com>
parents: 1037
diff changeset
  2906
                                    ordered=False))
616
6d307b088d92 4056 make_uninstall_plan misreports trying to uninstall a known, but uninstalled package
Brock Pytlik <bpytlik@sun.com>
parents: 596
diff changeset
  2907
                        except api_errors.InventoryException, e:
6d307b088d92 4056 make_uninstall_plan misreports trying to uninstall a known, but uninstalled package
Brock Pytlik <bpytlik@sun.com>
parents: 596
diff changeset
  2908
                                assert(not (e.notfound and e.illegal))
6d307b088d92 4056 make_uninstall_plan misreports trying to uninstall a known, but uninstalled package
Brock Pytlik <bpytlik@sun.com>
parents: 596
diff changeset
  2909
                                assert(e.notfound or e.illegal)
172
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  2910
                                error = 1
616
6d307b088d92 4056 make_uninstall_plan misreports trying to uninstall a known, but uninstalled package
Brock Pytlik <bpytlik@sun.com>
parents: 596
diff changeset
  2911
                                if e.notfound:
6d307b088d92 4056 make_uninstall_plan misreports trying to uninstall a known, but uninstalled package
Brock Pytlik <bpytlik@sun.com>
parents: 596
diff changeset
  2912
                                        unfound_fmris.append(p)
6d307b088d92 4056 make_uninstall_plan misreports trying to uninstall a known, but uninstalled package
Brock Pytlik <bpytlik@sun.com>
parents: 596
diff changeset
  2913
                                else:
6d307b088d92 4056 make_uninstall_plan misreports trying to uninstall a known, but uninstalled package
Brock Pytlik <bpytlik@sun.com>
parents: 596
diff changeset
  2914
                                        illegal_fmris.append(p)
172
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  2915
                                continue
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  2916
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  2917
                        pnames = {}
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  2918
                        pmatch = []
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  2919
                        npnames = {}
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  2920
                        npmatch = []
988
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2921
                        for m, st in matches:
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2922
                                if m.preferred_publisher():
988
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2923
                                        pnames[m.get_pkg_stem()] = st
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  2924
                                        pmatch.append(m)
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  2925
                                else:
988
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2926
                                        npnames[m.get_pkg_stem()] = st
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  2927
                                        npmatch.append(m)
172
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  2928
988
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2929
                        if len(pnames) > 1:
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2930
                                # There can only be one preferred publisher, so
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2931
                                # filtering is pointless and these are truly
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2932
                                # ambiguous matches.
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2933
                                multiple_matches.append((p, pnames.keys()))
172
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  2934
                                error = 1
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  2935
                                continue
988
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2936
                        elif not pnames and len(npnames) > 1:
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2937
                                npmatch, npnames = \
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2938
                                    self.__filter_install_matches(npmatch,
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2939
                                    npnames)
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2940
                                if len(npnames) > 1:
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2941
                                        # If there are still multiple matches
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2942
                                        # after filtering, fail.
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2943
                                        multiple_matches.append((p,
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2944
                                            npnames.keys()))
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2945
                                        error = 1
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2946
                                        continue
172
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  2947
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  2948
                        # 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
  2949
                        # the first; i.e., the latest.
988
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2950
                        if pmatch:
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  2951
                                ip.propose_fmri(pmatch[0])
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  2952
                        else:
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
  2953
                                ip.propose_fmri(npmatch[0])
172
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  2954
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  2955
                if error != 0:
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2956
                        raise api_errors.PlanCreationException(unfound_fmris,
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2957
                            multiple_matches, [], illegal_fmris,
655
6eef82185057 2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 648
diff changeset
  2958
                            constraint_violations=constraint_violations)
172
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  2959
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  2960
                if verbose:
384
9d4746e5dd3e 115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents: 383
diff changeset
  2961
                        msg(_("Before evaluation:"))
9d4746e5dd3e 115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents: 383
diff changeset
  2962
                        msg(ip)
172
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  2963
539
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  2964
                # A plan can be requested without actually performing an
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  2965
                # operation on the image.
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  2966
                if self.history.operation_name:
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  2967
                        self.history.operation_start_state = ip.get_plan()
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  2968
655
6eef82185057 2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 648
diff changeset
  2969
                try:
6eef82185057 2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 648
diff changeset
  2970
                        ip.evaluate()
6eef82185057 2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 648
diff changeset
  2971
                except constraint.ConstraintException, e:
6eef82185057 2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 648
diff changeset
  2972
                        raise api_errors.PlanCreationException(
6eef82185057 2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 648
diff changeset
  2973
                            constraint_violations=str(e).split("\n"))
6eef82185057 2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 648
diff changeset
  2974
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
  2975
                self.imageplan = ip
172
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  2976
539
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  2977
                if self.history.operation_name:
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  2978
                        self.history.operation_end_state = \
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  2979
                            ip.get_plan(full=False)
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
  2980
172
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  2981
                if verbose:
384
9d4746e5dd3e 115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents: 383
diff changeset
  2982
                        msg(_("After evaluation:"))
9d4746e5dd3e 115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents: 383
diff changeset
  2983
                        msg(ip.display())
45
8a3f00dea14f catalog refresh; basic catalog listing; precise manifest pulls
Stephen Hahn <sch@sun.com>
parents: 39
diff changeset
  2984
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2985
        def make_uninstall_plan(self, fmri_list, recursive_removal,
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2986
            progresstracker, check_cancelation, noexecute, verbose=False):
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2987
                ip = imageplan.ImagePlan(self, progresstracker,
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2988
                    check_cancelation, recursive_removal, noexecute=noexecute)
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2989
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2990
                self.load_catalogs(progresstracker)
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2991
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2992
                err = 0
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2993
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2994
                unfound_fmris = []
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2995
                multiple_matches = []
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2996
                missing_matches = []
616
6d307b088d92 4056 make_uninstall_plan misreports trying to uninstall a known, but uninstalled package
Brock Pytlik <bpytlik@sun.com>
parents: 596
diff changeset
  2997
                illegal_fmris = []
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2998
625
e46b345645d6 3799 need to start progress tracker going early on
Brock Pytlik <bpytlik@sun.com>
parents: 621
diff changeset
  2999
                progresstracker.evaluate_start()
e46b345645d6 3799 need to start progress tracker going early on
Brock Pytlik <bpytlik@sun.com>
parents: 621
diff changeset
  3000
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  3001
                for ppat in fmri_list:
625
e46b345645d6 3799 need to start progress tracker going early on
Brock Pytlik <bpytlik@sun.com>
parents: 621
diff changeset
  3002
                        progresstracker.evaluate_progress()
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  3003
                        try:
1045
62656c214151 8135 plan creation could be faster for install and uninstall
Shawn Walker <srw@sun.com>
parents: 1037
diff changeset
  3004
                                matches = list(self.inventory([ppat],
62656c214151 8135 plan creation could be faster for install and uninstall
Shawn Walker <srw@sun.com>
parents: 1037
diff changeset
  3005
                                    ordered=False))
616
6d307b088d92 4056 make_uninstall_plan misreports trying to uninstall a known, but uninstalled package
Brock Pytlik <bpytlik@sun.com>
parents: 596
diff changeset
  3006
                        except api_errors.InventoryException, e:
6d307b088d92 4056 make_uninstall_plan misreports trying to uninstall a known, but uninstalled package
Brock Pytlik <bpytlik@sun.com>
parents: 596
diff changeset
  3007
                                assert(not (e.notfound and e.illegal))
6d307b088d92 4056 make_uninstall_plan misreports trying to uninstall a known, but uninstalled package
Brock Pytlik <bpytlik@sun.com>
parents: 596
diff changeset
  3008
                                if e.notfound:
6d307b088d92 4056 make_uninstall_plan misreports trying to uninstall a known, but uninstalled package
Brock Pytlik <bpytlik@sun.com>
parents: 596
diff changeset
  3009
                                        try:
6d307b088d92 4056 make_uninstall_plan misreports trying to uninstall a known, but uninstalled package
Brock Pytlik <bpytlik@sun.com>
parents: 596
diff changeset
  3010
                                                list(self.inventory([ppat],
1045
62656c214151 8135 plan creation could be faster for install and uninstall
Shawn Walker <srw@sun.com>
parents: 1037
diff changeset
  3011
                                                    all_known=True,
62656c214151 8135 plan creation could be faster for install and uninstall
Shawn Walker <srw@sun.com>
parents: 1037
diff changeset
  3012
                                                    ordered=False))
616
6d307b088d92 4056 make_uninstall_plan misreports trying to uninstall a known, but uninstalled package
Brock Pytlik <bpytlik@sun.com>
parents: 596
diff changeset
  3013
                                                missing_matches.append(ppat)
6d307b088d92 4056 make_uninstall_plan misreports trying to uninstall a known, but uninstalled package
Brock Pytlik <bpytlik@sun.com>
parents: 596
diff changeset
  3014
                                        except api_errors.InventoryException:
6d307b088d92 4056 make_uninstall_plan misreports trying to uninstall a known, but uninstalled package
Brock Pytlik <bpytlik@sun.com>
parents: 596
diff changeset
  3015
                                                unfound_fmris.append(ppat)
6d307b088d92 4056 make_uninstall_plan misreports trying to uninstall a known, but uninstalled package
Brock Pytlik <bpytlik@sun.com>
parents: 596
diff changeset
  3016
                                elif e.illegal:
6d307b088d92 4056 make_uninstall_plan misreports trying to uninstall a known, but uninstalled package
Brock Pytlik <bpytlik@sun.com>
parents: 596
diff changeset
  3017
                                        illegal_fmris.append(ppat)
6d307b088d92 4056 make_uninstall_plan misreports trying to uninstall a known, but uninstalled package
Brock Pytlik <bpytlik@sun.com>
parents: 596
diff changeset
  3018
                                else:
6d307b088d92 4056 make_uninstall_plan misreports trying to uninstall a known, but uninstalled package
Brock Pytlik <bpytlik@sun.com>
parents: 596
diff changeset
  3019
                                        raise RuntimeError("Caught inventory "
6d307b088d92 4056 make_uninstall_plan misreports trying to uninstall a known, but uninstalled package
Brock Pytlik <bpytlik@sun.com>
parents: 596
diff changeset
  3020
                                            "exception without unfound or "
6d307b088d92 4056 make_uninstall_plan misreports trying to uninstall a known, but uninstalled package
Brock Pytlik <bpytlik@sun.com>
parents: 596
diff changeset
  3021
                                            "illegal fmris set.")
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  3022
                                err = 1
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  3023
                                continue
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  3024
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  3025
                        if len(matches) > 1:
922
0074b10d84e0 6874 stack trace on install with ambiguous package names
Danek Duvall <danek.duvall@sun.com>
parents: 918
diff changeset
  3026
                                matchlist = [m for m, state in matches]
0074b10d84e0 6874 stack trace on install with ambiguous package names
Danek Duvall <danek.duvall@sun.com>
parents: 918
diff changeset
  3027
                                multiple_matches.append((ppat, matchlist))
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  3028
                                err = 1
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  3029
                                continue
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  3030
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  3031
                        # Propose the removal of the first (and only!) match.
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  3032
                        ip.propose_fmri_removal(matches[0][0])
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  3033
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  3034
                if err == 1:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  3035
                        raise api_errors.PlanCreationException(unfound_fmris,
616
6d307b088d92 4056 make_uninstall_plan misreports trying to uninstall a known, but uninstalled package
Brock Pytlik <bpytlik@sun.com>
parents: 596
diff changeset
  3036
                            multiple_matches, missing_matches, illegal_fmris)
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  3037
                if verbose:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  3038
                        msg(_("Before evaluation:"))
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  3039
                        msg(ip)
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  3040
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  3041
                self.history.operation_start_state = ip.get_plan()
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  3042
                ip.evaluate()
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  3043
                self.history.operation_end_state = ip.get_plan(full=False)
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  3044
                self.imageplan = ip
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  3045
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  3046
                if verbose:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  3047
                        msg(_("After evaluation:"))
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  3048
                        ip.display()
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  3049
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  3050
        def ipkg_is_up_to_date(self, actual_cmd, check_cancelation, noexecute,
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  3051
            refresh_allowed=True, progtrack=None):
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  3052
                """ Test whether SUNWipkg is updated to the latest version
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  3053
                    known to be available for this image """
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  3054
                #
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  3055
                # This routine makes the distinction between the "target image",
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  3056
                # which will be altered, and the "running image", which is
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  3057
                # to say whatever image appears to contain the version of the
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  3058
                # pkg command we're running.
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  3059
                #
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  3060
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  3061
                #
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  3062
                # There are two relevant cases here:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  3063
                #     1) Packaging code and image we're updating are the same
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  3064
                #        image.  (i.e. 'pkg image-update')
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  3065
                #
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  3066
                #     2) Packaging code's image and the image we're updating are
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  3067
                #        different (i.e. 'pkg image-update -R')
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  3068
                #
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  3069
                # In general, we care about getting the user to run the
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  3070
                # most recent packaging code available for their build.  So,
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  3071
                # if we're not in the liveroot case, we create a new image
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  3072
                # which represents "/" on the system.
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  3073
                #
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  3074
625
e46b345645d6 3799 need to start progress tracker going early on
Brock Pytlik <bpytlik@sun.com>
parents: 621
diff changeset
  3075
                if not progtrack:
e46b345645d6 3799 need to start progress tracker going early on
Brock Pytlik <bpytlik@sun.com>
parents: 621
diff changeset
  3076
                        progtrack = progress.QuietProgressTracker()
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  3077
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  3078
                img = self
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  3079
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  3080
                if not img.is_liveroot():
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  3081
                        newimg = Image()
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  3082
                        cmdpath = os.path.join(os.getcwd(), actual_cmd)
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  3083
                        cmdpath = os.path.realpath(cmdpath)
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  3084
                        cmddir = os.path.dirname(os.path.realpath(cmdpath))
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  3085
                        #
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  3086
                        # Find the path to ourselves, and use that
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  3087
                        # as a way to locate the image we're in.  It's
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  3088
                        # not perfect-- we could be in a developer's
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  3089
                        # workspace, for example.
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  3090
                        #
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  3091
                        newimg.find_root(cmddir)
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  3092
                        newimg.load_config()
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  3093
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  3094
                        if refresh_allowed:
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  3095
                                # If refreshing publisher metadata is allowed,
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  3096
                                # then perform a refresh so that a new SUNWipkg
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  3097
                                # can be discovered.
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  3098
                                try:
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  3099
                                        newimg.refresh_publishers(
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  3100
                                            progtrack=progtrack)
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  3101
                                except api_errors.CatalogRefreshException, cre:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  3102
                                        cre.message = \
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  3103
                                            _("SUNWipkg update check failed.")
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  3104
                                        raise
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  3105
                        else:
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  3106
                                # If refresh wasn't called, the catalogs have to
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  3107
                                # be manually loaded.
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  3108
                                newimg.load_catalogs(progtrack)
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  3109
                        img = newimg
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  3110
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  3111
                # XXX call to progress tracker that SUNWipkg is being refreshed
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  3112
625
e46b345645d6 3799 need to start progress tracker going early on
Brock Pytlik <bpytlik@sun.com>
parents: 621
diff changeset
  3113
                img.make_install_plan(["SUNWipkg"], progtrack,
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  3114
                    check_cancelation, noexecute, filters = [])
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  3115
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  3116
                return img.imageplan.nothingtodo()
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  3117
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  3118
        def installed_fmris_from_args(self, args):
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  3119
                """Helper function to translate client command line arguments
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  3120
                into a list of installed fmris.  Used by info, contents,
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  3121
                verify.
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  3122
                """
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  3123
                found = []
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  3124
                notfound = []
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  3125
                illegals = []
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  3126
                try:
1045
62656c214151 8135 plan creation could be faster for install and uninstall
Shawn Walker <srw@sun.com>
parents: 1037
diff changeset
  3127
                        for m in self.inventory(args, ordered=False):
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  3128
                                found.append(m[0])
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  3129
                except api_errors.InventoryException, e:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  3130
                        illegals = e.illegal
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  3131
                        notfound = e.notfound
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  3132
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  3133
                return found, notfound, illegals