src/modules/client/api.py
author Bart Smaalders <Bart.Smaalders@Oracle.COM>
Wed, 26 Jan 2011 21:41:55 -0800
changeset 2200 155eda704b2f
parent 2183 21ae45e8dfcf
child 2205 53d0be594162
permissions -rw-r--r--
16279 Need a way to revert certain editable files to a as-installed state 17775 introduction of system/volatile breaks device action tests
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
#
2183
21ae45e8dfcf 17581 There should be a way of removing a package as part of upgrade
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2158
diff changeset
    24
# Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 941
diff changeset
    25
#
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    26
1638
43c8e6c924a3 12852 pkg.server.api should have methods for getting package information
Rajkumar Srinivasan <rajkumar.srinivasan@sun.com>
parents: 1634
diff changeset
    27
"""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
    28
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
    29
2089
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
    30
Refer to pkg.api_common for additional core class documentation.
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
    31
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
    32
Consumers should catch ApiException when calling any API function, and
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
    33
may optionally catch any subclass of ApiException for further, specific
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
    34
error handling.
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
    35
"""
1638
43c8e6c924a3 12852 pkg.server.api should have methods for getting package information
Rajkumar Srinivasan <rajkumar.srinivasan@sun.com>
parents: 1634
diff changeset
    36
1853
8f8a90301844 15234 "pkg list -a" doesn't account for pattern versions
Shawn Walker <shawn.walker@oracle.com>
parents: 1843
diff changeset
    37
import collections
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
    38
import copy
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
    39
import errno
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
    40
import fnmatch
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 941
diff changeset
    41
import os
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
    42
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
    43
import sys
1569
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
    44
import threading
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
    45
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
    46
1019
e61c57c724c9 7663 disable_fmri should be synchronous
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 996
diff changeset
    47
import pkg.client.actuator as actuator
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
    48
import pkg.client.api_errors as apx
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
    49
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
    50
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
    51
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
    52
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
    53
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
    54
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
    55
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
    56
import pkg.fmri as fmri
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
    57
import pkg.misc as misc
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
    58
import pkg.nrlock
1257
d911e4542c41 9025 pkg.client.api needs to use p5i module
Shawn Walker <srw@sun.com>
parents: 1256
diff changeset
    59
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
    60
import pkg.search_errors as search_errors
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
    61
import pkg.version
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
    62
1638
43c8e6c924a3 12852 pkg.server.api should have methods for getting package information
Rajkumar Srinivasan <rajkumar.srinivasan@sun.com>
parents: 1634
diff changeset
    63
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
    64
    _get_pkg_cat_data)
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
    65
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
    66
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
    67
2200
155eda704b2f 16279 Need a way to revert certain editable files to a as-installed state
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2183
diff changeset
    68
CURRENT_API_VERSION = 50
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
    69
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
    70
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
    71
# Image type constants.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
    72
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
    73
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
    74
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
    75
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
    76
1431
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1389
diff changeset
    77
logger = global_settings.logger
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1389
diff changeset
    78
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    79
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
    80
        """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
    81
        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
    82
        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
    83
        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
    84
        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
    85
        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
    86
        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
    87
        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
    88
        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
    89
        running."""
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    90
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    91
        # 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
    92
        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
    93
        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
    94
        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
    95
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
    96
        LIST_ALL = 0
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
    97
        LIST_INSTALLED = 1
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
    98
        LIST_INSTALLED_NEWEST = 2
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
    99
        LIST_NEWEST = 3
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   100
        LIST_UPGRADABLE = 4
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   101
1835
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
   102
        MATCH_EXACT = 0
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
   103
        MATCH_FMRI = 1
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
   104
        MATCH_GLOB = 2
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
   105
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   106
        # Private constants used for tracking which type of plan was made.
2200
155eda704b2f 16279 Need a way to revert certain editable files to a as-installed state
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2183
diff changeset
   107
        __INSTALL   = 1
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   108
        __UNINSTALL = 2
2200
155eda704b2f 16279 Need a way to revert certain editable files to a as-installed state
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2183
diff changeset
   109
        __UPDATE    = 3
155eda704b2f 16279 Need a way to revert certain editable files to a as-installed state
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2183
diff changeset
   110
        __VARCET    = 4
155eda704b2f 16279 Need a way to revert certain editable files to a as-installed state
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2183
diff changeset
   111
        __REVERT    = 5
155eda704b2f 16279 Need a way to revert certain editable files to a as-installed state
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2183
diff changeset
   112
        __valid_plan_types = (1, 2, 3, 4, 5)
155eda704b2f 16279 Need a way to revert certain editable files to a as-installed state
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2183
diff changeset
   113
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
   114
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
   115
        def __init__(self, img_path, version_id, progresstracker,
2158
5a688b5b92a3 15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents: 2144
diff changeset
   116
            cancel_state_callable, pkg_client_name, exact_match=True):
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   117
                """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
   118
2158
5a688b5b92a3 15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents: 2144
diff changeset
   119
                'img_path' is the absolute path to an existing image or to a
5a688b5b92a3 15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents: 2144
diff changeset
   120
                path from which to start looking for an image.  To control this
5a688b5b92a3 15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents: 2144
diff changeset
   121
                behaviour use the 'exact_match' parameter.
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
   122
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   123
                '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
   124
                expecting to use.
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   125
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   126
                '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
   127
                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
   128
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
   129
                '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
   130
                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
   131
                changes.
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   132
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
   133
                'pkg_client_name' is a string containing the name of the client,
2158
5a688b5b92a3 15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents: 2144
diff changeset
   134
                such as "pkg" or "packagemanager".
5a688b5b92a3 15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents: 2144
diff changeset
   135
5a688b5b92a3 15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents: 2144
diff changeset
   136
                'exact_match' is a boolean indicating whether the API should
5a688b5b92a3 15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents: 2144
diff changeset
   137
                attempt to find a usable image starting from the specified
5a688b5b92a3 15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents: 2144
diff changeset
   138
                directory, going up to the filesystem root until it finds one.
5a688b5b92a3 15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents: 2144
diff changeset
   139
                If set to True, an image must exist at the location indicated
5a688b5b92a3 15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents: 2144
diff changeset
   140
                by 'img_path'.  If set to False for a client running on the
5a688b5b92a3 15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents: 2144
diff changeset
   141
                Solaris platform, an ImageLocationAmbiguous exception will be
5a688b5b92a3 15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents: 2144
diff changeset
   142
                raised if an image is found somewhere other than '/'.  For all
5a688b5b92a3 15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents: 2144
diff changeset
   143
                other platforms, a value of False will allow any image location.
5a688b5b92a3 15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents: 2144
diff changeset
   144
                """
5a688b5b92a3 15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents: 2144
diff changeset
   145
2200
155eda704b2f 16279 Need a way to revert certain editable files to a as-installed state
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2183
diff changeset
   146
                compatible_versions = set([46, 47, 48, 49, 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
   147
598
c53f6107fdb6 2863 pkg install should have a way to disable indexing
Brock Pytlik <bpytlik@sun.com>
parents: 594
diff changeset
   148
                if version_id not in compatible_versions:
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
   149
                        raise apx.VersionException(CURRENT_API_VERSION,
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   150
                            version_id)
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   151
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
   152
                # 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
   153
                # 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
   154
                # 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
   155
                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
   156
                        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
   157
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
   158
                if isinstance(img_path, basestring):
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
   159
                        # Store this for reset().
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
   160
                        self.__img_path = img_path
1370
face1fe579ab 11400 image objects should always have a root
Brock Pytlik <bpytlik@sun.com>
parents: 1360
diff changeset
   161
                        self.__img = image.Image(img_path,
2158
5a688b5b92a3 15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents: 2144
diff changeset
   162
                            progtrack=progresstracker,
5a688b5b92a3 15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents: 2144
diff changeset
   163
                            user_provided_dir=exact_match)
5a688b5b92a3 15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents: 2144
diff changeset
   164
5a688b5b92a3 15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents: 2144
diff changeset
   165
                        # Store final image path.
5a688b5b92a3 15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents: 2144
diff changeset
   166
                        self.__img_path = self.__img.get_root()
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
   167
                elif isinstance(img_path, image.Image):
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
   168
                        # 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
   169
                        # until the image api is complete.
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
   170
                        self.__img = img_path
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
   171
                        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
   172
                else:
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
   173
                        # 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
   174
                        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
   175
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
   176
                self.__progresstracker = progresstracker
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
   177
                self.__cancel_state_callable = cancel_state_callable
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
   178
                self.__plan_type = None
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
   179
                self.__plan_desc = None
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
   180
                self.__prepared = False
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
   181
                self.__executed = False
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
   182
                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
   183
                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
   184
                self.__canceling = False
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   185
                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
   186
                self.__blocking_locks = False
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   187
                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
   188
                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
   189
                self.__cancel_cv = threading.Condition(self.__cancel_lock)
2034
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
   190
                self.__new_be = None # create if needed
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   191
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   192
        def __set_blocking_locks(self, value):
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   193
                self.__activity_lock.acquire()
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   194
                self.__blocking_locks = value
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   195
                self.__img.blocking_locks = value
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   196
                self.__activity_lock.release()
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   197
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   198
        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
   199
            __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
   200
            "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
   201
            "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
   202
            "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
   203
            "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
   204
            "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
   205
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
   206
        @property
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
   207
        def excludes(self):
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
   208
                """The list of excludes for the image."""
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
   209
                return self.__img.list_excludes()
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
   210
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
   211
        @property
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
   212
        def img(self):
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
   213
                """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
   214
                a later date.  Do not use."""
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
   215
                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
   216
1255
13914487fd06 8854 access to ImageInterface img root desired
Shawn Walker <srw@sun.com>
parents: 1254
diff changeset
   217
        @property
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
   218
        def img_type(self):
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
   219
                """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
   220
                if not self.__img:
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
   221
                        return None
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
   222
                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
   223
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
   224
        @property
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
   225
        def is_zone(self):
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
   226
                """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
   227
                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
   228
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
   229
        @property
2073
9fcacc9e5eaa 16998 transport should support publisher-specific write and read caches
Shawn Walker <shawn.walker@oracle.com>
parents: 2055
diff changeset
   230
        def last_modified(self):
9fcacc9e5eaa 16998 transport should support publisher-specific write and read caches
Shawn Walker <shawn.walker@oracle.com>
parents: 2055
diff changeset
   231
                """A datetime object representing when the image's metadata was
9fcacc9e5eaa 16998 transport should support publisher-specific write and read caches
Shawn Walker <shawn.walker@oracle.com>
parents: 2055
diff changeset
   232
                last updated."""
9fcacc9e5eaa 16998 transport should support publisher-specific write and read caches
Shawn Walker <shawn.walker@oracle.com>
parents: 2055
diff changeset
   233
9fcacc9e5eaa 16998 transport should support publisher-specific write and read caches
Shawn Walker <shawn.walker@oracle.com>
parents: 2055
diff changeset
   234
                return self.__img.get_last_modified()
9fcacc9e5eaa 16998 transport should support publisher-specific write and read caches
Shawn Walker <shawn.walker@oracle.com>
parents: 2055
diff changeset
   235
2158
5a688b5b92a3 15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents: 2144
diff changeset
   236
        def __set_progresstracker(self, value):
5a688b5b92a3 15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents: 2144
diff changeset
   237
                self.__activity_lock.acquire()
5a688b5b92a3 15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents: 2144
diff changeset
   238
                self.__progresstracker = value
5a688b5b92a3 15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents: 2144
diff changeset
   239
                self.__activity_lock.release()
5a688b5b92a3 15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents: 2144
diff changeset
   240
5a688b5b92a3 15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents: 2144
diff changeset
   241
        progresstracker = property(lambda self: self.__progresstracker,
5a688b5b92a3 15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents: 2144
diff changeset
   242
            __set_progresstracker, doc="The current ProgressTracker object.  "
5a688b5b92a3 15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents: 2144
diff changeset
   243
            "This value should only be set when no other API calls are in "
5a688b5b92a3 15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents: 2144
diff changeset
   244
            "progress.")
5a688b5b92a3 15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents: 2144
diff changeset
   245
2073
9fcacc9e5eaa 16998 transport should support publisher-specific write and read caches
Shawn Walker <shawn.walker@oracle.com>
parents: 2055
diff changeset
   246
        @property
1255
13914487fd06 8854 access to ImageInterface img root desired
Shawn Walker <srw@sun.com>
parents: 1254
diff changeset
   247
        def root(self):
13914487fd06 8854 access to ImageInterface img root desired
Shawn Walker <srw@sun.com>
parents: 1254
diff changeset
   248
                """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
   249
                This property is read-only."""
13914487fd06 8854 access to ImageInterface img root desired
Shawn Walker <srw@sun.com>
parents: 1254
diff changeset
   250
                if not self.__img:
13914487fd06 8854 access to ImageInterface img root desired
Shawn Walker <srw@sun.com>
parents: 1254
diff changeset
   251
                        return None
13914487fd06 8854 access to ImageInterface img root desired
Shawn Walker <srw@sun.com>
parents: 1254
diff changeset
   252
                return self.__img.root
13914487fd06 8854 access to ImageInterface img root desired
Shawn Walker <srw@sun.com>
parents: 1254
diff changeset
   253
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
   254
        @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
   255
        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
   256
                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
   257
                return True
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
   258
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   259
        def __cert_verify(self, log_op_end=None):
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
   260
                """Verify validity of certificates.  Any apx.ExpiringCertificate
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
   261
                exceptions are caught here, a message is displayed, and
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
   262
                execution continues.
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
   263
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
   264
                All other exceptions will be passed to the calling context.
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
   265
                The caller can also set log_op_end to a list of exceptions
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
   266
                that should result in a call to self.log_operation_end()
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
   267
                before the exception is passed on.
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
   268
                """
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   269
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   270
                if log_op_end == None:
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   271
                        log_op_end = []
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   272
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
   273
                # we always explicitly handle apx.ExpiringCertificate
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
   274
                assert apx.ExpiringCertificate not in log_op_end
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   275
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   276
                try:
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   277
                        self.__img.check_cert_validity()
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
   278
                except apx.ExpiringCertificate, e:
1431
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1389
diff changeset
   279
                        logger.error(e)
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   280
                except:
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   281
                        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
   282
                        if exc_type in log_op_end:
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   283
                                self.log_operation_end(error=exc_value)
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   284
                        raise
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   285
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
   286
        def __refresh_publishers(self):
2144
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2141
diff changeset
   287
                """Refresh publisher metadata; this should only be used by
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2141
diff changeset
   288
                functions in this module for implicit refresh cases."""
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   289
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   290
                #
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   291
                # Verify validity of certificates before possibly
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   292
                # attempting network operations.
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   293
                #
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   294
                self.__cert_verify()
2144
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2141
diff changeset
   295
                try:
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2141
diff changeset
   296
                        self.__img.refresh_publishers(immediate=True,
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2141
diff changeset
   297
                            progtrack=self.__progresstracker)
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2141
diff changeset
   298
                except apx.ImageFormatUpdateNeeded:
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2141
diff changeset
   299
                        # If image format update is needed to perform refresh,
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2141
diff changeset
   300
                        # continue on and allow failure to happen later since
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2141
diff changeset
   301
                        # an implicit refresh failing for this reason isn't
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2141
diff changeset
   302
                        # important.  (This allows planning installs and updates
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2141
diff changeset
   303
                        # before the format of an image is updated.  Yes, this
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2141
diff changeset
   304
                        # means that if the refresh was needed to do that, then
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2141
diff changeset
   305
                        # this isn't useful, but this is as good as it gets.)
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2141
diff changeset
   306
                        logger.warning(_("Skipping publisher metadata refresh;"
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2141
diff changeset
   307
                            "image rooted at %s must have its format updated "
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2141
diff changeset
   308
                            "before a refresh can occur.") % self.__img.root)
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   309
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   310
        def __acquire_activity_lock(self):
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   311
                """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
   312
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   313
                rc = self.__activity_lock.acquire(
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   314
                    blocking=self.__blocking_locks)
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   315
                if not rc:
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
   316
                        raise apx.ImageLockedError()
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   317
2034
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
   318
        def __plan_common_start(self, operation, noexecute, new_be, be_name):
2183
21ae45e8dfcf 17581 There should be a way of removing a package as part of upgrade
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2158
diff changeset
   319
                """Start planning an operation:
2034
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
   320
                    Acquire locks.
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
   321
                    Log the start of the operation.
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
   322
                    Check be_name."""
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   323
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   324
                self.__acquire_activity_lock()
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   325
                try:
1693
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
   326
                        self.__enable_cancel()
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   327
                        if self.__plan_type is not None:
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
   328
                                raise apx.PlanExistsException(
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   329
                                    self.__plan_type)
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   330
                        self.__img.lock(allow_unprivileged=noexecute)
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   331
                except:
1764
478a51c88bfe 14533 Nasty depot needs some love
johansen <johansen@sun.com>
parents: 1755
diff changeset
   332
                        self.__cancel_cleanup_exception()
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   333
                        self.__activity_lock.release()
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   334
                        raise
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   335
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   336
                assert self.__activity_lock._is_owned()
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   337
                self.log_operation_start(operation)
2034
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
   338
                self.__new_be = new_be
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
   339
                self.__be_name = be_name
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
   340
                if self.__be_name is not None:
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
   341
                        self.check_be_name(be_name)
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
   342
                        if not self.__img.is_liveroot():
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
   343
                                raise apx.BENameGivenOnDeadBE(self.__be_name)
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   344
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   345
        def __plan_common_finish(self):
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   346
                """Finish planning an operation."""
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   347
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   348
                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
   349
                self.__img.cleanup_downloads()
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   350
                self.__img.unlock()
1895
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1893
diff changeset
   351
                try:
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1893
diff changeset
   352
                        if int(os.environ.get("PKG_DUMP_STATS", 0)) > 0:
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1893
diff changeset
   353
                                self.__img.transport.stats.dump()
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1893
diff changeset
   354
                except ValueError:
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1893
diff changeset
   355
                        # Don't generate stats if an invalid value
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1893
diff changeset
   356
                        # is supplied.
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1893
diff changeset
   357
                        pass
2034
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
   358
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   359
                self.__activity_lock.release()
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   360
2034
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
   361
        def __set_new_be(self):
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
   362
                """Figure out whether or not we'd create a new boot environment
2183
21ae45e8dfcf 17581 There should be a way of removing a package as part of upgrade
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2158
diff changeset
   363
                given inputs and plan.  Toss cookies if we need a new be and
2034
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
   364
                can't have one."""
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
   365
                # decide whether or not to create new BE.
2089
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   366
2034
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
   367
                if self.__img.is_liveroot():
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
   368
                        if self.__new_be is None:
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
   369
                                self.__new_be = self.__img.imageplan.reboot_needed()
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
   370
                        elif self.__new_be is False and \
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
   371
                            self.__img.imageplan.reboot_needed():
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
   372
                                raise apx.ImageUpdateOnLiveImageException()
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
   373
                else:
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
   374
                        self.__new_be = False
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
   375
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   376
        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
   377
                """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
   378
                operation.  Any exceptions generated here are passed
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   379
                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
   380
                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
   381
                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
   382
                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
   383
                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
   384
                log_op_end."""
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   385
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   386
                if log_op_end == None:
2034
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
   387
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   388
                        log_op_end = []
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   389
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
   390
                # we always explicity handle apx.PlanCreationException
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
   391
                assert apx.PlanCreationException not in log_op_end
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   392
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   393
                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
   394
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
   395
                if exc_type == apx.PlanCreationException:
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   396
                        self.__set_history_PlanCreationException(exc_value)
2034
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
   397
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
   398
                elif exc_type == apx.CanceledException:
1569
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
   399
                        self.__cancel_done()
1346
c4d21b460a66 10539 Package Manager hangs after canceling Update All
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1337
diff changeset
   400
                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
   401
                        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
   402
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
   403
                if exc_type != apx.ImageLockedError:
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   404
                        # 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
   405
                        # 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
   406
                        self.__img.unlock()
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   407
1895
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1893
diff changeset
   408
                try:
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1893
diff changeset
   409
                        if int(os.environ.get("PKG_DUMP_STATS", 0)) > 0:
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1893
diff changeset
   410
                                self.__img.transport.stats.dump()
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1893
diff changeset
   411
                except ValueError:
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1893
diff changeset
   412
                        # Don't generate stats if an invalid value
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1893
diff changeset
   413
                        # is supplied.
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1893
diff changeset
   414
                        pass
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1893
diff changeset
   415
1346
c4d21b460a66 10539 Package Manager hangs after canceling Update All
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1337
diff changeset
   416
                self.__reset_unlock()
c4d21b460a66 10539 Package Manager hangs after canceling Update All
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1337
diff changeset
   417
                self.__activity_lock.release()
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   418
                raise
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   419
1505
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
   420
        def plan_install(self, pkg_list, refresh_catalogs=True,
2183
21ae45e8dfcf 17581 There should be a way of removing a package as part of upgrade
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2158
diff changeset
   421
            noexecute=False, update_index=True, be_name=None,
21ae45e8dfcf 17581 There should be a way of removing a package as part of upgrade
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2158
diff changeset
   422
            reject_list=misc.EmptyI, new_be=False):
2089
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   423
                """Constructs a plan to install the packages provided in
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   424
                pkg_list.  Once an operation has been planned, it may be
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   425
                executed by first calling prepare(), and then execute_plan().
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   426
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   427
                'pkg_list' is a list of packages to install.
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   428
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   429
                'refresh_catalogs' controls whether the catalogs will
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   430
                automatically be refreshed.
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   431
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   432
                'noexecute' determines whether the resulting plan can be
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   433
                executed and whether history will be recorded after
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   434
                planning is finished.
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   435
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   436
                'update_index' determines whether client search indexes
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   437
                will be updated after operation completion during plan
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   438
                execution.
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   439
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   440
                'be_name' is a string to use as the name of any new boot
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   441
                environment created during the operation.
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   442
2183
21ae45e8dfcf 17581 There should be a way of removing a package as part of upgrade
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2158
diff changeset
   443
                'reject_list' is a list of patterns not to be permitted
21ae45e8dfcf 17581 There should be a way of removing a package as part of upgrade
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2158
diff changeset
   444
                in solution; installed packages matching these patterns
21ae45e8dfcf 17581 There should be a way of removing a package as part of upgrade
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2158
diff changeset
   445
                are removed.
21ae45e8dfcf 17581 There should be a way of removing a package as part of upgrade
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2158
diff changeset
   446
2089
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   447
                'new_be' indicates whether a new boot environment should be
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   448
                created during the operation.  If True, a new boot environment
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   449
                will be created.  If False, and a new boot environment is
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   450
                needed, an ImageUpdateOnLiveImageException will be raised.
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   451
                If None, a new boot environment will be created only if needed.
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   452
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   453
                This function returns a boolean indicating whether there is
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   454
                anything to do."""
2034
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
   455
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
   456
                self.__plan_common_start("install", noexecute, new_be, 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
   457
                try:
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
   458
                        if refresh_catalogs:
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
   459
                                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
   460
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   461
                        self.__img.make_install_plan(pkg_list,
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   462
                            self.__progresstracker,
2183
21ae45e8dfcf 17581 There should be a way of removing a package as part of upgrade
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2158
diff changeset
   463
                            self.__check_cancelation, noexecute,
21ae45e8dfcf 17581 There should be a way of removing a package as part of upgrade
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2158
diff changeset
   464
                            reject_list=reject_list)
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   465
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   466
                        assert self.__img.imageplan
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   467
1569
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
   468
                        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
   469
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   470
                        if not noexecute:
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   471
                                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
   472
2034
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
   473
                        self.__set_new_be()
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
   474
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
   475
                        self.__plan_desc = PlanDescription(self.__img, self.__new_be)
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   476
                        if self.__img.imageplan.nothingtodo() or noexecute:
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   477
                                self.log_operation_end(
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   478
                                    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
   479
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   480
                        self.__img.imageplan.update_index = update_index
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   481
                except:
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   482
                        self.__plan_common_exception(log_op_end=[
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
   483
                            apx.CanceledException, fmri.IllegalFmri,
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   484
                            Exception])
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   485
                        # NOTREACHED
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
   486
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   487
                self.__plan_common_finish()
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   488
                res = not self.__img.imageplan.nothingtodo()
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   489
                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
   490
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   491
        def plan_uninstall(self, pkg_list, recursive_removal, noexecute=False,
2034
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
   492
            update_index=True, be_name=None, new_be=False):
2089
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   493
                """Constructs a plan to remove the packages provided in
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   494
                pkg_list.  Once an operation has been planned, it may be
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   495
                executed by first calling prepare(), and then execute_plan().
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   496
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   497
                'pkg_list' is a list of packages to install.
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   498
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   499
                'recursive_removal' controls whether recursive removal is
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   500
                allowed.
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   501
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   502
                For all other parameters, refer to the 'plan_install' function
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   503
                for an explanation of their usage and effects.
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   504
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   505
                This function returns a boolean which indicates whether there
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   506
                is anything to do."""
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   507
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   508
                self.__plan_common_start("uninstall", noexecute, new_be,
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   509
                    be_name)
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   510
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   511
                try:
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   512
                        self.__img.make_uninstall_plan(pkg_list,
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   513
                            recursive_removal, self.__progresstracker,
2034
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
   514
                            self.__check_cancelation, noexecute)
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   515
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   516
                        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
   517
1569
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
   518
                        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
   519
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   520
                        if not noexecute:
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   521
                                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
   522
2034
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
   523
                        self.__set_new_be()
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
   524
2089
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   525
                        self.__plan_desc = PlanDescription(self.__img,
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   526
                            self.__new_be)
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   527
                        if noexecute:
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   528
                                self.log_operation_end(
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   529
                                    result=history.RESULT_NOTHING_TO_DO)
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   530
                        self.__img.imageplan.update_index = update_index
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   531
                except:
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   532
                        self.__plan_common_exception()
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   533
                        # NOTREACHED
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   534
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   535
                self.__plan_common_finish()
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   536
                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
   537
                return res
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
   538
2089
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   539
        def plan_update(self, pkg_list, refresh_catalogs=True,
2183
21ae45e8dfcf 17581 There should be a way of removing a package as part of upgrade
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2158
diff changeset
   540
            reject_list=misc.EmptyI, noexecute=False, update_index=True,
21ae45e8dfcf 17581 There should be a way of removing a package as part of upgrade
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2158
diff changeset
   541
            be_name=None, new_be=False):
2089
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   542
                """Constructs a plan to update the packages provided in
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   543
                pkg_list.  Once an operation has been planned, it may be
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   544
                executed by first calling prepare(), and then execute_plan().
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   545
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   546
                'pkg_list' is a list of packages to update.
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   547
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   548
                For all other parameters, refer to the 'plan_install' function
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   549
                for an explanation of their usage and effects.
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   550
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   551
                This function returns a boolean which indicates whether there
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   552
                is anything to do."""
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   553
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   554
                self.__plan_common_start("update", noexecute, new_be,
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   555
                    be_name)
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   556
                try:
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   557
                        if refresh_catalogs:
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   558
                                self.__refresh_publishers()
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   559
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   560
                        self.__img.make_update_plan(self.__progresstracker,
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   561
                            self.__check_cancelation, noexecute,
2183
21ae45e8dfcf 17581 There should be a way of removing a package as part of upgrade
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2158
diff changeset
   562
                            pkg_list=pkg_list, reject_list=reject_list)
2089
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   563
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   564
                        assert self.__img.imageplan
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   565
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   566
                        self.__disable_cancel()
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   567
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   568
                        if not noexecute:
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   569
                                self.__plan_type = self.__UPDATE
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   570
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   571
                        self.__set_new_be()
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   572
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   573
                        self.__plan_desc = PlanDescription(self.__img,
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   574
                            self.__new_be)
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   575
                        if self.__img.imageplan.nothingtodo() or noexecute:
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   576
                                self.log_operation_end(
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   577
                                    result=history.RESULT_NOTHING_TO_DO)
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   578
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   579
                        self.__img.imageplan.update_index = update_index
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   580
                except:
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   581
                        self.__plan_common_exception(log_op_end=[
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   582
                            apx.CanceledException, fmri.IllegalFmri,
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   583
                            Exception])
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   584
                        # NOTREACHED
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   585
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   586
                self.__plan_common_finish()
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   587
                res = not self.__img.imageplan.nothingtodo()
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   588
                return res
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   589
1829
e581a205ec02 14907 references to old-style package names must be purged
Danek Duvall <danek.duvall@sun.com>
parents: 1795
diff changeset
   590
        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
   591
                """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
   592
                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
   593
                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
   594
e581a205ec02 14907 references to old-style package names must be purged
Danek Duvall <danek.duvall@sun.com>
parents: 1795
diff changeset
   595
                # 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
   596
                # exists and contains metadata saying this is Solaris.
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
   597
                results = self.get_pkg_list(self.LIST_INSTALLED,
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
   598
                    patterns=["release/name"], return_fmris=True)
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
   599
                results = [e for e in results]
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
   600
                if results:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
   601
                        pfmri, summary, categories, states = \
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
   602
                            results[0]
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
   603
                        mfst = self.__img.get_manifest(pfmri)
1829
e581a205ec02 14907 references to old-style package names must be purged
Danek Duvall <danek.duvall@sun.com>
parents: 1795
diff changeset
   604
                        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
   605
                        if osname == "sunos":
e581a205ec02 14907 references to old-style package names must be purged
Danek Duvall <danek.duvall@sun.com>
parents: 1795
diff changeset
   606
                                return True
e581a205ec02 14907 references to old-style package names must be purged
Danek Duvall <danek.duvall@sun.com>
parents: 1795
diff changeset
   607
e581a205ec02 14907 references to old-style package names must be purged
Danek Duvall <danek.duvall@sun.com>
parents: 1795
diff changeset
   608
                # 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
   609
                # SUNWcs.
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
   610
                results = self.get_pkg_list(self.LIST_INSTALLED,
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
   611
                    patterns=["pkg:/package/pkg", "SUNWipkg", "SUNWcs"])
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
   612
                installed = set(e[0][1] for e in results)
1829
e581a205ec02 14907 references to old-style package names must be purged
Danek Duvall <danek.duvall@sun.com>
parents: 1795
diff changeset
   613
                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
   614
                    "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
   615
                        return True
e581a205ec02 14907 references to old-style package names must be purged
Danek Duvall <danek.duvall@sun.com>
parents: 1795
diff changeset
   616
e581a205ec02 14907 references to old-style package names must be purged
Danek Duvall <danek.duvall@sun.com>
parents: 1795
diff changeset
   617
                return False
e581a205ec02 14907 references to old-style package names must be purged
Danek Duvall <danek.duvall@sun.com>
parents: 1795
diff changeset
   618
2092
0ef66bf272d3 16852 pkg should look at its image for certs if active image lacks certs
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2089
diff changeset
   619
        def plan_update_all(self, refresh_catalogs=True,
2183
21ae45e8dfcf 17581 There should be a way of removing a package as part of upgrade
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2158
diff changeset
   620
            reject_list=misc.EmptyI, noexecute=False, force=False,
21ae45e8dfcf 17581 There should be a way of removing a package as part of upgrade
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2158
diff changeset
   621
            update_index=True, be_name=None, new_be=True):
2089
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   622
                """Constructs a plan to update all packages on the system
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   623
                to the latest known versions.  Once an operation has been
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   624
                planned, it may be executed by first calling prepare(), and
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   625
                then execute_plan().
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   626
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   627
                'force' indicates whether update should skip the package
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   628
                system up to date check.
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   629
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   630
                For all other parameters, refer to the 'plan_install' function
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   631
                for an explanation of their usage and effects.
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   632
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   633
                This function returns a tuple of booleans of the form
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   634
                (stuff_to_do, solaris_image)."""
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   635
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   636
                self.__plan_common_start("update", noexecute, new_be, 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
   637
                try:
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
   638
                        if refresh_catalogs:
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
   639
                                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
   640
1829
e581a205ec02 14907 references to old-style package names must be purged
Danek Duvall <danek.duvall@sun.com>
parents: 1795
diff changeset
   641
                        # 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
   642
                        # 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
   643
                        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
   644
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   645
                        if opensolaris_image and not force:
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   646
                                try:
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   647
                                        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
   648
                                            self.__check_cancelation,
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   649
                                            noexecute,
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   650
                                            refresh_allowed=refresh_catalogs,
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   651
                                            progtrack=self.__progresstracker):
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
   652
                                                raise apx.IpkgOutOfDateException()
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
   653
                                except apx.ImageNotFoundException:
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   654
                                        # Can't do anything in this
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   655
                                        # case; so proceed.
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   656
                                        pass
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   657
1505
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
   658
                        self.__img.make_update_plan(self.__progresstracker,
2183
21ae45e8dfcf 17581 There should be a way of removing a package as part of upgrade
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2158
diff changeset
   659
                            self.__check_cancelation, noexecute,
21ae45e8dfcf 17581 There should be a way of removing a package as part of upgrade
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2158
diff changeset
   660
                            reject_list=reject_list)
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   661
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   662
                        assert self.__img.imageplan
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   663
1569
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
   664
                        self.__disable_cancel()
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   665
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   666
                        if not noexecute:
2089
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   667
                                self.__plan_type = self.__UPDATE
2034
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
   668
                        self.__set_new_be()
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
   669
2089
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   670
                        self.__plan_desc = PlanDescription(self.__img,
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   671
                            self.__new_be)
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   672
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   673
                        if self.__img.imageplan.nothingtodo() or noexecute:
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   674
                                self.log_operation_end(
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   675
                                    result=history.RESULT_NOTHING_TO_DO)
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   676
                        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
   677
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   678
                except:
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   679
                        self.__plan_common_exception(
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
   680
                            log_op_end=[apx.IpkgOutOfDateException])
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   681
                        # NOTREACHED
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   682
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   683
                self.__plan_common_finish()
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   684
                res = not self.__img.imageplan.nothingtodo()
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   685
                return res, opensolaris_image
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   686
1505
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
   687
        def plan_change_varcets(self, variants=None, facets=None,
2034
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
   688
            noexecute=False, be_name=None, new_be=None):
2089
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   689
                """Creates a plan to change the specified variants and/or facets
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   690
                for the image.
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   691
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   692
                'variants' is a dict of the variants to change the values of.
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   693
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   694
                'facets' is a dict of the facets to change the values of.
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   695
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   696
                For all other parameters, refer to the 'plan_install' function
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   697
                for an explanation of their usage and effects.
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   698
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   699
                This function returns a boolean which indicates whether there
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   700
                is anything to do.
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   701
                """
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   702
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   703
                self.__plan_common_start("change-variant", noexecute, new_be,
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   704
                    be_name)
1505
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
   705
                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
   706
                        raise ValueError, "Nothing to do"
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   707
                try:
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
   708
                        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
   709
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   710
                        self.__img.image_change_varcets(variants,
2034
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
   711
                            facets, self.__progresstracker,
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
   712
                            self.__check_cancelation, noexecute)
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   713
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   714
                        assert self.__img.imageplan
2034
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
   715
                        self.__set_new_be()
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   716
1569
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
   717
                        self.__disable_cancel()
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   718
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   719
                        if not noexecute:
2200
155eda704b2f 16279 Need a way to revert certain editable files to a as-installed state
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2183
diff changeset
   720
                                self.__plan_type = self.__VARCET
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   721
2034
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
   722
                        self.__plan_desc = PlanDescription(self.__img, self.__new_be)
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   723
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   724
                        if self.__img.imageplan.nothingtodo() or noexecute:
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   725
                                self.log_operation_end(
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   726
                                    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
   727
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   728
                        #
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   729
                        # 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
   730
                        # variant change
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   731
                        #
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   732
                        self.__img.imageplan.update_index = True
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
   733
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   734
                except:
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   735
                        self.__plan_common_exception()
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   736
                        # NOTREACHED
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   737
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   738
                self.__plan_common_finish()
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   739
                res = not self.__img.imageplan.nothingtodo()
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   740
                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
   741
2200
155eda704b2f 16279 Need a way to revert certain editable files to a as-installed state
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2183
diff changeset
   742
        def plan_revert(self, args, tagged=False, noexecute=True, be_name=None,
155eda704b2f 16279 Need a way to revert certain editable files to a as-installed state
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2183
diff changeset
   743
            new_be=None):
155eda704b2f 16279 Need a way to revert certain editable files to a as-installed state
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2183
diff changeset
   744
                """Plan to revert either files or all files tagged with
155eda704b2f 16279 Need a way to revert certain editable files to a as-installed state
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2183
diff changeset
   745
                specified values.  Args contains either path names or tag names
155eda704b2f 16279 Need a way to revert certain editable files to a as-installed state
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2183
diff changeset
   746
                to be reverted, tagged is True if args contains tags. 
155eda704b2f 16279 Need a way to revert certain editable files to a as-installed state
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2183
diff changeset
   747
155eda704b2f 16279 Need a way to revert certain editable files to a as-installed state
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2183
diff changeset
   748
                For all other parameters, refer to the 'plan_install' function
155eda704b2f 16279 Need a way to revert certain editable files to a as-installed state
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2183
diff changeset
   749
                for an explanation of their usage and effects."""
155eda704b2f 16279 Need a way to revert certain editable files to a as-installed state
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2183
diff changeset
   750
155eda704b2f 16279 Need a way to revert certain editable files to a as-installed state
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2183
diff changeset
   751
                self.__plan_common_start("revert", noexecute, new_be, be_name)
155eda704b2f 16279 Need a way to revert certain editable files to a as-installed state
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2183
diff changeset
   752
                try:
155eda704b2f 16279 Need a way to revert certain editable files to a as-installed state
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2183
diff changeset
   753
                        self.__img.make_revert_plan(args,
155eda704b2f 16279 Need a way to revert certain editable files to a as-installed state
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2183
diff changeset
   754
                            tagged,
155eda704b2f 16279 Need a way to revert certain editable files to a as-installed state
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2183
diff changeset
   755
                            self.__progresstracker,
155eda704b2f 16279 Need a way to revert certain editable files to a as-installed state
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2183
diff changeset
   756
                            self.__check_cancelation,
155eda704b2f 16279 Need a way to revert certain editable files to a as-installed state
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2183
diff changeset
   757
                            noexecute)
155eda704b2f 16279 Need a way to revert certain editable files to a as-installed state
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2183
diff changeset
   758
155eda704b2f 16279 Need a way to revert certain editable files to a as-installed state
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2183
diff changeset
   759
                        assert self.__img.imageplan
155eda704b2f 16279 Need a way to revert certain editable files to a as-installed state
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2183
diff changeset
   760
155eda704b2f 16279 Need a way to revert certain editable files to a as-installed state
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2183
diff changeset
   761
                        self.__disable_cancel()
155eda704b2f 16279 Need a way to revert certain editable files to a as-installed state
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2183
diff changeset
   762
155eda704b2f 16279 Need a way to revert certain editable files to a as-installed state
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2183
diff changeset
   763
                        if not noexecute:
155eda704b2f 16279 Need a way to revert certain editable files to a as-installed state
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2183
diff changeset
   764
                                self.__plan_type = self.__REVERT
155eda704b2f 16279 Need a way to revert certain editable files to a as-installed state
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2183
diff changeset
   765
155eda704b2f 16279 Need a way to revert certain editable files to a as-installed state
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2183
diff changeset
   766
                        self.__set_new_be()
155eda704b2f 16279 Need a way to revert certain editable files to a as-installed state
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2183
diff changeset
   767
155eda704b2f 16279 Need a way to revert certain editable files to a as-installed state
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2183
diff changeset
   768
                        self.__plan_desc = PlanDescription(self.__img, self.__new_be)
155eda704b2f 16279 Need a way to revert certain editable files to a as-installed state
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2183
diff changeset
   769
                        if self.__img.imageplan.nothingtodo() or noexecute:
155eda704b2f 16279 Need a way to revert certain editable files to a as-installed state
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2183
diff changeset
   770
                                self.log_operation_end(
155eda704b2f 16279 Need a way to revert certain editable files to a as-installed state
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2183
diff changeset
   771
                                    result=history.RESULT_NOTHING_TO_DO)
155eda704b2f 16279 Need a way to revert certain editable files to a as-installed state
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2183
diff changeset
   772
155eda704b2f 16279 Need a way to revert certain editable files to a as-installed state
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2183
diff changeset
   773
                        self.__img.imageplan.update_index = False
155eda704b2f 16279 Need a way to revert certain editable files to a as-installed state
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2183
diff changeset
   774
                except:
155eda704b2f 16279 Need a way to revert certain editable files to a as-installed state
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2183
diff changeset
   775
                        self.__plan_common_exception(log_op_end=[
155eda704b2f 16279 Need a way to revert certain editable files to a as-installed state
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2183
diff changeset
   776
                            apx.CanceledException, fmri.IllegalFmri,
155eda704b2f 16279 Need a way to revert certain editable files to a as-installed state
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2183
diff changeset
   777
                            Exception])
155eda704b2f 16279 Need a way to revert certain editable files to a as-installed state
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2183
diff changeset
   778
                        # NOTREACHED
155eda704b2f 16279 Need a way to revert certain editable files to a as-installed state
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2183
diff changeset
   779
155eda704b2f 16279 Need a way to revert certain editable files to a as-installed state
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2183
diff changeset
   780
                self.__plan_common_finish()
155eda704b2f 16279 Need a way to revert certain editable files to a as-installed state
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2183
diff changeset
   781
                res = not self.__img.imageplan.nothingtodo()
155eda704b2f 16279 Need a way to revert certain editable files to a as-installed state
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2183
diff changeset
   782
                return res
155eda704b2f 16279 Need a way to revert certain editable files to a as-installed state
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2183
diff changeset
   783
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   784
        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
   785
                """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
   786
                a PlanDescription."""
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
   787
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
   788
                return self.__plan_desc
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
   789
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   790
        def prepare(self):
2089
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   791
                """Takes care of things which must be done before the plan can
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   792
                be executed. This includes downloading the packages to disk and
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   793
                preparing the indexes to be updated during execution.  Should
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   794
                only be called once a plan_X method has been called."""
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   795
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   796
                self.__acquire_activity_lock()
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   797
                try:
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   798
                        self.__img.lock()
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   799
                except:
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   800
                        self.__activity_lock.release()
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   801
                        raise
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   802
1569
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
   803
                try:
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
   804
                        if not self.__img.imageplan:
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
   805
                                raise apx.PlanMissingException()
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   806
1569
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
   807
                        if self.__prepared:
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
   808
                                raise apx.AlreadyPreparedException()
2200
155eda704b2f 16279 Need a way to revert certain editable files to a as-installed state
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2183
diff changeset
   809
155eda704b2f 16279 Need a way to revert certain editable files to a as-installed state
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2183
diff changeset
   810
                        assert self.__plan_type in self.__valid_plan_types
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   811
1693
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
   812
                        self.__enable_cancel()
1569
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
   813
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
   814
                        try:
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
   815
                                self.__img.imageplan.preexecute()
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
   816
                        except search_errors.ProblematicPermissionsIndexException, e:
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
   817
                                raise apx.ProblematicPermissionsIndexException(e)
1569
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
   818
                        except:
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
   819
                                raise
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   820
1569
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
   821
                        self.__disable_cancel()
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
   822
                        self.__prepared = True
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
   823
                except apx.CanceledException, e:
1569
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
   824
                        self.__cancel_done()
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
   825
                        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
   826
                                # 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
   827
                                # 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
   828
                                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
   829
                        raise
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
   830
                except Exception, e:
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
   831
                        self.__cancel_cleanup_exception()
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
   832
                        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
   833
                                # 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
   834
                                # 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
   835
                                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
   836
                        raise
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
   837
                except:
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
   838
                        # 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
   839
                        # Exception.
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
   840
                        self.__cancel_cleanup_exception()
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
   841
                        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
   842
                                # 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
   843
                                # 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
   844
                                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
   845
                                    sys.exc_info()
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
   846
                                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
   847
                        raise
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   848
                finally:
1503
78d56b8ee320 12698 download directory must be accessible to non-privileged users
johansen <johansen@sun.com>
parents: 1472
diff changeset
   849
                        self.__img.cleanup_downloads()
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   850
                        self.__img.unlock()
1895
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1893
diff changeset
   851
                        try:
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1893
diff changeset
   852
                                if int(os.environ.get("PKG_DUMP_STATS", 0)) > 0:
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1893
diff changeset
   853
                                        self.__img.transport.stats.dump()
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1893
diff changeset
   854
                        except ValueError:
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1893
diff changeset
   855
                                # Don't generate stats if an invalid value
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1893
diff changeset
   856
                                # is supplied.
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1893
diff changeset
   857
                                pass
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   858
                        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
   859
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   860
        def execute_plan(self):
2089
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   861
                """Executes the plan. This is uncancelable once it begins.
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   862
                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
   863
                called."""
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   864
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   865
                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
   866
                try:
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
   867
                        self.__disable_cancel()
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   868
                        self.__img.lock()
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   869
                except:
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   870
                        self.__activity_lock.release()
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   871
                        raise
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   872
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   873
                try:
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
   874
                        if not self.__img.imageplan:
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
   875
                                raise apx.PlanMissingException()
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   876
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
   877
                        if not self.__prepared:
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
   878
                                raise apx.PrematureExecutionException()
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   879
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
   880
                        if self.__executed:
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
   881
                                raise apx.AlreadyExecutedException()
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
   882
2200
155eda704b2f 16279 Need a way to revert certain editable files to a as-installed state
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2183
diff changeset
   883
                        assert self.__plan_type in self.__valid_plan_types
1027
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
   884
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   885
                        try:
2105
212a253a462a 12530 pkg -R install doesn't update boot archive
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2100
diff changeset
   886
                                be = bootenv.BootEnv(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
   887
                        except RuntimeError:
2105
212a253a462a 12530 pkg -R install doesn't update boot archive
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2100
diff changeset
   888
                                be = bootenv.BootEnvNull(self.__img)
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
   889
                        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
   890
2034
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
   891
                        if self.__new_be == False and \
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
   892
                            self.__img.imageplan.reboot_needed() and \
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
   893
                            self.__img.is_liveroot():
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
   894
                                e = apx.RebootNeededOnLiveImageException()
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
   895
                                self.log_operation_end(error=e)
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
   896
                                raise e
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
   897
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
   898
                        if self.__new_be == True:
1027
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
   899
                                try:
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
   900
                                        be.init_image_recovery(self.__img,
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
   901
                                            self.__be_name)
1027
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
   902
                                except Exception, e:
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
   903
                                        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
   904
                                        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
   905
                                except:
1102
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1100
diff changeset
   906
                                        # 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
   907
                                        # 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
   908
                                        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
   909
                                            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
   910
                                        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
   911
                                        raise
2034
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
   912
                                # check if things gained underneath us
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
   913
                                if self.__img.is_liveroot():
2034
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
   914
                                        e = apx.UnableToCopyBE()
1027
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
   915
                                        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
   916
                                        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
   917
                        try:
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
   918
                                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
   919
                        except RuntimeError, e:
2034
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
   920
                                if self.__new_be == True:
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   921
                                        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
   922
                                else:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   923
                                        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
   924
                                # 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
   925
                                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
   926
                                raise
2028
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
   927
                        except search_errors.IndexLockedException, e:
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
   928
                                error = apx.IndexLockedException(e)
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
   929
                                self.log_operation_end(error=error)
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
   930
                                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
   931
                        except search_errors.ProblematicPermissionsIndexException, e:
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
   932
                                error = apx.ProblematicPermissionsIndexException(e)
1027
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
   933
                                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
   934
                                raise error
2028
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
   935
                        except search_errors.InconsistentIndexException, e:
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
   936
                                error = apx.CorruptedIndexException(e)
1027
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
   937
                                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
   938
                                raise error
1019
e61c57c724c9 7663 disable_fmri should be synchronous
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 996
diff changeset
   939
                        except actuator.NonzeroExitException, e:
2089
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
   940
                                # Won't happen during update
1019
e61c57c724c9 7663 disable_fmri should be synchronous
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 996
diff changeset
   941
                                be.restore_install_uninstall()
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
   942
                                error = apx.ActuatorException(e)
1027
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
   943
                                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
   944
                                raise error
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
   945
                        except apx.WrapIndexingException, e:
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
   946
                                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
   947
                                raise
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   948
                        except Exception, e:
2034
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
   949
                                if self.__new_be == True:
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   950
                                        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
   951
                                else:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   952
                                        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
   953
                                # 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
   954
                                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
   955
                                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
   956
                        except:
ff3c6b09f430 8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents: 1027
diff changeset
   957
                                # 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
   958
                                # Exception.
ff3c6b09f430 8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents: 1027
diff changeset
   959
                                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
   960
                                    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
   961
2034
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
   962
                                if self.__new_be == True:
1032
ff3c6b09f430 8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents: 1027
diff changeset
   963
                                        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
   964
                                else:
ff3c6b09f430 8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents: 1027
diff changeset
   965
                                        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
   966
                                # 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
   967
                                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
   968
                                raise
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   969
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
   970
                        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
   971
                finally:
1503
78d56b8ee320 12698 download directory must be accessible to non-privileged users
johansen <johansen@sun.com>
parents: 1472
diff changeset
   972
                        self.__img.cleanup_downloads()
2134
c9985876d799 17327 pkg image-update to 151 raises NRLockException
johansen <johansen@opensolaris.org>
parents: 2105
diff changeset
   973
                        if self.__img.locked:
c9985876d799 17327 pkg image-update to 151 raises NRLockException
johansen <johansen@opensolaris.org>
parents: 2105
diff changeset
   974
                                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
   975
                        self.__activity_lock.release()
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
   976
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
   977
        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
   978
                if self.__img.imageplan.state != EXECUTED_OK:
2034
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
   979
                        if self.__new_be == True:
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
   980
                                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
   981
                        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
   982
                                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
   983
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
   984
                        error = apx.ImageplanStateException(
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
   985
                            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
   986
                        # 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
   987
                        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
   988
                        raise error
2105
212a253a462a 12530 pkg -R install doesn't update boot archive
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2100
diff changeset
   989
212a253a462a 12530 pkg -R install doesn't update boot archive
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2100
diff changeset
   990
                if self.__img.imageplan.boot_archive_needed() or \
212a253a462a 12530 pkg -R install doesn't update boot archive
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2100
diff changeset
   991
                    self.__new_be:
212a253a462a 12530 pkg -R install doesn't update boot archive
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2100
diff changeset
   992
                        be.update_boot_archive()
212a253a462a 12530 pkg -R install doesn't update boot archive
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2100
diff changeset
   993
2034
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
   994
                if self.__new_be == True:
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
   995
                        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
   996
                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
   997
                        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
   998
                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
   999
                # 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
  1000
                # 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
  1001
                # ending now.
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
  1002
                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
  1003
                        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
  1004
                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
  1005
1618
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  1006
        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
  1007
            displayed=None):
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  1008
                """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
  1009
                license entry.
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  1010
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  1011
                '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
  1012
                values:
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  1013
                        None    leaves accepted status unchanged
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  1014
                        False   sets accepted status to False
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  1015
                        True    sets accepted status to True
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  1016
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  1017
                '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
  1018
                values:
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  1019
                        None    leaves displayed status unchanged
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  1020
                        False   sets displayed status to False
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  1021
                        True    sets displayed status to True"""
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  1022
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
  1023
                self.__acquire_activity_lock()
1618
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  1024
                try:
1693
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  1025
                        try:
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  1026
                                self.__disable_cancel()
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1027
                        except apx.CanceledException:
1693
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  1028
                                self.__cancel_done()
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  1029
                                raise
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  1030
1618
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  1031
                        if not self.__img.imageplan:
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1032
                                raise apx.PlanMissingException()
1618
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  1033
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  1034
                        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
  1035
                                if pp.destination_fmri == pfmri:
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  1036
                                        pp.set_license_status(plicense,
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  1037
                                            accepted=accepted,
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  1038
                                            displayed=displayed)
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  1039
                                        break
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  1040
                finally:
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  1041
                        self.__activity_lock.release()
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  1042
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 941
diff changeset
  1043
        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
  1044
                """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
  1045
                publishers.
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 941
diff changeset
  1046
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 941
diff changeset
  1047
                '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
  1048
                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
  1049
                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
  1050
                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
  1051
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 941
diff changeset
  1052
                '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
  1053
                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
  1054
                implies all publishers.
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1055
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
  1056
                '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
  1057
                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
  1058
                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
  1059
                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
  1060
                exceeded.
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1061
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1062
                Currently returns an image object, allowing existing code to
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1063
                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
  1064
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
  1065
                self.__acquire_activity_lock()
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
  1066
                try:
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  1067
                        self.__disable_cancel()
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
  1068
                        self.__img.lock()
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  1069
                        try:
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  1070
                                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
  1071
                                    pubs=pubs, immediate=immediate)
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  1072
                                return self.__img
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  1073
                        finally:
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  1074
                                self.__img.unlock()
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  1075
                                self.__img.cleanup_downloads()
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1076
                except apx.CanceledException:
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  1077
                        self.__cancel_done()
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
  1078
                        raise
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
  1079
                finally:
1895
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1893
diff changeset
  1080
                        try:
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1893
diff changeset
  1081
                                if int(os.environ.get("PKG_DUMP_STATS", 0)) > 0:
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1893
diff changeset
  1082
                                        self.__img.transport.stats.dump()
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1893
diff changeset
  1083
                        except ValueError:
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1893
diff changeset
  1084
                                # Don't generate stats if an invalid value
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1893
diff changeset
  1085
                                # is supplied.
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1893
diff changeset
  1086
                                pass
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
  1087
                        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
  1088
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
  1089
        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
  1090
                """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
  1091
                cleanup."""
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
  1092
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
  1093
                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
  1094
                    immediate=immediate, pubs=pubs,
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
  1095
                    progtrack=self.__progresstracker)
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
  1096
1618
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  1097
        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
  1098
                """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
  1099
                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
  1100
                license_lst = []
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1101
                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
  1102
                        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
  1103
                            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
  1104
                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
  1105
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1106
        def get_pkg_categories(self, installed=False, pubs=misc.EmptyI):
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1107
                """Returns an order list of tuples of the form (scheme,
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1108
                category) containing the names of all categories in use by
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1109
                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
  1110
                per-publisher basis.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1111
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1112
                'installed' is an optional boolean value indicating whether
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1113
                only the categories used by currently installed packages
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1114
                should be returned.  If False, the categories used by the
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1115
                latest vesion of every known package will be returned
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1116
                instead.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1117
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1118
                'pubs' is an optional list of publisher prefixes to restrict
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1119
                the results to."""
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1120
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1121
                if installed:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1122
                        img_cat = self.__img.get_catalog(
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1123
                            self.__img.IMG_CATALOG_INSTALLED)
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1124
                        excludes = misc.EmptyI
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1125
                else:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1126
                        img_cat = self.__img.get_catalog(
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1127
                            self.__img.IMG_CATALOG_KNOWN)
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1128
                        excludes = self.__img.list_excludes()
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1129
                return sorted(img_cat.categories(excludes=excludes, pubs=pubs))
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1130
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1131
        def __map_installed_newest(self, brelease, pubs):
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1132
                """Private function.  Maps incorporations and publisher
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1133
                relationships for installed packages and returns them
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1134
                as a tuple of (pub_ranks, inc_stems, inc_vers, inst_stems,
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1135
                ren_stems, ren_inst_stems).
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1136
                """
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1137
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1138
                img_cat = self.__img.get_catalog(
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1139
                    self.__img.IMG_CATALOG_INSTALLED)
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1140
                cat_info = frozenset([img_cat.DEPENDENCY])
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1141
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1142
                inst_stems = {}
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1143
                ren_inst_stems = {}
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1144
                ren_stems = {}
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1145
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1146
                inc_stems = {}
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1147
                inc_vers = {}
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1148
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1149
                pub_ranks = self.__img.get_publisher_ranks()
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1150
2183
21ae45e8dfcf 17581 There should be a way of removing a package as part of upgrade
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2158
diff changeset
  1151
                # The incorporation list should include all installed,
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1152
                # incorporated packages from all publishers.
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1153
                for t in img_cat.entry_actions(cat_info):
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1154
                        (pub, stem, ver), entry, actions = t
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1155
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1156
                        inst_stems[stem] = ver
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1157
                        pkgr = False
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1158
                        targets = set()
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1159
                        try:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1160
                                for a in actions:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1161
                                        if a.name == "set" and \
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1162
                                            a.attrs["name"] == "pkg.renamed":
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1163
                                                pkgr = True
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1164
                                                continue
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1165
                                        elif a.name != "depend":
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1166
                                                continue
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1167
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1168
                                        if a.attrs["type"] == "require":
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1169
                                                # Because the actions are not
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1170
                                                # returned in a guaranteed
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1171
                                                # order, the dependencies will
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1172
                                                # have to be recorded for
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1173
                                                # evaluation later.
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1174
                                                targets.add(a.attrs["fmri"])
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1175
                                        elif a.attrs["type"] == "incorporate":
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1176
                                                # Record incorporated packages.
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1177
                                                tgt = fmri.PkgFmri(
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1178
                                                    a.attrs["fmri"], brelease)
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1179
                                                tver = tgt.version
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1180
                                                over = inc_vers.get(
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1181
                                                    tgt.pkg_name, None)
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1182
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1183
                                                # In case this package has been
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1184
                                                # incorporated more than once,
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1185
                                                # use the newest version.
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1186
                                                if over is not None and \
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1187
                                                    over > tver:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1188
                                                        continue
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1189
                                                inc_vers[tgt.pkg_name] = tver
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1190
                        except apx.InvalidPackageErrors:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1191
                                # For mapping purposes, ignore unsupported
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1192
                                # (and invalid) actions.  This is necessary so
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1193
                                # that API consumers can discover new package
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1194
                                # data that may be needed to perform an upgrade
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1195
                                # so that the API can understand them.
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1196
                                pass
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1197
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1198
                        if pkgr:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1199
                                for f in targets:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1200
                                        tgt = fmri.PkgFmri(f, brelease)
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1201
                                        ren_stems[tgt.pkg_name] = stem
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1202
                                        ren_inst_stems.setdefault(stem,
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1203
                                            set())
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1204
                                        ren_inst_stems[stem].add(
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1205
                                            tgt.pkg_name)
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1206
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1207
                def check_stem(t, entry):
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1208
                        pub, stem, ver = t
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1209
                        if stem in inst_stems:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1210
                                iver = inst_stems[stem]
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1211
                                if stem in ren_inst_stems or \
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1212
                                    ver == iver:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1213
                                        # The package has been renamed
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1214
                                        # or the entry is for the same
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1215
                                        # version as that which is
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1216
                                        # installed, so doesn't need
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1217
                                        # to be checked.
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1218
                                        return False
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1219
                                # The package may have been renamed in
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1220
                                # a newer version, so must be checked.
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1221
                                return True
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1222
                        elif stem in inc_vers:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1223
                                # Package is incorporated, but not
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1224
                                # installed, so should be checked.
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1225
                                return True
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1226
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1227
                        tgt = ren_stems.get(stem, None)
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1228
                        while tgt is not None:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1229
                                # This seems counter-intuitive, but
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1230
                                # for performance and other reasons,
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1231
                                # this stem should only be checked
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1232
                                # for a rename if it is incorporated
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1233
                                # or installed using a previous name.
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1234
                                if tgt in inst_stems or \
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1235
                                    tgt in inc_vers:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1236
                                        return True
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1237
                                tgt = ren_stems.get(tgt, None)
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1238
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1239
                        # Package should not be checked.
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1240
                        return False
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1241
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1242
                img_cat = self.__img.get_catalog(self.__img.IMG_CATALOG_KNOWN)
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1243
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1244
                # Find terminal rename entry for all known packages not
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1245
                # rejected by check_stem().
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1246
                for t, entry, actions in img_cat.entry_actions(cat_info,
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1247
                    cb=check_stem, last=True):
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1248
                        pkgr = False
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1249
                        targets = set()
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1250
                        try:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1251
                                for a in actions:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1252
                                        if a.name == "set" and \
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1253
                                            a.attrs["name"] == "pkg.renamed":
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1254
                                                pkgr = True
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1255
                                                continue
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1256
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1257
                                        if a.name != "depend":
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1258
                                                continue
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1259
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1260
                                        if a.attrs["type"] != "require":
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1261
                                                continue
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1262
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1263
                                        # Because the actions are not
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1264
                                        # returned in a guaranteed
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1265
                                        # order, the dependencies will
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1266
                                        # have to be recorded for
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1267
                                        # evaluation later.
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1268
                                        targets.add(a.attrs["fmri"])
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1269
                        except apx.InvalidPackageErrors:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1270
                                # For mapping purposes, ignore unsupported
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1271
                                # (and invalid) actions.  This is necessary so
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1272
                                # that API consumers can discover new package
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1273
                                # data that may be needed to perform an upgrade
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1274
                                # so that the API can understand them.
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1275
                                pass
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1276
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1277
                        if pkgr:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1278
                                pub, stem, ver = t
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1279
                                for f in targets:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1280
                                        tgt = fmri.PkgFmri(f, brelease)
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1281
                                        ren_stems[tgt.pkg_name] = stem
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1282
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1283
                # Determine highest ranked publisher for package stems
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1284
                # listed in installed incorporations.
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1285
                def pub_order(a, b):
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1286
                        return cmp(pub_ranks[a][0], pub_ranks[b][0])
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1287
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1288
                for p in sorted(pub_ranks, cmp=pub_order):
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1289
                        if pubs and p not in pubs:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1290
                                continue
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1291
                        for stem in img_cat.names(pubs=[p]):
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1292
                                if stem in inc_vers:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1293
                                        inc_stems.setdefault(stem, p)
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1294
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1295
                return (pub_ranks, inc_stems, inc_vers, inst_stems, ren_stems,
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1296
                    ren_inst_stems)
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1297
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1298
        def get_pkg_list(self, pkg_list, cats=None, patterns=misc.EmptyI,
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1299
            pubs=misc.EmptyI, raise_unmatched=False, return_fmris=False,
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1300
            variants=False):
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1301
                """A generator function that produces tuples of the form:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1302
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1303
                    (
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1304
                        (
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1305
                            pub,    - (string) the publisher of the package
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1306
                            stem,   - (string) the name of the package
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1307
                            version - (string) the version of the package
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1308
                        ),
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1309
                        summary,    - (string) the package summary
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1310
                        categories, - (list) string tuples of (scheme, category)
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1311
                        states      - (list) PackageInfo states
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1312
                    )
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1313
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1314
                Results are always sorted by stem, publisher, and then in
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1315
                descending version order.
1537
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
                'pkg_list' is one of the following constant values indicating
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1318
                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
  1319
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1320
                        LIST_ALL
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1321
                                All known packages.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1322
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1323
                        LIST_INSTALLED
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1324
                                Installed packages.
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
                        LIST_INSTALLED_NEWEST
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1327
                                Installed packages and the newest
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1328
                                versions of packages not installed.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1329
                                Renamed packages that are listed in
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1330
                                an installed incorporation will be
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1331
                                excluded unless they are installed.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1332
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1333
                        LIST_NEWEST
2024
95751b5fb20b 16651 can't access versions of packages other than newest for list -n, info -r, and contents -r
Shawn Walker <shawn.walker@oracle.com>
parents: 1970
diff changeset
  1334
                                The newest versions of all known packages
95751b5fb20b 16651 can't access versions of packages other than newest for list -n, info -r, and contents -r
Shawn Walker <shawn.walker@oracle.com>
parents: 1970
diff changeset
  1335
                                that match the provided patterns and
95751b5fb20b 16651 can't access versions of packages other than newest for list -n, info -r, and contents -r
Shawn Walker <shawn.walker@oracle.com>
parents: 1970
diff changeset
  1336
                                other criteria.
1537
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
                        LIST_UPGRADABLE
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1339
                                Packages that are installed and upgradable.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1340
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1341
                '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
  1342
                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
  1343
                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
  1344
                returned.  A value of [] will return packages not assigned
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1345
                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
  1346
                package category filtering should be applied.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1347
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1348
                'patterns' is an optional list of FMRI wildcard strings to
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1349
                filter results by.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1350
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1351
                'pubs' is an optional list of publisher prefixes to restrict
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1352
                the results to.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1353
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1354
                'raise_unmatched' is an optional boolean value that indicates
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1355
                whether an InventoryException should be raised if any patterns
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1356
                (after applying all other filtering and returning all results)
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1357
                didn't match any packages.
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1358
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1359
                'return_fmris' is an optional boolean value that indicates that
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1360
                an FMRI object should be returned in place of the (pub, stem,
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1361
                ver) tuple that is normally returned.
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1362
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1363
                'variants' is an optional boolean value that indicates that
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1364
                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
  1365
                this image should be returned.
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
                Please note that this function may invoke network operations
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1368
                to retrieve the requested package information."""
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1369
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1370
                installed = inst_newest = newest = upgradable = False
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1371
                if pkg_list == self.LIST_INSTALLED:
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1372
                        installed = True
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1373
                elif pkg_list == self.LIST_INSTALLED_NEWEST:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1374
                        inst_newest = True
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1375
                elif pkg_list == self.LIST_NEWEST:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1376
                        newest = True
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1377
                elif pkg_list == self.LIST_UPGRADABLE:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1378
                        upgradable = True
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1379
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1380
                brelease = self.__img.attrs["Build-Release"]
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1381
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1382
                # 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
  1383
                # extract the individual components for use in filtering.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1384
                illegals = []
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1385
                pat_tuples = {}
2024
95751b5fb20b 16651 can't access versions of packages other than newest for list -n, info -r, and contents -r
Shawn Walker <shawn.walker@oracle.com>
parents: 1970
diff changeset
  1386
                pat_versioned = False
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1387
                for pat in patterns:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1388
                        try:
2024
95751b5fb20b 16651 can't access versions of packages other than newest for list -n, info -r, and contents -r
Shawn Walker <shawn.walker@oracle.com>
parents: 1970
diff changeset
  1389
                                if "@" in pat:
95751b5fb20b 16651 can't access versions of packages other than newest for list -n, info -r, and contents -r
Shawn Walker <shawn.walker@oracle.com>
parents: 1970
diff changeset
  1390
                                        # Mark that a pattern containing
95751b5fb20b 16651 can't access versions of packages other than newest for list -n, info -r, and contents -r
Shawn Walker <shawn.walker@oracle.com>
parents: 1970
diff changeset
  1391
                                        # version information was found.
95751b5fb20b 16651 can't access versions of packages other than newest for list -n, info -r, and contents -r
Shawn Walker <shawn.walker@oracle.com>
parents: 1970
diff changeset
  1392
                                        pat_versioned = True
95751b5fb20b 16651 can't access versions of packages other than newest for list -n, info -r, and contents -r
Shawn Walker <shawn.walker@oracle.com>
parents: 1970
diff changeset
  1393
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1394
                                if "*" in pat or "?" in pat:
1835
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  1395
                                        matcher = self.MATCH_GLOB
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1396
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1397
                                        # XXX By default, matching FMRIs
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1398
                                        # currently do not also use
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1399
                                        # MatchingVersion.  If that changes,
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1400
                                        # this should change too.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1401
                                        parts = pat.split("@", 1)
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1402
                                        if len(parts) == 1:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1403
                                                npat = pkg.fmri.MatchingPkgFmri(
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1404
                                                    pat, brelease)
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1405
                                        else:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1406
                                                npat = pkg.fmri.MatchingPkgFmri(
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1407
                                                    parts[0], brelease)
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1408
                                                npat.version = \
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1409
                                                    pkg.version.MatchingVersion(
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1410
                                                    str(parts[1]), brelease)
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1411
                                elif pat.startswith("pkg:/"):
1835
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  1412
                                        matcher = self.MATCH_EXACT
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1413
                                        npat = pkg.fmri.PkgFmri(pat,
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1414
                                            brelease)
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1415
                                else:
1835
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  1416
                                        matcher = self.MATCH_FMRI
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1417
                                        npat = pkg.fmri.PkgFmri(pat,
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1418
                                            brelease)
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1419
                                pat_tuples[pat] = (npat.tuple(), matcher)
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1420
                        except (pkg.fmri.FmriError,
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1421
                            pkg.version.VersionError), e:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1422
                                illegals.append(e)
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1423
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1424
                if illegals:
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1425
                        raise apx.InventoryException(illegal=illegals)
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1426
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1427
                # For LIST_INSTALLED_NEWEST, installed packages need to be
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1428
                # determined and incorporation and publisher relationships
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1429
                # mapped.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1430
                if inst_newest:
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1431
                        pub_ranks, inc_stems, inc_vers, inst_stems, ren_stems, \
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1432
                            ren_inst_stems = self.__map_installed_newest(
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1433
                            brelease, pubs)
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1434
                else:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1435
                        pub_ranks = inc_stems = inc_vers = inst_stems = \
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1436
                            ren_stems = ren_inst_stems = misc.EmptyDict
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1437
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1438
                if installed or upgradable:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1439
                        img_cat = self.__img.get_catalog(
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1440
                            self.__img.IMG_CATALOG_INSTALLED)
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1441
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1442
                        # Don't need to perform variant filtering if only
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1443
                        # listing installed packages.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1444
                        variants = True
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1445
                else:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1446
                        img_cat = self.__img.get_catalog(
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1447
                            self.__img.IMG_CATALOG_KNOWN)
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1448
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1449
                cat_info = frozenset([img_cat.DEPENDENCY, img_cat.SUMMARY])
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1450
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1451
                # 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
  1452
                # each incorporated stem.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1453
                slist = set()
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1454
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1455
                # 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
  1456
                # per-publisher basis.
1853
8f8a90301844 15234 "pkg list -a" doesn't account for pattern versions
Shawn Walker <shawn.walker@oracle.com>
parents: 1843
diff changeset
  1457
                nlist = collections.defaultdict(int)
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1458
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1459
                def check_state(t, entry):
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1460
                        states = entry["metadata"]["states"]
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1461
                        pkgi = self.__img.PKG_STATE_INSTALLED in states
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1462
                        pkgu = self.__img.PKG_STATE_UPGRADABLE in states
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1463
                        pub, stem, ver = t
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1464
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1465
                        if upgradable:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1466
                                # If package is marked upgradable, return it.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1467
                                return pkgu
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1468
                        elif pkgi:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1469
                                # Nothing more to do here.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1470
                                return True
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1471
                        elif stem in inst_stems:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1472
                                # Some other version of this package is
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1473
                                # installed, so this one should not be
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1474
                                # returned.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1475
                                return False
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1476
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1477
                        # Attempt to determine if this package is installed
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1478
                        # under a different name or constrained under a
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1479
                        # different name.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1480
                        tgt = ren_stems.get(stem, None)
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1481
                        while tgt is not None:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1482
                                if tgt in inc_vers:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1483
                                        # Package is incorporated under a
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1484
                                        # different name, so allow this
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1485
                                        # to fallthrough to the incoporation
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1486
                                        # evaluation.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1487
                                        break
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1488
                                elif tgt in inst_stems:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1489
                                        # Package is installed under a
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1490
                                        # different name, so skip it.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1491
                                        return False
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1492
                                tgt = ren_stems.get(tgt, None)
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1493
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1494
                        # Attempt to find a suitable version to return.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1495
                        if stem in inc_vers:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1496
                                # For package stems that are incorporated, only
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1497
                                # return the newest successor version  based on
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1498
                                # publisher rank.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1499
                                if stem in slist:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1500
                                        # Newest version already returned.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1501
                                        return False
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1502
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1503
                                if stem in inc_stems and \
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1504
                                    pub != inc_stems[stem]:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1505
                                        # This entry is for a lower-ranked
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1506
                                        # publisher.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1507
                                        return False
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1508
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1509
                                # XXX version should not require build release.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1510
                                ever = pkg.version.Version(ver, brelease)
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1511
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1512
                                # If the entry's version is a successor to
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1513
                                # the incorporated version, then this is the
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1514
                                # 'newest' version of this package since
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1515
                                # entries are processed in descending version
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1516
                                # order.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1517
                                iver = inc_vers[stem]
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1518
                                if ever.is_successor(iver,
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1519
                                    pkg.version.CONSTRAINT_AUTO):
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1520
                                        slist.add(stem)
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1521
                                        return True
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1522
                                return False
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1523
1853
8f8a90301844 15234 "pkg list -a" doesn't account for pattern versions
Shawn Walker <shawn.walker@oracle.com>
parents: 1843
diff changeset
  1524
                        pkg_stem = "!".join((pub, stem))
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1525
                        if pkg_stem in nlist:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1526
                                # A newer version has already been listed for
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1527
                                # this stem and publisher.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1528
                                return False
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1529
                        return True
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1530
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1531
                filter_cb = None
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1532
                if inst_newest or upgradable:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1533
                        # Filtering needs to be applied.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1534
                        filter_cb = check_state
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1535
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1536
                arch = self.__img.get_arch()
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1537
                excludes = self.__img.list_excludes()
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1538
                is_zone = self.__img.is_zone()
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1539
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1540
                matched_pats = set()
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1541
                pkg_matching_pats = None
2024
95751b5fb20b 16651 can't access versions of packages other than newest for list -n, info -r, and contents -r
Shawn Walker <shawn.walker@oracle.com>
parents: 1970
diff changeset
  1542
95751b5fb20b 16651 can't access versions of packages other than newest for list -n, info -r, and contents -r
Shawn Walker <shawn.walker@oracle.com>
parents: 1970
diff changeset
  1543
                # Retrieve only the newest package versions for LIST_NEWEST if
95751b5fb20b 16651 can't access versions of packages other than newest for list -n, info -r, and contents -r
Shawn Walker <shawn.walker@oracle.com>
parents: 1970
diff changeset
  1544
                # none of the patterns have version information.  (This cuts
95751b5fb20b 16651 can't access versions of packages other than newest for list -n, info -r, and contents -r
Shawn Walker <shawn.walker@oracle.com>
parents: 1970
diff changeset
  1545
                # down on the number of entries that have to be filtered.)
95751b5fb20b 16651 can't access versions of packages other than newest for list -n, info -r, and contents -r
Shawn Walker <shawn.walker@oracle.com>
parents: 1970
diff changeset
  1546
                use_last = newest and not pat_versioned
95751b5fb20b 16651 can't access versions of packages other than newest for list -n, info -r, and contents -r
Shawn Walker <shawn.walker@oracle.com>
parents: 1970
diff changeset
  1547
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1548
                for t, entry, actions in img_cat.entry_actions(cat_info,
2024
95751b5fb20b 16651 can't access versions of packages other than newest for list -n, info -r, and contents -r
Shawn Walker <shawn.walker@oracle.com>
parents: 1970
diff changeset
  1549
                    cb=filter_cb, excludes=excludes, last=use_last,
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1550
                    ordered=True, pubs=pubs):
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1551
                        pub, stem, ver = t
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1552
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1553
                        omit_ver = False
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1554
                        omit_package = None
2033
601cc09f180a 16811 get_pkg_list LIST_NEWEST returns all matching instead of newest matching version
Shawn Walker <shawn.walker@oracle.com>
parents: 2028
diff changeset
  1555
601cc09f180a 16811 get_pkg_list LIST_NEWEST returns all matching instead of newest matching version
Shawn Walker <shawn.walker@oracle.com>
parents: 2028
diff changeset
  1556
                        pkg_stem = "!".join((pub, stem))
601cc09f180a 16811 get_pkg_list LIST_NEWEST returns all matching instead of newest matching version
Shawn Walker <shawn.walker@oracle.com>
parents: 2028
diff changeset
  1557
                        if newest and pat_versioned and pkg_stem in nlist:
601cc09f180a 16811 get_pkg_list LIST_NEWEST returns all matching instead of newest matching version
Shawn Walker <shawn.walker@oracle.com>
parents: 2028
diff changeset
  1558
                                # A newer version has already been listed and
601cc09f180a 16811 get_pkg_list LIST_NEWEST returns all matching instead of newest matching version
Shawn Walker <shawn.walker@oracle.com>
parents: 2028
diff changeset
  1559
                                # because a pattern with a version was specified
601cc09f180a 16811 get_pkg_list LIST_NEWEST returns all matching instead of newest matching version
Shawn Walker <shawn.walker@oracle.com>
parents: 2028
diff changeset
  1560
                                # any additional entries need to be marked for
601cc09f180a 16811 get_pkg_list LIST_NEWEST returns all matching instead of newest matching version
Shawn Walker <shawn.walker@oracle.com>
parents: 2028
diff changeset
  1561
                                # omission before continuing.
601cc09f180a 16811 get_pkg_list LIST_NEWEST returns all matching instead of newest matching version
Shawn Walker <shawn.walker@oracle.com>
parents: 2028
diff changeset
  1562
                                omit_package = True
601cc09f180a 16811 get_pkg_list LIST_NEWEST returns all matching instead of newest matching version
Shawn Walker <shawn.walker@oracle.com>
parents: 2028
diff changeset
  1563
                                omit_ver = True
601cc09f180a 16811 get_pkg_list LIST_NEWEST returns all matching instead of newest matching version
Shawn Walker <shawn.walker@oracle.com>
parents: 2028
diff changeset
  1564
                        else:
601cc09f180a 16811 get_pkg_list LIST_NEWEST returns all matching instead of newest matching version
Shawn Walker <shawn.walker@oracle.com>
parents: 2028
diff changeset
  1565
                                nlist[pkg_stem] += 1
601cc09f180a 16811 get_pkg_list LIST_NEWEST returns all matching instead of newest matching version
Shawn Walker <shawn.walker@oracle.com>
parents: 2028
diff changeset
  1566
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1567
                        if raise_unmatched:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1568
                                pkg_matching_pats = set()
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1569
                        if not omit_package:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1570
                                ever = None
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1571
                                for pat in patterns:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1572
                                        (pat_pub, pat_stem, pat_ver), matcher = \
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1573
                                            pat_tuples[pat]
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1574
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1575
                                        if pat_pub is not None and \
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1576
                                            pub != pat_pub:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1577
                                                # Publisher doesn't match.
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1578
                                                if omit_package is None:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1579
                                                        omit_package = True
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1580
                                                continue
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1581
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1582
                                        if matcher == self.MATCH_EXACT:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1583
                                                if pat_stem != stem:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1584
                                                        # Stem doesn't match.
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1585
                                                        if omit_package is None:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1586
                                                                omit_package = \
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1587
                                                                    True
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1588
                                                        continue
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1589
                                        elif matcher == self.MATCH_FMRI:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1590
                                                if not ("/" + stem).endswith(
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1591
                                                    "/" + pat_stem):
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1592
                                                        # Stem doesn't match.
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1593
                                                        if omit_package is None:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1594
                                                                omit_package = \
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1595
                                                                    True
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1596
                                                        continue
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1597
                                        elif matcher == self.MATCH_GLOB:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1598
                                                if not fnmatch.fnmatchcase(stem,
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1599
                                                    pat_stem):
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1600
                                                        # Stem doesn't match.
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1601
                                                        if omit_package is None:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1602
                                                                omit_package = \
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1603
                                                                    True
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1604
                                                        continue
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1605
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1606
                                        if pat_ver is not None:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1607
                                                if ever is None:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1608
                                                        # Avoid constructing a
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1609
                                                        # version object more
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1610
                                                        # than once for each
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1611
                                                        # entry.
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1612
                                                        ever = pkg.version.Version(ver,
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1613
                                                            brelease)
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1614
                                                if not ever.is_successor(pat_ver,
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1615
                                                    pkg.version.CONSTRAINT_AUTO):
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1616
                                                        if omit_package is None:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1617
                                                                omit_package = \
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1618
                                                                    True
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1619
                                                        omit_ver = True
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1620
                                                        continue
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1621
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1622
                                        # If this entry matched at least one
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1623
                                        # pattern, then ensure it is returned.
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1624
                                        omit_package = False
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1625
                                        if not raise_unmatched:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1626
                                                # It's faster to stop as soon
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1627
                                                # as a match is found.
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1628
                                                break
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1629
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1630
                                        # If caller has requested other match
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1631
                                        # cases be raised as an exception, then
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1632
                                        # all patterns must be tested for every
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1633
                                        # entry.  This is slower, so only done
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1634
                                        # if necessary.
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1635
                                        pkg_matching_pats.add(pat)
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1636
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1637
                        if omit_package:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1638
                                # Package didn't match critera; skip it.
2033
601cc09f180a 16811 get_pkg_list LIST_NEWEST returns all matching instead of newest matching version
Shawn Walker <shawn.walker@oracle.com>
parents: 2028
diff changeset
  1639
                                if (filter_cb is not None or (newest and
601cc09f180a 16811 get_pkg_list LIST_NEWEST returns all matching instead of newest matching version
Shawn Walker <shawn.walker@oracle.com>
parents: 2028
diff changeset
  1640
                                    pat_versioned)) and omit_ver and \
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1641
                                    nlist[pkg_stem] == 1:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1642
                                        # If omitting because of version, and
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1643
                                        # no other versions have been returned
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1644
                                        # yet for this stem, then discard
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1645
                                        # tracking entry so that other
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1646
                                        # versions will be listed.
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1647
                                        del nlist[pkg_stem]
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1648
                                        slist.discard(stem)
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1649
                                continue
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1650
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1651
                        # Perform image arch and zone variant filtering so
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1652
                        # that only packages appropriate for this image are
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1653
                        # returned, but only do this for packages that are
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1654
                        # not installed.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1655
                        pcats = []
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1656
                        pkgr = False
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1657
                        unsupported = False
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1658
                        summ = None
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1659
                        targets = set()
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1660
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1661
                        states = entry["metadata"]["states"]
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1662
                        pkgi = self.__img.PKG_STATE_INSTALLED in states
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1663
                        try:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1664
                                for a in actions:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1665
                                        if a.name == "depend" and \
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1666
                                            a.attrs["type"] == "require":
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1667
                                                targets.add(a.attrs["fmri"])
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1668
                                                continue
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1669
                                        if a.name != "set":
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1670
                                                continue
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1671
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1672
                                        atname = a.attrs["name"]
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1673
                                        atvalue = a.attrs["value"]
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1674
                                        if atname == "pkg.summary":
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1675
                                                summ = atvalue
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1676
                                                continue
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1677
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1678
                                        if atname == "description":
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1679
                                                if summ is None:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1680
                                                        # Historical summary
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1681
                                                        # field.
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1682
                                                        summ = atvalue
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1683
                                                continue
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1684
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1685
                                        if atname == "info.classification":
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1686
                                                pcats.extend(
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1687
                                                    a.parse_category_info())
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1688
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1689
                                        if pkgi:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1690
                                                # No filtering for installed
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1691
                                                # packages.
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1692
                                                continue
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1693
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1694
                                        # Rename filtering should only be
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1695
                                        # performed for incorporated packages
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1696
                                        # at this point.
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1697
                                        if atname == "pkg.renamed":
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1698
                                                if stem in inc_vers:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1699
                                                        pkgr = True
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1700
                                                continue
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1701
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1702
                                        if variants:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1703
                                                # No variant filtering.
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1704
                                                continue
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1705
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1706
                                        is_list = type(atvalue) == list
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1707
                                        if atname == "variant.arch":
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1708
                                                if (is_list and
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1709
                                                    arch not in atvalue) or \
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1710
                                                   (not is_list and
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1711
                                                   arch != atvalue):
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1712
                                                        # Package is not for the
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1713
                                                        # image's architecture.
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1714
                                                        omit_package = True
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1715
                                                        continue
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1716
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1717
                                        if atname == "variant.opensolaris.zone":
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1718
                                                if (is_zone and is_list and
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1719
                                                    "nonglobal" not in atvalue) or \
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1720
                                                   (is_zone and not is_list and
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1721
                                                    atvalue != "nonglobal"):
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1722
                                                        # Package is for zones
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1723
                                                        # only.
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1724
                                                        omit_package = True
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1725
                        except apx.InvalidPackageErrors:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1726
                                # Ignore errors for packages that have invalid
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1727
                                # or unsupported metadata.  This is necessary so
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1728
                                # that API consumers can discover new package
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1729
                                # data that may be needed to perform an upgrade
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1730
                                # so that the API can understand them.
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1731
                                states = set(states)
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1732
                                states.add(PackageInfo.UNSUPPORTED)
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1733
                                unsupported = True
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1734
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1735
                        if not pkgi and pkgr and stem in inc_vers:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1736
                                # If the package is not installed, but this is
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1737
                                # the terminal version entry for the stem and
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1738
                                # it is an incorporated package, then omit the
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1739
                                # package if it has been installed or is
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1740
                                # incorporated using one of the new names.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1741
                                for e in targets:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1742
                                        tgt = e
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1743
                                        while tgt is not None:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1744
                                                if tgt in ren_inst_stems or \
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1745
                                                    tgt in inc_vers:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1746
                                                        omit_package = True
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1747
                                                        break
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1748
                                                tgt = ren_stems.get(tgt, None)
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1749
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1750
                        if omit_package:
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1751
                                # Package didn't match critera; skip it.
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1752
                                continue
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1753
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1754
                        if cats is not None:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1755
                                if not cats:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1756
                                        if pcats:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1757
                                                # Only want packages with no
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1758
                                                # categories.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1759
                                                continue
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1760
                                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
  1761
                                        # Package doesn't match specified
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1762
                                        # category criteria.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1763
                                        continue
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1764
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1765
                        # Return the requested package data.
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1766
                        if not unsupported:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1767
                                # Prevent modification of state data.
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1768
                                states = frozenset(states)
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1769
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1770
                        if raise_unmatched:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1771
                                # Only after all other filtering has been
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1772
                                # applied are the patterns that the package
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1773
                                # matched considered "matching".
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1774
                                matched_pats.update(pkg_matching_pats)
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1775
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1776
                        if return_fmris:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1777
                                pfmri = fmri.PkgFmri("%s@%s" % (stem, ver),
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1778
                                    build_release=brelease, publisher=pub)
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1779
                                yield (pfmri, summ, pcats, states)
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1780
                        else:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1781
                                yield (t, summ, pcats, states)
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1782
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1783
                if raise_unmatched:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1784
                        # Caller has requested that non-matching patterns or
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1785
                        # patterns that match multiple packages cause an
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1786
                        # exception to be raised.
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1787
                        notfound = set(pat_tuples.keys()) - matched_pats
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1788
                        if raise_unmatched and notfound:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1789
                                raise apx.InventoryException(notfound=notfound)
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1790
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
  1791
        def info(self, fmri_strings, local, info_needed):
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1792
                """Gathers information about fmris.  fmri_strings is a list
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1793
                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
  1794
                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
  1795
                (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
  1796
                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
  1797
                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
  1798
                strings."""
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1799
1191
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  1800
                # 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
  1801
                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
  1802
                try:
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  1803
                        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
  1804
                finally:
1503
78d56b8ee320 12698 download directory must be accessible to non-privileged users
johansen <johansen@sun.com>
parents: 1472
diff changeset
  1805
                        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
  1806
                        self.__activity_lock.release()
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  1807
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  1808
                return i
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  1809
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  1810
        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
  1811
                """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
  1812
                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
  1813
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
  1814
                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
  1815
                if bad_opts:
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1816
                        raise apx.UnrecognizedOptionsToInfo(bad_opts)
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1817
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1818
                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
  1819
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1820
                if local is True:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1821
                        img_cat = self.__img.get_catalog(
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1822
                            self.__img.IMG_CATALOG_INSTALLED)
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1823
                        if not fmri_strings and img_cat.package_count == 0:
1027
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
  1824
                                self.log_operation_end(
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
  1825
                                    result=history.RESULT_NOTHING_TO_DO)
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1826
                                raise apx.NoPackagesInstalledException()
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1827
                        ilist = self.LIST_INSTALLED
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1828
                else:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1829
                        # Verify validity of certificates before attempting
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1830
                        # network operations.
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
  1831
                        self.__cert_verify(
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1832
                            log_op_end=[apx.CertificateError])
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1833
1431
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1389
diff changeset
  1834
                        img_cat = self.__img.get_catalog(
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1389
diff changeset
  1835
                            self.__img.IMG_CATALOG_KNOWN)
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1836
                        ilist = self.LIST_NEWEST
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1837
1431
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1389
diff changeset
  1838
                excludes = self.__img.list_excludes()
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1389
diff changeset
  1839
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1840
                # Set of options that can use catalog data.
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1841
                cat_opts = frozenset([PackageInfo.DESCRIPTION,
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1842
                    PackageInfo.DEPENDENCIES])
1431
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1389
diff changeset
  1843
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1389
diff changeset
  1844
                # Set of options that require manifest retrieval.
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1389
diff changeset
  1845
                act_opts = PackageInfo.ACTION_OPTIONS - \
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1389
diff changeset
  1846
                    frozenset([PackageInfo.DEPENDENCIES])
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1389
diff changeset
  1847
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1848
                pis = []
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1849
                rval = {
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1850
                    self.INFO_FOUND: pis,
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1851
                    self.INFO_MISSING: misc.EmptyI,
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1852
                    self.INFO_ILLEGALS: misc.EmptyI,
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1853
                }
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1854
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1855
                try:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1856
                        for pfmri, summary, cats, states in self.get_pkg_list(
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1857
                            ilist, patterns=fmri_strings, raise_unmatched=True,
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1858
                            return_fmris=True, variants=True):
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1859
                                pub = name = version = release = \
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1860
                                    build_release = branch = \
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1861
                                    packaging_date = None
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1862
                                if PackageInfo.IDENTITY in info_needed:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1863
                                        pub, name, version = pfmri.tuple()
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1864
                                        release = version.release
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1865
                                        build_release = version.build_release
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1866
                                        branch = version.branch
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1867
                                        packaging_date = \
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1868
                                            version.get_timestamp().strftime(
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1869
                                            "%c")
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1870
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1871
                                links = hardlinks = files = dirs = \
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1872
                                    size = licenses = cat_info = \
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1873
                                    description = None
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1874
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1875
                                if PackageInfo.CATEGORIES in info_needed:
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
  1876
                                        cat_info = [
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1877
                                            PackageCategory(scheme, cat)
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1878
                                            for scheme, cat in cats
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1879
                                        ]
1431
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1389
diff changeset
  1880
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1881
                                ret_cat_data = cat_opts & info_needed
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1882
                                dependencies = None
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1883
                                unsupported = False
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1884
                                if ret_cat_data:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1885
                                        try:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1886
                                                ignored, description, ignored, \
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1887
                                                    dependencies = \
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1888
                                                    _get_pkg_cat_data(img_cat,
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1889
                                                        ret_cat_data,
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1890
                                                        excludes=excludes,
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1891
                                                        pfmri=pfmri)
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1892
                                        except apx.InvalidPackageErrors:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1893
                                                # If the information can't be
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1894
                                                # retrieved because the manifest
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1895
                                                # can't be parsed, mark it and
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1896
                                                # continue.
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1897
                                                unsupported = True
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1898
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1899
                                if dependencies is None:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1900
                                        dependencies = misc.EmptyI
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1901
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1902
                                mfst = None
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1903
                                if not unsupported and \
2183
21ae45e8dfcf 17581 There should be a way of removing a package as part of upgrade
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2158
diff changeset
  1904
                                    (frozenset([PackageInfo.SIZE,
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1905
                                    PackageInfo.LICENSES]) | act_opts) & \
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1906
                                    info_needed:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1907
                                        try:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1908
                                                mfst = self.__img.get_manifest(
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1909
                                                    pfmri)
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1910
                                        except apx.InvalidPackageErrors:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1911
                                                # If the information can't be
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1912
                                                # retrieved because the manifest
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1913
                                                # can't be parsed, mark it and
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1914
                                                # continue.
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1915
                                                unsupported = True
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1916
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1917
                                if mfst is not None:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1918
                                        if PackageInfo.LICENSES in info_needed:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1919
                                                licenses = self.__licenses(pfmri,
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1920
                                                    mfst)
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1921
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1922
                                        if PackageInfo.SIZE in info_needed:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1923
                                                size = mfst.get_size(
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1924
                                                    excludes=excludes)
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1925
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1926
                                        if act_opts & info_needed:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1927
                                                if PackageInfo.LINKS in info_needed:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1928
                                                        links = list(
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1929
                                                            mfst.gen_key_attribute_value_by_type(
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1930
                                                            "link", excludes))
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1931
                                                if PackageInfo.HARDLINKS in info_needed:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1932
                                                        hardlinks = list(
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1933
                                                            mfst.gen_key_attribute_value_by_type(
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1934
                                                            "hardlink", excludes))
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1935
                                                if PackageInfo.FILES in info_needed:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1936
                                                        files = list(
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1937
                                                            mfst.gen_key_attribute_value_by_type(
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1938
                                                            "file", excludes))
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1939
                                                if PackageInfo.DIRS in info_needed:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1940
                                                        dirs = list(
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1941
                                                            mfst.gen_key_attribute_value_by_type(
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1942
                                                            "dir", excludes))
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1943
                                elif PackageInfo.SIZE in info_needed:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1944
                                        size = 0
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1945
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1946
                                # Trim response set.
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1947
                                if PackageInfo.STATE in info_needed:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1948
                                        if unsupported is True and \
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1949
                                            PackageInfo.UNSUPPORTED not in states:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1950
                                                # Mark package as
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1951
                                                # unsupported so that
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1952
                                                # caller can decide
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1953
                                                # what to do.
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1954
                                                states = set(states)
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1955
                                                states.add(
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1956
                                                    PackageInfo.UNSUPPORTED)
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1957
                                else:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1958
                                        states = misc.EmptyI
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1959
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1960
                                if PackageInfo.CATEGORIES not in info_needed:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1961
                                        cats = None
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1962
                                if PackageInfo.SUMMARY in info_needed:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1963
                                        if summary is None:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1964
                                                summary = ""
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1965
                                else:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1966
                                        summary = None
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1967
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1968
                                pis.append(PackageInfo(pkg_stem=name,
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1969
                                    summary=summary, category_info_list=cat_info,
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1970
                                    states=states, publisher=pub, version=release,
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1971
                                    build_release=build_release, branch=branch,
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1972
                                    packaging_date=packaging_date, size=size,
2183
21ae45e8dfcf 17581 There should be a way of removing a package as part of upgrade
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2158
diff changeset
  1973
                                    pfmri=str(pfmri), licenses=licenses,
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1974
                                    links=links, hardlinks=hardlinks, files=files,
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1975
                                    dirs=dirs, dependencies=dependencies,
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1976
                                    description=description))
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1977
                except apx.InventoryException, e:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1978
                        if e.illegal:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1979
                                self.log_operation_end(
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1980
                                    result=history.RESULT_FAILED_BAD_REQUEST)
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1981
                        rval[self.INFO_MISSING] = e.notfound
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1982
                        rval[self.INFO_ILLEGALS] = e.illegal
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1983
                else:
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1984
                        if pis:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1985
                                self.log_operation_end()
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1986
                        else:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1987
                                self.log_operation_end(
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1988
                                    result=history.RESULT_NOTHING_TO_DO)
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1989
                return rval
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1990
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1991
        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
  1992
                """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
  1993
                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
  1994
1569
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  1995
        def __disable_cancel(self):
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  1996
                """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
  1997
                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
  1998
                cancellation is pending."""
1569
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  1999
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  2000
                self.__cancel_lock.acquire()
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  2001
                if self.__canceling:
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  2002
                        self.__cancel_lock.release()
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  2003
                        self.__img.transport.reset()
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2004
                        raise apx.CanceledException()
1569
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  2005
                else:
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  2006
                        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
  2007
                self.__cancel_lock.release()
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  2008
1693
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  2009
        def __enable_cancel(self):
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  2010
                """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
  2011
                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
  2012
                calling this function."""
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  2013
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  2014
                self.__cancel_lock.acquire()
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  2015
                self.__set_can_be_canceled(True)
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  2016
                self.__cancel_lock.release()
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  2017
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  2018
        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
  2019
                """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
  2020
                cancelable state."""
1693
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  2021
                assert self.__cancel_lock._is_owned()
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  2022
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  2023
                # 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
  2024
                # nothing to do.
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  2025
                if self.__can_be_canceled == status:
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  2026
                        return
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  2027
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  2028
                if status == True:
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  2029
                        # 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
  2030
                        # that they will make cancelable.
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  2031
                        assert self.__activity_lock._is_owned()
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  2032
                        # 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
  2033
                        # 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
  2034
                        # 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
  2035
                        # 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
  2036
                        # 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
  2037
                        # canceling.
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  2038
                        assert not self.__canceling
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  2039
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  2040
                self.__can_be_canceled = status
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  2041
                if self.__cancel_state_callable:
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  2042
                        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
  2043
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  2044
        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
  2045
                """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
  2046
                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
  2047
                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
  2048
                the prepare method."""
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
  2049
                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
  2050
                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
  2051
                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
  2052
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  2053
        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
  2054
                """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
  2055
                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
  2056
                holds the activity lock."""
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
  2057
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
  2058
                assert self.__activity_lock._is_owned()
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
  2059
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
  2060
                # 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
  2061
                self.__progresstracker.reset()
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
  2062
1503
78d56b8ee320 12698 download directory must be accessible to non-privileged users
johansen <johansen@sun.com>
parents: 1472
diff changeset
  2063
                self.__img.cleanup_downloads()
1634
915de177f257 13746 transport should close connections after download phase
johansen <johansen@sun.com>
parents: 1618
diff changeset
  2064
                self.__img.transport.shutdown()
1242
f6aa06e1c391 6758 api should recreate image object on reset
Shawn Walker <srw@sun.com>
parents: 1240
diff changeset
  2065
                # 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
  2066
                # 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
  2067
                self.__img = image.Image(self.__img_path,
2158
5a688b5b92a3 15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents: 2144
diff changeset
  2068
                    progtrack=self.__progresstracker,
5a688b5b92a3 15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents: 2144
diff changeset
  2069
                    user_provided_dir=True)
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
  2070
                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
  2071
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
  2072
                self.__plan_desc = None
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
  2073
                self.__plan_type = None
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
  2074
                self.__prepared = False
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
  2075
                self.__executed = False
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
  2076
                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
  2077
1569
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  2078
                self.__cancel_cleanup_exception()
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
  2079
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  2080
        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
  2081
                """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
  2082
                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
  2083
                canceled."""
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  2084
                return self.__canceling
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2085
1569
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  2086
        def __cancel_cleanup_exception(self):
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  2087
                """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
  2088
                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
  2089
                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
  2090
                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
  2091
                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
  2092
                it could raise a CanceledException."""
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  2093
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  2094
                self.__cancel_lock.acquire()
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  2095
                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
  2096
                self.__canceling = False
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  2097
                # 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
  2098
                # operation.
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  2099
                self.__cancel_cv.notify_all()
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  2100
                self.__cancel_lock.release()
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  2101
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  2102
        def __cancel_done(self):
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  2103
                """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
  2104
                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
  2105
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  2106
                self.__cancel_lock.acquire()
1693
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  2107
                if self.__canceling:
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  2108
                        self.__canceling = False
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  2109
                        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
  2110
                self.__cancel_lock.release()
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  2111
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  2112
        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
  2113
                """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
  2114
                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
  2115
                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
  2116
                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
  2117
                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
  2118
                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
  2119
                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
  2120
                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
  2121
                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
  2122
                prepare method."""
1569
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  2123
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  2124
                self.__cancel_lock.acquire()
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  2125
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  2126
                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
  2127
                        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
  2128
                        return False
1569
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  2129
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  2130
                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
  2131
                self.__canceling = True
1569
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  2132
                # 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
  2133
                self.__cancel_cv.wait()
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  2134
                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
  2135
                return True
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  2136
716
b836c1b14137 4639 history result info differs for install and uninstall of nonexistent packages
Brock Pytlik <bpytlik@sun.com>
parents: 707
diff changeset
  2137
        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
  2138
                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
  2139
                    e.missing_matches or e.illegal:
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2140
                        self.log_operation_end(error=e,
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2141
                            result=history.RESULT_FAILED_BAD_REQUEST)
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2142
                else:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2143
                        self.log_operation_end(error=e)
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2144
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  2145
        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
  2146
                """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
  2147
                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
  2148
1360
fbf184c6d55b 1059 search both original input and paths with image root removed
Brock Pytlik <bpytlik@sun.com>
parents: 1352
diff changeset
  2149
                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
  2150
                l.build()
fbf184c6d55b 1059 search both original input and paths with image root removed
Brock Pytlik <bpytlik@sun.com>
parents: 1352
diff changeset
  2151
                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
  2152
                ssu = None
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  2153
                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
  2154
                        try:
1893
d935808d8050 15457 pkg search -p should do more than just wrap the query in <>
Brock Pytlik <bpytlik@sun.com>
parents: 1877
diff changeset
  2155
                                query = qp.parse(q.text)
d935808d8050 15457 pkg search -p should do more than just wrap the query in <>
Brock Pytlik <bpytlik@sun.com>
parents: 1877
diff changeset
  2156
                                query_rr = qp.parse(q.text)
1360
fbf184c6d55b 1059 search both original input and paths with image root removed
Brock Pytlik <bpytlik@sun.com>
parents: 1352
diff changeset
  2157
                                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
  2158
                                        query.add_or(query_rr)
1893
d935808d8050 15457 pkg search -p should do more than just wrap the query in <>
Brock Pytlik <bpytlik@sun.com>
parents: 1877
diff changeset
  2159
                                if q.return_type == \
d935808d8050 15457 pkg search -p should do more than just wrap the query in <>
Brock Pytlik <bpytlik@sun.com>
parents: 1877
diff changeset
  2160
                                    query_p.Query.RETURN_PACKAGES:
d935808d8050 15457 pkg search -p should do more than just wrap the query in <>
Brock Pytlik <bpytlik@sun.com>
parents: 1877
diff changeset
  2161
                                        query.propagate_pkg_return()
1053
00fe9773d072 8098 parsing errors should not cause a stacktrace
Brock Pytlik <bpytlik@sun.com>
parents: 1051
diff changeset
  2162
                        except query_p.BooleanQueryException, e:
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2163
                                raise apx.BooleanQueryException(e)
1053
00fe9773d072 8098 parsing errors should not cause a stacktrace
Brock Pytlik <bpytlik@sun.com>
parents: 1051
diff changeset
  2164
                        except query_p.ParseError, e:
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2165
                                raise apx.ParseError(e)
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
  2166
                        self.__img.update_index_dir()
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
  2167
                        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
  2168
                        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
  2169
                                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
  2170
                                    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
  2171
                                    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
  2172
                                    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
  2173
                                        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
  2174
                                    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
  2175
                                        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
  2176
                                    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
  2177
                                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
  2178
                                    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
  2179
                                    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
  2180
                                    self.__img.list_excludes())
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  2181
                        except search_errors.InconsistentIndexException, e:
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2182
                                raise apx.InconsistentIndexException(e)
1100
22a8b08d460a 7364 documentation and code comments needed for fix for 6175
Brock Pytlik <bpytlik@sun.com>
parents: 1087
diff changeset
  2183
                        # 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
  2184
                        # 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
  2185
                        # 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
  2186
                        try:
fbf184c6d55b 1059 search both original input and paths with image root removed
Brock Pytlik <bpytlik@sun.com>
parents: 1352
diff changeset
  2187
                                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
  2188
                                        yield i, None, r
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2189
                        except apx.SlowSearchUsed, e:
1360
fbf184c6d55b 1059 search both original input and paths with image root removed
Brock Pytlik <bpytlik@sun.com>
parents: 1352
diff changeset
  2190
                                ssu = e
fbf184c6d55b 1059 search both original input and paths with image root removed
Brock Pytlik <bpytlik@sun.com>
parents: 1352
diff changeset
  2191
                if ssu:
fbf184c6d55b 1059 search both original input and paths with image root removed
Brock Pytlik <bpytlik@sun.com>
parents: 1352
diff changeset
  2192
                        raise ssu
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  2193
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  2194
        @staticmethod
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  2195
        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
  2196
                """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
  2197
                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
  2198
                (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
  2199
1100
22a8b08d460a 7364 documentation and code comments needed for fix for 6175
Brock Pytlik <bpytlik@sun.com>
parents: 1087
diff changeset
  2200
                "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
  2201
                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
  2202
                request."""
22a8b08d460a 7364 documentation and code comments needed for fix for 6175
Brock Pytlik <bpytlik@sun.com>
parents: 1087
diff changeset
  2203
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  2204
                line = line.strip()
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  2205
                fields = line.split(None, 3)
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  2206
                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
  2207
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  2208
        @staticmethod
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  2209
        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
  2210
                """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
  2211
                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
  2212
                (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
  2213
                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
  2214
                ServerReturnError."""
22a8b08d460a 7364 documentation and code comments needed for fix for 6175
Brock Pytlik <bpytlik@sun.com>
parents: 1087
diff changeset
  2215
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  2216
                fields = line.split(None, 2)
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  2217
                if len(fields) != 3:
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2218
                        raise apx.ServerReturnError(line)
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  2219
                try:
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  2220
                        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
  2221
                        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
  2222
                except ValueError:
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2223
                        raise apx.ServerReturnError(line)
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  2224
                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
  2225
                        subfields = fields[2].split(None, 2)
1843
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  2226
                        pfmri = fmri.PkgFmri(subfields[0])
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  2227
                        return pfmri, (query_num, pub, (v, return_type,
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  2228
                            (pfmri, urllib.unquote(subfields[1]),
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  2229
                            subfields[2])))
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  2230
                elif return_type == Query.RETURN_PACKAGES:
1843
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  2231
                        pfmri = fmri.PkgFmri(fields[2])
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  2232
                        return pfmri, (query_num, pub, (v, return_type, pfmri))
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  2233
                else:
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2234
                        raise apx.ServerReturnError(line)
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  2235
1843
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  2236
        def remote_search(self, query_str_and_args_lst, servers=None,
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  2237
            prune_versions=True):
1100
22a8b08d460a 7364 documentation and code comments needed for fix for 6175
Brock Pytlik <bpytlik@sun.com>
parents: 1087
diff changeset
  2238
                """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
  2239
                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
  2240
                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
  2241
                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
  2242
                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
  2243
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  2244
                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
  2245
                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
  2246
                dictionary, or a Publisher object.
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  2247
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  2248
                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
  2249
                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
  2250
                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
  2251
                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
  2252
                exceptions."""
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  2253
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  2254
                clean_exit = True
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  2255
                canceled = False
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  2256
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
  2257
                self.__acquire_activity_lock()
1693
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  2258
                self.__enable_cancel()
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  2259
                try:
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  2260
                        for r in self._remote_search(query_str_and_args_lst,
1843
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  2261
                            servers, prune_versions):
1693
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  2262
                                yield r
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  2263
                except GeneratorExit:
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  2264
                        return
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2265
                except apx.CanceledException:
1693
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  2266
                        canceled = True
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  2267
                        raise
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  2268
                except Exception:
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  2269
                        clean_exit = False
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  2270
                        raise
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  2271
                finally:
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  2272
                        if canceled:
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  2273
                                self.__cancel_done()
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  2274
                        elif clean_exit:
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  2275
                                try:
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  2276
                                        self.__disable_cancel()
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2277
                                except apx.CanceledException:
1693
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  2278
                                        self.__cancel_done()
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  2279
                                        self.__activity_lock.release()
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  2280
                                        raise
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  2281
                        else:
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  2282
                                self.__cancel_cleanup_exception()
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  2283
                        self.__activity_lock.release()
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  2284
1843
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  2285
        def _remote_search(self, query_str_and_args_lst, servers=None,
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  2286
            prune_versions=True):
1693
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  2287
                """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
  2288
                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
  2289
                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
  2290
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  2291
                failed = []
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  2292
                invalid = []
1191
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  2293
                unsupported = []
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 941
diff changeset
  2294
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  2295
                if not servers:
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
  2296
                        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
  2297
1360
fbf184c6d55b 1059 search both original input and paths with image root removed
Brock Pytlik <bpytlik@sun.com>
parents: 1352
diff changeset
  2298
                new_qs = []
fbf184c6d55b 1059 search both original input and paths with image root removed
Brock Pytlik <bpytlik@sun.com>
parents: 1352
diff changeset
  2299
                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
  2300
                l.build()
fbf184c6d55b 1059 search both original input and paths with image root removed
Brock Pytlik <bpytlik@sun.com>
parents: 1352
diff changeset
  2301
                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
  2302
                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
  2303
                        try:
1893
d935808d8050 15457 pkg search -p should do more than just wrap the query in <>
Brock Pytlik <bpytlik@sun.com>
parents: 1877
diff changeset
  2304
                                query = qp.parse(q.text)
d935808d8050 15457 pkg search -p should do more than just wrap the query in <>
Brock Pytlik <bpytlik@sun.com>
parents: 1877
diff changeset
  2305
                                query_rr = qp.parse(q.text)
1360
fbf184c6d55b 1059 search both original input and paths with image root removed
Brock Pytlik <bpytlik@sun.com>
parents: 1352
diff changeset
  2306
                                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
  2307
                                        query.add_or(query_rr)
1893
d935808d8050 15457 pkg search -p should do more than just wrap the query in <>
Brock Pytlik <bpytlik@sun.com>
parents: 1877
diff changeset
  2308
                                if q.return_type == \
d935808d8050 15457 pkg search -p should do more than just wrap the query in <>
Brock Pytlik <bpytlik@sun.com>
parents: 1877
diff changeset
  2309
                                    query_p.Query.RETURN_PACKAGES:
d935808d8050 15457 pkg search -p should do more than just wrap the query in <>
Brock Pytlik <bpytlik@sun.com>
parents: 1877
diff changeset
  2310
                                        query.propagate_pkg_return()
d935808d8050 15457 pkg search -p should do more than just wrap the query in <>
Brock Pytlik <bpytlik@sun.com>
parents: 1877
diff changeset
  2311
                                new_qs.append(query_p.Query(str(query),
d935808d8050 15457 pkg search -p should do more than just wrap the query in <>
Brock Pytlik <bpytlik@sun.com>
parents: 1877
diff changeset
  2312
                                    q.case_sensitive, q.return_type,
d935808d8050 15457 pkg search -p should do more than just wrap the query in <>
Brock Pytlik <bpytlik@sun.com>
parents: 1877
diff changeset
  2313
                                    q.num_to_return, q.start_point))
1360
fbf184c6d55b 1059 search both original input and paths with image root removed
Brock Pytlik <bpytlik@sun.com>
parents: 1352
diff changeset
  2314
                        except query_p.BooleanQueryException, e:
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2315
                                raise apx.BooleanQueryException(e)
1360
fbf184c6d55b 1059 search both original input and paths with image root removed
Brock Pytlik <bpytlik@sun.com>
parents: 1352
diff changeset
  2316
                        except query_p.ParseError, e:
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2317
                                raise apx.ParseError(e)
1569
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  2318
1360
fbf184c6d55b 1059 search both original input and paths with image root removed
Brock Pytlik <bpytlik@sun.com>
parents: 1352
diff changeset
  2319
                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
  2320
1843
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  2321
                incorp_info, inst_stems = self.get_incorp_info()
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  2322
1191
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  2323
                for pub in servers:
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  2324
                        descriptive_name = None
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 941
diff changeset
  2325
1569
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  2326
                        if self.__canceling:
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2327
                                raise apx.CanceledException()
1569
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  2328
1191
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  2329
                        if isinstance(pub, dict):
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  2330
                                origin = pub["origin"]
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  2331
                                try:
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
  2332
                                        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
  2333
                                            origin=origin)
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2334
                                except apx.UnknownPublisher:
1191
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  2335
                                        pub = publisher.RepositoryURI(origin)
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  2336
                                        descriptive_name = origin
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  2337
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  2338
                        if not descriptive_name:
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  2339
                                descriptive_name = pub.prefix
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  2340
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  2341
                        try:
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
  2342
                                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
  2343
                                    query_str_and_args_lst,
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  2344
                                    ccancel=self.__check_cancelation)
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2345
                        except apx.CanceledException:
1569
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  2346
                                raise
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2347
                        except apx.NegativeSearchResult:
1191
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  2348
                                continue
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2349
                        except apx.TransportError, e:
1191
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  2350
                                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
  2351
                                continue
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2352
                        except apx.UnsupportedSearchError, e:
1191
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  2353
                                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
  2354
                                continue
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2355
                        except apx.MalformedSearchRequest, e:
1191
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  2356
                                ex = self._validate_search(
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  2357
                                    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
  2358
                                if ex:
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  2359
                                        raise ex
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  2360
                                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
  2361
                                continue
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  2362
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  2363
                        try:
1191
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  2364
                                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
  2365
                                        invalid.append(descriptive_name)
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  2366
                                        continue
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  2367
                                for line in res:
1843
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  2368
                                        pfmri, ret = self.__parse_v_1(line, pub,
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  2369
                                            1)
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  2370
                                        pstem = pfmri.pkg_name
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  2371
                                        pver = pfmri.version
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  2372
                                        # Skip this package if a newer version
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  2373
                                        # is already installed and version
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  2374
                                        # pruning is enabled.
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  2375
                                        if prune_versions and \
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  2376
                                            pstem in inst_stems and \
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  2377
                                            pver < inst_stems[pstem]:
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  2378
                                                continue
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  2379
                                        # Return this result if version pruning
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  2380
                                        # is disabled, the package is not
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  2381
                                        # incorporated, or the version of the
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  2382
                                        # package matches the incorporation.
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  2383
                                        if not prune_versions or \
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  2384
                                            pstem not in incorp_info or \
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  2385
                                            pfmri.version.is_successor(
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  2386
                                                incorp_info[pstem],
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  2387
                                                pkg.version.CONSTRAINT_AUTO):
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  2388
                                                yield ret
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  2389
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2390
                        except apx.CanceledException:
1569
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  2391
                                raise
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2392
                        except apx.TransportError, e:
1191
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  2393
                                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
  2394
                                continue
1191
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  2395
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  2396
                if failed or invalid or unsupported:
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2397
                        raise apx.ProblematicSearchServers(failed,
1191
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  2398
                            invalid, unsupported)
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  2399
1843
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  2400
        def get_incorp_info(self):
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  2401
                """This function returns a mapping of package stems to the
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  2402
                version at which they are incorporated, if they are
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  2403
                incorporated, and the version at which they are installed, if
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  2404
                they are installed."""
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  2405
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  2406
                # This maps fmris to the version at which they're incorporated.
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  2407
                inc_vers = {}
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  2408
                inst_stems = {}
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  2409
                brelease = self.__img.attrs["Build-Release"]
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  2410
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  2411
                img_cat = self.__img.get_catalog(
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  2412
                    self.__img.IMG_CATALOG_INSTALLED)
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  2413
                cat_info = frozenset([img_cat.DEPENDENCY])
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  2414
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  2415
                # The incorporation list should include all installed,
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  2416
                # incorporated packages from all publishers.
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  2417
                for pfmri, actions in img_cat.actions(cat_info):
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  2418
                        inst_stems[pfmri.pkg_name] = pfmri.version
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  2419
                        for a in actions:
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  2420
                                if a.name != "depend" or \
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  2421
                                    a.attrs["type"] != "incorporate":
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  2422
                                        continue
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  2423
                                # Record incorporated packages.
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  2424
                                tgt = fmri.PkgFmri(
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  2425
                                    a.attrs["fmri"], brelease)
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  2426
                                tver = tgt.version
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  2427
                                over = inc_vers.get(
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  2428
                                    tgt.pkg_name, None)
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  2429
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  2430
                                # In case this package has been
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  2431
                                # incorporated more than once,
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  2432
                                # use the newest version.
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  2433
                                if over > tver:
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  2434
                                        continue
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  2435
                                inc_vers[tgt.pkg_name] = tver
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  2436
                return inc_vers, inst_stems
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  2437
1360
fbf184c6d55b 1059 search both original input and paths with image root removed
Brock Pytlik <bpytlik@sun.com>
parents: 1352
diff changeset
  2438
        @staticmethod
fbf184c6d55b 1059 search both original input and paths with image root removed
Brock Pytlik <bpytlik@sun.com>
parents: 1352
diff changeset
  2439
        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
  2440
                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
  2441
1191
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  2442
        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
  2443
                """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
  2444
                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
  2445
                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
  2446
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  2447
                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
  2448
                        l = query_p.QueryLexer()
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  2449
                        l.build()
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  2450
                        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
  2451
                        try:
1893
d935808d8050 15457 pkg search -p should do more than just wrap the query in <>
Brock Pytlik <bpytlik@sun.com>
parents: 1877
diff changeset
  2452
                                query = qp.parse(q.text)
1191
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  2453
                        except query_p.BooleanQueryException, e:
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2454
                                return apx.BooleanQueryException(e)
1191
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  2455
                        except query_p.ParseError, e:
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2456
                                return apx.ParseError(e)
1191
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  2457
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  2458
                return None
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  2459
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  2460
        def rebuild_search_index(self):
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  2461
                """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
  2462
                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
  2463
                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
  2464
                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
  2465
                been corrupted."""
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
  2466
                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
  2467
                self.log_operation_start("rebuild-index")
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
  2468
                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
  2469
                        self.__img.mkdirs()
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  2470
                try:
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
  2471
                        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
  2472
                            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
  2473
                            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
  2474
                        ind.rebuild_index_from_scratch(
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
  2475
                            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
  2476
                except search_errors.ProblematicPermissionsIndexException, e:
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2477
                        error = apx.ProblematicPermissionsIndexException(e)
1027
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
  2478
                        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
  2479
                        raise error
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  2480
                else:
1027
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
  2481
                        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
  2482
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2483
        def get_manifest(self, pfmri, all_variants=True):
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2484
                """Returns the Manifest object for the given package FMRI.
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2485
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2486
                'all_variants' is an optional boolean value indicating whther
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2487
                the manifest should include metadata for all variants.
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2488
                """
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2489
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2490
                return self.__img.get_manifest(pfmri, all_variants=all_variants)
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
  2491
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  2492
        @staticmethod
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  2493
        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
  2494
                """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
  2495
                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
  2496
                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
  2497
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  2498
                try:
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  2499
                        s = res.next()
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  2500
                        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
  2501
                except StopIteration:
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  2502
                        return False
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  2503
2026
d1b30615bc99 9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents: 2024
diff changeset
  2504
        def add_publisher(self, pub, refresh_allowed=True,
d1b30615bc99 9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents: 2024
diff changeset
  2505
            approved_cas=misc.EmptyI, revoked_cas=misc.EmptyI,
d1b30615bc99 9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents: 2024
diff changeset
  2506
            unset_cas=misc.EmptyI):
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2507
                """Add the provided publisher object to the image
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2508
                configuration."""
1503
78d56b8ee320 12698 download directory must be accessible to non-privileged users
johansen <johansen@sun.com>
parents: 1472
diff changeset
  2509
                try:
78d56b8ee320 12698 download directory must be accessible to non-privileged users
johansen <johansen@sun.com>
parents: 1472
diff changeset
  2510
                        self.__img.add_publisher(pub,
78d56b8ee320 12698 download directory must be accessible to non-privileged users
johansen <johansen@sun.com>
parents: 1472
diff changeset
  2511
                            refresh_allowed=refresh_allowed,
2026
d1b30615bc99 9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents: 2024
diff changeset
  2512
                            progtrack=self.__progresstracker,
d1b30615bc99 9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents: 2024
diff changeset
  2513
                            approved_cas=approved_cas, revoked_cas=revoked_cas,
d1b30615bc99 9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents: 2024
diff changeset
  2514
                            unset_cas=unset_cas)
1503
78d56b8ee320 12698 download directory must be accessible to non-privileged users
johansen <johansen@sun.com>
parents: 1472
diff changeset
  2515
                finally:
78d56b8ee320 12698 download directory must be accessible to non-privileged users
johansen <johansen@sun.com>
parents: 1472
diff changeset
  2516
                        self.__img.cleanup_downloads()
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2517
1505
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  2518
        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
  2519
                """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
  2520
                disabled publishers"""
2097
068cc63b4d6e 17055 image configuration should use pkg.config classes
Shawn Walker <shawn.walker@oracle.com>
parents: 2092
diff changeset
  2521
                return self.__img.cfg.get_property("property",
068cc63b4d6e 17055 image configuration should use pkg.config classes
Shawn Walker <shawn.walker@oracle.com>
parents: 2092
diff changeset
  2522
                    "publisher-search-order")
1505
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  2523
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  2524
        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
  2525
                """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
  2526
                searched after staying_put"""
2097
068cc63b4d6e 17055 image configuration should use pkg.config classes
Shawn Walker <shawn.walker@oracle.com>
parents: 2092
diff changeset
  2527
                self.__img.pub_search_after(being_moved_prefix,
068cc63b4d6e 17055 image configuration should use pkg.config classes
Shawn Walker <shawn.walker@oracle.com>
parents: 2092
diff changeset
  2528
                    staying_put_prefix)
1505
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  2529
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  2530
        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
  2531
                """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
  2532
                searched before staying_put"""
2097
068cc63b4d6e 17055 image configuration should use pkg.config classes
Shawn Walker <shawn.walker@oracle.com>
parents: 2092
diff changeset
  2533
                self.__img.pub_search_before(being_moved_prefix,
068cc63b4d6e 17055 image configuration should use pkg.config classes
Shawn Walker <shawn.walker@oracle.com>
parents: 2092
diff changeset
  2534
                    staying_put_prefix)
1505
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  2535
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2536
        def get_preferred_publisher(self):
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2537
                """Returns the preferred publisher object for the image."""
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2538
                return self.get_publisher(
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
  2539
                    prefix=self.__img.get_preferred_publisher())
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2540
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2541
        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
  2542
                """Retrieves a publisher object matching the provided prefix
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2543
                (name) or alias.
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2544
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2545
                'duplicate' is an optional boolean value indicating whether
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2546
                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
  2547
                of the original.
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2548
                """
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
  2549
                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
  2550
                if duplicate:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2551
                        # Never return the original so that changes to the
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2552
                        # retrieved object are not reflected until
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2553
                        # update_publisher is called.
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2554
                        return copy.copy(pub)
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2555
                return pub
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2556
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2557
        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
  2558
                """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
  2559
                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
  2560
                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
  2561
                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
  2562
                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
  2563
                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
  2564
                specified repository, an UnsupportedRepositoryOperation
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2565
                exception will be raised.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2566
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2567
                '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
  2568
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2569
                '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
  2570
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2571
                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
  2572
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2573
                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
  2574
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2575
                # 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
  2576
                # 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
  2577
                pub = max(pub, repo)
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2578
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2579
                self.__activity_lock.acquire()
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2580
                try:
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2581
                        self.__enable_cancel()
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2582
                        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
  2583
                            ccancel=self.__check_cancelation)
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2584
                        self.__disable_cancel()
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2585
                        return data
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2586
                except apx.CanceledException:
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2587
                        self.__cancel_done()
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2588
                        raise
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2589
                except:
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2590
                        self.__cancel_cleanup_exception()
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2591
                        raise
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2592
                finally:
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2593
                        self.__img.cleanup_downloads()
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2594
                        self.__activity_lock.release()
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2595
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2596
        def get_publishers(self, duplicate=False):
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2597
                """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
  2598
                image.
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2599
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2600
                'duplicate' is an optional boolean value indicating whether
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2601
                copies of the publisher objects should be returned instead
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2602
                of the originals.
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2603
                """
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2604
                if duplicate:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2605
                        # 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
  2606
                        # are not reflected until update_publisher is called.
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2607
                        pubs = [
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2608
                            copy.copy(p)
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
  2609
                            for p in self.__img.get_publishers().values()
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2610
                        ]
716
b836c1b14137 4639 history result info differs for install and uninstall of nonexistent packages
Brock Pytlik <bpytlik@sun.com>
parents: 707
diff changeset
  2611
                else:
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
  2612
                        pubs = self.__img.get_publishers().values()
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2613
                return misc.get_sorted_publishers(pubs,
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
  2614
                    preferred=self.__img.get_preferred_publisher())
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2615
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2616
        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
  2617
                """Returns a datetime object representing the last time the
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2618
                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
  2619
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2620
                if alias:
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
  2621
                        pub = self.get_publisher(alias=alias)
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
  2622
                else:
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
  2623
                        pub = self.get_publisher(prefix=prefix)
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
  2624
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
  2625
                if pub.disabled:
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
  2626
                        return None
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
  2627
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2628
                dt = None
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
  2629
                self.__acquire_activity_lock()
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2630
                try:
1693
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  2631
                        self.__enable_cancel()
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2632
                        try:
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
  2633
                                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
  2634
                        except:
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2635
                                self.__reset_unlock()
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2636
                                raise
1693
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  2637
                        try:
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  2638
                                self.__disable_cancel()
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2639
                        except apx.CanceledException:
1693
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  2640
                                self.__cancel_done()
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  2641
                                raise
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2642
                finally:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2643
                        self.__activity_lock.release()
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2644
                return dt
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2645
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2646
        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
  2647
                """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
  2648
                the given prefix or alias exists."""
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
  2649
                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
  2650
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2651
        def remove_publisher(self, prefix=None, alias=None):
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2652
                """Removes a publisher object matching the provided prefix
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2653
                (name) or alias."""
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
  2654
                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
  2655
                    progtrack=self.__progresstracker)
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2656
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2657
        def set_preferred_publisher(self, prefix=None, alias=None):
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2658
                """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
  2659
                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
  2660
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2661
        def update_publisher(self, pub, refresh_allowed=True):
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2662
                """Replaces an existing publisher object with the provided one
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2663
                using the _source_object_id identifier set during copy.
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2664
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2665
                'refresh_allowed' is an optional boolean value indicating
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2666
                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
  2667
                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
  2668
                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
  2669
                made to retrieve publisher metadata."""
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2670
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
  2671
                self.__acquire_activity_lock()
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
  2672
                try:
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2673
                        self.__disable_cancel()
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
  2674
                        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
  2675
                                return self.__update_publisher(pub,
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
  2676
                                    refresh_allowed=refresh_allowed)
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2677
                except apx.CanceledException, e:
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2678
                        self.__cancel_done()
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2679
                        raise
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
  2680
                finally:
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
  2681
                        self.__img.cleanup_downloads()
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
  2682
                        self.__activity_lock.release()
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
  2683
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
  2684
        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
  2685
                """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
  2686
                locking."""
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2687
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2688
                if pub.disabled and \
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
  2689
                    pub.prefix == self.__img.get_preferred_publisher():
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2690
                        raise apx.SetPreferredPublisherDisabled(
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2691
                            pub.prefix)
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2692
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2693
                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
  2694
                        old_origins = set([
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2695
                            (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
  2696
                                o.ssl_key)
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2697
                            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
  2698
                        ])
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2699
                        new_origins = set([
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2700
                            (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
  2701
                                o.ssl_key)
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2702
                            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
  2703
                        ])
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2704
                        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
  2705
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2706
                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
  2707
                        if newo.disabled:
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  2708
                                # 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
  2709
                                # should be performed.
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  2710
                                return False
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  2711
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2712
                        if oldo.disabled and not newo.disabled:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2713
                                # The publisher has been re-enabled, so
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2714
                                # retrieve the catalog.
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2715
                                return True
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2716
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2717
                        if len(newo.repositories) != len(oldo.repositories):
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2718
                                # If there are an unequal number of repositories
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2719
                                # then some have been added or removed.
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2720
                                return True
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2721
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2722
                        oldr = oldo.selected_repository
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2723
                        newr = newo.selected_repository
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2724
                        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
  2725
                                # Selected repository has changed.
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2726
                                return True
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2727
                        return len(origins_changed(oldr, newr)) != 0
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2728
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 941
diff changeset
  2729
                refresh_catalog = False
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  2730
                disable = False
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  2731
                orig_pub = None
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
  2732
                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
  2733
7ffa6f902aa0 9218 pkg.client.api should check for cross-alias/prefix duplicates
Shawn Walker <srw@sun.com>
parents: 1710
diff changeset
  2734
                # 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
  2735
                # 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
  2736
                # copy().
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2737
                for key, old in publishers.iteritems():
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2738
                        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
  2739
                                # 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
  2740
                                # 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
  2741
                                # update operation fails.
7ffa6f902aa0 9218 pkg.client.api should check for cross-alias/prefix duplicates
Shawn Walker <srw@sun.com>
parents: 1710
diff changeset
  2742
                                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
  2743
                                break
7ffa6f902aa0 9218 pkg.client.api should check for cross-alias/prefix duplicates
Shawn Walker <srw@sun.com>
parents: 1710
diff changeset
  2744
7ffa6f902aa0 9218 pkg.client.api should check for cross-alias/prefix duplicates
Shawn Walker <srw@sun.com>
parents: 1710
diff changeset
  2745
                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
  2746
                        # 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
  2747
                        # 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
  2748
                        # error).
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2749
                        raise apx.UnknownPublisher(pub)
1733
7ffa6f902aa0 9218 pkg.client.api should check for cross-alias/prefix duplicates
Shawn Walker <srw@sun.com>
parents: 1710
diff changeset
  2750
7ffa6f902aa0 9218 pkg.client.api should check for cross-alias/prefix duplicates
Shawn Walker <srw@sun.com>
parents: 1710
diff changeset
  2751
                # 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
  2752
                # 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
  2753
                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
  2754
                        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
  2755
                                # 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
  2756
                                continue
7ffa6f902aa0 9218 pkg.client.api should check for cross-alias/prefix duplicates
Shawn Walker <srw@sun.com>
parents: 1710
diff changeset
  2757
7ffa6f902aa0 9218 pkg.client.api should check for cross-alias/prefix duplicates
Shawn Walker <srw@sun.com>
parents: 1710
diff changeset
  2758
                        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
  2759
                            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
  2760
                            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
  2761
                            pub.alias == old.prefix):
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2762
                                raise apx.DuplicatePublisher(pub)
1733
7ffa6f902aa0 9218 pkg.client.api should check for cross-alias/prefix duplicates
Shawn Walker <srw@sun.com>
parents: 1710
diff changeset
  2763
7ffa6f902aa0 9218 pkg.client.api should check for cross-alias/prefix duplicates
Shawn Walker <srw@sun.com>
parents: 1710
diff changeset
  2764
                # 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
  2765
                # publisher.
7ffa6f902aa0 9218 pkg.client.api should check for cross-alias/prefix duplicates
Shawn Walker <srw@sun.com>
parents: 1710
diff changeset
  2766
                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
  2767
                        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
  2768
                                old = orig_pub[-1]
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2769
                                if need_refresh(old, pub):
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2770
                                        refresh_catalog = True
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  2771
                                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
  2772
                                        disable = True
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  2773
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  2774
                                # 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
  2775
                                # 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
  2776
                                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
  2777
                                        del publishers[key]
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  2778
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
  2779
                                # Prepare the new publisher object.
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
  2780
                                pub.meta_root = \
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
  2781
                                    self.__img._get_publisher_meta_root(
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
  2782
                                    pub.prefix)
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
  2783
                                pub.transport = self.__img.transport
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
  2784
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  2785
                                # Finally, add the new publisher object.
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2786
                                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
  2787
                                break
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2788
1102
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1100
diff changeset
  2789
                def cleanup():
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1100
diff changeset
  2790
                        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
  2791
                        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
  2792
                                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
  2793
                                        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
  2794
                                        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
  2795
                                        break
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1100
diff changeset
  2796
1504
265a1d6b86bd 9969 client support for multiple origins desired
Shawn Walker <srw@sun.com>
parents: 1503
diff changeset
  2797
                repo = pub.selected_repository
265a1d6b86bd 9969 client support for multiple origins desired
Shawn Walker <srw@sun.com>
parents: 1503
diff changeset
  2798
                if not repo.origins:
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2799
                        raise apx.PublisherOriginRequired(pub.prefix)
1504
265a1d6b86bd 9969 client support for multiple origins desired
Shawn Walker <srw@sun.com>
parents: 1503
diff changeset
  2800
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2801
                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
  2802
                    pub.selected_repository)
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2803
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  2804
                try:
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  2805
                        if disable:
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  2806
                                # 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
  2807
                                # 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
  2808
                                # 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
  2809
                                # 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
  2810
                                # refresh() will do the right thing.
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
  2811
                                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
  2812
                        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
  2813
                                refresh_catalog = pub.needs_refresh
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2814
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2815
                        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
  2816
                                # 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
  2817
                                # 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
  2818
                                # revalidated.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2819
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2820
                                if validate:
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
  2821
                                        self.__img.transport.valid_publisher_test(
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
  2822
                                            pub)
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2823
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2824
                                # 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
  2825
                                # configuration.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2826
                                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
  2827
                                        repo = publisher.RepositoryURI(uri,
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2828
                                            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
  2829
                                        pub.validate_config(repo)
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2830
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2831
                                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
  2832
                        elif refresh_catalog:
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2833
                                # 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
  2834
                                # 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
  2835
                                # 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
  2836
                                # 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
  2837
                                # 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
  2838
                                # 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
  2839
                                pub.last_refreshed = None
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2840
                except Exception, e:
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2841
                        # 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
  2842
                        # 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
  2843
                        # consistent.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2844
                        cleanup()
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2845
                        raise
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  2846
                except:
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  2847
                        # 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
  2848
                        # 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
  2849
                        # consistent.
1102
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1100
diff changeset
  2850
                        cleanup()
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  2851
                        raise
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2852
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 941
diff changeset
  2853
                # Successful; so save configuration.
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
  2854
                self.__img.save_config()
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2855
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2856
        def log_operation_end(self, error=None, result=None):
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2857
                """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
  2858
                history.
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2859
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2860
                'result' should be a pkg.client.history constant value
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2861
                representing the outcome of an operation.  If not provided,
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2862
                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
  2863
                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
  2864
                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
  2865
                provided, success is assumed."""
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
  2866
                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
  2867
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2868
        def log_operation_error(self, error):
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2869
                """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
  2870
                history for the current opreation."""
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
  2871
                self.__img.history.log_operation_error(error)
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2872
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2873
        def log_operation_start(self, name):
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2874
                """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
  2875
                history."""
2141
3757a0f8a7d1 17385 history should store uuids for boot environments
Tim Foster <tim.s.foster@oracle.com>
parents: 2135
diff changeset
  2876
                be_name, be_uuid = bootenv.BootEnv.get_be_name(self.__img.root)
2135
6eeb55920e13 3419 history command -- ability to specify dates or date ranges desired
Tim Foster <tim.s.foster@oracle.com>
parents: 2134
diff changeset
  2877
                self.__img.history.log_operation_start(name,
2141
3757a0f8a7d1 17385 history should store uuids for boot environments
Tim Foster <tim.s.foster@oracle.com>
parents: 2135
diff changeset
  2878
                    be_name=be_name, be_uuid=be_uuid)
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2879
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2880
        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
  2881
                """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
  2882
                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
  2883
                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
  2884
                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
  2885
                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
  2886
                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
  2887
                pkg_names).
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2888
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2889
                '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
  2890
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2891
                '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
  2892
                'read' method for retrieving data.
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2893
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2894
                '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
  2895
                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
  2896
                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
  2897
                'ftp', 'http', and 'https'.
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2898
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2899
                '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
  2900
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2901
                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
  2902
1835
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  2903
        def parse_fmri_patterns(self, patterns):
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  2904
                """A generator function that yields a list of tuples of the form
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  2905
                (pattern, error, fmri, matcher) based on the provided patterns,
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  2906
                where 'error' is any exception encountered while parsing the
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  2907
                pattern, 'fmri' is the resulting FMRI object, and 'matcher' is
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  2908
                one of the following constant values:
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  2909
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  2910
                        MATCH_EXACT
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  2911
                                Indicates that the name portion of the pattern
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  2912
                                must match exactly and the version (if provided)
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  2913
                                must be considered a successor or equal to the
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  2914
                                target FMRI.
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  2915
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  2916
                        MATCH_FMRI
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  2917
                                Indicates that the name portion of the pattern
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  2918
                                must be a proper subset and the version (if
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  2919
                                provided) must be considered a successor or
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  2920
                                equal to the target FMRI.
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  2921
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  2922
                        MATCH_GLOB
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  2923
                                Indicates that the name portion of the pattern
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  2924
                                uses fnmatch rules for pattern matching (shell-
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  2925
                                style wildcards) and that the version can either
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  2926
                                match exactly, match partially, or contain
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  2927
                                wildcards.
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  2928
                """
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  2929
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  2930
                brelease = self.__img.attrs["Build-Release"]
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  2931
                for pat in patterns:
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  2932
                        error = None
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  2933
                        matcher = None
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  2934
                        npat = None
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  2935
                        try:
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  2936
                                if "*" in pat or "?" in pat:
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  2937
                                        # XXX By default, matching FMRIs
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  2938
                                        # currently do not also use
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  2939
                                        # MatchingVersion.  If that changes,
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  2940
                                        # this should  change too.
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  2941
                                        parts = pat.split("@", 1)
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  2942
                                        if len(parts) == 1:
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  2943
                                                npat = fmri.MatchingPkgFmri(pat,
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  2944
                                                    brelease)
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  2945
                                        else:
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  2946
                                                npat = fmri.MatchingPkgFmri(
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  2947
                                                    parts[0], brelease)
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  2948
                                                npat.version = \
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  2949
                                                    pkg.version.MatchingVersion(
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  2950
                                                    str(parts[1]), brelease)
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  2951
                                        matcher = self.MATCH_GLOB
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  2952
                                elif pat.startswith("pkg:/"):
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  2953
                                        npat = fmri.PkgFmri(pat, brelease)
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  2954
                                        matcher = self.MATCH_EXACT
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  2955
                                else:
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  2956
                                        npat = pkg.fmri.PkgFmri(pat, brelease)
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  2957
                                        matcher = self.MATCH_FMRI
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  2958
                        except (fmri.FmriError, pkg.version.VersionError), e:
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  2959
                                # Whatever the error was, return it.
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  2960
                                error = e
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  2961
                        yield (pat, error, npat, matcher)
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  2962
2144
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2141
diff changeset
  2963
        def update_format(self):
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2141
diff changeset
  2964
                """Attempt to update the on-disk format of the image to the
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2141
diff changeset
  2965
                newest version.  Returns a boolean indicating whether any action
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2141
diff changeset
  2966
                was taken."""
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2141
diff changeset
  2967
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2141
diff changeset
  2968
                self.__acquire_activity_lock()
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2141
diff changeset
  2969
                try:
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2141
diff changeset
  2970
                        self.__disable_cancel()
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2141
diff changeset
  2971
                        self.__img.allow_ondisk_upgrade = True
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2141
diff changeset
  2972
                        return self.__img.update_format(
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2141
diff changeset
  2973
                            progtrack=self.__progresstracker)
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2141
diff changeset
  2974
                except apx.CanceledException, e:
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2141
diff changeset
  2975
                        self.__cancel_done()
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2141
diff changeset
  2976
                        raise
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2141
diff changeset
  2977
                finally:
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2141
diff changeset
  2978
                        self.__activity_lock.release()
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2141
diff changeset
  2979
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2980
        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
  2981
                """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
  2982
                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
  2983
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2984
                '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
  2985
                data to be written as a parameter.
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2986
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2987
                '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
  2988
                publisher prefix that contain package names, FMRI strings, or
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2989
                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
  2990
                that are not specific to a publisher.
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2991
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2992
                '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
  2993
                objects.  If not provided, the information for all publishers
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2994
                (excluding those disabled) will be output."""
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2995
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2996
                if not pubs:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2997
                        plist = [
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2998
                            p for p in self.get_publishers()
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2999
                            if not p.disabled
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  3000
                        ]
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  3001
                else:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  3002
                        plist = []
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  3003
                        for p in pubs:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  3004
                                if not isinstance(p, publisher.Publisher):
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
  3005
                                        plist.append(self.__img.get_publisher(
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  3006
                                            prefix=p, alias=p))
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  3007
                                else:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  3008
                                        plist.append(p)
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  3009
1257
d911e4542c41 9025 pkg.client.api needs to use p5i module
Shawn Walker <srw@sun.com>
parents: 1256
diff changeset
  3010
                # 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
  3011
                # 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
  3012
                new_pkg_names = {}
d911e4542c41 9025 pkg.client.api needs to use p5i module
Shawn Walker <srw@sun.com>
parents: 1256
diff changeset
  3013
                for pub in pkg_names:
d911e4542c41 9025 pkg.client.api needs to use p5i module
Shawn Walker <srw@sun.com>
parents: 1256
diff changeset
  3014
                        pkglist = []
d911e4542c41 9025 pkg.client.api needs to use p5i module
Shawn Walker <srw@sun.com>
parents: 1256
diff changeset
  3015
                        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
  3016
                                if isinstance(p, PackageInfo):
d911e4542c41 9025 pkg.client.api needs to use p5i module
Shawn Walker <srw@sun.com>
parents: 1256
diff changeset
  3017
                                        pkglist.append(p.fmri)
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  3018
                                else:
1257
d911e4542c41 9025 pkg.client.api needs to use p5i module
Shawn Walker <srw@sun.com>
parents: 1256
diff changeset
  3019
                                        pkglist.append(p)
d911e4542c41 9025 pkg.client.api needs to use p5i module
Shawn Walker <srw@sun.com>
parents: 1256
diff changeset
  3020
                        new_pkg_names[pub] = pkglist
d911e4542c41 9025 pkg.client.api needs to use p5i module
Shawn Walker <srw@sun.com>
parents: 1256
diff changeset
  3021
                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
  3022
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  3023
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  3024
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
  3025
        """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
  3026
        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
  3027
        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
  3028
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  3029
        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
  3030
            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
  3031
                if return_actions:
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  3032
                        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
  3033
                else:
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  3034
                        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
  3035
                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
  3036
                    num_to_return, start_point)
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  3037
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  3038
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  3039
class PlanDescription(object):
1618
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  3040
        """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
  3041
2034
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
  3042
        def __init__(self, img, new_be):
1618
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  3043
                self.__plan = img.imageplan
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  3044
                self.__img = img
2034
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
  3045
                self.__new_be = new_be
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
  3046
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
  3047
        def get_services(self):
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
  3048
                """Returns a list of services affected in this plan."""
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
  3049
                return self.__plan.services
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
  3050
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
  3051
        def get_varcets(self):
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
  3052
                """Returns a list of variant/facet changes in this plan"""
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
  3053
                return self.__plan.varcets
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  3054
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  3055
        def get_changes(self):
1618
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  3056
                """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
  3057
                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
  3058
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  3059
                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
  3060
                installed.
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  3061
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  3062
                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
  3063
                is the package being removed.
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  3064
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  3065
                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
  3066
                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
  3067
                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
  3068
                being upgraded to."""
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  3069
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  3070
                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
  3071
                        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
  3072
                            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
  3073
2034
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
  3074
        def get_actions(self):
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
  3075
                """A generator function that returns action changes for all
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
  3076
                the package plans"""
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
  3077
                for pp in self.__plan.pkg_plans:
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
  3078
                        yield str(pp)
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
  3079
1618
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  3080
        def get_licenses(self, pfmri=None):
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  3081
                """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
  3082
                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
  3083
                (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
  3084
                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
  3085
                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
  3086
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  3087
                '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
  3088
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  3089
                '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
  3090
                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
  3091
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  3092
                '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
  3093
                installed.
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  3094
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  3095
                '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
  3096
                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
  3097
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  3098
                '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
  3099
                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
  3100
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  3101
                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
  3102
                        dfmri = pp.destination_fmri
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  3103
                        if pfmri and dfmri != pfmri:
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  3104
                                continue
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  3105
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  3106
                        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
  3107
                                src = entry["src"]
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  3108
                                src_li = None
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  3109
                                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
  3110
                                        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
  3111
                                            src, img=self.__img)
1618
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  3112
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  3113
                                dest = entry["dest"]
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  3114
                                dest_li = None
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  3115
                                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
  3116
                                        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
  3117
                                            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
  3118
                                            img=self.__img)
1618
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  3119
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  3120
                                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
  3121
                                    entry["accepted"], entry["displayed"])
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  3122
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  3123
                        if pfmri:
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  3124
                                break
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3125
1877
3bdaef023cdb 5907 api info needs to return reboot required info
Padraig O'Briain <padraig.obriain@oracle.com>
parents: 1859
diff changeset
  3126
        @property
3bdaef023cdb 5907 api info needs to return reboot required info
Padraig O'Briain <padraig.obriain@oracle.com>
parents: 1859
diff changeset
  3127
        def reboot_needed(self):
3bdaef023cdb 5907 api info needs to return reboot required info
Padraig O'Briain <padraig.obriain@oracle.com>
parents: 1859
diff changeset
  3128
                """A boolean value indicating that execution of the plan will
3bdaef023cdb 5907 api info needs to return reboot required info
Padraig O'Briain <padraig.obriain@oracle.com>
parents: 1859
diff changeset
  3129
                require a restart of the system to take effect if the target
3bdaef023cdb 5907 api info needs to return reboot required info
Padraig O'Briain <padraig.obriain@oracle.com>
parents: 1859
diff changeset
  3130
                image is an existing boot environment."""
3bdaef023cdb 5907 api info needs to return reboot required info
Padraig O'Briain <padraig.obriain@oracle.com>
parents: 1859
diff changeset
  3131
                return self.__plan.reboot_needed()
3bdaef023cdb 5907 api info needs to return reboot required info
Padraig O'Briain <padraig.obriain@oracle.com>
parents: 1859
diff changeset
  3132
2034
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
  3133
        @property
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
  3134
        def new_be(self):
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
  3135
                """A boolean value indicating that execution of the plan will
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
  3136
                take place in a clone of the current live environment"""
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
  3137
                return self.__new_be
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
  3138
2105
212a253a462a 12530 pkg -R install doesn't update boot archive
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2100
diff changeset
  3139
        @property
212a253a462a 12530 pkg -R install doesn't update boot archive
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2100
diff changeset
  3140
        def update_boot_archive(self):
212a253a462a 12530 pkg -R install doesn't update boot archive
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2100
diff changeset
  3141
                """A boolean value indicating whether or not the boot archive
212a253a462a 12530 pkg -R install doesn't update boot archive
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2100
diff changeset
  3142
                will be rebuilt"""
212a253a462a 12530 pkg -R install doesn't update boot archive
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2100
diff changeset
  3143
                return self.__plan.boot_archive_needed()
212a253a462a 12530 pkg -R install doesn't update boot archive
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2100
diff changeset
  3144
2034
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
  3145
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3146
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
  3147
    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
  3148
    mirrors=misc.EmptyI, origins=misc.EmptyI, prefix=None, refresh_allowed=True,
2100
6a366b063036 17144 Unix socket support is defunct
johansen <johansen@opensolaris.org>
parents: 2097
diff changeset
  3149
    repo_uri=None, ssl_cert=None, ssl_key=None, user_provided_dir=False,
6a366b063036 17144 Unix socket support is defunct
johansen <johansen@opensolaris.org>
parents: 2097
diff changeset
  3150
    progtrack=None, variants=misc.EmptyDict, props=misc.EmptyDict):
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3151
        """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
  3152
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3153
        '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
  3154
        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
  3155
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3156
        '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
  3157
        expecting to use.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3158
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3159
        '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
  3160
        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
  3161
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3162
        '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
  3163
        to create.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3164
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3165
        '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
  3166
        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
  3167
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3168
        '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
  3169
        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
  3170
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3171
        '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
  3172
        the image creation process.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3173
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3174
        '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
  3175
        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
  3176
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3177
        '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
  3178
        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
  3179
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3180
        '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
  3181
        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
  3182
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3183
        '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
  3184
        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
  3185
        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
  3186
        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
  3187
        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
  3188
        '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
  3189
2026
d1b30615bc99 9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents: 2024
diff changeset
  3190
        'props' is an optional dictionary mapping image property names to values
d1b30615bc99 9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents: 2024
diff changeset
  3191
        to be set while creating the image.
d1b30615bc99 9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents: 2024
diff changeset
  3192
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3193
        '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
  3194
        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
  3195
        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
  3196
        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
  3197
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3198
        '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
  3199
        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
  3200
        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
  3201
        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
  3202
        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
  3203
        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
  3204
        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
  3205
        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
  3206
        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
  3207
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3208
        '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
  3209
        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
  3210
        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
  3211
        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
  3212
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3213
        '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
  3214
        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
  3215
        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
  3216
        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
  3217
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3218
        '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
  3219
        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
  3220
        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
  3221
        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
  3222
        directory.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3223
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3224
        '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
  3225
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3226
        '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
  3227
        the image creation process.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3228
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3229
        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
  3230
         * 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
  3231
         * 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
  3232
         * a 'prefix' and 'origins'
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3233
        """
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3234
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3235
        # 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
  3236
        # 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
  3237
        assert (prefix and repo_uri) or (not prefix and repo_uri) or (prefix and
2100
6a366b063036 17144 Unix socket support is defunct
johansen <johansen@opensolaris.org>
parents: 2097
diff changeset
  3238
            origins)
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3239
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3240
        # 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
  3241
        # cannot be done.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3242
        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
  3243
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3244
        destroy_root = False
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3245
        try:
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3246
                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
  3247
        except EnvironmentError, e:
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3248
                if e.errno == errno.EACCES:
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3249
                        raise apx.PermissionsException(
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3250
                            e.filename)
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3251
                raise
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3252
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3253
        # 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
  3254
        # 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
  3255
        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
  3256
            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
  3257
            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
  3258
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3259
        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
  3260
            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
  3261
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3262
        try:
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3263
                if repo_uri:
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3264
                        # Assume auto configuration.
1834
43fcb0ca2c26 15120 image-create fails for ssl-based publisher repositories
Shawn Walker <shawn.walker@oracle.com>
parents: 1829
diff changeset
  3265
                        if ssl_cert:
43fcb0ca2c26 15120 image-create fails for ssl-based publisher repositories
Shawn Walker <shawn.walker@oracle.com>
parents: 1829
diff changeset
  3266
                                misc.validate_ssl_cert(ssl_cert, prefix=prefix,
43fcb0ca2c26 15120 image-create fails for ssl-based publisher repositories
Shawn Walker <shawn.walker@oracle.com>
parents: 1829
diff changeset
  3267
                                    uri=repo_uri)
43fcb0ca2c26 15120 image-create fails for ssl-based publisher repositories
Shawn Walker <shawn.walker@oracle.com>
parents: 1829
diff changeset
  3268
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3269
                        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
  3270
                            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
  3271
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3272
                        pubs = None
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3273
                        try:
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3274
                                pubs = api_inst.get_publisherdata(repo=repo)
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3275
                        except apx.UnsupportedRepositoryOperation:
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3276
                                if not prefix:
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3277
                                        raise apx.RepoPubConfigUnavailable(
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3278
                                            location=repo_uri)
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3279
                                # 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
  3280
                                # fallback to manual configuration.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3281
                                if not origins:
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3282
                                        origins = [repo_uri]
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3283
                                repo_uri = None
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3284
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3285
                        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
  3286
                                # Empty repository configuration.
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3287
                                raise apx.RepoPubConfigUnavailable(
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3288
                                    location=repo_uri)
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3289
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3290
                        if repo_uri:
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3291
                                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
  3292
                                        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
  3293
                                        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
  3294
                                                # 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
  3295
                                                # 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
  3296
                                                # 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
  3297
                                                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
  3298
                                                    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
  3299
                                                    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
  3300
                                        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
  3301
                                                # 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
  3302
                                                # 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
  3303
                                                # 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
  3304
                                                # 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
  3305
                                                psrepo.add_origin(repo_uri)
1895
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1893
diff changeset
  3306
                                        elif repo not in psrepo.origins:
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1893
diff changeset
  3307
                                                # If the repo_uri used is not
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1893
diff changeset
  3308
                                                # in the list of sources, then
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1893
diff changeset
  3309
                                                # add it as the first origin.
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1893
diff changeset
  3310
                                                psrepo.origins.insert(0, repo)
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3311
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3312
                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
  3313
                        # Auto-configuration not possible or not requested.
1834
43fcb0ca2c26 15120 image-create fails for ssl-based publisher repositories
Shawn Walker <shawn.walker@oracle.com>
parents: 1829
diff changeset
  3314
                        if ssl_cert:
43fcb0ca2c26 15120 image-create fails for ssl-based publisher repositories
Shawn Walker <shawn.walker@oracle.com>
parents: 1829
diff changeset
  3315
                                misc.validate_ssl_cert(ssl_cert, prefix=prefix,
43fcb0ca2c26 15120 image-create fails for ssl-based publisher repositories
Shawn Walker <shawn.walker@oracle.com>
parents: 1829
diff changeset
  3316
                                    uri=origins[0])
43fcb0ca2c26 15120 image-create fails for ssl-based publisher repositories
Shawn Walker <shawn.walker@oracle.com>
parents: 1829
diff changeset
  3317
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3318
                        repo = publisher.Repository()
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3319
                        for o in origins:
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3320
                                repo.add_origin(o)
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3321
                        for m in mirrors:
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3322
                                repo.add_mirror(m)
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3323
                        pub = publisher.Publisher(prefix,
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3324
                            repositories=[repo])
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3325
                        pubs = [pub]
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3326
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3327
                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
  3328
                        # 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
  3329
                        # 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
  3330
                        # possible.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3331
                        known = [p.prefix for p in pubs]
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3332
                        raise apx.UnknownRepositoryPublishers(
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3333
                            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
  3334
                elif prefix:
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3335
                        # 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
  3336
                        pubs = [
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3337
                            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
  3338
                            if p.prefix == prefix
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3339
                        ]
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3340
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3341
                # 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
  3342
                # publisher configuration if provided.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3343
                for p in pubs:
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3344
                        pr = p.selected_repository
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3345
                        for o in origins:
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3346
                                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
  3347
                                        pr.add_origin(o)
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3348
                        for m in mirrors:
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3349
                                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
  3350
                                        pr.add_mirror(m)
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3351
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3352
                # 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
  3353
                for p in pubs:
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3354
                        repo = p.selected_repository
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3355
                        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
  3356
                                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
  3357
                                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
  3358
                        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
  3359
                                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
  3360
                                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
  3361
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3362
                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
  3363
                    progtrack=progtrack, refresh_allowed=refresh_allowed,
2026
d1b30615bc99 9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents: 2024
diff changeset
  3364
                    variants=variants, props=props)
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3365
        except EnvironmentError, e:
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3366
                if e.errno == errno.EACCES:
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3367
                        raise apx.PermissionsException(
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3368
                            e.filename)
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3369
                if e.errno == errno.EROFS:
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3370
                        raise apx.ReadOnlyFileSystemException(
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3371
                            e.filename)
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3372
                raise
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3373
        except:
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3374
                # 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
  3375
                img.destroy()
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3376
                if destroy_root and \
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3377
                    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
  3378
                    os.path.exists(root):
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3379
                        # 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
  3380
                        # so remove it.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3381
                        shutil.rmtree(root, True)
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3382
                raise
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3383
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3384
        img.cleanup_downloads()
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3385
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3386
        return api_inst
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  3387