src/modules/client/api.py
author Danek Duvall <danek.duvall@sun.com>
Thu, 01 Apr 2010 17:32:11 -0700
changeset 1829 e581a205ec02
parent 1795 1b3bed835773
child 1834 43fcb0ca2c26
permissions -rw-r--r--
14907 references to old-style package names must be purged
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1516
8c950a3b4171 10485 move pkg(5) to Python 2.6
Rich Burridge <rich.burridge@sun.com>
parents: 1505
diff changeset
     1
#!/usr/bin/python
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
     2
#
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
     3
# CDDL HEADER START
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
     4
#
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
     5
# The contents of this file are subject to the terms of the
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
     6
# Common Development and Distribution License (the "License").
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
     7
# You may not use this file except in compliance with the License.
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
     8
#
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
     9
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    10
# or http://www.opensolaris.org/os/licensing.
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    11
# See the License for the specific language governing permissions
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    12
# and limitations under the License.
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    13
#
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    14
# When distributing Covered Code, include this CDDL HEADER in each
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    15
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    16
# If applicable, add the following below this CDDL HEADER, with the
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    17
# fields enclosed by brackets "[]" replaced with your own identifying
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    18
# information: Portions Copyright [yyyy] [name of copyright owner]
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    19
#
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    20
# CDDL HEADER END
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    21
#
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 941
diff changeset
    22
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 941
diff changeset
    23
#
1638
43c8e6c924a3 12852 pkg.server.api should have methods for getting package information
Rajkumar Srinivasan <rajkumar.srinivasan@sun.com>
parents: 1634
diff changeset
    24
# Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    25
# Use is subject to license terms.
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 941
diff changeset
    26
#
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    27
1638
43c8e6c924a3 12852 pkg.server.api should have methods for getting package information
Rajkumar Srinivasan <rajkumar.srinivasan@sun.com>
parents: 1634
diff changeset
    28
"""This module provides the supported, documented interface for clients to
43c8e6c924a3 12852 pkg.server.api should have methods for getting package information
Rajkumar Srinivasan <rajkumar.srinivasan@sun.com>
parents: 1634
diff changeset
    29
interface with the pkg(5) system.
43c8e6c924a3 12852 pkg.server.api should have methods for getting package information
Rajkumar Srinivasan <rajkumar.srinivasan@sun.com>
parents: 1634
diff changeset
    30
43c8e6c924a3 12852 pkg.server.api should have methods for getting package information
Rajkumar Srinivasan <rajkumar.srinivasan@sun.com>
parents: 1634
diff changeset
    31
Refer to pkg.api_common for additional core class documentation."""
43c8e6c924a3 12852 pkg.server.api should have methods for getting package information
Rajkumar Srinivasan <rajkumar.srinivasan@sun.com>
parents: 1634
diff changeset
    32
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
    33
import copy
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
    34
import errno
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
    35
import fnmatch
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 941
diff changeset
    36
import os
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
    37
import shutil
1032
ff3c6b09f430 8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents: 1027
diff changeset
    38
import sys
1569
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
    39
import threading
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
    40
import urllib
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    41
1019
e61c57c724c9 7663 disable_fmri should be synchronous
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 996
diff changeset
    42
import pkg.client.actuator as actuator
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
    43
import pkg.client.api_errors as api_errors
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
    44
import pkg.client.bootenv as bootenv
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
    45
import pkg.client.history as history
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
    46
import pkg.client.image as image
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
    47
import pkg.client.imagetypes as imgtypes
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
    48
import pkg.client.indexer as indexer
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
    49
import pkg.client.publisher as publisher
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
    50
import pkg.client.query_parser as query_p
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
    51
import pkg.fmri as fmri
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
    52
import pkg.misc as misc
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
    53
import pkg.nrlock
1257
d911e4542c41 9025 pkg.client.api needs to use p5i module
Shawn Walker <srw@sun.com>
parents: 1256
diff changeset
    54
import pkg.p5i as p5i
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
    55
import pkg.search_errors as search_errors
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
    56
import pkg.version
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
    57
1638
43c8e6c924a3 12852 pkg.server.api should have methods for getting package information
Rajkumar Srinivasan <rajkumar.srinivasan@sun.com>
parents: 1634
diff changeset
    58
from pkg.api_common import (PackageInfo, LicenseInfo, PackageCategory,
43c8e6c924a3 12852 pkg.server.api should have methods for getting package information
Rajkumar Srinivasan <rajkumar.srinivasan@sun.com>
parents: 1634
diff changeset
    59
    _get_pkg_cat_data)
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
    60
from pkg.client.imageplan import EXECUTED_OK
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
    61
from pkg.client import global_settings
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
    62
1795
1b3bed835773 14856 image-create / set-publisher shouldn't require repository configuration to have origins
Shawn Walker <srw@sun.com>
parents: 1764
diff changeset
    63
CURRENT_API_VERSION = 34
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
    64
CURRENT_P5I_VERSION = 1
696
6bbfd2dece6f 4371 user-agent string needs to be different for different client front-ends
Danek Duvall <danek.duvall@sun.com>
parents: 688
diff changeset
    65
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
    66
# Image type constants.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
    67
IMG_TYPE_NONE = imgtypes.IMG_NONE # No image.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
    68
IMG_TYPE_ENTIRE = imgtypes.IMG_ENTIRE # Full image ('/').
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
    69
IMG_TYPE_PARTIAL = imgtypes.IMG_PARTIAL  # Not yet implemented.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
    70
IMG_TYPE_USER = imgtypes.IMG_USER # Not '/'; some other location.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
    71
1431
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1389
diff changeset
    72
logger = global_settings.logger
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1389
diff changeset
    73
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    74
class ImageInterface(object):
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    75
        """This class presents an interface to images that clients may use.
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    76
        There is a specific order of methods which must be used to install
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    77
        or uninstall packages, or update an image. First, plan_install,
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
    78
        plan_uninstall, plan_update_all or plan_change_variant must be
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
    79
        called.  After that method completes successfully, describe may be
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
    80
        called, and prepare must be called. Finally, execute_plan may be
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
    81
        called to implement the previous created plan. The other methods
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
    82
        do not have an ordering imposed upon them, and may be used as
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
    83
        needed. Cancel may only be invoked while a cancelable method is
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
    84
        running."""
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    85
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    86
        # Constants used to reference specific values that info can return.
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    87
        INFO_FOUND = 0
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    88
        INFO_MISSING = 1
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    89
        INFO_MULTI_MATCH = 2
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    90
        INFO_ILLEGALS = 3
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    91
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
    92
        LIST_ALL = 0
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
    93
        LIST_INSTALLED = 1
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
    94
        LIST_INSTALLED_NEWEST = 2
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
    95
        LIST_NEWEST = 3
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
    96
        LIST_UPGRADABLE = 4
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
    97
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    98
        # Private constants used for tracking which type of plan was made.
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    99
        __INSTALL = 1
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   100
        __UNINSTALL = 2
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   101
        __IMAGE_UPDATE = 3
696
6bbfd2dece6f 4371 user-agent string needs to be different for different client front-ends
Danek Duvall <danek.duvall@sun.com>
parents: 688
diff changeset
   102
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
   103
        def __init__(self, img_path, version_id, progresstracker,
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   104
            cancel_state_callable, pkg_client_name):
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   105
                """Constructs an ImageInterface object.
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
   106
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   107
                'img_path' is the absolute path to an existing image.
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
   108
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   109
                'version_id' indicates the version of the api the client is
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   110
                expecting to use.
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   111
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   112
                'progresstracker' is the ProgressTracker object the client wants
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   113
                the api to use for UI progress callbacks.
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   114
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
   115
                'cancel_state_callable' is an optional function reference that
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
   116
                will be called if the cancellable status of an operation
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   117
                changes.
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   118
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
   119
                'pkg_client_name' is a string containing the name of the client,
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
   120
                such as "pkg" or "packagemanager".
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
   121
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   122
                This function can raise VersionException and
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   123
                ImageNotFoundException."""
696
6bbfd2dece6f 4371 user-agent string needs to be different for different client front-ends
Danek Duvall <danek.duvall@sun.com>
parents: 688
diff changeset
   124
1795
1b3bed835773 14856 image-create / set-publisher shouldn't require repository configuration to have origins
Shawn Walker <srw@sun.com>
parents: 1764
diff changeset
   125
                compatible_versions = set([CURRENT_API_VERSION])
696
6bbfd2dece6f 4371 user-agent string needs to be different for different client front-ends
Danek Duvall <danek.duvall@sun.com>
parents: 688
diff changeset
   126
598
c53f6107fdb6 2863 pkg install should have a way to disable indexing
Brock Pytlik <bpytlik@sun.com>
parents: 594
diff changeset
   127
                if version_id not in compatible_versions:
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   128
                        raise api_errors.VersionException(CURRENT_API_VERSION,
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   129
                            version_id)
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   130
696
6bbfd2dece6f 4371 user-agent string needs to be different for different client front-ends
Danek Duvall <danek.duvall@sun.com>
parents: 688
diff changeset
   131
                # The image's History object will use client_name from
6bbfd2dece6f 4371 user-agent string needs to be different for different client front-ends
Danek Duvall <danek.duvall@sun.com>
parents: 688
diff changeset
   132
                # global_settings, but if the program forgot to set it,
6bbfd2dece6f 4371 user-agent string needs to be different for different client front-ends
Danek Duvall <danek.duvall@sun.com>
parents: 688
diff changeset
   133
                # we'll go ahead and do so here.
6bbfd2dece6f 4371 user-agent string needs to be different for different client front-ends
Danek Duvall <danek.duvall@sun.com>
parents: 688
diff changeset
   134
                if global_settings.client_name is None:
6bbfd2dece6f 4371 user-agent string needs to be different for different client front-ends
Danek Duvall <danek.duvall@sun.com>
parents: 688
diff changeset
   135
                        global_settings.client_name = pkg_client_name
6bbfd2dece6f 4371 user-agent string needs to be different for different client front-ends
Danek Duvall <danek.duvall@sun.com>
parents: 688
diff changeset
   136
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
   137
                if isinstance(img_path, basestring):
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
   138
                        # Store this for reset().
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
   139
                        self.__img_path = img_path
1370
face1fe579ab 11400 image objects should always have a root
Brock Pytlik <bpytlik@sun.com>
parents: 1360
diff changeset
   140
                        self.__img = image.Image(img_path,
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
   141
                            progtrack=progresstracker)
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
   142
                elif isinstance(img_path, image.Image):
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
   143
                        # This is a temporary, special case for client.py
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
   144
                        # until the image api is complete.
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
   145
                        self.__img = img_path
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
   146
                        self.__img_path = img_path.get_root()
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
   147
                else:
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
   148
                        # API consumer passed an unknown type for img_path.
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
   149
                        raise TypeError(_("Unknown img_path type."))
1242
f6aa06e1c391 6758 api should recreate image object on reset
Shawn Walker <srw@sun.com>
parents: 1240
diff changeset
   150
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
   151
                self.__progresstracker = progresstracker
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
   152
                self.__cancel_state_callable = cancel_state_callable
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
   153
                self.__plan_type = None
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
   154
                self.__plan_desc = None
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
   155
                self.__prepared = False
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
   156
                self.__executed = False
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
   157
                self.__be_name = None
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   158
                self.__can_be_canceled = False
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   159
                self.__canceling = False
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   160
                self.__activity_lock = pkg.nrlock.NRLock()
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   161
                self.__blocking_locks = False
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   162
                self.__img.blocking_locks = self.__blocking_locks
1693
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
   163
                self.__cancel_lock = pkg.nrlock.NRLock()
1569
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
   164
                self.__cancel_cv = threading.Condition(self.__cancel_lock)
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   165
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   166
        def __set_blocking_locks(self, value):
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   167
                self.__activity_lock.acquire()
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   168
                self.__blocking_locks = value
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   169
                self.__img.blocking_locks = value
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   170
                self.__activity_lock.release()
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   171
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   172
        blocking_locks = property(lambda self: self.__blocking_locks,
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   173
            __set_blocking_locks, doc="A boolean value indicating whether "
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   174
            "the API should wait until the image interface can be locked if "
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   175
            "it is in use by another thread or process.  Clients should be "
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   176
            "aware that there is no timeout mechanism in place if blocking is "
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   177
            "enabled, and so should take steps to remain responsive to user "
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   178
            "input or provide a way for users to cancel operations.")
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   179
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
   180
        @property
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
   181
        def img(self):
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
   182
                """Private; public access to this property will be removed at
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
   183
                a later date.  Do not use."""
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
   184
                return self.__img
884
d780afc023ff 3718 plan_update_all needs to have an optional argument for the new BE name
Brock Pytlik <bpytlik@sun.com>
parents: 838
diff changeset
   185
1255
13914487fd06 8854 access to ImageInterface img root desired
Shawn Walker <srw@sun.com>
parents: 1254
diff changeset
   186
        @property
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
   187
        def img_type(self):
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
   188
                """Returns the IMG_TYPE constant for the image's type."""
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
   189
                if not self.__img:
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
   190
                        return None
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
   191
                return self.__img.image_type(self.__img.root)
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
   192
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
   193
        @property
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
   194
        def is_zone(self):
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
   195
                """A boolean value indicating whether the image is a zone."""
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
   196
                return self.__img.is_zone()
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
   197
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
   198
        @property
1255
13914487fd06 8854 access to ImageInterface img root desired
Shawn Walker <srw@sun.com>
parents: 1254
diff changeset
   199
        def root(self):
13914487fd06 8854 access to ImageInterface img root desired
Shawn Walker <srw@sun.com>
parents: 1254
diff changeset
   200
                """The absolute pathname of the filesystem root of the image.
13914487fd06 8854 access to ImageInterface img root desired
Shawn Walker <srw@sun.com>
parents: 1254
diff changeset
   201
                This property is read-only."""
13914487fd06 8854 access to ImageInterface img root desired
Shawn Walker <srw@sun.com>
parents: 1254
diff changeset
   202
                if not self.__img:
13914487fd06 8854 access to ImageInterface img root desired
Shawn Walker <srw@sun.com>
parents: 1254
diff changeset
   203
                        return None
13914487fd06 8854 access to ImageInterface img root desired
Shawn Walker <srw@sun.com>
parents: 1254
diff changeset
   204
                return self.__img.root
13914487fd06 8854 access to ImageInterface img root desired
Shawn Walker <srw@sun.com>
parents: 1254
diff changeset
   205
884
d780afc023ff 3718 plan_update_all needs to have an optional argument for the new BE name
Brock Pytlik <bpytlik@sun.com>
parents: 838
diff changeset
   206
        @staticmethod
d780afc023ff 3718 plan_update_all needs to have an optional argument for the new BE name
Brock Pytlik <bpytlik@sun.com>
parents: 838
diff changeset
   207
        def check_be_name(be_name):
1076
db86977aa656 8048 image update doesn't check to see if specified be-name already exists
Rich Burridge <rich.burridge@sun.com>
parents: 1072
diff changeset
   208
                bootenv.BootEnv.check_be_name(be_name)
1080
147a665c552c 8394 image-update without a --be-name fails.
Rich Burridge <rich.burridge@sun.com>
parents: 1076
diff changeset
   209
                return True
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
   210
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   211
        def __cert_verify(self, log_op_end=None):
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   212
                """Verify validity of certificates.  Any
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   213
                api_errors.ExpiringCertificate exceptions are caught
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   214
                here, a message is displayed, and execution continues.
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   215
                All other exceptions will be passed to the calling
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   216
                context.  The caller can also set log_op_end to a list
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   217
                of exceptions that should result in a call to
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   218
                self.log_operation_end() before the exception is passed
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   219
                on."""
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   220
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   221
                if log_op_end == None:
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   222
                        log_op_end = []
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   223
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   224
                # we always explicitly handle api_errors.ExpiringCertificate
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   225
                assert api_errors.ExpiringCertificate not in log_op_end
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   226
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   227
                try:
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   228
                        self.__img.check_cert_validity()
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   229
                except api_errors.ExpiringCertificate, e:
1431
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1389
diff changeset
   230
                        logger.error(e)
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   231
                except:
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   232
                        exc_type, exc_value, exc_traceback = sys.exc_info()
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   233
                        if exc_type in log_op_end:
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   234
                                self.log_operation_end(error=exc_value)
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   235
                        raise
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   236
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
   237
        def __refresh_publishers(self):
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
   238
                """Refresh publisher metadata."""
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   239
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   240
                #
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   241
                # Verify validity of certificates before possibly
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   242
                # attempting network operations.
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   243
                #
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   244
                self.__cert_verify()
1538
78ac66abc186 12130 install/update operations should always refresh publisher metadata (when allowed)
Shawn Walker <srw@sun.com>
parents: 1537
diff changeset
   245
                self.__img.refresh_publishers(immediate=True,
78ac66abc186 12130 install/update operations should always refresh publisher metadata (when allowed)
Shawn Walker <srw@sun.com>
parents: 1537
diff changeset
   246
                    progtrack=self.__progresstracker)
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   247
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   248
        def __acquire_activity_lock(self):
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   249
                """Private helper method to aqcuire activity lock."""
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   250
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   251
                rc = self.__activity_lock.acquire(
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   252
                    blocking=self.__blocking_locks)
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   253
                if not rc:
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   254
                        raise api_errors.ImageLockedError()
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   255
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   256
        def __plan_common_start(self, operation, noexecute):
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   257
                """Start planning an operation.  Acquire locks and log
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   258
                the start of the operation."""
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   259
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   260
                self.__acquire_activity_lock()
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   261
                try:
1693
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
   262
                        self.__enable_cancel()
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   263
                        if self.__plan_type is not None:
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   264
                                raise api_errors.PlanExistsException(
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   265
                                    self.__plan_type)
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   266
                        self.__img.lock(allow_unprivileged=noexecute)
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   267
                except:
1764
478a51c88bfe 14533 Nasty depot needs some love
johansen <johansen@sun.com>
parents: 1755
diff changeset
   268
                        self.__cancel_cleanup_exception()
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   269
                        self.__activity_lock.release()
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   270
                        raise
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   272
                assert self.__activity_lock._is_owned()
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   273
                self.log_operation_start(operation)
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   274
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   275
        def __plan_common_finish(self):
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   276
                """Finish planning an operation."""
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   277
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   278
                assert self.__activity_lock._is_owned()
1503
78d56b8ee320 12698 download directory must be accessible to non-privileged users
johansen <johansen@sun.com>
parents: 1472
diff changeset
   279
                self.__img.cleanup_downloads()
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   280
                self.__img.unlock()
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   281
                self.__activity_lock.release()
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   282
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   283
        def __plan_common_exception(self, log_op_end=None):
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   284
                """Deal with exceptions that can occur while planning an
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   285
                operation.  Any exceptions generated here are passed
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   286
                onto the calling context.  By default all exceptions
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   287
                will result in a call to self.log_operation_end() before
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   288
                they are passed onto the calling context.  Optionally,
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   289
                the caller can specify the exceptions that should result
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   290
                in a call to self.log_operation_end() by setting
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   291
                log_op_end."""
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   292
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   293
                if log_op_end == None:
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   294
                        log_op_end = []
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   295
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   296
                # we always explicity handle api_errors.PlanCreationException
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   297
                assert api_errors.PlanCreationException not in log_op_end
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   298
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   299
                exc_type, exc_value, exc_traceback = sys.exc_info()
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   300
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   301
                if exc_type == api_errors.PlanCreationException:
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   302
                        self.__set_history_PlanCreationException(exc_value)
1569
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
   303
                elif exc_type == api_errors.CanceledException:
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
   304
                        self.__cancel_done()
1346
c4d21b460a66 10539 Package Manager hangs after canceling Update All
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1337
diff changeset
   305
                elif not log_op_end or exc_type in log_op_end:
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   306
                        self.log_operation_end(error=exc_value)
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   307
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   308
                if exc_type != api_errors.ImageLockedError:
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   309
                        # Must be called before reset_unlock, and only if
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   310
                        # the exception was not a locked error.
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   311
                        self.__img.unlock()
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   312
1346
c4d21b460a66 10539 Package Manager hangs after canceling Update All
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1337
diff changeset
   313
                self.__reset_unlock()
c4d21b460a66 10539 Package Manager hangs after canceling Update All
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1337
diff changeset
   314
                self.__activity_lock.release()
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   315
                raise
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   316
1505
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
   317
        def plan_install(self, pkg_list, refresh_catalogs=True,
598
c53f6107fdb6 2863 pkg install should have a way to disable indexing
Brock Pytlik <bpytlik@sun.com>
parents: 594
diff changeset
   318
            noexecute=False, verbose=False, update_index=True):
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   319
                """Contructs a plan to install the packages provided in
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   320
                pkg_list.  pkg_list is a list of packages to install.
1505
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
   321
                refresh_catalogs controls whether the catalogs will
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   322
                automatically be refreshed. noexecute determines whether the
1279
12624144230f 10419 client api revisions doc update required
Shawn Walker <srw@sun.com>
parents: 1271
diff changeset
   323
                history will be recorded after planning is finished.  verbose
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   324
                controls whether verbose debugging output will be printed to the
1279
12624144230f 10419 client api revisions doc update required
Shawn Walker <srw@sun.com>
parents: 1271
diff changeset
   325
                terminal.  Its existence is temporary.  It returns a boolean
12624144230f 10419 client api revisions doc update required
Shawn Walker <srw@sun.com>
parents: 1271
diff changeset
   326
                which tells the client whether there is anything to do.  It can
12624144230f 10419 client api revisions doc update required
Shawn Walker <srw@sun.com>
parents: 1271
diff changeset
   327
                raise PlanCreationException, PermissionsException and
12624144230f 10419 client api revisions doc update required
Shawn Walker <srw@sun.com>
parents: 1271
diff changeset
   328
                InventoryException. The noexecute argument is included for
12624144230f 10419 client api revisions doc update required
Shawn Walker <srw@sun.com>
parents: 1271
diff changeset
   329
                compatibility with operational history.  The hope is it can be
12624144230f 10419 client api revisions doc update required
Shawn Walker <srw@sun.com>
parents: 1271
diff changeset
   330
                removed in the future."""
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   331
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   332
                self.__plan_common_start("install", noexecute)
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   333
                try:
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
   334
                        if refresh_catalogs:
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
   335
                                self.__refresh_publishers()
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   336
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   337
                        self.__img.make_install_plan(pkg_list,
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   338
                            self.__progresstracker,
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   339
                            self.__check_cancelation, noexecute,
1505
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
   340
                            verbose=verbose)
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   341
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   342
                        assert self.__img.imageplan
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   343
1569
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
   344
                        self.__disable_cancel()
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   345
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   346
                        if not noexecute:
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   347
                                self.__plan_type = self.__INSTALL
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   348
1618
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
   349
                        self.__plan_desc = PlanDescription(self.__img)
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   350
                        if self.__img.imageplan.nothingtodo() or noexecute:
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   351
                                self.log_operation_end(
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   352
                                    result=history.RESULT_NOTHING_TO_DO)
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   353
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   354
                        self.__img.imageplan.update_index = update_index
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   355
                except:
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   356
                        self.__plan_common_exception(log_op_end=[
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   357
                            api_errors.CanceledException, fmri.IllegalFmri,
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   358
                            Exception])
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   359
                        # NOTREACHED
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
   360
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   361
                self.__plan_common_finish()
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   362
                res = not self.__img.imageplan.nothingtodo()
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   363
                return res
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   364
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   365
        def plan_uninstall(self, pkg_list, recursive_removal, noexecute=False,
598
c53f6107fdb6 2863 pkg install should have a way to disable indexing
Brock Pytlik <bpytlik@sun.com>
parents: 594
diff changeset
   366
            verbose=False, update_index=True):
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   367
                """Contructs a plan to uninstall the packages provided in
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   368
                pkg_list. pkg_list is a list of packages to install.
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   369
                recursive_removal controls whether recursive removal is
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   370
                allowed. noexecute determines whether the history will be
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   371
                recorded after planning is finished. verbose controls whether
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   372
                verbose debugging output will be printed to the terminal. Its
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   373
                existence is temporary. If there are things to do to complete
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   374
                the uninstall, it returns True, otherwise it returns False. It
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   375
                can raise NonLeafPackageException and PlanCreationException."""
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   376
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   377
                self.__plan_common_start("uninstall", noexecute)
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   378
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   379
                try:
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   380
                        self.__img.make_uninstall_plan(pkg_list,
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   381
                            recursive_removal, self.__progresstracker,
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   382
                            self.__check_cancelation, noexecute,
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   383
                            verbose=verbose)
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   384
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   385
                        assert self.__img.imageplan
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   386
1569
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
   387
                        self.__disable_cancel()
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   388
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   389
                        if not noexecute:
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   390
                                self.__plan_type = self.__UNINSTALL
1032
ff3c6b09f430 8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents: 1027
diff changeset
   391
1618
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
   392
                        self.__plan_desc = PlanDescription(self.__img)
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   393
                        if noexecute:
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   394
                                self.log_operation_end(
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   395
                                    result=history.RESULT_NOTHING_TO_DO)
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   396
                        self.__img.imageplan.update_index = update_index
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   397
                except:
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   398
                        self.__plan_common_exception()
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   399
                        # NOTREACHED
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   400
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   401
                self.__plan_common_finish()
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   402
                res = not self.__img.imageplan.nothingtodo()
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   403
                return res
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
   404
1829
e581a205ec02 14907 references to old-style package names must be purged
Danek Duvall <danek.duvall@sun.com>
parents: 1795
diff changeset
   405
        def __is_pkg5_native_packaging(self):
e581a205ec02 14907 references to old-style package names must be purged
Danek Duvall <danek.duvall@sun.com>
parents: 1795
diff changeset
   406
                """Helper routine that returns True if this object represents an
e581a205ec02 14907 references to old-style package names must be purged
Danek Duvall <danek.duvall@sun.com>
parents: 1795
diff changeset
   407
                image where pkg(5) is the native packaging system and needs to
e581a205ec02 14907 references to old-style package names must be purged
Danek Duvall <danek.duvall@sun.com>
parents: 1795
diff changeset
   408
                be upgraded before the image can be."""
e581a205ec02 14907 references to old-style package names must be purged
Danek Duvall <danek.duvall@sun.com>
parents: 1795
diff changeset
   409
e581a205ec02 14907 references to old-style package names must be purged
Danek Duvall <danek.duvall@sun.com>
parents: 1795
diff changeset
   410
                # First check to see if the special package "release/name"
e581a205ec02 14907 references to old-style package names must be purged
Danek Duvall <danek.duvall@sun.com>
parents: 1795
diff changeset
   411
                # exists and contains metadata saying this is Solaris.
e581a205ec02 14907 references to old-style package names must be purged
Danek Duvall <danek.duvall@sun.com>
parents: 1795
diff changeset
   412
                fmris, notfound, illegals = \
e581a205ec02 14907 references to old-style package names must be purged
Danek Duvall <danek.duvall@sun.com>
parents: 1795
diff changeset
   413
                    self.__img.installed_fmris_from_args(["release/name"])
e581a205ec02 14907 references to old-style package names must be purged
Danek Duvall <danek.duvall@sun.com>
parents: 1795
diff changeset
   414
                assert(not illegals)
e581a205ec02 14907 references to old-style package names must be purged
Danek Duvall <danek.duvall@sun.com>
parents: 1795
diff changeset
   415
                if fmris:
e581a205ec02 14907 references to old-style package names must be purged
Danek Duvall <danek.duvall@sun.com>
parents: 1795
diff changeset
   416
                        mfst = self.__img.get_manifest(fmris[0][0])
e581a205ec02 14907 references to old-style package names must be purged
Danek Duvall <danek.duvall@sun.com>
parents: 1795
diff changeset
   417
                        osname = mfst.get("pkg.release.osname", None)
e581a205ec02 14907 references to old-style package names must be purged
Danek Duvall <danek.duvall@sun.com>
parents: 1795
diff changeset
   418
                        if osname == "sunos":
e581a205ec02 14907 references to old-style package names must be purged
Danek Duvall <danek.duvall@sun.com>
parents: 1795
diff changeset
   419
                                return True
e581a205ec02 14907 references to old-style package names must be purged
Danek Duvall <danek.duvall@sun.com>
parents: 1795
diff changeset
   420
e581a205ec02 14907 references to old-style package names must be purged
Danek Duvall <danek.duvall@sun.com>
parents: 1795
diff changeset
   421
                # Otherwise, see if we can find package/pkg (or SUNWipkg) and
e581a205ec02 14907 references to old-style package names must be purged
Danek Duvall <danek.duvall@sun.com>
parents: 1795
diff changeset
   422
                # SUNWcs.
e581a205ec02 14907 references to old-style package names must be purged
Danek Duvall <danek.duvall@sun.com>
parents: 1795
diff changeset
   423
                fmris, notfound, illegals = \
e581a205ec02 14907 references to old-style package names must be purged
Danek Duvall <danek.duvall@sun.com>
parents: 1795
diff changeset
   424
                    self.__img.installed_fmris_from_args(
e581a205ec02 14907 references to old-style package names must be purged
Danek Duvall <danek.duvall@sun.com>
parents: 1795
diff changeset
   425
                        ["pkg:/package/pkg", "SUNWipkg", "SUNWcs"])
e581a205ec02 14907 references to old-style package names must be purged
Danek Duvall <danek.duvall@sun.com>
parents: 1795
diff changeset
   426
                assert(not illegals)
e581a205ec02 14907 references to old-style package names must be purged
Danek Duvall <danek.duvall@sun.com>
parents: 1795
diff changeset
   427
                installed = set((f[0].pkg_name for f in fmris))
e581a205ec02 14907 references to old-style package names must be purged
Danek Duvall <danek.duvall@sun.com>
parents: 1795
diff changeset
   428
                if "SUNWcs" in installed and ("SUNWipkg" in installed or
e581a205ec02 14907 references to old-style package names must be purged
Danek Duvall <danek.duvall@sun.com>
parents: 1795
diff changeset
   429
                    "package/pkg" in installed):
e581a205ec02 14907 references to old-style package names must be purged
Danek Duvall <danek.duvall@sun.com>
parents: 1795
diff changeset
   430
                        return True
e581a205ec02 14907 references to old-style package names must be purged
Danek Duvall <danek.duvall@sun.com>
parents: 1795
diff changeset
   431
e581a205ec02 14907 references to old-style package names must be purged
Danek Duvall <danek.duvall@sun.com>
parents: 1795
diff changeset
   432
                return False
e581a205ec02 14907 references to old-style package names must be purged
Danek Duvall <danek.duvall@sun.com>
parents: 1795
diff changeset
   433
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   434
        def plan_update_all(self, actual_cmd, refresh_catalogs=True,
884
d780afc023ff 3718 plan_update_all needs to have an optional argument for the new BE name
Brock Pytlik <bpytlik@sun.com>
parents: 838
diff changeset
   435
            noexecute=False, force=False, verbose=False, update_index=True,
d780afc023ff 3718 plan_update_all needs to have an optional argument for the new BE name
Brock Pytlik <bpytlik@sun.com>
parents: 838
diff changeset
   436
            be_name=None):
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   437
                """Creates a plan to update all packages on the system to the
1279
12624144230f 10419 client api revisions doc update required
Shawn Walker <srw@sun.com>
parents: 1271
diff changeset
   438
                latest known versions.  actual_cmd is the command used to start
12624144230f 10419 client api revisions doc update required
Shawn Walker <srw@sun.com>
parents: 1271
diff changeset
   439
                the client.  It is used to determine the image to check whether
1829
e581a205ec02 14907 references to old-style package names must be purged
Danek Duvall <danek.duvall@sun.com>
parents: 1795
diff changeset
   440
                the packaging system is up to date.  refresh_catalogs controls
e581a205ec02 14907 references to old-style package names must be purged
Danek Duvall <danek.duvall@sun.com>
parents: 1795
diff changeset
   441
                whether the catalogs will automatically be refreshed.  noexecute
e581a205ec02 14907 references to old-style package names must be purged
Danek Duvall <danek.duvall@sun.com>
parents: 1795
diff changeset
   442
                determines whether the history will be recorded after planning
e581a205ec02 14907 references to old-style package names must be purged
Danek Duvall <danek.duvall@sun.com>
parents: 1795
diff changeset
   443
                is finished.  force controls whether update should proceed even
e581a205ec02 14907 references to old-style package names must be purged
Danek Duvall <danek.duvall@sun.com>
parents: 1795
diff changeset
   444
                if ipkg is not up to date.  verbose controls whether verbose
e581a205ec02 14907 references to old-style package names must be purged
Danek Duvall <danek.duvall@sun.com>
parents: 1795
diff changeset
   445
                debugging output will be printed to the terminal.  Its existence
e581a205ec02 14907 references to old-style package names must be purged
Danek Duvall <danek.duvall@sun.com>
parents: 1795
diff changeset
   446
                is temporary. It returns a tuple of two things.  The first is a
e581a205ec02 14907 references to old-style package names must be purged
Danek Duvall <danek.duvall@sun.com>
parents: 1795
diff changeset
   447
                boolean which tells the client whether there is anything to do.
e581a205ec02 14907 references to old-style package names must be purged
Danek Duvall <danek.duvall@sun.com>
parents: 1795
diff changeset
   448
                The second tells whether the image is an opensolaris image.  It
e581a205ec02 14907 references to old-style package names must be purged
Danek Duvall <danek.duvall@sun.com>
parents: 1795
diff changeset
   449
                can raise CatalogRefreshException, IpkgOutOfDateException,
1279
12624144230f 10419 client api revisions doc update required
Shawn Walker <srw@sun.com>
parents: 1271
diff changeset
   450
                PlanCreationException and PermissionsException."""
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   451
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   452
                self.__plan_common_start("image-update", noexecute)
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   453
                try:
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   454
                        self.check_be_name(be_name)
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   455
                        self.__be_name = be_name
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   456
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
   457
                        if refresh_catalogs:
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
   458
                                self.__refresh_publishers()
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   459
1829
e581a205ec02 14907 references to old-style package names must be purged
Danek Duvall <danek.duvall@sun.com>
parents: 1795
diff changeset
   460
                        # If the target image is an opensolaris image, we
e581a205ec02 14907 references to old-style package names must be purged
Danek Duvall <danek.duvall@sun.com>
parents: 1795
diff changeset
   461
                        # activate some special behavior.
e581a205ec02 14907 references to old-style package names must be purged
Danek Duvall <danek.duvall@sun.com>
parents: 1795
diff changeset
   462
                        opensolaris_image = self.__is_pkg5_native_packaging()
625
e46b345645d6 3799 need to start progress tracker going early on
Brock Pytlik <bpytlik@sun.com>
parents: 615
diff changeset
   463
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   464
                        if opensolaris_image and not force:
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   465
                                try:
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   466
                                        if not self.__img.ipkg_is_up_to_date(
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   467
                                            actual_cmd,
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   468
                                            self.__check_cancelation,
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   469
                                            noexecute,
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   470
                                            refresh_allowed=refresh_catalogs,
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   471
                                            progtrack=self.__progresstracker):
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   472
                                                raise api_errors.IpkgOutOfDateException()
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   473
                                except api_errors.ImageNotFoundException:
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   474
                                        # Can't do anything in this
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   475
                                        # case; so proceed.
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   476
                                        pass
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   477
1505
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
   478
                        self.__img.make_update_plan(self.__progresstracker,
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
   479
                            self.__check_cancelation, noexecute,
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
   480
                            verbose=verbose)
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   481
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   482
                        assert self.__img.imageplan
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   483
1569
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
   484
                        self.__disable_cancel()
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   485
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   486
                        if not noexecute:
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   487
                                self.__plan_type = self.__IMAGE_UPDATE
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   488
1618
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
   489
                        self.__plan_desc = PlanDescription(self.__img)
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   490
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   491
                        if self.__img.imageplan.nothingtodo() or noexecute:
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   492
                                self.log_operation_end(
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   493
                                    result=history.RESULT_NOTHING_TO_DO)
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   494
                        self.__img.imageplan.update_index = update_index
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   495
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   496
                except:
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   497
                        self.__plan_common_exception(
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   498
                            log_op_end=[api_errors.IpkgOutOfDateException])
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   499
                        # NOTREACHED
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   500
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   501
                self.__plan_common_finish()
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   502
                res = not self.__img.imageplan.nothingtodo()
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   503
                return res, opensolaris_image
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   504
1505
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
   505
        def plan_change_varcets(self, variants=None, facets=None,
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
   506
            noexecute=False, verbose=False, be_name=None):
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
   507
                """Creates a plan to change the specified variants/facets on an image.
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
   508
                verbose controls
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   509
                whether verbose debugging output will be printed to the
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   510
                terminal.  This function has two return values.  The first is
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   511
                a boolean which tells the client whether there is anything to
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   512
                do.  The third is either None, or an exception which indicates
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   513
                partial success.  This is currently used to indicate a failure
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   514
                in refreshing catalogs. It can raise CatalogRefreshException,
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   515
                IpkgOutOfDateException, NetworkUnavailableException,
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   516
                PlanCreationException and PermissionsException."""
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   517
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   518
                self.__plan_common_start("change-variant", noexecute)
1505
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
   519
                if not variants and not facets:
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
   520
                        raise ValueError, "Nothing to do"
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   521
                try:
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   522
                        self.check_be_name(be_name)
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   523
                        self.be_name = be_name
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   524
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
   525
                        self.__refresh_publishers()
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   526
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   527
                        self.__img.image_change_varcets(variants,
1505
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
   528
                            facets,
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   529
                            self.__progresstracker,
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   530
                            self.__check_cancelation,
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   531
                            noexecute, verbose=verbose)
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   532
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   533
                        assert self.__img.imageplan
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   534
1569
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
   535
                        self.__disable_cancel()
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   536
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   537
                        if not noexecute:
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   538
                                self.__plan_type = self.__IMAGE_UPDATE
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   539
1618
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
   540
                        self.__plan_desc = PlanDescription(self.__img)
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   541
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   542
                        if self.__img.imageplan.nothingtodo() or noexecute:
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   543
                                self.log_operation_end(
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   544
                                    result=history.RESULT_NOTHING_TO_DO)
1032
ff3c6b09f430 8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents: 1027
diff changeset
   545
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   546
                        #
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   547
                        # We always rebuild the search index after a
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   548
                        # variant change
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   549
                        #
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   550
                        self.__img.imageplan.update_index = True
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
   551
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   552
                except:
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   553
                        self.__plan_common_exception()
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   554
                        # NOTREACHED
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   555
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   556
                self.__plan_common_finish()
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   557
                res = not self.__img.imageplan.nothingtodo()
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   558
                return res
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   559
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   560
        def describe(self):
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   561
                """Returns None if no plan is ready yet, otherwise returns
1618
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
   562
                a PlanDescription."""
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
   563
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
   564
                return self.__plan_desc
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
   565
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   566
        def prepare(self):
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   567
                """Takes care of things which must be done before the plan
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   568
                can be executed. This includes downloading the packages to
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   569
                disk and preparing the indexes to be updated during
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   570
                execution. It can raise ProblematicPermissionsIndexException,
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   571
                and PlanMissingException. Should only be called once a
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   572
                plan_X method has been called."""
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   573
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   574
                self.__acquire_activity_lock()
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   575
                try:
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   576
                        self.__img.lock()
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   577
                except:
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   578
                        self.__activity_lock.release()
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   579
                        raise
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   580
1569
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
   581
                try:
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
   582
                        if not self.__img.imageplan:
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
   583
                                raise api_errors.PlanMissingException()
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   584
1569
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
   585
                        if self.__prepared:
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
   586
                                raise api_errors.AlreadyPreparedException()
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
   587
                        assert self.__plan_type == self.__INSTALL or \
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
   588
                            self.__plan_type == self.__UNINSTALL or \
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
   589
                            self.__plan_type == self.__IMAGE_UPDATE
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   590
1693
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
   591
                        self.__enable_cancel()
1569
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
   592
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
   593
                        try:
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
   594
                                self.__img.imageplan.preexecute()
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
   595
                        except search_errors.ProblematicPermissionsIndexException, e:
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
   596
                                raise api_errors.ProblematicPermissionsIndexException(e)
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
   597
                        except:
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
   598
                                raise
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   599
1569
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
   600
                        self.__disable_cancel()
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
   601
                        self.__prepared = True
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
   602
                except api_errors.CanceledException, e:
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
   603
                        self.__cancel_done()
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
   604
                        if self.__img.history.operation_name:
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
   605
                                # If an operation is in progress, log
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
   606
                                # the error and mark its end.
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
   607
                                self.log_operation_end(error=e)
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
   608
                        raise
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
   609
                except Exception, e:
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
   610
                        self.__cancel_cleanup_exception()
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
   611
                        if self.__img.history.operation_name:
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
   612
                                # If an operation is in progress, log
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
   613
                                # the error and mark its end.
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
   614
                                self.log_operation_end(error=e)
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
   615
                        raise
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
   616
                except:
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
   617
                        # Handle exceptions that are not subclasses of
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
   618
                        # Exception.
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
   619
                        self.__cancel_cleanup_exception()
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
   620
                        if self.__img.history.operation_name:
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
   621
                                # If an operation is in progress, log
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
   622
                                # the error and mark its end.
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
   623
                                exc_type, exc_value, exc_traceback = \
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
   624
                                    sys.exc_info()
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
   625
                                self.log_operation_end(error=exc_type)
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
   626
                        raise
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   627
                finally:
1503
78d56b8ee320 12698 download directory must be accessible to non-privileged users
johansen <johansen@sun.com>
parents: 1472
diff changeset
   628
                        self.__img.cleanup_downloads()
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   629
                        self.__img.unlock()
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   630
                        self.__activity_lock.release()
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   631
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   632
        def execute_plan(self):
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   633
                """Executes the plan. This is uncancelable one it begins. It
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   634
                can raise CorruptedIndexException, ImageLockedError,
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   635
                ProblematicPermissionsIndexException, ImageplanStateException,
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   636
                ImageUpdateOnLiveImageException, and PlanMissingException.
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   637
                Should only be called after the prepare method has been
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   638
                called."""
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   639
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   640
                self.__acquire_activity_lock()
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   641
                try:
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
   642
                        self.__disable_cancel()
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   643
                        self.__img.lock()
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   644
                except:
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   645
                        self.__activity_lock.release()
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   646
                        raise
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   647
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   648
                try:
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
   649
                        if not self.__img.imageplan:
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   650
                                raise api_errors.PlanMissingException()
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   651
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
   652
                        if not self.__prepared:
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   653
                                raise api_errors.PrematureExecutionException()
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   654
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
   655
                        if self.__executed:
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   656
                                raise api_errors.AlreadyExecutedException()
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
   657
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
   658
                        assert self.__plan_type == self.__INSTALL or \
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
   659
                            self.__plan_type == self.__UNINSTALL or \
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
   660
                            self.__plan_type == self.__IMAGE_UPDATE
1027
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
   661
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   662
                        try:
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
   663
                                be = bootenv.BootEnv(self.__img.get_root())
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   664
                        except RuntimeError:
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
   665
                                be = bootenv.BootEnvNull(self.__img.get_root())
1306
9a02ddf28dea 10630 driver action gets confused by driver_aliases entries not covered by an action
Danek Duvall <danek.duvall@sun.com>
parents: 1286
diff changeset
   666
                        self.__img.bootenv = be
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   667
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
   668
                        if self.__plan_type is self.__IMAGE_UPDATE:
1027
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
   669
                                try:
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
   670
                                        be.init_image_recovery(self.__img,
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
   671
                                            self.__be_name)
1027
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
   672
                                except Exception, e:
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
   673
                                        self.log_operation_end(error=e)
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
   674
                                        raise
1032
ff3c6b09f430 8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents: 1027
diff changeset
   675
                                except:
1102
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1100
diff changeset
   676
                                        # Handle exceptions that are not
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1100
diff changeset
   677
                                        # subclasses of Exception.
1032
ff3c6b09f430 8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents: 1027
diff changeset
   678
                                        exc_type, exc_value, exc_traceback = \
ff3c6b09f430 8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents: 1027
diff changeset
   679
                                            sys.exc_info()
ff3c6b09f430 8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents: 1027
diff changeset
   680
                                        self.log_operation_end(error=exc_type)
ff3c6b09f430 8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents: 1027
diff changeset
   681
                                        raise
1027
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
   682
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
   683
                                if self.__img.is_liveroot():
1027
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
   684
                                        e = api_errors.ImageUpdateOnLiveImageException()
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
   685
                                        self.log_operation_end(error=e)
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
   686
                                        raise e
1328
5c3747a4fe0a 9387 pkg fix should honor reboot-needed flag
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1314
diff changeset
   687
                        else:
1505
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
   688
                                if self.__img.imageplan.reboot_needed() and \
1328
5c3747a4fe0a 9387 pkg fix should honor reboot-needed flag
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1314
diff changeset
   689
                                    self.__img.is_liveroot():
5c3747a4fe0a 9387 pkg fix should honor reboot-needed flag
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1314
diff changeset
   690
                                        e = api_errors.RebootNeededOnLiveImageException()
5c3747a4fe0a 9387 pkg fix should honor reboot-needed flag
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1314
diff changeset
   691
                                        self.log_operation_end(error=e)
5c3747a4fe0a 9387 pkg fix should honor reboot-needed flag
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1314
diff changeset
   692
                                        raise e
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   693
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   694
                        try:
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
   695
                                self.__img.imageplan.execute()
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   696
                        except RuntimeError, e:
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
   697
                                if self.__plan_type is self.__IMAGE_UPDATE:
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   698
                                        be.restore_image()
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   699
                                else:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   700
                                        be.restore_install_uninstall()
1027
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
   701
                                # Must be done after bootenv restore.
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
   702
                                self.log_operation_end(error=e)
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   703
                                raise
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   704
                        except search_errors.ProblematicPermissionsIndexException, e:
1027
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
   705
                                error = api_errors.ProblematicPermissionsIndexException(e)
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
   706
                                self.log_operation_end(error=error)
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
   707
                                raise error
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   708
                        except (search_errors.InconsistentIndexException,
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   709
                                search_errors.PartialIndexingException), e:
1027
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
   710
                                error = api_errors.CorruptedIndexException(e)
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
   711
                                self.log_operation_end(error=error)
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
   712
                                raise error
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
   713
                        except search_errors.MainDictParsingException, e:
1027
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
   714
                                error = api_errors.MainDictParsingException(e)
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
   715
                                self.log_operation_end(error=error)
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
   716
                                raise error
1019
e61c57c724c9 7663 disable_fmri should be synchronous
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 996
diff changeset
   717
                        except actuator.NonzeroExitException, e:
1027
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
   718
                                # Won't happen during image-update
1019
e61c57c724c9 7663 disable_fmri should be synchronous
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 996
diff changeset
   719
                                be.restore_install_uninstall()
1027
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
   720
                                error = api_errors.ActuatorException(e)
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
   721
                                self.log_operation_end(error=error)
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
   722
                                raise error
1286
2e5bb564a9e2 8948 search errors should make it clear that the rest of the command worked
Brock Pytlik <bpytlik@sun.com>
parents: 1279
diff changeset
   723
                        except api_errors.WrapIndexingException, e:
2e5bb564a9e2 8948 search errors should make it clear that the rest of the command worked
Brock Pytlik <bpytlik@sun.com>
parents: 1279
diff changeset
   724
                                self.__finished_execution(be)
2e5bb564a9e2 8948 search errors should make it clear that the rest of the command worked
Brock Pytlik <bpytlik@sun.com>
parents: 1279
diff changeset
   725
                                raise
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   726
                        except Exception, e:
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
   727
                                if self.__plan_type is self.__IMAGE_UPDATE:
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   728
                                        be.restore_image()
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   729
                                else:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   730
                                        be.restore_install_uninstall()
1027
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
   731
                                # Must be done after bootenv restore.
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
   732
                                self.log_operation_end(error=e)
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   733
                                raise
1032
ff3c6b09f430 8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents: 1027
diff changeset
   734
                        except:
ff3c6b09f430 8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents: 1027
diff changeset
   735
                                # Handle exceptions that are not subclasses of
ff3c6b09f430 8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents: 1027
diff changeset
   736
                                # Exception.
ff3c6b09f430 8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents: 1027
diff changeset
   737
                                exc_type, exc_value, exc_traceback = \
ff3c6b09f430 8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents: 1027
diff changeset
   738
                                    sys.exc_info()
ff3c6b09f430 8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents: 1027
diff changeset
   739
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
   740
                                if self.__plan_type is self.__IMAGE_UPDATE:
1032
ff3c6b09f430 8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents: 1027
diff changeset
   741
                                        be.restore_image()
ff3c6b09f430 8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents: 1027
diff changeset
   742
                                else:
ff3c6b09f430 8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents: 1027
diff changeset
   743
                                        be.restore_install_uninstall()
ff3c6b09f430 8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents: 1027
diff changeset
   744
                                # Must be done after bootenv restore.
ff3c6b09f430 8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents: 1027
diff changeset
   745
                                self.log_operation_end(error=exc_type)
ff3c6b09f430 8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents: 1027
diff changeset
   746
                                raise
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   747
1286
2e5bb564a9e2 8948 search errors should make it clear that the rest of the command worked
Brock Pytlik <bpytlik@sun.com>
parents: 1279
diff changeset
   748
                        self.__finished_execution(be)
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   749
                finally:
1503
78d56b8ee320 12698 download directory must be accessible to non-privileged users
johansen <johansen@sun.com>
parents: 1472
diff changeset
   750
                        self.__img.cleanup_downloads()
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   751
                        self.__img.unlock()
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   752
                        self.__activity_lock.release()
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
   753
1286
2e5bb564a9e2 8948 search errors should make it clear that the rest of the command worked
Brock Pytlik <bpytlik@sun.com>
parents: 1279
diff changeset
   754
        def __finished_execution(self, be):
2e5bb564a9e2 8948 search errors should make it clear that the rest of the command worked
Brock Pytlik <bpytlik@sun.com>
parents: 1279
diff changeset
   755
                if self.__img.imageplan.state != EXECUTED_OK:
2e5bb564a9e2 8948 search errors should make it clear that the rest of the command worked
Brock Pytlik <bpytlik@sun.com>
parents: 1279
diff changeset
   756
                        if self.__plan_type is self.__IMAGE_UPDATE:
2e5bb564a9e2 8948 search errors should make it clear that the rest of the command worked
Brock Pytlik <bpytlik@sun.com>
parents: 1279
diff changeset
   757
                                be.restore_image()
2e5bb564a9e2 8948 search errors should make it clear that the rest of the command worked
Brock Pytlik <bpytlik@sun.com>
parents: 1279
diff changeset
   758
                        else:
2e5bb564a9e2 8948 search errors should make it clear that the rest of the command worked
Brock Pytlik <bpytlik@sun.com>
parents: 1279
diff changeset
   759
                                be.restore_install_uninstall()
2e5bb564a9e2 8948 search errors should make it clear that the rest of the command worked
Brock Pytlik <bpytlik@sun.com>
parents: 1279
diff changeset
   760
2e5bb564a9e2 8948 search errors should make it clear that the rest of the command worked
Brock Pytlik <bpytlik@sun.com>
parents: 1279
diff changeset
   761
                        error = api_errors.ImageplanStateException(
2e5bb564a9e2 8948 search errors should make it clear that the rest of the command worked
Brock Pytlik <bpytlik@sun.com>
parents: 1279
diff changeset
   762
                            self.__img.imageplan.state)
2e5bb564a9e2 8948 search errors should make it clear that the rest of the command worked
Brock Pytlik <bpytlik@sun.com>
parents: 1279
diff changeset
   763
                        # Must be done after bootenv restore.
2e5bb564a9e2 8948 search errors should make it clear that the rest of the command worked
Brock Pytlik <bpytlik@sun.com>
parents: 1279
diff changeset
   764
                        self.log_operation_end(error=error)
2e5bb564a9e2 8948 search errors should make it clear that the rest of the command worked
Brock Pytlik <bpytlik@sun.com>
parents: 1279
diff changeset
   765
                        raise error
2e5bb564a9e2 8948 search errors should make it clear that the rest of the command worked
Brock Pytlik <bpytlik@sun.com>
parents: 1279
diff changeset
   766
                if self.__plan_type is self.__IMAGE_UPDATE:
2e5bb564a9e2 8948 search errors should make it clear that the rest of the command worked
Brock Pytlik <bpytlik@sun.com>
parents: 1279
diff changeset
   767
                        be.activate_image()
2e5bb564a9e2 8948 search errors should make it clear that the rest of the command worked
Brock Pytlik <bpytlik@sun.com>
parents: 1279
diff changeset
   768
                else:
2e5bb564a9e2 8948 search errors should make it clear that the rest of the command worked
Brock Pytlik <bpytlik@sun.com>
parents: 1279
diff changeset
   769
                        be.activate_install_uninstall()
2e5bb564a9e2 8948 search errors should make it clear that the rest of the command worked
Brock Pytlik <bpytlik@sun.com>
parents: 1279
diff changeset
   770
                self.__img.cleanup_cached_content()
2e5bb564a9e2 8948 search errors should make it clear that the rest of the command worked
Brock Pytlik <bpytlik@sun.com>
parents: 1279
diff changeset
   771
                # If the end of the operation wasn't already logged
2e5bb564a9e2 8948 search errors should make it clear that the rest of the command worked
Brock Pytlik <bpytlik@sun.com>
parents: 1279
diff changeset
   772
                # by one of the previous operations, then log it as
2e5bb564a9e2 8948 search errors should make it clear that the rest of the command worked
Brock Pytlik <bpytlik@sun.com>
parents: 1279
diff changeset
   773
                # ending now.
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
   774
                if self.__img.history.operation_name:
1286
2e5bb564a9e2 8948 search errors should make it clear that the rest of the command worked
Brock Pytlik <bpytlik@sun.com>
parents: 1279
diff changeset
   775
                        self.log_operation_end()
2e5bb564a9e2 8948 search errors should make it clear that the rest of the command worked
Brock Pytlik <bpytlik@sun.com>
parents: 1279
diff changeset
   776
                self.__executed = True
2e5bb564a9e2 8948 search errors should make it clear that the rest of the command worked
Brock Pytlik <bpytlik@sun.com>
parents: 1279
diff changeset
   777
                try:
2e5bb564a9e2 8948 search errors should make it clear that the rest of the command worked
Brock Pytlik <bpytlik@sun.com>
parents: 1279
diff changeset
   778
                        if int(os.environ.get("PKG_DUMP_STATS", 0)) > 0:
2e5bb564a9e2 8948 search errors should make it clear that the rest of the command worked
Brock Pytlik <bpytlik@sun.com>
parents: 1279
diff changeset
   779
                                self.__img.transport.stats.dump()
2e5bb564a9e2 8948 search errors should make it clear that the rest of the command worked
Brock Pytlik <bpytlik@sun.com>
parents: 1279
diff changeset
   780
                except ValueError:
2e5bb564a9e2 8948 search errors should make it clear that the rest of the command worked
Brock Pytlik <bpytlik@sun.com>
parents: 1279
diff changeset
   781
                        # Don't generate stats if an invalid value
2e5bb564a9e2 8948 search errors should make it clear that the rest of the command worked
Brock Pytlik <bpytlik@sun.com>
parents: 1279
diff changeset
   782
                        # is supplied.
2e5bb564a9e2 8948 search errors should make it clear that the rest of the command worked
Brock Pytlik <bpytlik@sun.com>
parents: 1279
diff changeset
   783
                        pass
2e5bb564a9e2 8948 search errors should make it clear that the rest of the command worked
Brock Pytlik <bpytlik@sun.com>
parents: 1279
diff changeset
   784
1618
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
   785
        def set_plan_license_status(self, pfmri, plicense, accepted=None,
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
   786
            displayed=None):
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
   787
                """Sets the license status for the given package FMRI and
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
   788
                license entry.
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
   789
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
   790
                'accepted' is an optional parameter that can be one of three
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
   791
                values:
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
   792
                        None    leaves accepted status unchanged
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
   793
                        False   sets accepted status to False
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
   794
                        True    sets accepted status to True
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
   795
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
   796
                'displayed' is an optional parameter that can be one of three
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
   797
                values:
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
   798
                        None    leaves displayed status unchanged
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
   799
                        False   sets displayed status to False
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
   800
                        True    sets displayed status to True"""
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
   801
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   802
                self.__acquire_activity_lock()
1618
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
   803
                try:
1693
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
   804
                        try:
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
   805
                                self.__disable_cancel()
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
   806
                        except api_errors.CanceledException:
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
   807
                                self.__cancel_done()
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
   808
                                raise
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
   809
1618
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
   810
                        if not self.__img.imageplan:
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
   811
                                raise api_errors.PlanMissingException()
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
   812
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
   813
                        for pp in self.__img.imageplan.pkg_plans:
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
   814
                                if pp.destination_fmri == pfmri:
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
   815
                                        pp.set_license_status(plicense,
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
   816
                                            accepted=accepted,
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
   817
                                            displayed=displayed)
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
   818
                                        break
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
   819
                finally:
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
   820
                        self.__activity_lock.release()
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
   821
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 941
diff changeset
   822
        def refresh(self, full_refresh=False, pubs=None, immediate=False):
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 941
diff changeset
   823
                """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: 941
diff changeset
   824
                publishers.
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 941
diff changeset
   825
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 941
diff changeset
   826
                '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: 941
diff changeset
   827
                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: 941
diff changeset
   828
                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: 941
diff changeset
   829
                True, 'immediate' is also set to True.
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   830
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 941
diff changeset
   831
                '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: 941
diff changeset
   832
                to refresh.  Passing an empty list or using the default value
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 941
diff changeset
   833
                implies all publishers.
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
   834
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
   835
                'immediate' is an optional boolean value indicating whether
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 941
diff changeset
   836
                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: 941
diff changeset
   837
                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: 941
diff changeset
   838
                interval period recorded in the image configuration has been
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
   839
                exceeded.
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
   840
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
   841
                Currently returns an image object, allowing existing code to
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
   842
                work while the rest of the API is put into place."""
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
   843
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   844
                self.__acquire_activity_lock()
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
   845
                try:
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
   846
                        self.__disable_cancel()
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   847
                        self.__img.lock()
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
   848
                        try:
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
   849
                                self.__refresh(full_refresh=full_refresh,
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
   850
                                    pubs=pubs, immediate=immediate)
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
   851
                                return self.__img
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
   852
                        finally:
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
   853
                                self.__img.unlock()
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
   854
                                self.__img.cleanup_downloads()
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
   855
                except api_errors.CanceledException:
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
   856
                        self.__cancel_done()
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   857
                        raise
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
   858
                finally:
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
   859
                        self.__activity_lock.release()
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   860
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   861
        def __refresh(self, full_refresh=False, pubs=None, immediate=False):
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   862
                """Private refresh method; caller responsible for locking and
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   863
                cleanup."""
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   864
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   865
                self.__img.refresh_publishers(full_refresh=full_refresh,
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   866
                    immediate=immediate, pubs=pubs,
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   867
                    progtrack=self.__progresstracker)
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   868
1618
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
   869
        def __licenses(self, pfmri, mfst):
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   870
                """Private function. Returns the license info from the
1618
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
   871
                manifest mfst."""
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   872
                license_lst = []
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   873
                for lic in mfst.gen_actions_by_type("license"):
1638
43c8e6c924a3 12852 pkg.server.api should have methods for getting package information
Rajkumar Srinivasan <rajkumar.srinivasan@sun.com>
parents: 1634
diff changeset
   874
                        license_lst.append(LicenseInfo(pfmri, lic,
43c8e6c924a3 12852 pkg.server.api should have methods for getting package information
Rajkumar Srinivasan <rajkumar.srinivasan@sun.com>
parents: 1634
diff changeset
   875
                            img=self.__img))
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   876
                return license_lst
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   877
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   878
        def get_pkg_categories(self, installed=False, pubs=misc.EmptyI):
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   879
                """Returns an order list of tuples of the form (scheme,
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   880
                category) containing the names of all categories in use by
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   881
                the last version of each unique package in the catalog on a
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   882
                per-publisher basis.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   883
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   884
                'installed' is an optional boolean value indicating whether
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   885
                only the categories used by currently installed packages
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   886
                should be returned.  If False, the categories used by the
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   887
                latest vesion of every known package will be returned
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   888
                instead.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   889
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   890
                'pubs' is an optional list of publisher prefixes to restrict
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   891
                the results to."""
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   892
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   893
                if installed:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   894
                        img_cat = self.__img.get_catalog(
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   895
                            self.__img.IMG_CATALOG_INSTALLED)
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   896
                        excludes = misc.EmptyI
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   897
                else:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   898
                        img_cat = self.__img.get_catalog(
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   899
                            self.__img.IMG_CATALOG_KNOWN)
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   900
                        excludes = self.__img.list_excludes()
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   901
                return sorted(img_cat.categories(excludes=excludes, pubs=pubs))
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   902
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   903
        def get_pkg_list(self, pkg_list, cats=None, patterns=misc.EmptyI,
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   904
            pubs=misc.EmptyI, variants=False):
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   905
                """A generator function that produces tuples of the form ((pub,
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   906
                stem, version), summary, categories, states).  Where 'pub' is
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   907
                the publisher of the package, 'stem' is the name of the package,
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   908
                'version' is a string for the package version, 'summary' is the
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   909
                package summary, 'categories' is a list of tuples of the form
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   910
                (scheme, category), and 'states' is a list of PackageInfo states
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   911
                for the package.  Results are always sorted by stem, publisher,
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   912
                and then in descending version order.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   913
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   914
                'pkg_list' is one of the following constant values indicating
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   915
                what base set of package data should be used for results:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   916
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   917
                        LIST_ALL
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   918
                                All known packages.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   919
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   920
                        LIST_INSTALLED
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   921
                                Installed packages.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   922
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   923
                        LIST_INSTALLED_NEWEST
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   924
                                Installed packages and the newest
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   925
                                versions of packages not installed.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   926
                                Renamed packages that are listed in
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   927
                                an installed incorporation will be
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   928
                                excluded unless they are installed.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   929
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   930
                        LIST_NEWEST
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   931
                                The newest versions of all known packages.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   932
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   933
                        LIST_UPGRADABLE
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   934
                                Packages that are installed and upgradable.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   935
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   936
                'cats' is an optional list of package category tuples of the
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   937
                form (scheme, cat) to restrict the results to.  If a package
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   938
                is assigned to any of the given categories, it will be
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   939
                returned.  A value of [] will return packages not assigned
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   940
                to any package category.  A value of None indicates that no
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   941
                package category filtering should be applied.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   942
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   943
                'patterns' is an optional list of FMRI wildcard strings to
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   944
                filter results by.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   945
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   946
                'pubs' is an optional list of publisher prefixes to restrict
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   947
                the results to.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   948
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   949
                'variants' is an optional boolean value that indicates that
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   950
                packages that are for arch or zone variants not applicable to
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   951
                this image should be returned.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   952
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   953
                Please note that this function may invoke network operations
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   954
                to retrieve the requested package information."""
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   955
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   956
                all = installed = inst_newest = newest = upgradable = False
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   957
                if pkg_list == self.LIST_ALL:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   958
                        all = True
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   959
                elif pkg_list == self.LIST_INSTALLED:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   960
                        installed = True
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   961
                elif pkg_list == self.LIST_INSTALLED_NEWEST:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   962
                        inst_newest = True
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   963
                elif pkg_list == self.LIST_NEWEST:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   964
                        newest = True
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   965
                elif pkg_list == self.LIST_UPGRADABLE:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   966
                        upgradable = True
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   967
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   968
                inc_vers = {}
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   969
                brelease = self.__img.attrs["Build-Release"]
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   970
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   971
                # Each pattern in patterns can be a partial or full FMRI, so
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   972
                # extract the individual components for use in filtering.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   973
                illegals = []
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   974
                pat_tuples = {}
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   975
                MATCH_EXACT = 0
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   976
                MATCH_FMRI = 1
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   977
                MATCH_GLOB = 2
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   978
                for pat in patterns:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   979
                        try:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   980
                                if "*" in pat or "?" in pat:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   981
                                        matcher = MATCH_GLOB
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   982
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   983
                                        # XXX By default, matching FMRIs
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   984
                                        # currently do not also use
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   985
                                        # MatchingVersion.  If that changes,
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   986
                                        # this should change too.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   987
                                        parts = pat.split("@", 1)
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   988
                                        if len(parts) == 1:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   989
                                                npat = pkg.fmri.MatchingPkgFmri(
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   990
                                                    pat, brelease)
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   991
                                        else:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   992
                                                npat = pkg.fmri.MatchingPkgFmri(
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   993
                                                    parts[0], brelease)
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   994
                                                npat.version = \
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   995
                                                    pkg.version.MatchingVersion(
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   996
                                                    str(parts[1]), brelease)
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   997
                                elif pat.startswith("pkg:/"):
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   998
                                        matcher = MATCH_EXACT
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   999
                                        npat = pkg.fmri.PkgFmri(pat,
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1000
                                            brelease)
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1001
                                else:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1002
                                        matcher = MATCH_FMRI
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1003
                                        npat = pkg.fmri.PkgFmri(pat,
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1004
                                            brelease)
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1005
                                pat_tuples[pat] = (npat.tuple(), matcher)
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1006
                        except (pkg.fmri.FmriError, pkg.version.VersionError):
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1007
                                illegals.append(pat)
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1008
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1009
                if illegals:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1010
                        raise api_errors.InventoryException(illegal=illegals)
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1011
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1012
                # For LIST_INSTALLED_NEWEST, installed packages need to be
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1013
                # determined and incorporation and publisher relationships
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1014
                # mapped.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1015
                inst_stems = {}
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1016
                ren_inst_stems = {}
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1017
                ren_stems = {}
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1018
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1019
                pub_ranks = {}
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1020
                inc_stems = {}
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1021
                if inst_newest:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1022
                        img_cat = self.__img.get_catalog(
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1023
                            self.__img.IMG_CATALOG_INSTALLED)
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1024
                        cat_info = frozenset([img_cat.DEPENDENCY])
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1025
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1026
                        pub_ranks = self.__img.get_publisher_ranks()
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1027
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1028
                        # The incorporation list should include all installed,
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1029
                        # incorporated packages from all publishers.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1030
                        for t in img_cat.entry_actions(cat_info):
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1031
                                (pub, stem, ver), entry, actions = t
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1032
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1033
                                inst_stems[stem] = ver
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1034
                                pkgr = False
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1035
                                targets = set()
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1036
                                for a in actions:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1037
                                        if a.name == "set" and \
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1038
                                            a.attrs["name"] == "pkg.renamed":
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1039
                                                pkgr = True
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1040
                                                continue
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1041
                                        elif a.name != "depend":
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1042
                                                continue
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1043
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1044
                                        if a.attrs["type"] == "require":
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1045
                                                # Because the actions are not
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1046
                                                # returned in a guaranteed
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1047
                                                # order, the dependencies will
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1048
                                                # have to be recorded for
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1049
                                                # evaluation later.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1050
                                                targets.add(a.attrs["fmri"])
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1051
                                        elif a.attrs["type"] == "incorporate":
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1052
                                                # Record incorporated packages.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1053
                                                tgt = fmri.PkgFmri(
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1054
                                                    a.attrs["fmri"], brelease)
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1055
                                                tver = tgt.version
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1056
                                                over = inc_vers.get(
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1057
                                                    tgt.pkg_name, None)
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1058
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1059
                                                # In case this package has been
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1060
                                                # incorporated more than once,
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1061
                                                # use the newest version.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1062
                                                if over is not None and \
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1063
                                                    over > tver:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1064
                                                        continue
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1065
                                                inc_vers[tgt.pkg_name] = tver
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1066
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1067
                                if pkgr:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1068
                                        for f in targets:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1069
                                                tgt = fmri.PkgFmri(f, brelease)
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1070
                                                ren_stems[tgt.pkg_name] = stem
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1071
                                                ren_inst_stems.setdefault(stem,
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1072
                                                    set())
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1073
                                                ren_inst_stems[stem].add(
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1074
                                                    tgt.pkg_name)
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1075
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1076
                        def check_stem(t, entry):
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1077
                                pub, stem, ver = t
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1078
                                if stem in inst_stems:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1079
                                        iver = inst_stems[stem]
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1080
                                        if stem in ren_inst_stems or \
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1081
                                            ver == iver:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1082
                                                # The package has been renamed
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1083
                                                # or the entry is for the same
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1084
                                                # version as that which is
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1085
                                                # installed, so doesn't need
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1086
                                                # to be checked.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1087
                                                return False
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1088
                                        # The package may have been renamed in
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1089
                                        # a newer version, so must be checked.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1090
                                        return True
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1091
                                elif stem in inc_vers:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1092
                                        # Package is incorporated, but not
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1093
                                        # installed, so should be checked.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1094
                                        return True
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1095
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1096
                                tgt = ren_stems.get(stem, None)
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1097
                                while tgt is not None:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1098
                                        # This seems counter-intuitive, but
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1099
                                        # for performance and other reasons,
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1100
                                        # this stem should only be checked
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1101
                                        # for a rename if it is incorporated
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1102
                                        # or installed using a previous name.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1103
                                        if tgt in inst_stems or \
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1104
                                            tgt in inc_vers:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1105
                                                return True
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1106
                                        tgt = ren_stems.get(tgt, None)
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1107
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1108
                                # Package should not be checked.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1109
                                return False
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1110
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1111
                        img_cat = self.__img.get_catalog(
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1112
                            self.__img.IMG_CATALOG_KNOWN)
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1113
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1114
                        # Find terminal rename entry for all known packages not
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1115
                        # rejected by check_stem().
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1116
                        for t, entry, actions in img_cat.entry_actions(cat_info,
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1117
                            cb=check_stem, last=True):
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1118
                                pkgr = False
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1119
                                targets = set()
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1120
                                for a in actions:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1121
                                        if a.name == "set" and \
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1122
                                            a.attrs["name"] == "pkg.renamed":
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1123
                                                pkgr = True
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1124
                                                continue
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1125
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1126
                                        if a.name != "depend":
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1127
                                                continue
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1128
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1129
                                        if a.attrs["type"] != "require":
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1130
                                                continue
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1131
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1132
                                        # Because the actions are not
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1133
                                        # returned in a guaranteed
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1134
                                        # order, the dependencies will
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1135
                                        # have to be recorded for
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1136
                                        # evaluation later.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1137
                                        targets.add(a.attrs["fmri"])
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1138
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1139
                                if pkgr:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1140
                                        pub, stem, ver = t
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1141
                                        for f in targets:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1142
                                                tgt = fmri.PkgFmri(f, brelease)
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1143
                                                ren_stems[tgt.pkg_name] = stem
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1144
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1145
                        # Determine highest ranked publisher for package stems
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1146
                        # listed in installed incorporations.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1147
                        def pub_order(a, b):
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1148
                                return cmp(pub_ranks[a][0], pub_ranks[b][0])
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1149
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1150
                        for p in sorted(pub_ranks, cmp=pub_order):
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1151
                                if pubs and p not in pubs:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1152
                                        continue
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1153
                                for stem in img_cat.names(pubs=[p]):
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1154
                                        if stem in inc_vers:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1155
                                                inc_stems.setdefault(stem, p)
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1156
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1157
                if installed or upgradable:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1158
                        img_cat = self.__img.get_catalog(
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1159
                            self.__img.IMG_CATALOG_INSTALLED)
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1160
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1161
                        # Don't need to perform variant filtering if only
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1162
                        # listing installed packages.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1163
                        variants = True
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1164
                else:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1165
                        img_cat = self.__img.get_catalog(
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1166
                            self.__img.IMG_CATALOG_KNOWN)
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1167
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1168
                cat_info = frozenset([img_cat.DEPENDENCY, img_cat.SUMMARY])
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1169
                api_info = frozenset([PackageInfo.SUMMARY,
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1170
                    PackageInfo.CATEGORIES])
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1171
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1172
                # Keep track of when the newest version has been found for
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1173
                # each incorporated stem.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1174
                slist = set()
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1175
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1176
                # Keep track of listed stems for all other packages on a
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1177
                # per-publisher basis.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1178
                nlist = set()
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1179
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1180
                def check_state(t, entry):
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1181
                        states = entry["metadata"]["states"]
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1182
                        pkgi = self.__img.PKG_STATE_INSTALLED in states
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1183
                        pkgu = self.__img.PKG_STATE_UPGRADABLE in states
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1184
                        pub, stem, ver = t
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1185
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1186
                        if upgradable:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1187
                                # If package is marked upgradable, return it.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1188
                                return pkgu
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1189
                        elif pkgi:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1190
                                # Nothing more to do here.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1191
                                return True
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1192
                        elif stem in inst_stems:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1193
                                # Some other version of this package is
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1194
                                # installed, so this one should not be
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1195
                                # returned.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1196
                                return False
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1197
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1198
                        # Attempt to determine if this package is installed
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1199
                        # under a different name or constrained under a
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1200
                        # different name.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1201
                        tgt = ren_stems.get(stem, None)
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1202
                        while tgt is not None:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1203
                                if tgt in inc_vers:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1204
                                        # Package is incorporated under a
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1205
                                        # different name, so allow this
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1206
                                        # to fallthrough to the incoporation
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1207
                                        # evaluation.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1208
                                        break
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1209
                                elif tgt in inst_stems:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1210
                                        # Package is installed under a
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1211
                                        # different name, so skip it.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1212
                                        return False
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1213
                                tgt = ren_stems.get(tgt, None)
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1214
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1215
                        # Attempt to find a suitable version to return.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1216
                        if stem in inc_vers:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1217
                                # For package stems that are incorporated, only
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1218
                                # return the newest successor version  based on
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1219
                                # publisher rank.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1220
                                if stem in slist:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1221
                                        # Newest version already returned.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1222
                                        return False
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1223
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1224
                                if stem in inc_stems and \
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1225
                                    pub != inc_stems[stem]:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1226
                                        # This entry is for a lower-ranked
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1227
                                        # publisher.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1228
                                        return False
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1229
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1230
                                # XXX version should not require build release.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1231
                                ever = pkg.version.Version(ver, brelease)
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1232
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1233
                                # If the entry's version is a successor to
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1234
                                # the incorporated version, then this is the
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1235
                                # 'newest' version of this package since
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1236
                                # entries are processed in descending version
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1237
                                # order.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1238
                                iver = inc_vers[stem]
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1239
                                if ever.is_successor(iver,
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1240
                                    pkg.version.CONSTRAINT_AUTO):
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1241
                                        slist.add(stem)
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1242
                                        return True
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1243
                                return False
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1244
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1245
                        pkg_stem = pub + "!" + stem
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1246
                        if pkg_stem in nlist:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1247
                                # A newer version has already been listed for
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1248
                                # this stem and publisher.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1249
                                return False
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1250
                        return True
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1251
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1252
                filter_cb = None
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1253
                if inst_newest or upgradable:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1254
                        # Filtering needs to be applied.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1255
                        filter_cb = check_state
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1256
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1257
                arch = self.__img.get_arch()
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1258
                excludes = self.__img.list_excludes()
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1259
                is_zone = self.__img.is_zone()
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1260
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1261
                for t, entry, actions in img_cat.entry_actions(cat_info,
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1262
                    cb=filter_cb, excludes=excludes, last=newest,
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1263
                    ordered=True, pubs=pubs):
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1264
                        pub, stem, ver = t
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1265
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1266
                        # Perform image arch and zone variant filtering so
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1267
                        # that only packages appropriate for this image are
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1268
                        # returned, but only do this for packages that are
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1269
                        # not installed.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1270
                        pcats = []
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1271
                        pkgr = False
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1272
                        omit_package = False
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1273
                        summ = None
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1274
                        targets = set()
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1275
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1276
                        states = entry["metadata"]["states"]
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1277
                        pkgi = self.__img.PKG_STATE_INSTALLED in states
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1278
                        for a in actions:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1279
                                if a.name == "depend" and \
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1280
                                    a.attrs["type"] == "require":
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1281
                                        targets.add(a.attrs["fmri"])
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1282
                                        continue
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1283
                                if a.name != "set":
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1284
                                        continue
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1285
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1286
                                atname = a.attrs["name"]
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1287
                                atvalue = a.attrs["value"]
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1288
                                if atname == "pkg.summary":
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1289
                                        summ = atvalue
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1290
                                        continue
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1291
1735
041c87b656eb 14250 client api should prefer pkg.description for description, pkg.summary for summary
Shawn Walker <srw@sun.com>
parents: 1733
diff changeset
  1292
                                if atname == "description":
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1293
                                        if summ is None:
1735
041c87b656eb 14250 client api should prefer pkg.description for description, pkg.summary for summary
Shawn Walker <srw@sun.com>
parents: 1733
diff changeset
  1294
                                                # Historical summary field.
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1295
                                                summ = atvalue
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1296
                                        continue
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1297
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1298
                                if atname == "info.classification":
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1299
                                        pcats.extend(
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1300
                                            a.parse_category_info())
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1301
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1302
                                if pkgi:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1303
                                        # No filtering for installed packages.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1304
                                        continue
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1305
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1306
                                # Rename filtering should only be performed for
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1307
                                # incorporated packages at this point.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1308
                                if atname == "pkg.renamed":
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1309
                                        if stem in inc_vers:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1310
                                                pkgr = True
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1311
                                        continue
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1312
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1313
                                if variants:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1314
                                        # No variant filtering.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1315
                                        continue
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1316
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1317
                                is_list = type(atvalue) == list
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1318
                                if atname == "variant.arch":
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1319
                                        if (is_list and arch not in atvalue) or \
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1320
                                           (not is_list and arch != atvalue):
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1321
                                                # Package is not for the
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1322
                                                # image's architecture.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1323
                                                omit_package = True
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1324
                                                continue
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1325
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1326
                                if atname == "variant.opensolaris.zone":
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
  1327
                                        if (is_zone and is_list and
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1328
                                            "nonglobal" not in atvalue) or \
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1329
                                           (is_zone and not is_list and
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1330
                                            atvalue != "nonglobal"):
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1331
                                                # Package is for zones only.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1332
                                                omit_package = True
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1333
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1334
                        if filter_cb is not None:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1335
                                pkg_stem = pub + "!" + stem
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1336
                                nlist.add(pkg_stem)
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1337
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1338
                        if not pkgi and pkgr and stem in inc_vers:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1339
                                # If the package is not installed, but this is
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1340
                                # the terminal version entry for the stem and
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1341
                                # it is an incorporated package, then omit the
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1342
                                # package if it has been installed or is
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1343
                                # incorporated using one of the new names.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1344
                                for e in targets:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1345
                                        tgt = e
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1346
                                        while tgt is not None:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1347
                                                if tgt in ren_inst_stems or \
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1348
                                                    tgt in inc_vers:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1349
                                                        omit_package = True
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1350
                                                        break
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1351
                                                tgt = ren_stems.get(tgt, None)
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1352
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1353
                        # Pattern filtering has to be applied last so that
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1354
                        # renames, incorporations, and everything else is
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1355
                        # handled correctly.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1356
                        if not omit_package:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1357
                                for pat in patterns:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1358
                                        (pat_pub, pat_stem, pat_ver), matcher = \
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1359
                                            pat_tuples[pat]
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1360
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1361
                                        if pat_pub is not None and \
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1362
                                            pub != pat_pub:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1363
                                                # Publisher doesn't match.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1364
                                                omit_package = True
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1365
                                                continue
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1366
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1367
                                        if matcher == MATCH_EXACT:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1368
                                                if pat_stem != stem:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1369
                                                        # Stem doesn't match.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1370
                                                        omit_package = True
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1371
                                                        continue
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1372
                                        elif matcher == MATCH_FMRI:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1373
                                                if not ("/" + stem).endswith(
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1374
                                                    "/" + pat_stem):
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1375
                                                        # Stem doesn't match.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1376
                                                        omit_package = True
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1377
                                                        continue
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1378
                                        elif matcher == MATCH_GLOB:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1379
                                                if not fnmatch.fnmatchcase(stem,
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1380
                                                    pat_stem):
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1381
                                                        # Stem doesn't match.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1382
                                                        omit_package = True
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1383
                                                        continue
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1384
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1385
                                        if pat_ver is not None:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1386
                                                ever = pkg.version.Version(ver,
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1387
                                                    brelease)
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1388
                                                if not ever.is_successor(pat_ver,
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1389
                                                    pkg.version.CONSTRAINT_AUTO):
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1390
                                                        omit_package = True
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1391
                                                        continue
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1392
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1393
                                        # If this entry matched at least one
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1394
                                        # pattern, then ensure it is returned.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1395
                                        omit_package = False
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1396
                                        break
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1397
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1398
                        if omit_package:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1399
                                continue
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1400
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1401
                        if cats is not None:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1402
                                if not cats:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1403
                                        if pcats:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1404
                                                # Only want packages with no
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1405
                                                # categories.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1406
                                                continue
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1407
                                elif not [sc for sc in cats if sc in pcats]:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1408
                                        # Package doesn't match specified
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1409
                                        # category criteria.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1410
                                        continue
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1411
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1412
                        # Return the requested package data.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1413
                        yield (t, summ, pcats,
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1414
                            frozenset(entry["metadata"]["states"]))
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1415
917
eed22f430a9f 6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents: 884
diff changeset
  1416
        def info(self, fmri_strings, local, info_needed):
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1417
                """Gathers information about fmris.  fmri_strings is a list
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1418
                of fmri_names for which information is desired.  local
1618
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  1419
                determines whether to retrieve the information locally
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  1420
                (if possible).  It returns a dictionary of lists.  The keys
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  1421
                for the dictionary are the constants specified in the class
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  1422
                definition.  The values are lists of PackageInfo objects or
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  1423
                strings."""
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1424
1191
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  1425
                # Currently, this is mostly a wapper for activity locking.
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
  1426
                self.__acquire_activity_lock()
1191
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  1427
                try:
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  1428
                        i = self._info_op(fmri_strings, local, info_needed)
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  1429
                finally:
1503
78d56b8ee320 12698 download directory must be accessible to non-privileged users
johansen <johansen@sun.com>
parents: 1472
diff changeset
  1430
                        self.__img.cleanup_downloads()
1191
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  1431
                        self.__activity_lock.release()
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  1432
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  1433
                return i
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  1434
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  1435
        def _info_op(self, fmri_strings, local, info_needed):
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  1436
                """Performs the actual info operation.  The external
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  1437
                interface to the API's consumers is defined in info()."""
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  1438
917
eed22f430a9f 6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents: 884
diff changeset
  1439
                bad_opts = info_needed - PackageInfo.ALL_OPTIONS
eed22f430a9f 6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents: 884
diff changeset
  1440
                if bad_opts:
eed22f430a9f 6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents: 884
diff changeset
  1441
                        raise api_errors.UnrecognizedOptionsToInfo(bad_opts)
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1442
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1443
                self.log_operation_start("info")
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1444
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1445
                fmris = []
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1446
                notfound = []
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1447
                multiple_matches = []
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1448
                illegals = []
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1449
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
  1450
                ppub = self.__img.get_preferred_publisher()
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1451
                if local:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1452
                        fmris, notfound, illegals = \
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
  1453
                            self.__img.installed_fmris_from_args(fmri_strings)
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1454
                        if not fmris and not notfound and not illegals:
1027
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
  1455
                                self.log_operation_end(
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
  1456
                                    result=history.RESULT_NOTHING_TO_DO)
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1457
                                raise api_errors.NoPackagesInstalledException()
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1458
                else:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1459
                        # Verify validity of certificates before attempting
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1460
                        # network operations.
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
  1461
                        self.__cert_verify(
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
  1462
                            log_op_end=[api_errors.CertificateError])
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1463
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1464
                        # XXX This loop really needs not to be copied from
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1465
                        # Image.make_install_plan()!
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1466
                        for p in fmri_strings:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1467
                                try:
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
  1468
                                        matches = list(self.__img.inventory([p],
1045
62656c214151 8135 plan creation could be faster for install and uninstall
Shawn Walker <srw@sun.com>
parents: 1044
diff changeset
  1469
                                            all_known=True, ordered=False))
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1470
                                except api_errors.InventoryException, e:
707
d37b19989de2 4878 pkg info traceback when given invalid input
Brock Pytlik <bpytlik@sun.com>
parents: 696
diff changeset
  1471
                                        assert(len(e.notfound) == 1 or \
d37b19989de2 4878 pkg info traceback when given invalid input
Brock Pytlik <bpytlik@sun.com>
parents: 696
diff changeset
  1472
                                            len(e.illegal) == 1)
d37b19989de2 4878 pkg info traceback when given invalid input
Brock Pytlik <bpytlik@sun.com>
parents: 696
diff changeset
  1473
                                        if e.notfound:
d37b19989de2 4878 pkg info traceback when given invalid input
Brock Pytlik <bpytlik@sun.com>
parents: 696
diff changeset
  1474
                                                notfound.append(e.notfound[0])
d37b19989de2 4878 pkg info traceback when given invalid input
Brock Pytlik <bpytlik@sun.com>
parents: 696
diff changeset
  1475
                                        else:
d37b19989de2 4878 pkg info traceback when given invalid input
Brock Pytlik <bpytlik@sun.com>
parents: 696
diff changeset
  1476
                                                illegals.append(e.illegal[0])
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1477
                                        err = 1
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1478
                                        continue
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1479
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1480
                                pnames = {}
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1481
                                pmatch = []
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1482
                                npnames = {}
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1483
                                npmatch = []
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1484
                                for m, state in matches:
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
  1485
                                        if m.get_publisher() == ppub:
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1486
                                                pnames[m.get_pkg_stem()] = 1
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1487
                                                pmatch.append((m, state))
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1488
                                        else:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1489
                                                npnames[m.get_pkg_stem()] = 1
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1490
                                                npmatch.append((m, state))
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1491
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1492
                                if len(pnames.keys()) > 1:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1493
                                        multiple_matches.append(
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1494
                                            (p, pnames.keys()))
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1495
                                        error = 1
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1496
                                        continue
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1497
                                elif len(pnames.keys()) < 1 and \
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1498
                                    len(npnames.keys()) > 1:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1499
                                        multiple_matches.append(
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1500
                                            (p, pnames.keys()))
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1501
                                        error = 1
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1502
                                        continue
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1503
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1504
                                # matches is a list reverse sorted by version,
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1505
                                # so take the first; i.e., the latest.
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1506
                                if len(pmatch) > 0:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1507
                                        fmris.append(pmatch[0])
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1508
                                else:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1509
                                        fmris.append(npmatch[0])
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1510
1431
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1389
diff changeset
  1511
                if local:
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1389
diff changeset
  1512
                        img_cat = self.__img.get_catalog(
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1389
diff changeset
  1513
                            self.__img.IMG_CATALOG_INSTALLED)
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1389
diff changeset
  1514
                else:
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1389
diff changeset
  1515
                        img_cat = self.__img.get_catalog(
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1389
diff changeset
  1516
                            self.__img.IMG_CATALOG_KNOWN)
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1389
diff changeset
  1517
                excludes = self.__img.list_excludes()
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1389
diff changeset
  1518
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1519
                # Set of options that can use catalog data.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1520
                cat_opts = frozenset([PackageInfo.SUMMARY,
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1521
                    PackageInfo.CATEGORIES, PackageInfo.DESCRIPTION,
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1522
                    PackageInfo.DEPENDENCIES])
1431
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1389
diff changeset
  1523
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1389
diff changeset
  1524
                # Set of options that require manifest retrieval.
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1389
diff changeset
  1525
                act_opts = PackageInfo.ACTION_OPTIONS - \
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1389
diff changeset
  1526
                    frozenset([PackageInfo.DEPENDENCIES])
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1389
diff changeset
  1527
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1528
                pis = []
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1529
                for f, fstate in fmris:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1530
                        pub = name = version = release = None
917
eed22f430a9f 6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents: 884
diff changeset
  1531
                        build_release = branch = packaging_date = None
eed22f430a9f 6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents: 884
diff changeset
  1532
                        if PackageInfo.IDENTITY in info_needed:
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1533
                                pub, name, version = f.tuple()
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1534
                                pub = fmri.strip_pub_pfx(pub)
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1535
                                release = version.release
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1536
                                build_release = version.build_release
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1537
                                branch = version.branch
1150
2b8aaf0b0b4e 4346 use of ctime() creates non-localized time strings
Rich Burridge <rich.burridge@sun.com>
parents: 1141
diff changeset
  1538
                                packaging_date = \
2b8aaf0b0b4e 4346 use of ctime() creates non-localized time strings
Rich Burridge <rich.burridge@sun.com>
parents: 1141
diff changeset
  1539
                                    version.get_timestamp().strftime("%c")
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1540
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1541
                        pref_pub = None
938
eeb932b9b44e 7336 putback for 5871 missed a few vestiges of authority
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 926
diff changeset
  1542
                        if PackageInfo.PREF_PUBLISHER in info_needed:
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1543
                                pref_pub = (f.get_publisher() == ppub)
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1544
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1545
                        # XXX gross; info needs to switch to using get_pkg_list
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1546
                        # routines at a later date once matching is figured
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1547
                        # out.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1548
                        states = set()
917
eed22f430a9f 6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents: 884
diff changeset
  1549
                        if PackageInfo.STATE in info_needed:
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1550
                                if fstate["state"] == \
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1551
                                    self.__img.PKG_STATE_INSTALLED:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1552
                                        states.add(PackageInfo.INSTALLED)
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1553
                                if fstate["in_catalog"]:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1554
                                        states.add(PackageInfo.KNOWN)
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1555
                                if fstate["upgradable"]:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1556
                                        states.add(PackageInfo.UPGRADABLE)
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1557
                                if fstate["obsolete"]:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1558
                                        states.add(PackageInfo.OBSOLETE)
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1559
                                if fstate["renamed"]:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1560
                                        states.add(PackageInfo.RENAMED)
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1561
615
aeeeb9f31173 4114 Api.Info needs to provide more info
Brock Pytlik <bpytlik@sun.com>
parents: 610
diff changeset
  1562
                        links = hardlinks = files = dirs = dependencies = None
1389
1827f487a235 8868 Changes needed to handle package descriptions in the pkg Python API.
Brock Pytlik <bpytlik@sun.com>
parents: 1370
diff changeset
  1563
                        summary = size = licenses = cat_info = description = \
1827f487a235 8868 Changes needed to handle package descriptions in the pkg Python API.
Brock Pytlik <bpytlik@sun.com>
parents: 1370
diff changeset
  1564
                            None
917
eed22f430a9f 6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents: 884
diff changeset
  1565
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1566
                        if cat_opts & info_needed:
1431
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1389
diff changeset
  1567
                                summary, description, cat_info, dependencies = \
1638
43c8e6c924a3 12852 pkg.server.api should have methods for getting package information
Rajkumar Srinivasan <rajkumar.srinivasan@sun.com>
parents: 1634
diff changeset
  1568
                                    _get_pkg_cat_data(img_cat, info_needed,
43c8e6c924a3 12852 pkg.server.api should have methods for getting package information
Rajkumar Srinivasan <rajkumar.srinivasan@sun.com>
parents: 1634
diff changeset
  1569
                                        excludes=excludes, pfmri=f)
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1570
                                if cat_info is not None:
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
  1571
                                        cat_info = [
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1572
                                            PackageCategory(scheme, cat)
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1573
                                            for scheme, cat in cat_info
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1574
                                        ]
1431
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1389
diff changeset
  1575
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1389
diff changeset
  1576
                        if (frozenset([PackageInfo.SIZE,
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1389
diff changeset
  1577
                            PackageInfo.LICENSES]) | act_opts) & info_needed:
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
  1578
                                mfst = self.__img.get_manifest(f)
1431
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1389
diff changeset
  1579
                                if PackageInfo.LICENSES in info_needed:
1618
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  1580
                                        licenses = self.__licenses(f, mfst)
1431
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1389
diff changeset
  1581
917
eed22f430a9f 6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents: 884
diff changeset
  1582
                                if PackageInfo.SIZE in info_needed:
1044
046981c42149 8102 pkg.client.api info reports size of zero for packages with cached manifests
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 1032
diff changeset
  1583
                                        size = mfst.get_size(excludes=excludes)
917
eed22f430a9f 6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents: 884
diff changeset
  1584
1431
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1389
diff changeset
  1585
                                if act_opts & info_needed:
917
eed22f430a9f 6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents: 884
diff changeset
  1586
                                        if PackageInfo.LINKS in info_needed:
eed22f430a9f 6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents: 884
diff changeset
  1587
                                                links = list(
eed22f430a9f 6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents: 884
diff changeset
  1588
                                                    mfst.gen_key_attribute_value_by_type(
eed22f430a9f 6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents: 884
diff changeset
  1589
                                                    "link", excludes))
eed22f430a9f 6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents: 884
diff changeset
  1590
                                        if PackageInfo.HARDLINKS in info_needed:
eed22f430a9f 6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents: 884
diff changeset
  1591
                                                hardlinks = list(
eed22f430a9f 6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents: 884
diff changeset
  1592
                                                    mfst.gen_key_attribute_value_by_type(
eed22f430a9f 6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents: 884
diff changeset
  1593
                                                    "hardlink", excludes))
eed22f430a9f 6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents: 884
diff changeset
  1594
                                        if PackageInfo.FILES in info_needed:
eed22f430a9f 6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents: 884
diff changeset
  1595
                                                files = list(
eed22f430a9f 6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents: 884
diff changeset
  1596
                                                    mfst.gen_key_attribute_value_by_type(
eed22f430a9f 6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents: 884
diff changeset
  1597
                                                    "file", excludes))
eed22f430a9f 6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents: 884
diff changeset
  1598
                                        if PackageInfo.DIRS in info_needed:
eed22f430a9f 6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents: 884
diff changeset
  1599
                                                dirs = list(
eed22f430a9f 6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents: 884
diff changeset
  1600
                                                    mfst.gen_key_attribute_value_by_type(
eed22f430a9f 6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents: 884
diff changeset
  1601
                                                    "dir", excludes))
615
aeeeb9f31173 4114 Api.Info needs to provide more info
Brock Pytlik <bpytlik@sun.com>
parents: 610
diff changeset
  1602
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1603
                        pis.append(PackageInfo(pkg_stem=name, summary=summary,
1461
fdf40c8c6765 820 Need a way to obsolete packages
Danek Duvall <danek.duvall@sun.com>
parents: 1431
diff changeset
  1604
                            category_info_list=cat_info, states=states,
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1605
                            publisher=pub, preferred_publisher=pref_pub,
917
eed22f430a9f 6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents: 884
diff changeset
  1606
                            version=release, build_release=build_release,
eed22f430a9f 6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents: 884
diff changeset
  1607
                            branch=branch, packaging_date=packaging_date,
eed22f430a9f 6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents: 884
diff changeset
  1608
                            size=size, pfmri=str(f), licenses=licenses,
615
aeeeb9f31173 4114 Api.Info needs to provide more info
Brock Pytlik <bpytlik@sun.com>
parents: 610
diff changeset
  1609
                            links=links, hardlinks=hardlinks, files=files,
1389
1827f487a235 8868 Changes needed to handle package descriptions in the pkg Python API.
Brock Pytlik <bpytlik@sun.com>
parents: 1370
diff changeset
  1610
                            dirs=dirs, dependencies=dependencies,
1827f487a235 8868 Changes needed to handle package descriptions in the pkg Python API.
Brock Pytlik <bpytlik@sun.com>
parents: 1370
diff changeset
  1611
                            description=description))
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1612
                if pis:
1027
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
  1613
                        self.log_operation_end()
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1614
                elif illegals or multiple_matches:
1027
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
  1615
                        self.log_operation_end(
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
  1616
                            result=history.RESULT_FAILED_BAD_REQUEST)
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1617
                else:
1027
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
  1618
                        self.log_operation_end(
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
  1619
                            result=history.RESULT_NOTHING_TO_DO)
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1620
                return {
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1621
                    self.INFO_FOUND: pis,
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1622
                    self.INFO_MISSING: notfound,
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1623
                    self.INFO_MULTI_MATCH: multiple_matches,
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1624
                    self.INFO_ILLEGALS: illegals
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1625
                }
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1626
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1627
        def can_be_canceled(self):
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1628
                """Returns true if the API is in a cancelable state."""
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1629
                return self.__can_be_canceled
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1630
1569
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  1631
        def __disable_cancel(self):
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  1632
                """Sets_can_be_canceled to False in a way that prevents missed
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  1633
                wakeups.  This may raise CanceledException, if a
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
  1634
                cancellation is pending."""
1569
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  1635
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  1636
                self.__cancel_lock.acquire()
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  1637
                if self.__canceling:
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  1638
                        self.__cancel_lock.release()
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  1639
                        self.__img.transport.reset()
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  1640
                        raise api_errors.CanceledException()
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  1641
                else:
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  1642
                        self.__set_can_be_canceled(False)
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  1643
                self.__cancel_lock.release()
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  1644
1693
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  1645
        def __enable_cancel(self):
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  1646
                """Sets can_be_canceled to True while grabbing the cancel
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  1647
                locks.  The caller must still hold the activity lock while
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  1648
                calling this function."""
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  1649
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  1650
                self.__cancel_lock.acquire()
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  1651
                self.__set_can_be_canceled(True)
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  1652
                self.__cancel_lock.release()
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  1653
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1654
        def __set_can_be_canceled(self, status):
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1655
                """Private method. Handles the details of changing the
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1656
                cancelable state."""
1693
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  1657
                assert self.__cancel_lock._is_owned()
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  1658
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  1659
                # If caller requests a change to current state there is
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  1660
                # nothing to do.
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  1661
                if self.__can_be_canceled == status:
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  1662
                        return
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  1663
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  1664
                if status == True:
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  1665
                        # Callers must hold activity lock for operations
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  1666
                        # that they will make cancelable.
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  1667
                        assert self.__activity_lock._is_owned()
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  1668
                        # In any situation where the caller holds the activity
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  1669
                        # lock and wants to set cancelable to true, a cancel
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  1670
                        # should not already be in progress.  This is because
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  1671
                        # it should not be possible to invoke cancel until
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  1672
                        # this routine has finished.  Assert that we're not
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  1673
                        # canceling.
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  1674
                        assert not self.__canceling
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  1675
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  1676
                self.__can_be_canceled = status
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  1677
                if self.__cancel_state_callable:
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  1678
                        self.__cancel_state_callable(self.__can_be_canceled)
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1679
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1680
        def reset(self):
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1681
                """Resets the API back the the initial state. Note:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1682
                this does not necessarily return the disk to its initial state
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1683
                since the indexes or download cache may have been changed by
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1684
                the prepare method."""
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
  1685
                self.__acquire_activity_lock()
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1686
                self.__reset_unlock()
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1687
                self.__activity_lock.release()
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1688
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1689
        def __reset_unlock(self):
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1690
                """Private method. Provides a way to reset without taking the
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1691
                activity lock. Should only be called by a thread which already
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1692
                holds the activity lock."""
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
  1693
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
  1694
                assert self.__activity_lock._is_owned()
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
  1695
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
  1696
                # This needs to be done first so that find_root can use it.
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
  1697
                self.__progresstracker.reset()
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
  1698
1503
78d56b8ee320 12698 download directory must be accessible to non-privileged users
johansen <johansen@sun.com>
parents: 1472
diff changeset
  1699
                self.__img.cleanup_downloads()
1634
915de177f257 13746 transport should close connections after download phase
johansen <johansen@sun.com>
parents: 1618
diff changeset
  1700
                self.__img.transport.shutdown()
1242
f6aa06e1c391 6758 api should recreate image object on reset
Shawn Walker <srw@sun.com>
parents: 1240
diff changeset
  1701
                # Recreate the image object using the path the api
f6aa06e1c391 6758 api should recreate image object on reset
Shawn Walker <srw@sun.com>
parents: 1240
diff changeset
  1702
                # object was created with instead of the current path.
1370
face1fe579ab 11400 image objects should always have a root
Brock Pytlik <bpytlik@sun.com>
parents: 1360
diff changeset
  1703
                self.__img = image.Image(self.__img_path,
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
  1704
                    progtrack=self.__progresstracker)
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
  1705
                self.__img.blocking_locks = self.__blocking_locks
1242
f6aa06e1c391 6758 api should recreate image object on reset
Shawn Walker <srw@sun.com>
parents: 1240
diff changeset
  1706
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
  1707
                self.__plan_desc = None
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
  1708
                self.__plan_type = None
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
  1709
                self.__prepared = False
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
  1710
                self.__executed = False
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
  1711
                self.__be_name = None
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1712
1569
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  1713
                self.__cancel_cleanup_exception()
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
  1714
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1715
        def __check_cancelation(self):
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1716
                """Private method. Provides a callback method for internal
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1717
                code to use to determine whether the current action has been
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1718
                canceled."""
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1719
                return self.__canceling
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1720
1569
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  1721
        def __cancel_cleanup_exception(self):
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  1722
                """A private method that is called from exception handlers.
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  1723
                This is not needed if the method calls reset unlock,
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  1724
                which will call this method too.  This catches the case
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  1725
                where a caller might have called cancel and gone to sleep,
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  1726
                but the requested operation failed with an exception before
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  1727
                it could raise a CanceledException."""
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  1728
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  1729
                self.__cancel_lock.acquire()
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  1730
                self.__set_can_be_canceled(False)
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  1731
                self.__canceling = False
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  1732
                # Wake up any threads that are waiting on this aborted
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  1733
                # operation.
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  1734
                self.__cancel_cv.notify_all()
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  1735
                self.__cancel_lock.release()
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  1736
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  1737
        def __cancel_done(self):
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  1738
                """A private method that wakes any threads that have been
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  1739
                sleeping, waiting for a cancellation to finish."""
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  1740
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  1741
                self.__cancel_lock.acquire()
1693
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  1742
                if self.__canceling:
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  1743
                        self.__canceling = False
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  1744
                        self.__cancel_cv.notify_all()
1569
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  1745
                self.__cancel_lock.release()
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  1746
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1747
        def cancel(self):
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1748
                """Used for asynchronous cancelation. It returns the API
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1749
                to the state it was in prior to the current method being
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1750
                invoked.  Canceling during a plan phase returns the API to
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1751
                its initial state. Canceling during prepare puts the API
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1752
                into the state it was in just after planning had completed.
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1753
                Plan execution cannot be canceled. A call to this method blocks
1569
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  1754
                until the cancellation has happened. Note: this does not
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1755
                necessarily return the disk to its initial state since the
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1756
                indexes or download cache may have been changed by the
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1757
                prepare method."""
1569
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  1758
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  1759
                self.__cancel_lock.acquire()
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  1760
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1761
                if not self.__can_be_canceled:
1569
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  1762
                        self.__cancel_lock.release()
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1763
                        return False
1569
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  1764
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1765
                self.__set_can_be_canceled(False)
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1766
                self.__canceling = True
1569
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  1767
                # Wait until the cancelled operation wakes us up.
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  1768
                self.__cancel_cv.wait()
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  1769
                self.__cancel_lock.release()
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1770
                return True
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1771
716
b836c1b14137 4639 history result info differs for install and uninstall of nonexistent packages
Brock Pytlik <bpytlik@sun.com>
parents: 707
diff changeset
  1772
        def __set_history_PlanCreationException(self, e):
1141
a74d6815a7fc 4178 unfound_fmris is a poor name
Rich Burridge <rich.burridge@sun.com>
parents: 1140
diff changeset
  1773
                if e.unmatched_fmris or e.multiple_matches or \
716
b836c1b14137 4639 history result info differs for install and uninstall of nonexistent packages
Brock Pytlik <bpytlik@sun.com>
parents: 707
diff changeset
  1774
                    e.missing_matches or e.illegal:
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1775
                        self.log_operation_end(error=e,
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1776
                            result=history.RESULT_FAILED_BAD_REQUEST)
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1777
                else:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1778
                        self.log_operation_end(error=e)
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1779
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1780
        def local_search(self, query_lst):
1100
22a8b08d460a 7364 documentation and code comments needed for fix for 6175
Brock Pytlik <bpytlik@sun.com>
parents: 1087
diff changeset
  1781
                """local_search takes a list of Query objects and performs
22a8b08d460a 7364 documentation and code comments needed for fix for 6175
Brock Pytlik <bpytlik@sun.com>
parents: 1087
diff changeset
  1782
                each query against the installed packages of the image."""
22a8b08d460a 7364 documentation and code comments needed for fix for 6175
Brock Pytlik <bpytlik@sun.com>
parents: 1087
diff changeset
  1783
1360
fbf184c6d55b 1059 search both original input and paths with image root removed
Brock Pytlik <bpytlik@sun.com>
parents: 1352
diff changeset
  1784
                l = query_p.QueryLexer()
fbf184c6d55b 1059 search both original input and paths with image root removed
Brock Pytlik <bpytlik@sun.com>
parents: 1352
diff changeset
  1785
                l.build()
fbf184c6d55b 1059 search both original input and paths with image root removed
Brock Pytlik <bpytlik@sun.com>
parents: 1352
diff changeset
  1786
                qp = query_p.QueryParser(l)
fbf184c6d55b 1059 search both original input and paths with image root removed
Brock Pytlik <bpytlik@sun.com>
parents: 1352
diff changeset
  1787
                ssu = None
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1788
                for i, q in enumerate(query_lst):
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1789
                        try:
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1790
                                query = qp.parse(q.encoded_text())
1360
fbf184c6d55b 1059 search both original input and paths with image root removed
Brock Pytlik <bpytlik@sun.com>
parents: 1352
diff changeset
  1791
                                query_rr = qp.parse(q.encoded_text())
fbf184c6d55b 1059 search both original input and paths with image root removed
Brock Pytlik <bpytlik@sun.com>
parents: 1352
diff changeset
  1792
                                if query_rr.remove_root(self.__img.root):
fbf184c6d55b 1059 search both original input and paths with image root removed
Brock Pytlik <bpytlik@sun.com>
parents: 1352
diff changeset
  1793
                                        query.add_or(query_rr)
1053
00fe9773d072 8098 parsing errors should not cause a stacktrace
Brock Pytlik <bpytlik@sun.com>
parents: 1051
diff changeset
  1794
                        except query_p.BooleanQueryException, e:
00fe9773d072 8098 parsing errors should not cause a stacktrace
Brock Pytlik <bpytlik@sun.com>
parents: 1051
diff changeset
  1795
                                raise api_errors.BooleanQueryException(e)
00fe9773d072 8098 parsing errors should not cause a stacktrace
Brock Pytlik <bpytlik@sun.com>
parents: 1051
diff changeset
  1796
                        except query_p.ParseError, e:
00fe9773d072 8098 parsing errors should not cause a stacktrace
Brock Pytlik <bpytlik@sun.com>
parents: 1051
diff changeset
  1797
                                raise api_errors.ParseError(e)
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
  1798
                        self.__img.update_index_dir()
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
  1799
                        assert self.__img.index_dir
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1800
                        try:
1337
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1335
diff changeset
  1801
                                query.set_info(num_to_return=q.num_to_return,
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1335
diff changeset
  1802
                                    start_point=q.start_point,
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1335
diff changeset
  1803
                                    index_dir=self.__img.index_dir,
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1335
diff changeset
  1804
                                    get_manifest_path=\
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1335
diff changeset
  1805
                                        self.__img.get_manifest_path,
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1335
diff changeset
  1806
                                    gen_installed_pkg_names=\
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1335
diff changeset
  1807
                                        self.__img.gen_installed_pkg_names,
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1335
diff changeset
  1808
                                    case_sensitive=q.case_sensitive)
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1335
diff changeset
  1809
                                res = query.search(
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1335
diff changeset
  1810
                                    self.__img.gen_installed_pkgs,
1505
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  1811
                                    self.__img.get_manifest_path,
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  1812
                                    self.__img.list_excludes())
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1813
                        except search_errors.InconsistentIndexException, e:
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1814
                                raise api_errors.InconsistentIndexException(e)
1100
22a8b08d460a 7364 documentation and code comments needed for fix for 6175
Brock Pytlik <bpytlik@sun.com>
parents: 1087
diff changeset
  1815
                        # i is being inserted to track which query the results
22a8b08d460a 7364 documentation and code comments needed for fix for 6175
Brock Pytlik <bpytlik@sun.com>
parents: 1087
diff changeset
  1816
                        # are for.  None is being inserted since there is no
22a8b08d460a 7364 documentation and code comments needed for fix for 6175
Brock Pytlik <bpytlik@sun.com>
parents: 1087
diff changeset
  1817
                        # publisher being searched against.
1360
fbf184c6d55b 1059 search both original input and paths with image root removed
Brock Pytlik <bpytlik@sun.com>
parents: 1352
diff changeset
  1818
                        try:
fbf184c6d55b 1059 search both original input and paths with image root removed
Brock Pytlik <bpytlik@sun.com>
parents: 1352
diff changeset
  1819
                                for r in res:
fbf184c6d55b 1059 search both original input and paths with image root removed
Brock Pytlik <bpytlik@sun.com>
parents: 1352
diff changeset
  1820
                                        yield i, None, r
fbf184c6d55b 1059 search both original input and paths with image root removed
Brock Pytlik <bpytlik@sun.com>
parents: 1352
diff changeset
  1821
                        except api_errors.SlowSearchUsed, e:
fbf184c6d55b 1059 search both original input and paths with image root removed
Brock Pytlik <bpytlik@sun.com>
parents: 1352
diff changeset
  1822
                                ssu = e
fbf184c6d55b 1059 search both original input and paths with image root removed
Brock Pytlik <bpytlik@sun.com>
parents: 1352
diff changeset
  1823
                if ssu:
fbf184c6d55b 1059 search both original input and paths with image root removed
Brock Pytlik <bpytlik@sun.com>
parents: 1352
diff changeset
  1824
                        raise ssu
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1825
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1826
        @staticmethod
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1827
        def __parse_v_0(line, pub, v):
1100
22a8b08d460a 7364 documentation and code comments needed for fix for 6175
Brock Pytlik <bpytlik@sun.com>
parents: 1087
diff changeset
  1828
                """This function parses the string returned by a version 0
22a8b08d460a 7364 documentation and code comments needed for fix for 6175
Brock Pytlik <bpytlik@sun.com>
parents: 1087
diff changeset
  1829
                search server and puts it into the expected format of
22a8b08d460a 7364 documentation and code comments needed for fix for 6175
Brock Pytlik <bpytlik@sun.com>
parents: 1087
diff changeset
  1830
                (query_number, publisher, (version, return_type, (results))).
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
  1831
1100
22a8b08d460a 7364 documentation and code comments needed for fix for 6175
Brock Pytlik <bpytlik@sun.com>
parents: 1087
diff changeset
  1832
                "query_number" in the return value is fixed at 0 since search
22a8b08d460a 7364 documentation and code comments needed for fix for 6175
Brock Pytlik <bpytlik@sun.com>
parents: 1087
diff changeset
  1833
                v0 servers cannot accept multiple queries in a single HTTP
22a8b08d460a 7364 documentation and code comments needed for fix for 6175
Brock Pytlik <bpytlik@sun.com>
parents: 1087
diff changeset
  1834
                request."""
22a8b08d460a 7364 documentation and code comments needed for fix for 6175
Brock Pytlik <bpytlik@sun.com>
parents: 1087
diff changeset
  1835
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1836
                line = line.strip()
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1837
                fields = line.split(None, 3)
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1838
                return (0, pub, (v, Query.RETURN_ACTIONS, (fields[:4])))
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1839
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1840
        @staticmethod
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1841
        def __parse_v_1(line, pub, v):
1100
22a8b08d460a 7364 documentation and code comments needed for fix for 6175
Brock Pytlik <bpytlik@sun.com>
parents: 1087
diff changeset
  1842
                """This function parses the string returned by a version 1
22a8b08d460a 7364 documentation and code comments needed for fix for 6175
Brock Pytlik <bpytlik@sun.com>
parents: 1087
diff changeset
  1843
                search server and puts it into the expected format of
22a8b08d460a 7364 documentation and code comments needed for fix for 6175
Brock Pytlik <bpytlik@sun.com>
parents: 1087
diff changeset
  1844
                (query_number, publisher, (version, return_type, (results)))
22a8b08d460a 7364 documentation and code comments needed for fix for 6175
Brock Pytlik <bpytlik@sun.com>
parents: 1087
diff changeset
  1845
                If it receives a line it can't parse, it raises a
22a8b08d460a 7364 documentation and code comments needed for fix for 6175
Brock Pytlik <bpytlik@sun.com>
parents: 1087
diff changeset
  1846
                ServerReturnError."""
22a8b08d460a 7364 documentation and code comments needed for fix for 6175
Brock Pytlik <bpytlik@sun.com>
parents: 1087
diff changeset
  1847
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1848
                fields = line.split(None, 2)
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1849
                if len(fields) != 3:
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1850
                        raise api_errors.ServerReturnError(line)
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1851
                try:
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1852
                        return_type = int(fields[1])
1360
fbf184c6d55b 1059 search both original input and paths with image root removed
Brock Pytlik <bpytlik@sun.com>
parents: 1352
diff changeset
  1853
                        query_num = int(fields[0])
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1854
                except ValueError:
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1855
                        raise api_errors.ServerReturnError(line)
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1856
                if return_type == Query.RETURN_ACTIONS:
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1857
                        subfields = fields[2].split(None, 2)
1360
fbf184c6d55b 1059 search both original input and paths with image root removed
Brock Pytlik <bpytlik@sun.com>
parents: 1352
diff changeset
  1858
                        return (query_num, pub, (v, return_type,
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1859
                            (subfields[0], urllib.unquote(subfields[1]),
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1860
                            subfields[2])))
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1861
                elif return_type == Query.RETURN_PACKAGES:
1360
fbf184c6d55b 1059 search both original input and paths with image root removed
Brock Pytlik <bpytlik@sun.com>
parents: 1352
diff changeset
  1862
                        return (query_num, pub, (v, return_type, fields[2]))
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1863
                else:
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1864
                        raise api_errors.ServerReturnError(line)
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1865
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1866
        def remote_search(self, query_str_and_args_lst, servers=None):
1100
22a8b08d460a 7364 documentation and code comments needed for fix for 6175
Brock Pytlik <bpytlik@sun.com>
parents: 1087
diff changeset
  1867
                """This function takes a list of Query objects, and optionally
22a8b08d460a 7364 documentation and code comments needed for fix for 6175
Brock Pytlik <bpytlik@sun.com>
parents: 1087
diff changeset
  1868
                a list of servers to search against.  It performs each query
22a8b08d460a 7364 documentation and code comments needed for fix for 6175
Brock Pytlik <bpytlik@sun.com>
parents: 1087
diff changeset
  1869
                against each server and yields the results in turn.  If no
22a8b08d460a 7364 documentation and code comments needed for fix for 6175
Brock Pytlik <bpytlik@sun.com>
parents: 1087
diff changeset
  1870
                servers are provided, the search is conducted against all
1191
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  1871
                active servers known by the image.
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  1872
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  1873
                The servers argument is a list of servers in two possible
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  1874
                forms: the old deprecated form of a publisher, in a
1693
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  1875
                dictionary, or a Publisher object.
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  1876
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  1877
                A call to this function returns a generator that holds
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  1878
                API locks.  Callers must either iterate through all of the
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  1879
                results, or call close() on the resulting object.  Otherwise
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  1880
                it is possible to get deadlocks or NRLock reentrance
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  1881
                exceptions."""
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  1882
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  1883
                clean_exit = True
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  1884
                canceled = False
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  1885
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
  1886
                self.__acquire_activity_lock()
1693
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  1887
                self.__enable_cancel()
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  1888
                try:
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  1889
                        for r in self._remote_search(query_str_and_args_lst,
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  1890
                            servers):
1693
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  1891
                                yield r
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  1892
                except GeneratorExit:
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  1893
                        return
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  1894
                except api_errors.CanceledException:
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  1895
                        canceled = True
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  1896
                        raise
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  1897
                except Exception:
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  1898
                        clean_exit = False
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  1899
                        raise
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  1900
                finally:
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  1901
                        if canceled:
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  1902
                                self.__cancel_done()
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  1903
                        elif clean_exit:
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  1904
                                try:
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  1905
                                        self.__disable_cancel()
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  1906
                                except api_errors.CanceledException:
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  1907
                                        self.__cancel_done()
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  1908
                                        self.__activity_lock.release()
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  1909
                                        raise
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  1910
                        else:
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  1911
                                self.__cancel_cleanup_exception()
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  1912
                        self.__activity_lock.release()
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  1913
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  1914
        def _remote_search(self, query_str_and_args_lst, servers=None):
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  1915
                """This is the implementation of remote_search.  The other
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  1916
                function is a wrapper that handles locking and exception
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  1917
                handling.  This is a generator function."""
1100
22a8b08d460a 7364 documentation and code comments needed for fix for 6175
Brock Pytlik <bpytlik@sun.com>
parents: 1087
diff changeset
  1918
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1919
                failed = []
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1920
                invalid = []
1191
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  1921
                unsupported = []
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 941
diff changeset
  1922
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1923
                if not servers:
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
  1924
                        servers = self.__img.gen_publishers()
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1925
1360
fbf184c6d55b 1059 search both original input and paths with image root removed
Brock Pytlik <bpytlik@sun.com>
parents: 1352
diff changeset
  1926
                new_qs = []
fbf184c6d55b 1059 search both original input and paths with image root removed
Brock Pytlik <bpytlik@sun.com>
parents: 1352
diff changeset
  1927
                l = query_p.QueryLexer()
fbf184c6d55b 1059 search both original input and paths with image root removed
Brock Pytlik <bpytlik@sun.com>
parents: 1352
diff changeset
  1928
                l.build()
fbf184c6d55b 1059 search both original input and paths with image root removed
Brock Pytlik <bpytlik@sun.com>
parents: 1352
diff changeset
  1929
                qp = query_p.QueryParser(l)
fbf184c6d55b 1059 search both original input and paths with image root removed
Brock Pytlik <bpytlik@sun.com>
parents: 1352
diff changeset
  1930
                for q in query_str_and_args_lst:
fbf184c6d55b 1059 search both original input and paths with image root removed
Brock Pytlik <bpytlik@sun.com>
parents: 1352
diff changeset
  1931
                        try:
fbf184c6d55b 1059 search both original input and paths with image root removed
Brock Pytlik <bpytlik@sun.com>
parents: 1352
diff changeset
  1932
                                query = qp.parse(q.encoded_text())
fbf184c6d55b 1059 search both original input and paths with image root removed
Brock Pytlik <bpytlik@sun.com>
parents: 1352
diff changeset
  1933
                                query_rr = qp.parse(q.encoded_text())
fbf184c6d55b 1059 search both original input and paths with image root removed
Brock Pytlik <bpytlik@sun.com>
parents: 1352
diff changeset
  1934
                                if query_rr.remove_root(self.__img.root):
fbf184c6d55b 1059 search both original input and paths with image root removed
Brock Pytlik <bpytlik@sun.com>
parents: 1352
diff changeset
  1935
                                        query.add_or(query_rr)
fbf184c6d55b 1059 search both original input and paths with image root removed
Brock Pytlik <bpytlik@sun.com>
parents: 1352
diff changeset
  1936
                                        new_qs.append(query_p.Query(str(query),
fbf184c6d55b 1059 search both original input and paths with image root removed
Brock Pytlik <bpytlik@sun.com>
parents: 1352
diff changeset
  1937
                                            q.case_sensitive, q.return_type,
fbf184c6d55b 1059 search both original input and paths with image root removed
Brock Pytlik <bpytlik@sun.com>
parents: 1352
diff changeset
  1938
                                            q.num_to_return, q.start_point))
fbf184c6d55b 1059 search both original input and paths with image root removed
Brock Pytlik <bpytlik@sun.com>
parents: 1352
diff changeset
  1939
                                else:
fbf184c6d55b 1059 search both original input and paths with image root removed
Brock Pytlik <bpytlik@sun.com>
parents: 1352
diff changeset
  1940
                                        new_qs.append(q)
fbf184c6d55b 1059 search both original input and paths with image root removed
Brock Pytlik <bpytlik@sun.com>
parents: 1352
diff changeset
  1941
                        except query_p.BooleanQueryException, e:
fbf184c6d55b 1059 search both original input and paths with image root removed
Brock Pytlik <bpytlik@sun.com>
parents: 1352
diff changeset
  1942
                                raise api_errors.BooleanQueryException(e)
fbf184c6d55b 1059 search both original input and paths with image root removed
Brock Pytlik <bpytlik@sun.com>
parents: 1352
diff changeset
  1943
                        except query_p.ParseError, e:
fbf184c6d55b 1059 search both original input and paths with image root removed
Brock Pytlik <bpytlik@sun.com>
parents: 1352
diff changeset
  1944
                                raise api_errors.ParseError(e)
1569
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  1945
1360
fbf184c6d55b 1059 search both original input and paths with image root removed
Brock Pytlik <bpytlik@sun.com>
parents: 1352
diff changeset
  1946
                query_str_and_args_lst = new_qs
fbf184c6d55b 1059 search both original input and paths with image root removed
Brock Pytlik <bpytlik@sun.com>
parents: 1352
diff changeset
  1947
1191
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  1948
                for pub in servers:
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  1949
                        descriptive_name = None
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 941
diff changeset
  1950
1569
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  1951
                        if self.__canceling:
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  1952
                                raise api_errors.CanceledException()
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  1953
1191
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  1954
                        if isinstance(pub, dict):
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1955
                                origin = pub["origin"]
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1956
                                try:
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
  1957
                                        pub = self.__img.get_publisher(
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1958
                                            origin=origin)
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1959
                                except api_errors.UnknownPublisher:
1191
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  1960
                                        pub = publisher.RepositoryURI(origin)
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  1961
                                        descriptive_name = origin
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  1962
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  1963
                        if not descriptive_name:
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  1964
                                descriptive_name = pub.prefix
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1965
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1966
                        try:
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
  1967
                                res = self.__img.transport.do_search(pub,
1569
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  1968
                                    query_str_and_args_lst,
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  1969
                                    ccancel=self.__check_cancelation)
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  1970
                        except api_errors.CanceledException:
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  1971
                                raise
1191
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  1972
                        except api_errors.NegativeSearchResult:
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  1973
                                continue
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  1974
                        except api_errors.TransportError, e:
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  1975
                                failed.append((descriptive_name, e))
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1976
                                continue
1191
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  1977
                        except api_errors.UnsupportedSearchError, e:
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  1978
                                unsupported.append((descriptive_name, e))
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1979
                                continue
1191
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  1980
                        except api_errors.MalformedSearchRequest, e:
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  1981
                                ex = self._validate_search(
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  1982
                                    query_str_and_args_lst)
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  1983
                                if ex:
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  1984
                                        raise ex
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  1985
                                failed.append((descriptive_name, e))
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1986
                                continue
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1987
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1988
                        try:
1191
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  1989
                                if not self.validate_response(res, 1):
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  1990
                                        invalid.append(descriptive_name)
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  1991
                                        continue
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  1992
                                for line in res:
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  1993
                                        yield self.__parse_v_1(line, pub, 1)
1569
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  1994
                        except api_errors.CanceledException:
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  1995
                                raise
1191
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  1996
                        except api_errors.TransportError, e:
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  1997
                                failed.append((descriptive_name, e))
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1998
                                continue
1191
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  1999
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  2000
                if failed or invalid or unsupported:
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  2001
                        raise api_errors.ProblematicSearchServers(failed,
1191
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  2002
                            invalid, unsupported)
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  2003
1360
fbf184c6d55b 1059 search both original input and paths with image root removed
Brock Pytlik <bpytlik@sun.com>
parents: 1352
diff changeset
  2004
        @staticmethod
fbf184c6d55b 1059 search both original input and paths with image root removed
Brock Pytlik <bpytlik@sun.com>
parents: 1352
diff changeset
  2005
        def __unconvert_return_type(v):
fbf184c6d55b 1059 search both original input and paths with image root removed
Brock Pytlik <bpytlik@sun.com>
parents: 1352
diff changeset
  2006
                return v == query_p.Query.RETURN_ACTIONS
fbf184c6d55b 1059 search both original input and paths with image root removed
Brock Pytlik <bpytlik@sun.com>
parents: 1352
diff changeset
  2007
1191
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  2008
        def _validate_search(self, query_str_lst):
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  2009
                """Called by remote search if server responds that the
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  2010
                request was invalid.  In this case, parse the query on
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  2011
                the client-side and determine what went wrong."""
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  2012
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  2013
                for q in query_str_lst:
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  2014
                        l = query_p.QueryLexer()
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  2015
                        l.build()
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  2016
                        qp = query_p.QueryParser(l)
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  2017
                        try:
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  2018
                                query = qp.parse(q.encoded_text())
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  2019
                        except query_p.BooleanQueryException, e:
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  2020
                                return api_errors.BooleanQueryException(e)
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  2021
                        except query_p.ParseError, e:
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  2022
                                return api_errors.ParseError(e)
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  2023
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  2024
                return None
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  2025
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  2026
        def rebuild_search_index(self):
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  2027
                """Rebuilds the search indexes.  Removes all
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  2028
                existing indexes and replaces them from scratch rather than
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  2029
                performing the incremental update which is usually used.
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  2030
                This is useful for times when the index for the client has
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  2031
                been corrupted."""
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
  2032
                self.__img.update_index_dir()
1027
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
  2033
                self.log_operation_start("rebuild-index")
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
  2034
                if not os.path.isdir(self.__img.index_dir):
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
  2035
                        self.__img.mkdirs()
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  2036
                try:
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
  2037
                        ind = indexer.Indexer(self.__img, self.__img.get_manifest,
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
  2038
                            self.__img.get_manifest_path,
1505
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  2039
                            self.__progresstracker, self.__img.list_excludes())
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  2040
                        ind.rebuild_index_from_scratch(
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
  2041
                            self.__img.gen_installed_pkgs())
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  2042
                except search_errors.ProblematicPermissionsIndexException, e:
1027
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
  2043
                        error = api_errors.ProblematicPermissionsIndexException(e)
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
  2044
                        self.log_operation_end(error=error)
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
  2045
                        raise error
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  2046
                except search_errors.MainDictParsingException, e:
1027
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
  2047
                        error = api_errors.MainDictParsingException(e)
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
  2048
                        self.log_operation_end(error=error)
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
  2049
                        self.__img.cleanup_downloads()
1027
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
  2050
                        raise error
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  2051
                else:
1027
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
  2052
                        self.log_operation_end()
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 941
diff changeset
  2053
1581
37d9bf54ee23 13058 search makes resolve go slow
Brock Pytlik <bpytlik@sun.com>
parents: 1569
diff changeset
  2054
        def get_manifest(self, pfmri, all_variants=True, intent=None):
37d9bf54ee23 13058 search makes resolve go slow
Brock Pytlik <bpytlik@sun.com>
parents: 1569
diff changeset
  2055
                return self.__img.get_manifest(pfmri)
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
  2056
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  2057
        @staticmethod
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  2058
        def validate_response(res, v):
1100
22a8b08d460a 7364 documentation and code comments needed for fix for 6175
Brock Pytlik <bpytlik@sun.com>
parents: 1087
diff changeset
  2059
                """This function is used to determine whether the first
22a8b08d460a 7364 documentation and code comments needed for fix for 6175
Brock Pytlik <bpytlik@sun.com>
parents: 1087
diff changeset
  2060
                line returned from a server is expected.  This ensures that
22a8b08d460a 7364 documentation and code comments needed for fix for 6175
Brock Pytlik <bpytlik@sun.com>
parents: 1087
diff changeset
  2061
                search is really communicating with a search-enabled server."""
22a8b08d460a 7364 documentation and code comments needed for fix for 6175
Brock Pytlik <bpytlik@sun.com>
parents: 1087
diff changeset
  2062
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  2063
                try:
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  2064
                        s = res.next()
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  2065
                        return s == Query.VALIDATION_STRING[v]
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  2066
                except StopIteration:
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  2067
                        return False
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  2068
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2069
        def add_publisher(self, pub, refresh_allowed=True):
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2070
                """Add the provided publisher object to the image
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2071
                configuration."""
1503
78d56b8ee320 12698 download directory must be accessible to non-privileged users
johansen <johansen@sun.com>
parents: 1472
diff changeset
  2072
                try:
78d56b8ee320 12698 download directory must be accessible to non-privileged users
johansen <johansen@sun.com>
parents: 1472
diff changeset
  2073
                        self.__img.add_publisher(pub,
78d56b8ee320 12698 download directory must be accessible to non-privileged users
johansen <johansen@sun.com>
parents: 1472
diff changeset
  2074
                            refresh_allowed=refresh_allowed,
78d56b8ee320 12698 download directory must be accessible to non-privileged users
johansen <johansen@sun.com>
parents: 1472
diff changeset
  2075
                            progtrack=self.__progresstracker)
78d56b8ee320 12698 download directory must be accessible to non-privileged users
johansen <johansen@sun.com>
parents: 1472
diff changeset
  2076
                finally:
78d56b8ee320 12698 download directory must be accessible to non-privileged users
johansen <johansen@sun.com>
parents: 1472
diff changeset
  2077
                        self.__img.cleanup_downloads()
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2078
1505
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  2079
        def get_pub_search_order(self):
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  2080
                """Return current search order of publishers; includes
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  2081
                disabled publishers"""
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  2082
                return self.__img.cfg_cache.publisher_search_order
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  2083
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  2084
        def set_pub_search_after(self, being_moved_prefix, staying_put_prefix):
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  2085
                """Change the publisher search order so that being_moved is
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  2086
                searched after staying_put"""
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  2087
                self.__img.pub_search_after(being_moved_prefix, staying_put_prefix)
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  2088
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  2089
        def set_pub_search_before(self, being_moved_prefix, staying_put_prefix):
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  2090
                """Change the publisher search order so that being_moved is
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  2091
                searched before staying_put"""
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  2092
                self.__img.pub_search_before(being_moved_prefix, staying_put_prefix)
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  2093
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2094
        def get_preferred_publisher(self):
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2095
                """Returns the preferred publisher object for the image."""
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2096
                return self.get_publisher(
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
  2097
                    prefix=self.__img.get_preferred_publisher())
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2098
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2099
        def get_publisher(self, prefix=None, alias=None, duplicate=False):
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2100
                """Retrieves a publisher object matching the provided prefix
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2101
                (name) or alias.
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2102
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2103
                'duplicate' is an optional boolean value indicating whether
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2104
                a copy of the publisher object should be returned instead
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2105
                of the original.
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2106
                """
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
  2107
                pub = self.__img.get_publisher(prefix=prefix, alias=alias)
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2108
                if duplicate:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2109
                        # Never return the original so that changes to the
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2110
                        # retrieved object are not reflected until
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2111
                        # update_publisher is called.
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2112
                        return copy.copy(pub)
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2113
                return pub
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2114
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2115
        def get_publisherdata(self, pub=None, repo=None):
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2116
                """Attempts to retrieve publisher configuration information from
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2117
                the specified publisher's repository or the provided repository.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2118
                If successful, it will either return an empty list (in the case
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2119
                that the repository supports the operation, but doesn't offer
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2120
                configuration information) or a list of Publisher objects.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2121
                If this operation is not supported by the publisher or the
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2122
                specified repository, an UnsupportedRepositoryOperation
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2123
                exception will be raised.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2124
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2125
                'pub' is an optional Publisher object.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2126
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2127
                'repo' is an optional RepositoryURI object.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2128
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2129
                Either 'pub' or 'repo' must be provided."""
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2130
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2131
                assert (pub or repo) and not (pub and repo)
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2132
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2133
                # Transport accepts either type of object, but a distinction is
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2134
                # made in the client API for clarity.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2135
                pub = max(pub, repo)
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2136
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2137
                self.__activity_lock.acquire()
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2138
                try:
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2139
                        self.__enable_cancel()
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2140
                        data = self.__img.transport.get_publisherdata(pub,
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2141
                            ccancel=self.__check_cancelation)
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2142
                        self.__disable_cancel()
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2143
                        return data
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2144
                except api_errors.CanceledException:
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2145
                        self.__cancel_done()
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2146
                        raise
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2147
                except:
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2148
                        self.__cancel_cleanup_exception()
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2149
                        raise
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2150
                finally:
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2151
                        self.__img.cleanup_downloads()
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2152
                        self.__activity_lock.release()
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2153
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2154
        def get_publishers(self, duplicate=False):
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2155
                """Returns a list of the publisher objects for the current
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2156
                image.
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2157
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2158
                'duplicate' is an optional boolean value indicating whether
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2159
                copies of the publisher objects should be returned instead
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2160
                of the originals.
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2161
                """
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2162
                if duplicate:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2163
                        # Return a copy so that changes to the retrieved objects
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2164
                        # are not reflected until update_publisher is called.
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2165
                        pubs = [
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2166
                            copy.copy(p)
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
  2167
                            for p in self.__img.get_publishers().values()
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2168
                        ]
716
b836c1b14137 4639 history result info differs for install and uninstall of nonexistent packages
Brock Pytlik <bpytlik@sun.com>
parents: 707
diff changeset
  2169
                else:
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
  2170
                        pubs = self.__img.get_publishers().values()
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2171
                return misc.get_sorted_publishers(pubs,
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
  2172
                    preferred=self.__img.get_preferred_publisher())
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2173
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2174
        def get_publisher_last_update_time(self, prefix=None, alias=None):
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2175
                """Returns a datetime object representing the last time the
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2176
                catalog for a publisher was modified or None."""
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
  2177
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2178
                if alias:
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
  2179
                        pub = self.get_publisher(alias=alias)
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
  2180
                else:
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
  2181
                        pub = self.get_publisher(prefix=prefix)
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
  2182
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
  2183
                if pub.disabled:
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
  2184
                        return None
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
  2185
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2186
                dt = None
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
  2187
                self.__acquire_activity_lock()
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2188
                try:
1693
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  2189
                        self.__enable_cancel()
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2190
                        try:
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
  2191
                                dt = pub.catalog.last_modified
1032
ff3c6b09f430 8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents: 1027
diff changeset
  2192
                        except:
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2193
                                self.__reset_unlock()
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2194
                                raise
1693
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  2195
                        try:
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  2196
                                self.__disable_cancel()
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  2197
                        except api_errors.CanceledException:
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  2198
                                self.__cancel_done()
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  2199
                                raise
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2200
                finally:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2201
                        self.__activity_lock.release()
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2202
                return dt
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2203
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2204
        def has_publisher(self, prefix=None, alias=None):
1252
3b1b69011fcf 8709 ImageInterface.has_publisher has incorrect docstring
Shawn Walker <srw@sun.com>
parents: 1242
diff changeset
  2205
                """Returns a boolean value indicating whether a publisher using
3b1b69011fcf 8709 ImageInterface.has_publisher has incorrect docstring
Shawn Walker <srw@sun.com>
parents: 1242
diff changeset
  2206
                the given prefix or alias exists."""
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
  2207
                return self.__img.has_publisher(prefix=prefix, alias=alias)
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2208
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2209
        def remove_publisher(self, prefix=None, alias=None):
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2210
                """Removes a publisher object matching the provided prefix
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2211
                (name) or alias."""
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
  2212
                self.__img.remove_publisher(prefix=prefix, alias=alias,
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
  2213
                    progtrack=self.__progresstracker)
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2214
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2215
        def set_preferred_publisher(self, prefix=None, alias=None):
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2216
                """Sets the preferred publisher for the image."""
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
  2217
                self.__img.set_preferred_publisher(prefix=prefix, alias=alias)
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2218
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2219
        def update_publisher(self, pub, refresh_allowed=True):
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2220
                """Replaces an existing publisher object with the provided one
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2221
                using the _source_object_id identifier set during copy.
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2222
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2223
                'refresh_allowed' is an optional boolean value indicating
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2224
                whether a refresh of publisher metadata (such as its catalog)
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2225
                should be performed if transport information is changed for a
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2226
                repository, mirror, or origin.  If False, no attempt will be
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2227
                made to retrieve publisher metadata."""
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2228
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
  2229
                self.__acquire_activity_lock()
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
  2230
                try:
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2231
                        self.__disable_cancel()
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
  2232
                        with self.__img.locked_op("update-publisher"):
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
  2233
                                return self.__update_publisher(pub,
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
  2234
                                    refresh_allowed=refresh_allowed)
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2235
                except api_errors.CanceledException, e:
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2236
                        self.__cancel_done()
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2237
                        raise
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
  2238
                finally:
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
  2239
                        self.__img.cleanup_downloads()
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
  2240
                        self.__activity_lock.release()
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
  2241
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
  2242
        def __update_publisher(self, pub, refresh_allowed=True):
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
  2243
                """Private publisher update method; caller responsible for
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
  2244
                locking."""
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2245
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2246
                if pub.disabled and \
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
  2247
                    pub.prefix == self.__img.get_preferred_publisher():
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2248
                        raise api_errors.SetPreferredPublisherDisabled(
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2249
                            pub.prefix)
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2250
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2251
                def origins_changed(oldr, newr):
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2252
                        old_origins = set([
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2253
                            (o.uri, o.ssl_cert,
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2254
                                o.ssl_key)
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2255
                            for o in oldr.origins
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2256
                        ])
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2257
                        new_origins = set([
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2258
                            (o.uri, o.ssl_cert,
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2259
                                o.ssl_key)
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2260
                            for o in newr.origins
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2261
                        ])
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2262
                        return new_origins - old_origins
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2263
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2264
                def need_refresh(oldo, newo):
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  2265
                        if newo.disabled:
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  2266
                                # The publisher is disabled, so no refresh
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  2267
                                # should be performed.
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  2268
                                return False
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  2269
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2270
                        if oldo.disabled and not newo.disabled:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2271
                                # The publisher has been re-enabled, so
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2272
                                # retrieve the catalog.
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2273
                                return True
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2274
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2275
                        if len(newo.repositories) != len(oldo.repositories):
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2276
                                # If there are an unequal number of repositories
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2277
                                # then some have been added or removed.
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2278
                                return True
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2279
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2280
                        oldr = oldo.selected_repository
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2281
                        newr = newo.selected_repository
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2282
                        if newr._source_object_id != id(oldr):
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2283
                                # Selected repository has changed.
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2284
                                return True
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2285
                        return len(origins_changed(oldr, newr)) != 0
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2286
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 941
diff changeset
  2287
                refresh_catalog = False
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  2288
                disable = False
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  2289
                orig_pub = None
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
  2290
                publishers = self.__img.get_publishers()
1733
7ffa6f902aa0 9218 pkg.client.api should check for cross-alias/prefix duplicates
Shawn Walker <srw@sun.com>
parents: 1710
diff changeset
  2291
7ffa6f902aa0 9218 pkg.client.api should check for cross-alias/prefix duplicates
Shawn Walker <srw@sun.com>
parents: 1710
diff changeset
  2292
                # First, attempt to match the updated publisher object to an
7ffa6f902aa0 9218 pkg.client.api should check for cross-alias/prefix duplicates
Shawn Walker <srw@sun.com>
parents: 1710
diff changeset
  2293
                # existing one using the object id that was stored during
7ffa6f902aa0 9218 pkg.client.api should check for cross-alias/prefix duplicates
Shawn Walker <srw@sun.com>
parents: 1710
diff changeset
  2294
                # copy().
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2295
                for key, old in publishers.iteritems():
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2296
                        if pub._source_object_id == id(old):
1733
7ffa6f902aa0 9218 pkg.client.api should check for cross-alias/prefix duplicates
Shawn Walker <srw@sun.com>
parents: 1710
diff changeset
  2297
                                # Store the new publisher's id and the old
7ffa6f902aa0 9218 pkg.client.api should check for cross-alias/prefix duplicates
Shawn Walker <srw@sun.com>
parents: 1710
diff changeset
  2298
                                # publisher object so it can be restored if the
7ffa6f902aa0 9218 pkg.client.api should check for cross-alias/prefix duplicates
Shawn Walker <srw@sun.com>
parents: 1710
diff changeset
  2299
                                # update operation fails.
7ffa6f902aa0 9218 pkg.client.api should check for cross-alias/prefix duplicates
Shawn Walker <srw@sun.com>
parents: 1710
diff changeset
  2300
                                orig_pub = (id(pub), old)
7ffa6f902aa0 9218 pkg.client.api should check for cross-alias/prefix duplicates
Shawn Walker <srw@sun.com>
parents: 1710
diff changeset
  2301
                                break
7ffa6f902aa0 9218 pkg.client.api should check for cross-alias/prefix duplicates
Shawn Walker <srw@sun.com>
parents: 1710
diff changeset
  2302
7ffa6f902aa0 9218 pkg.client.api should check for cross-alias/prefix duplicates
Shawn Walker <srw@sun.com>
parents: 1710
diff changeset
  2303
                if not orig_pub:
7ffa6f902aa0 9218 pkg.client.api should check for cross-alias/prefix duplicates
Shawn Walker <srw@sun.com>
parents: 1710
diff changeset
  2304
                        # If a matching publisher couldn't be found and
7ffa6f902aa0 9218 pkg.client.api should check for cross-alias/prefix duplicates
Shawn Walker <srw@sun.com>
parents: 1710
diff changeset
  2305
                        # replaced, something is wrong (client api usage
7ffa6f902aa0 9218 pkg.client.api should check for cross-alias/prefix duplicates
Shawn Walker <srw@sun.com>
parents: 1710
diff changeset
  2306
                        # error).
7ffa6f902aa0 9218 pkg.client.api should check for cross-alias/prefix duplicates
Shawn Walker <srw@sun.com>
parents: 1710
diff changeset
  2307
                        raise api_errors.UnknownPublisher(pub)
7ffa6f902aa0 9218 pkg.client.api should check for cross-alias/prefix duplicates
Shawn Walker <srw@sun.com>
parents: 1710
diff changeset
  2308
7ffa6f902aa0 9218 pkg.client.api should check for cross-alias/prefix duplicates
Shawn Walker <srw@sun.com>
parents: 1710
diff changeset
  2309
                # Next, be certain that the publisher's prefix and alias
7ffa6f902aa0 9218 pkg.client.api should check for cross-alias/prefix duplicates
Shawn Walker <srw@sun.com>
parents: 1710
diff changeset
  2310
                # are not already in use by another publisher.
7ffa6f902aa0 9218 pkg.client.api should check for cross-alias/prefix duplicates
Shawn Walker <srw@sun.com>
parents: 1710
diff changeset
  2311
                for key, old in publishers.iteritems():
7ffa6f902aa0 9218 pkg.client.api should check for cross-alias/prefix duplicates
Shawn Walker <srw@sun.com>
parents: 1710
diff changeset
  2312
                        if pub._source_object_id == id(old):
7ffa6f902aa0 9218 pkg.client.api should check for cross-alias/prefix duplicates
Shawn Walker <srw@sun.com>
parents: 1710
diff changeset
  2313
                                # Don't check the object we're replacing.
7ffa6f902aa0 9218 pkg.client.api should check for cross-alias/prefix duplicates
Shawn Walker <srw@sun.com>
parents: 1710
diff changeset
  2314
                                continue
7ffa6f902aa0 9218 pkg.client.api should check for cross-alias/prefix duplicates
Shawn Walker <srw@sun.com>
parents: 1710
diff changeset
  2315
7ffa6f902aa0 9218 pkg.client.api should check for cross-alias/prefix duplicates
Shawn Walker <srw@sun.com>
parents: 1710
diff changeset
  2316
                        if pub.prefix == old.prefix or \
7ffa6f902aa0 9218 pkg.client.api should check for cross-alias/prefix duplicates
Shawn Walker <srw@sun.com>
parents: 1710
diff changeset
  2317
                            pub.prefix == old.alias or \
7ffa6f902aa0 9218 pkg.client.api should check for cross-alias/prefix duplicates
Shawn Walker <srw@sun.com>
parents: 1710
diff changeset
  2318
                            pub.alias and (pub.alias == old.alias or
7ffa6f902aa0 9218 pkg.client.api should check for cross-alias/prefix duplicates
Shawn Walker <srw@sun.com>
parents: 1710
diff changeset
  2319
                            pub.alias == old.prefix):
7ffa6f902aa0 9218 pkg.client.api should check for cross-alias/prefix duplicates
Shawn Walker <srw@sun.com>
parents: 1710
diff changeset
  2320
                                raise api_errors.DuplicatePublisher(pub)
7ffa6f902aa0 9218 pkg.client.api should check for cross-alias/prefix duplicates
Shawn Walker <srw@sun.com>
parents: 1710
diff changeset
  2321
7ffa6f902aa0 9218 pkg.client.api should check for cross-alias/prefix duplicates
Shawn Walker <srw@sun.com>
parents: 1710
diff changeset
  2322
                # Next, determine what needs updating and add the updated
7ffa6f902aa0 9218 pkg.client.api should check for cross-alias/prefix duplicates
Shawn Walker <srw@sun.com>
parents: 1710
diff changeset
  2323
                # publisher.
7ffa6f902aa0 9218 pkg.client.api should check for cross-alias/prefix duplicates
Shawn Walker <srw@sun.com>
parents: 1710
diff changeset
  2324
                for key, old in publishers.iteritems():
7ffa6f902aa0 9218 pkg.client.api should check for cross-alias/prefix duplicates
Shawn Walker <srw@sun.com>
parents: 1710
diff changeset
  2325
                        if pub._source_object_id == id(old):
7ffa6f902aa0 9218 pkg.client.api should check for cross-alias/prefix duplicates
Shawn Walker <srw@sun.com>
parents: 1710
diff changeset
  2326
                                old = orig_pub[-1]
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2327
                                if need_refresh(old, pub):
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2328
                                        refresh_catalog = True
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  2329
                                if not old.disabled and pub.disabled:
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  2330
                                        disable = True
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  2331
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  2332
                                # Now remove the old publisher object using the
1733
7ffa6f902aa0 9218 pkg.client.api should check for cross-alias/prefix duplicates
Shawn Walker <srw@sun.com>
parents: 1710
diff changeset
  2333
                                # iterator key if the prefix has changed.
1505
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  2334
                                if key != pub.prefix:
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  2335
                                        del publishers[key]
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  2336
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
  2337
                                # Prepare the new publisher object.
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
  2338
                                pub.meta_root = \
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
  2339
                                    self.__img._get_publisher_meta_root(
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
  2340
                                    pub.prefix)
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
  2341
                                pub.transport = self.__img.transport
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
  2342
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  2343
                                # Finally, add the new publisher object.
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2344
                                publishers[pub.prefix] = pub
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  2345
                                break
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2346
1102
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1100
diff changeset
  2347
                def cleanup():
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1100
diff changeset
  2348
                        new_id, old_pub = orig_pub
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1100
diff changeset
  2349
                        for new_pfx, new_pub in publishers.iteritems():
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1100
diff changeset
  2350
                                if id(new_pub) == new_id:
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1100
diff changeset
  2351
                                        del publishers[new_pfx]
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1100
diff changeset
  2352
                                        publishers[old_pub.prefix] = old_pub
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1100
diff changeset
  2353
                                        break
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1100
diff changeset
  2354
1504
265a1d6b86bd 9969 client support for multiple origins desired
Shawn Walker <srw@sun.com>
parents: 1503
diff changeset
  2355
                repo = pub.selected_repository
265a1d6b86bd 9969 client support for multiple origins desired
Shawn Walker <srw@sun.com>
parents: 1503
diff changeset
  2356
                if not repo.origins:
265a1d6b86bd 9969 client support for multiple origins desired
Shawn Walker <srw@sun.com>
parents: 1503
diff changeset
  2357
                        raise api_errors.PublisherOriginRequired(pub.prefix)
265a1d6b86bd 9969 client support for multiple origins desired
Shawn Walker <srw@sun.com>
parents: 1503
diff changeset
  2358
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2359
                validate = origins_changed(orig_pub[-1].selected_repository,
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2360
                    pub.selected_repository)
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2361
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  2362
                try:
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  2363
                        if disable:
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  2364
                                # Remove the publisher's metadata (such as
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  2365
                                # catalogs, etc.).  This only needs to be done
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  2366
                                # in the event that a publisher is disabled; in
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  2367
                                # any other case (the origin changing, etc.),
1102
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1100
diff changeset
  2368
                                # refresh() will do the right thing.
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
  2369
                                self.__img.remove_publisher_metadata(pub)
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  2370
                        elif not pub.disabled and not refresh_catalog:
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  2371
                                refresh_catalog = pub.needs_refresh
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2372
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2373
                        if refresh_catalog and refresh_allowed:
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2374
                                # One of the publisher's repository origins may
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2375
                                # have changed, so the publisher needs to be
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2376
                                # revalidated.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2377
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2378
                                if validate:
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
  2379
                                        self.__img.transport.valid_publisher_test(
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
  2380
                                            pub)
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2381
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2382
                                # Validate all new origins against publisher
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2383
                                # configuration.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2384
                                for uri, ssl_cert, ssl_key in validate:
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2385
                                        repo = publisher.RepositoryURI(uri,
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2386
                                            ssl_cert=ssl_cert, ssl_key=ssl_key)
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2387
                                        pub.validate_config(repo)
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2388
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2389
                                self.__refresh(pubs=[pub], immediate=True)
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2390
                        elif refresh_catalog:
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2391
                                # Something has changed (such as a repository
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2392
                                # origin) for the publisher, so a refresh should
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2393
                                # occur, but isn't currently allowed.  As such,
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2394
                                # clear the last_refreshed time so that the next
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2395
                                # time the client checks to see if a refresh is
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2396
                                # needed and is allowed, one will be performed.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2397
                                pub.last_refreshed = None
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2398
                except Exception, e:
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2399
                        # If any of the above fails, the original publisher
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2400
                        # information needs to be restored so that state is
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2401
                        # consistent.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2402
                        cleanup()
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2403
                        raise
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  2404
                except:
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  2405
                        # If any of the above fails, the original publisher
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  2406
                        # information needs to be restored so that state is
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  2407
                        # consistent.
1102
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1100
diff changeset
  2408
                        cleanup()
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  2409
                        raise
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2410
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 941
diff changeset
  2411
                # Successful; so save configuration.
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
  2412
                self.__img.save_config()
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2413
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2414
        def log_operation_end(self, error=None, result=None):
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2415
                """Marks the end of an operation to be recorded in image
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2416
                history.
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2417
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2418
                'result' should be a pkg.client.history constant value
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2419
                representing the outcome of an operation.  If not provided,
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2420
                and 'error' is provided, the final result of the operation will
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2421
                be based on the class of 'error' and 'error' will be recorded
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2422
                for the current operation.  If 'result' and 'error' is not
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2423
                provided, success is assumed."""
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
  2424
                self.__img.history.log_operation_end(error=error, result=result)
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2425
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2426
        def log_operation_error(self, error):
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2427
                """Adds an error to the list of errors to be recorded in image
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2428
                history for the current opreation."""
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
  2429
                self.__img.history.log_operation_error(error)
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2430
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2431
        def log_operation_start(self, name):
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2432
                """Marks the start of an operation to be recorded in image
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2433
                history."""
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
  2434
                self.__img.history.log_operation_start(name)
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2435
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2436
        def parse_p5i(self, data=None, fileobj=None, location=None):
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2437
                """Reads the pkg(5) publisher JSON formatted data at 'location'
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2438
                or from the provided file-like object 'fileobj' and returns a
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2439
                list of tuples of the format (publisher object, pkg_names).
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2440
                pkg_names is a list of strings representing package names or
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2441
                FMRIs.  If any pkg_names not specific to a publisher were
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2442
                provided, the last tuple returned will be of the format (None,
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2443
                pkg_names).
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2444
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2445
                'data' is an optional string containing the p5i data.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2446
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2447
                'fileobj' is an optional file-like object that must support a
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2448
                'read' method for retrieving data.
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2449
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2450
                'location' is an optional string value that should either start
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2451
                with a leading slash and be pathname of a file or a URI string.
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2452
                If it is a URI string, supported protocol schemes are 'file',
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2453
                'ftp', 'http', and 'https'.
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2454
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2455
                'data' or 'fileobj' or 'location' must be provided."""
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2456
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2457
                return p5i.parse(data=data, fileobj=fileobj, location=location)
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2458
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2459
        def write_p5i(self, fileobj, pkg_names=None, pubs=None):
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2460
                """Writes the publisher, repository, and provided package names
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2461
                to the provided file-like object 'fileobj' in JSON p5i format.
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2462
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2463
                'fileobj' is only required to have a 'write' method that accepts
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2464
                data to be written as a parameter.
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2465
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2466
                'pkg_names' is a dict of lists, tuples, or sets indexed by
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2467
                publisher prefix that contain package names, FMRI strings, or
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2468
                package info objects.  A prefix of "" can be used for packages
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2469
                that are not specific to a publisher.
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2470
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2471
                'pubs' is an optional list of publisher prefixes or Publisher
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2472
                objects.  If not provided, the information for all publishers
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2473
                (excluding those disabled) will be output."""
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2474
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2475
                if not pubs:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2476
                        plist = [
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2477
                            p for p in self.get_publishers()
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2478
                            if not p.disabled
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2479
                        ]
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2480
                else:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2481
                        plist = []
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2482
                        for p in pubs:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2483
                                if not isinstance(p, publisher.Publisher):
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
  2484
                                        plist.append(self.__img.get_publisher(
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2485
                                            prefix=p, alias=p))
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2486
                                else:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2487
                                        plist.append(p)
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2488
1257
d911e4542c41 9025 pkg.client.api needs to use p5i module
Shawn Walker <srw@sun.com>
parents: 1256
diff changeset
  2489
                # Transform PackageInfo object entries into PkgFmri entries
d911e4542c41 9025 pkg.client.api needs to use p5i module
Shawn Walker <srw@sun.com>
parents: 1256
diff changeset
  2490
                # before passing them to the p5i module.
d911e4542c41 9025 pkg.client.api needs to use p5i module
Shawn Walker <srw@sun.com>
parents: 1256
diff changeset
  2491
                new_pkg_names = {}
d911e4542c41 9025 pkg.client.api needs to use p5i module
Shawn Walker <srw@sun.com>
parents: 1256
diff changeset
  2492
                for pub in pkg_names:
d911e4542c41 9025 pkg.client.api needs to use p5i module
Shawn Walker <srw@sun.com>
parents: 1256
diff changeset
  2493
                        pkglist = []
d911e4542c41 9025 pkg.client.api needs to use p5i module
Shawn Walker <srw@sun.com>
parents: 1256
diff changeset
  2494
                        for p in pkg_names[pub]:
d911e4542c41 9025 pkg.client.api needs to use p5i module
Shawn Walker <srw@sun.com>
parents: 1256
diff changeset
  2495
                                if isinstance(p, PackageInfo):
d911e4542c41 9025 pkg.client.api needs to use p5i module
Shawn Walker <srw@sun.com>
parents: 1256
diff changeset
  2496
                                        pkglist.append(p.fmri)
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2497
                                else:
1257
d911e4542c41 9025 pkg.client.api needs to use p5i module
Shawn Walker <srw@sun.com>
parents: 1256
diff changeset
  2498
                                        pkglist.append(p)
d911e4542c41 9025 pkg.client.api needs to use p5i module
Shawn Walker <srw@sun.com>
parents: 1256
diff changeset
  2499
                        new_pkg_names[pub] = pkglist
d911e4542c41 9025 pkg.client.api needs to use p5i module
Shawn Walker <srw@sun.com>
parents: 1256
diff changeset
  2500
                p5i.write(fileobj, plist, pkg_names=new_pkg_names)
716
b836c1b14137 4639 history result info differs for install and uninstall of nonexistent packages
Brock Pytlik <bpytlik@sun.com>
parents: 707
diff changeset
  2501
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  2502
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  2503
class Query(query_p.Query):
1100
22a8b08d460a 7364 documentation and code comments needed for fix for 6175
Brock Pytlik <bpytlik@sun.com>
parents: 1087
diff changeset
  2504
        """This class is the object used to pass queries into the api functions.
22a8b08d460a 7364 documentation and code comments needed for fix for 6175
Brock Pytlik <bpytlik@sun.com>
parents: 1087
diff changeset
  2505
        It encapsulates the possible options available for a query as well as
22a8b08d460a 7364 documentation and code comments needed for fix for 6175
Brock Pytlik <bpytlik@sun.com>
parents: 1087
diff changeset
  2506
        the text of the query itself."""
22a8b08d460a 7364 documentation and code comments needed for fix for 6175
Brock Pytlik <bpytlik@sun.com>
parents: 1087
diff changeset
  2507
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  2508
        def __init__(self, text, case_sensitive, return_actions=True,
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  2509
            num_to_return=None, start_point=None):
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  2510
                if return_actions:
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  2511
                        return_type = query_p.Query.RETURN_ACTIONS
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  2512
                else:
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  2513
                        return_type = query_p.Query.RETURN_PACKAGES
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  2514
                query_p.Query.__init__(self, text, case_sensitive, return_type,
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  2515
                    num_to_return, start_point)
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  2516
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  2517
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  2518
class PlanDescription(object):
1618
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  2519
        """A class which describes the changes the plan will make."""
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  2520
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  2521
        def __init__(self, img):
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  2522
                self.__plan = img.imageplan
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  2523
                self.__img = img
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  2524
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  2525
        def get_changes(self):
1618
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  2526
                """A generation function that yields tuples of PackageInfo
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  2527
                objects of the form (src_pi, dest_pi).
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  2528
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  2529
                If 'src_pi' is None, then 'dest_pi' is the package being
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  2530
                installed.
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  2531
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  2532
                If 'src_pi' is not None, and 'dest_pi' is None, 'src_pi'
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  2533
                is the package being removed.
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  2534
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  2535
                If 'src_pi' is not None, and 'dest_pi' is not None,
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  2536
                then 'src_pi' is the original version of the package,
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  2537
                and 'dest_pi' is the new version of the package it is
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  2538
                being upgraded to."""
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  2539
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  2540
                for pp in self.__plan.pkg_plans:
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  2541
                        yield (PackageInfo.build_from_fmri(pp.origin_fmri),
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  2542
                            PackageInfo.build_from_fmri(pp.destination_fmri))
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  2543
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  2544
        def get_licenses(self, pfmri=None):
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  2545
                """A generator function that yields information about the
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  2546
                licenses related to the current plan in tuples of the form
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  2547
                (dest_fmri, src, dest, accepted, displayed) for the given
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  2548
                package FMRI or all packages in the plan.  This is only
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  2549
                available for licenses that are being installed or updated.
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  2550
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  2551
                'dest_fmri' is the FMRI of the package being installed.
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  2552
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  2553
                'src' is a LicenseInfo object if the license of the related
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  2554
                package is being updated; otherwise it is None.
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  2555
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  2556
                'dest' is the LicenseInfo object for the license that is being
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  2557
                installed.
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  2558
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  2559
                'accepted' is a boolean value indicating that the license has
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  2560
                been marked as accepted for the current plan.
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  2561
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  2562
                'displayed' is a boolean value indicating that the license has
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  2563
                been marked as displayed for the current plan."""
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  2564
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  2565
                for pp in self.__plan.pkg_plans:
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  2566
                        dfmri = pp.destination_fmri
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  2567
                        if pfmri and dfmri != pfmri:
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  2568
                                continue
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  2569
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  2570
                        for lid, entry in pp.get_licenses():
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  2571
                                src = entry["src"]
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  2572
                                src_li = None
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  2573
                                if src:
1638
43c8e6c924a3 12852 pkg.server.api should have methods for getting package information
Rajkumar Srinivasan <rajkumar.srinivasan@sun.com>
parents: 1634
diff changeset
  2574
                                        src_li = LicenseInfo(pp.origin_fmri,
43c8e6c924a3 12852 pkg.server.api should have methods for getting package information
Rajkumar Srinivasan <rajkumar.srinivasan@sun.com>
parents: 1634
diff changeset
  2575
                                            src, img=self.__img)
1618
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  2576
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  2577
                                dest = entry["dest"]
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  2578
                                dest_li = None
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  2579
                                if dest:
1638
43c8e6c924a3 12852 pkg.server.api should have methods for getting package information
Rajkumar Srinivasan <rajkumar.srinivasan@sun.com>
parents: 1634
diff changeset
  2580
                                        dest_li = LicenseInfo(
43c8e6c924a3 12852 pkg.server.api should have methods for getting package information
Rajkumar Srinivasan <rajkumar.srinivasan@sun.com>
parents: 1634
diff changeset
  2581
                                            pp.destination_fmri, dest,
43c8e6c924a3 12852 pkg.server.api should have methods for getting package information
Rajkumar Srinivasan <rajkumar.srinivasan@sun.com>
parents: 1634
diff changeset
  2582
                                            img=self.__img)
1618
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  2583
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  2584
                                yield (pp.destination_fmri, src_li, dest_li,
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  2585
                                    entry["accepted"], entry["displayed"])
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  2586
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  2587
                        if pfmri:
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  2588
                                break
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2589
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2590
def image_create(pkg_client_name, version_id, root, imgtype, is_zone,
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2591
    cancel_state_callable=None, facets=misc.EmptyDict, force=False,
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2592
    mirrors=misc.EmptyI, origins=misc.EmptyI, prefix=None, refresh_allowed=True,
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2593
    repo_uri=None, ssl_cert=None, ssl_key=None, user_provided_dir=False,
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2594
    progtrack=None, variants=misc.EmptyDict):
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2595
        """Creates an image at the specified location.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2596
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2597
        'pkg_client_name' is a string containing the name of the client,
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2598
        such as "pkg" or "packagemanager".
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2599
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2600
        'version_id' indicates the version of the api the client is
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2601
        expecting to use.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2602
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2603
        'root' is the absolute path of the directory where the image will
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2604
        be created.  If it does not exist, it will be created.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2605
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2606
        'imgtype' is an IMG_TYPE constant representing the type of image
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2607
        to create.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2608
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2609
        'is_zone' is a boolean value indicating whether the image being
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2610
        created is for a zone.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2611
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2612
        'cancel_state_callable' is an optional function reference that will
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2613
        be called if the cancellable status of an operation changes.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2614
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2615
        'facets' is a dictionary of facet names and values to set during
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2616
        the image creation process.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2617
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2618
        'force' is an optional boolean value indicating that if an image
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2619
        already exists at the specified 'root' that it should be overwritten.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2620
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2621
        'mirrors' is an optional list of URI strings that should be added to
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2622
        all publishers configured during image creation as mirrors.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2623
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2624
        'origins' is an optional list of URI strings that should be added to
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2625
        all publishers configured during image creation as origins.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2626
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2627
        'prefix' is an optional publisher prefix to configure as a publisher
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2628
        for the new image if origins is provided, or to restrict which publisher
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2629
        will be configured if 'repo_uri' is provided.  If this prefix does not
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2630
        match the publisher configuration retrieved from the repository, an
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2631
        UnknownRepositoryPublishers exception will be raised.  If not provided,
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2632
        'refresh_allowed' cannot be False.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2633
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2634
        'refresh_allowed' is an optional boolean value indicating whether
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2635
        publisher configuration data and metadata can be retrieved during
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2636
        image creation.  If False, 'repo_uri' cannot be specified and
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2637
        a 'prefix' must be provided.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2638
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2639
        'repo_uri' is an optional URI string of a package repository to
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2640
        retrieve publisher configuration information from.  If the target
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2641
        repository supports this, all publishers found will be added to the
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2642
        image and any origins or mirrors will be added to all of those
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2643
        publishers.  If the target repository does not support this, and a
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2644
        prefix was not specified, an UnsupportedRepositoryOperation exception
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2645
        will be raised.  If the target repository supports the operation, but
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2646
        does not provide complete configuration information, a
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2647
        RepoPubConfigUnavailable exception will be raised.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2648
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2649
        'ssl_cert' is an optional pathname of an SSL Certificate file to
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2650
        configure all publishers with and to use when retrieving publisher
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2651
        configuration information.  If provided, 'ssl_key' must also be
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2652
        provided.  The certificate file must be pem-encoded.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2653
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2654
        'ssl_key' is an optional pathname of an SSL Key file to configure all
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2655
        publishers with and to use when retrieving publisher configuration
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2656
        information.  If provided, 'ssl_cert' must also be provided.  The
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2657
        key file must be pem-encoded.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2658
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2659
        'user_provided_dir' is an optional boolean value indicating that the
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2660
        provided 'root' was user-supplied and that additional error handling
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2661
        should be enforced.  This primarily affects cases where a relative
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2662
        root has been provided or the root was based on the current working
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2663
        directory.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2664
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2665
        'progtrack' is an optional ProgressTracker object.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2666
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2667
        'variants' is a dictionary of variant names and values to set during
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2668
        the image creation process.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2669
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2670
        Callers must provide one of the following when calling this function:
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2671
         * a 'prefix' and 'repo_uri' (origins and mirrors are optional)
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2672
         * no 'prefix' and a 'repo_uri'  (origins and mirrors are optional)
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2673
         * a 'prefix' and 'origins'
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2674
        """
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2675
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2676
        # Caller must provide a prefix and repository, or no prefix and a
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2677
        # repository, or a prefix and origins.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2678
        assert (prefix and repo_uri) or (not prefix and repo_uri) or (prefix and
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2679
            origins)
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2680
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2681
        # If prefix isn't provided, and refresh isn't allowed, then auto-config
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2682
        # cannot be done.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2683
        assert not repo_uri or (repo_uri and refresh_allowed)
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2684
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2685
        destroy_root = False
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2686
        try:
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2687
                destroy_root = not os.path.exists(root)
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2688
        except EnvironmentError, e:
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2689
                if e.errno == errno.EACCES:
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2690
                        raise api_errors.PermissionsException(
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2691
                            e.filename)
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2692
                raise
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2693
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2694
        # The image object must be created first since transport may be
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2695
        # needed to retrieve publisher configuration information.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2696
        img = image.Image(root, force=force, imgtype=imgtype,
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2697
            progtrack=progtrack, should_exist=False,
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2698
            user_provided_dir=user_provided_dir)
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2699
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2700
        api_inst = ImageInterface(img, version_id,
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2701
            progtrack, cancel_state_callable, pkg_client_name)
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2702
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2703
        try:
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2704
                if repo_uri:
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2705
                        # Assume auto configuration.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2706
                        repo = publisher.RepositoryURI(repo_uri,
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2707
                            ssl_cert=ssl_cert, ssl_key=ssl_key)
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2708
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2709
                        pubs = None
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2710
                        try:
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2711
                                pubs = api_inst.get_publisherdata(repo=repo)
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2712
                        except api_errors.UnsupportedRepositoryOperation:
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2713
                                if not prefix:
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2714
                                        raise api_errors.RepoPubConfigUnavailable(
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2715
                                            location=repo_uri)
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2716
                                # For a v0 repo where a prefix was specified,
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2717
                                # fallback to manual configuration.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2718
                                if not origins:
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2719
                                        origins = [repo_uri]
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2720
                                repo_uri = None
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2721
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2722
                        if not prefix and not pubs:
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2723
                                # Empty repository configuration.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2724
                                raise api_errors.RepoPubConfigUnavailable(
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2725
                                    location=repo_uri)
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2726
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2727
                        if repo_uri:
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2728
                                for p in pubs:
1795
1b3bed835773 14856 image-create / set-publisher shouldn't require repository configuration to have origins
Shawn Walker <srw@sun.com>
parents: 1764
diff changeset
  2729
                                        psrepo = p.selected_repository
1b3bed835773 14856 image-create / set-publisher shouldn't require repository configuration to have origins
Shawn Walker <srw@sun.com>
parents: 1764
diff changeset
  2730
                                        if not psrepo:
1b3bed835773 14856 image-create / set-publisher shouldn't require repository configuration to have origins
Shawn Walker <srw@sun.com>
parents: 1764
diff changeset
  2731
                                                # Repository configuration info
1b3bed835773 14856 image-create / set-publisher shouldn't require repository configuration to have origins
Shawn Walker <srw@sun.com>
parents: 1764
diff changeset
  2732
                                                # was not provided, so assume
1b3bed835773 14856 image-create / set-publisher shouldn't require repository configuration to have origins
Shawn Walker <srw@sun.com>
parents: 1764
diff changeset
  2733
                                                # origin is repo_uri.
1b3bed835773 14856 image-create / set-publisher shouldn't require repository configuration to have origins
Shawn Walker <srw@sun.com>
parents: 1764
diff changeset
  2734
                                                p.add_repository(
1b3bed835773 14856 image-create / set-publisher shouldn't require repository configuration to have origins
Shawn Walker <srw@sun.com>
parents: 1764
diff changeset
  2735
                                                    publisher.Repository(
1b3bed835773 14856 image-create / set-publisher shouldn't require repository configuration to have origins
Shawn Walker <srw@sun.com>
parents: 1764
diff changeset
  2736
                                                    origins=[repo_uri]))
1b3bed835773 14856 image-create / set-publisher shouldn't require repository configuration to have origins
Shawn Walker <srw@sun.com>
parents: 1764
diff changeset
  2737
                                        elif not psrepo.origins:
1b3bed835773 14856 image-create / set-publisher shouldn't require repository configuration to have origins
Shawn Walker <srw@sun.com>
parents: 1764
diff changeset
  2738
                                                # Repository configuration was
1b3bed835773 14856 image-create / set-publisher shouldn't require repository configuration to have origins
Shawn Walker <srw@sun.com>
parents: 1764
diff changeset
  2739
                                                # provided, but without an
1b3bed835773 14856 image-create / set-publisher shouldn't require repository configuration to have origins
Shawn Walker <srw@sun.com>
parents: 1764
diff changeset
  2740
                                                # origin.  Assume the repo_uri
1b3bed835773 14856 image-create / set-publisher shouldn't require repository configuration to have origins
Shawn Walker <srw@sun.com>
parents: 1764
diff changeset
  2741
                                                # is the origin.
1b3bed835773 14856 image-create / set-publisher shouldn't require repository configuration to have origins
Shawn Walker <srw@sun.com>
parents: 1764
diff changeset
  2742
                                                psrepo.add_origin(repo_uri)
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2743
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2744
                if prefix and not repo_uri:
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2745
                        # Auto-configuration not possible or not requested.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2746
                        repo = publisher.Repository()
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2747
                        for o in origins:
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2748
                                repo.add_origin(o)
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2749
                        for m in mirrors:
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2750
                                repo.add_mirror(m)
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2751
                        pub = publisher.Publisher(prefix,
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2752
                            repositories=[repo])
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2753
                        pubs = [pub]
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2754
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2755
                if prefix and prefix not in pubs:
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2756
                        # If publisher prefix requested isn't found in the list
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2757
                        # of publishers at this point, then configuration isn't
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2758
                        # possible.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2759
                        known = [p.prefix for p in pubs]
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2760
                        raise api_errors.UnknownRepositoryPublishers(
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2761
                            known=known, unknown=[prefix], location=repo_uri)
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2762
                elif prefix:
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2763
                        # Filter out any publishers that weren't requested.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2764
                        pubs = [
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2765
                            p for p in pubs
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2766
                            if p.prefix == prefix
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2767
                        ]
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2768
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2769
                # Add additional origins and mirrors that weren't found in the
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2770
                # publisher configuration if provided.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2771
                for p in pubs:
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2772
                        pr = p.selected_repository
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2773
                        for o in origins:
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2774
                                if not pr.has_origin(o):
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2775
                                        pr.add_origin(o)
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2776
                        for m in mirrors:
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2777
                                if not pr.has_mirror(m):
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2778
                                        pr.add_mirror(m)
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2779
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2780
                # Set provided SSL Cert/Key for all configured publishers.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2781
                for p in pubs:
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2782
                        repo = p.selected_repository
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2783
                        for o in repo.origins:
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2784
                                o.ssl_cert = ssl_cert
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2785
                                o.ssl_key = ssl_key
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2786
                        for m in repo.mirrors:
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2787
                                m.ssl_cert = ssl_cert
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2788
                                m.ssl_key = ssl_key
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2789
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2790
                img.create(pubs, facets=facets, is_zone=is_zone,
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2791
                    progtrack=progtrack, refresh_allowed=refresh_allowed,
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2792
                    variants=variants)
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2793
        except EnvironmentError, e:
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2794
                if e.errno == errno.EACCES:
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2795
                        raise api_errors.PermissionsException(
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2796
                            e.filename)
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2797
                if e.errno == errno.EROFS:
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2798
                        raise api_errors.ReadOnlyFileSystemException(
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2799
                            e.filename)
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2800
                raise
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2801
        except:
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2802
                # Ensure a defunct image isn't left behind.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2803
                img.destroy()
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2804
                if destroy_root and \
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2805
                    os.path.abspath(root) != "/" and \
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2806
                    os.path.exists(root):
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2807
                        # Root didn't exist before create and isn't '/',
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2808
                        # so remove it.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2809
                        shutil.rmtree(root, True)
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2810
                raise
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2811
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2812
        img.cleanup_downloads()
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2813
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2814
        return api_inst
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2815