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