src/modules/client/api.py
author Shawn Walker <srw@sun.com>
Tue, 16 Jun 2009 20:45:12 -0500
changeset 1158 78582c4403a9
parent 1150 2b8aaf0b0b4e
child 1191 a48bee2a4b2e
permissions -rw-r--r--
8616 operations should use same publisher when only non-preferred has package
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
     1
#!/usr/bin/python2.4
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
#
835
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 786
diff changeset
    24
# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    25
# Use is subject to license terms.
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 941
diff changeset
    26
#
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    27
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
    28
import copy
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
    29
import httplib
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 941
diff changeset
    30
import os
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 941
diff changeset
    31
import socket
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 941
diff changeset
    32
import simplejson as json
1072
66ce6aa346d7 8132 __licenses should use StringIO
Rich Burridge <rich.burridge@sun.com>
parents: 1053
diff changeset
    33
import StringIO
1032
ff3c6b09f430 8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents: 1027
diff changeset
    34
import sys
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
    35
import threading
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
    36
import urllib
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
    37
import urllib2
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    38
1019
e61c57c724c9 7663 disable_fmri should be synchronous
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 996
diff changeset
    39
import pkg.client.actuator as actuator
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
    40
import pkg.client.api_errors as api_errors
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
    41
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
    42
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
    43
import pkg.client.image as image
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
    44
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
    45
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
    46
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
    47
import pkg.client.variant as variant
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
    48
import pkg.fmri as fmri
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
    49
import pkg.misc as misc
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
    50
import pkg.search_errors as search_errors
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
    51
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
    52
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
    53
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
    54
from pkg.misc import versioned_urlopen
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
    55
1141
a74d6815a7fc 4178 unfound_fmris is a poor name
Rich Burridge <rich.burridge@sun.com>
parents: 1140
diff changeset
    56
CURRENT_API_VERSION = 15
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
    57
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
    58
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    59
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
    60
        """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
    61
        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
    62
        or uninstall packages, or update an image. First, plan_install,
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    63
        plan_uninstall, or plan_update_all must be called. After that
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    64
        method completes successfully, describe may be called, and prepare
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    65
        must be called. Finally, execute_plan may be called to implement
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    66
        the previous created plan. The other methods do not hav an ordering
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    67
        imposed upon them, and may be used as needed. Cancel may only be
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    68
        invoked while a cancelable method is running."""
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    69
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    70
        # 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
    71
        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
    72
        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
    73
        INFO_MULTI_MATCH = 2
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    74
        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
    75
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    76
        # 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
    77
        __INSTALL = 1
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    78
        __UNINSTALL = 2
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    79
        __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
    80
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    81
        def __init__(self, img_path, version_id, progesstracker,
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    82
            cancel_state_callable, pkg_client_name):
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    83
                """Constructs an ImageInterface. img_path should point to an
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    84
                existing image. version_id indicates the version of the api
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    85
                the client is expecting to use. progesstracker is the
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    86
                progresstracker the client wants the api to use for UI
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    87
                callbacks. cancel_state_callable is a function which the client
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    88
                wishes to have called each time whether the operation can be
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    89
                canceled changes. It can raise VersionException and
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    90
                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
    91
1141
a74d6815a7fc 4178 unfound_fmris is a poor name
Rich Burridge <rich.burridge@sun.com>
parents: 1140
diff changeset
    92
                compatible_versions = set([15])
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
    93
598
c53f6107fdb6 2863 pkg install should have a way to disable indexing
Brock Pytlik <bpytlik@sun.com>
parents: 594
diff changeset
    94
                if version_id not in compatible_versions:
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    95
                        raise api_errors.VersionException(CURRENT_API_VERSION,
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    96
                            version_id)
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    97
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
    98
                # 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
    99
                # 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
   100
                # 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
   101
                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
   102
                        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
   103
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   104
                # These variables are private and not part of the API.
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   105
                self.img = image.Image()
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   106
                self.img.find_root(img_path)
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   107
                self.img.load_config()
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   108
                self.progresstracker = progesstracker
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   109
                self.cancel_state_callable = cancel_state_callable
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   110
                self.plan_type = None
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   111
                self.plan_desc = None
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   112
                self.prepared = False
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   113
                self.executed = False
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
   114
                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
   115
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   116
                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
   117
                self.__canceling = False
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   118
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   119
                self.__activity_lock = threading.Lock()
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
   120
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
   121
        @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
   122
        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
   123
                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
   124
                return True
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
   125
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   126
        def plan_install(self, pkg_list, filters, refresh_catalogs=True,
598
c53f6107fdb6 2863 pkg install should have a way to disable indexing
Brock Pytlik <bpytlik@sun.com>
parents: 594
diff changeset
   127
            noexecute=False, verbose=False, update_index=True):
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   128
                """Contructs a plan to install the packages provided in
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   129
                pkg_list. pkg_list is a list of packages to install. filters
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   130
                is a list of filters to apply to the actions of the installed
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   131
                packages. refresh_catalogs controls whether the catalogs will
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   132
                automatically be refreshed. noexecute determines whether the
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   133
                history will be recorded after planning is finished. verbose
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   134
                controls whether verbose debugging output will be printed to the
594
b072bc027c54 3770 pkg install when authority unavailable traces back
Brock Pytlik <bpytlik@sun.com>
parents: 565
diff changeset
   135
                terminal. Its existence is temporary. It returns a tuple of
b072bc027c54 3770 pkg install when authority unavailable traces back
Brock Pytlik <bpytlik@sun.com>
parents: 565
diff changeset
   136
                two things. The first is a boolean which tells the client
b072bc027c54 3770 pkg install when authority unavailable traces back
Brock Pytlik <bpytlik@sun.com>
parents: 565
diff changeset
   137
                whether there is anything to do. The third is either None, or an
b072bc027c54 3770 pkg install when authority unavailable traces back
Brock Pytlik <bpytlik@sun.com>
parents: 565
diff changeset
   138
                exception which indicates partial success. It can raise
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
   139
                PlanCreationException, NetworkUnavailableException,
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
   140
                PermissionsException and InventoryException. The noexecute
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
   141
                argument is included for compatibility with operational
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
   142
                history. The hope is it can be removed in the future."""
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   143
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   144
                self.__activity_lock.acquire()
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   145
                try:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   146
                        self.__set_can_be_canceled(True)
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   147
                        if self.plan_type is not None:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   148
                                raise api_errors.PlanExistsException(
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   149
                                    self.plan_type)
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   150
                        try:
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
   151
                                self.log_operation_start("install")
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   152
                                # Verify validity of certificates before
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
   153
                                # attempting network operations.
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
   154
                                try:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
   155
                                        self.img.check_cert_validity()
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
   156
                                except api_errors.ExpiringCertificate, e:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
   157
                                        misc.emsg(e)
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   158
594
b072bc027c54 3770 pkg install when authority unavailable traces back
Brock Pytlik <bpytlik@sun.com>
parents: 565
diff changeset
   159
                                exception_caught = None
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   160
                                if refresh_catalogs:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   161
                                        try:
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 941
diff changeset
   162
                                                self.img.refresh_publishers(
625
e46b345645d6 3799 need to start progress tracker going early on
Brock Pytlik <bpytlik@sun.com>
parents: 615
diff changeset
   163
                                                    progtrack=self.progresstracker)
1102
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1100
diff changeset
   164
                                        except KeyboardInterrupt:
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1100
diff changeset
   165
                                                raise
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1100
diff changeset
   166
                                        except:
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1100
diff changeset
   167
                                                # Since this is not a refresh
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1100
diff changeset
   168
                                                # that was explicitly requested,
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1100
diff changeset
   169
                                                # it doesn't matter if it fails.
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1100
diff changeset
   170
                                                pass
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   171
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   172
                                self.img.make_install_plan(pkg_list,
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   173
                                    self.progresstracker,
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   174
                                    self.__check_cancelation, noexecute,
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   175
                                    filters=filters, verbose=verbose)
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   176
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   177
                                assert self.img.imageplan
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   178
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   179
                                if self.__canceling:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   180
                                        raise api_errors.CanceledException()
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   181
                                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
   182
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   183
                                if not noexecute:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   184
                                        self.plan_type = self.__INSTALL
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   185
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   186
                                self.plan_desc = PlanDescription(
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   187
                                    self.img.imageplan)
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   188
                                if self.img.imageplan.nothingtodo() or \
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   189
                                    noexecute:
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
   190
                                        self.log_operation_end(
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
   191
                                            result=history.RESULT_NOTHING_TO_DO)
598
c53f6107fdb6 2863 pkg install should have a way to disable indexing
Brock Pytlik <bpytlik@sun.com>
parents: 594
diff changeset
   192
                                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
   193
                                res = not self.img.imageplan.nothingtodo()
716
b836c1b14137 4639 history result info differs for install and uninstall of nonexistent packages
Brock Pytlik <bpytlik@sun.com>
parents: 707
diff changeset
   194
                        except api_errors.PlanCreationException, e:
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
   195
                                self.__set_history_PlanCreationException(e)
716
b836c1b14137 4639 history result info differs for install and uninstall of nonexistent packages
Brock Pytlik <bpytlik@sun.com>
parents: 707
diff changeset
   196
                                self.__reset_unlock()
b836c1b14137 4639 history result info differs for install and uninstall of nonexistent packages
Brock Pytlik <bpytlik@sun.com>
parents: 707
diff changeset
   197
                                raise
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
   198
                        except (api_errors.CanceledException, fmri.IllegalFmri,
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
   199
                            Exception), e:
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
   200
                                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
   201
                                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
   202
                                raise
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   203
                finally:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   204
                        self.__activity_lock.release()
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
   205
598
c53f6107fdb6 2863 pkg install should have a way to disable indexing
Brock Pytlik <bpytlik@sun.com>
parents: 594
diff changeset
   206
                return res, exception_caught
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   207
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   208
        def plan_uninstall(self, pkg_list, recursive_removal, noexecute=False,
598
c53f6107fdb6 2863 pkg install should have a way to disable indexing
Brock Pytlik <bpytlik@sun.com>
parents: 594
diff changeset
   209
            verbose=False, update_index=True):
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   210
                """Contructs a plan to uninstall the packages provided in
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   211
                pkg_list. pkg_list is a list of packages to install.
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   212
                recursive_removal controls whether recursive removal is
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   213
                allowed. noexecute determines whether the history will be
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   214
                recorded after planning is finished. verbose controls whether
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   215
                verbose debugging output will be printed to the terminal. Its
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   216
                existence is temporary. If there are things to do to complete
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   217
                the uninstall, it returns True, otherwise it returns False. It
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   218
                can raise NonLeafPackageException and PlanCreationException."""
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   219
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   220
                self.__activity_lock.acquire()
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   221
                try:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   222
                        self.__set_can_be_canceled(True)
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   223
                        if self.plan_type is not None:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   224
                                raise api_errors.PlanExistsException(
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   225
                                    self.plan_type)
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   226
                        try:
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
   227
                                self.log_operation_start("uninstall")
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   228
                                self.img.make_uninstall_plan(pkg_list,
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   229
                                    recursive_removal, self.progresstracker,
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   230
                                    self.__check_cancelation, noexecute,
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   231
                                    verbose=verbose)
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   232
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   233
                                assert self.img.imageplan
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   234
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   235
                                if self.__canceling:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   236
                                        raise api_errors.CanceledException()
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   237
                                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
   238
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   239
                                if not noexecute:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   240
                                        self.plan_type = self.__UNINSTALL
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   241
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   242
                                self.plan_desc = PlanDescription(
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   243
                                    self.img.imageplan)
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   244
                                if noexecute:
1027
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
   245
                                        self.log_operation_end(
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
   246
                                            result=history.RESULT_NOTHING_TO_DO)
598
c53f6107fdb6 2863 pkg install should have a way to disable indexing
Brock Pytlik <bpytlik@sun.com>
parents: 594
diff changeset
   247
                                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
   248
                                res = not self.img.imageplan.nothingtodo()
716
b836c1b14137 4639 history result info differs for install and uninstall of nonexistent packages
Brock Pytlik <bpytlik@sun.com>
parents: 707
diff changeset
   249
                        except api_errors.PlanCreationException, e:
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
   250
                                self.__set_history_PlanCreationException(e)
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   251
                                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
   252
                                raise
1027
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
   253
                        except Exception, e:
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
   254
                                self.log_operation_end(error=e)
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
   255
                                self.__reset_unlock()
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   256
                                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
   257
                        except:
ff3c6b09f430 8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents: 1027
diff changeset
   258
                                # 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
   259
                                # Exception.
ff3c6b09f430 8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents: 1027
diff changeset
   260
                                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
   261
                                    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
   262
ff3c6b09f430 8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents: 1027
diff changeset
   263
                                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
   264
                                self.__reset_unlock()
ff3c6b09f430 8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents: 1027
diff changeset
   265
                                raise
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   266
                finally:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   267
                        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
   268
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   269
                return res
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
   270
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   271
        def plan_update_all(self, actual_cmd, refresh_catalogs=True,
884
d780afc023ff 3718 plan_update_all needs to have an optional argument for the new BE name
Brock Pytlik <bpytlik@sun.com>
parents: 838
diff changeset
   272
            noexecute=False, force=False, verbose=False, update_index=True,
d780afc023ff 3718 plan_update_all needs to have an optional argument for the new BE name
Brock Pytlik <bpytlik@sun.com>
parents: 838
diff changeset
   273
            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
   274
                """Creates a plan to update all packages on the system to the
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   275
                latest known versions. actual_cmd is the command used to start
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   276
                the client. It is used to determine the image to check whether
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   277
                SUNWipkg is up to date. refresh_catalogs controls whether the
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   278
                catalogs will automatically be refreshed. noexecute determines
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   279
                whether the history will be recorded after planning is finished.
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   280
                force controls whether update should proceed even if ipkg is not
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   281
                up to date. verbose controls whether verbose debugging output
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   282
                will be printed to the terminal. Its existence is temporary. It
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   283
                returns a tuple of three things. The first is a boolean which
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   284
                tells the client whether there is anything to do. The second
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   285
                tells whether the image is an opensolaris image. The third is
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   286
                either None, or an exception which indicates partial success.
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   287
                This is currently used to indicate a failure in refreshing
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   288
                catalogs. It can raise CatalogRefreshException,
685
6f53483db920 1469 image-update by unprivileged user should give better error message
Brock Pytlik <bpytlik@sun.com>
parents: 655
diff changeset
   289
                IpkgOutOfDateException, NetworkUnavailableException,
6f53483db920 1469 image-update by unprivileged user should give better error message
Brock Pytlik <bpytlik@sun.com>
parents: 655
diff changeset
   290
                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
   291
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   292
                self.__activity_lock.acquire()
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   293
                try:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   294
                        self.__set_can_be_canceled(True)
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   295
                        if self.plan_type is not None:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   296
                                raise api_errors.PlanExistsException(
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   297
                                    self.plan_type)
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   298
                        try:
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
   299
                                self.log_operation_start("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
   300
                                exception_caught = None
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
   301
                                self.check_be_name(be_name)
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
   302
                                self.be_name = be_name
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   303
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   304
                                # Verify validity of certificates before
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
   305
                                # attempting network operations.
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
   306
                                try:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
   307
                                        self.img.check_cert_validity()
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
   308
                                except api_errors.ExpiringCertificate, e:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
   309
                                        misc.emsg(e)
625
e46b345645d6 3799 need to start progress tracker going early on
Brock Pytlik <bpytlik@sun.com>
parents: 615
diff changeset
   310
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   311
                                if refresh_catalogs:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   312
                                        try:
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 941
diff changeset
   313
                                                self.img.refresh_publishers(
625
e46b345645d6 3799 need to start progress tracker going early on
Brock Pytlik <bpytlik@sun.com>
parents: 615
diff changeset
   314
                                                    progtrack=self.progresstracker)
1102
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1100
diff changeset
   315
                                        except KeyboardInterrupt:
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1100
diff changeset
   316
                                                raise
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1100
diff changeset
   317
                                        except:
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1100
diff changeset
   318
                                                # Since this is not a refresh
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1100
diff changeset
   319
                                                # that was explicitly requested,
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1100
diff changeset
   320
                                                # it doesn't matter if it fails.
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1100
diff changeset
   321
                                                pass
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 941
diff changeset
   322
                                else:
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 941
diff changeset
   323
                                        # If refresh wasn't called, the catalogs
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 941
diff changeset
   324
                                        # have to be manually loaded.
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   325
                                        self.img.load_catalogs(
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   326
                                            self.progresstracker)
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   327
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   328
                                # If we can find SUNWipkg and SUNWcs in the
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   329
                                # target image, then we assume this is a valid
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   330
                                # opensolaris image, and activate some
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   331
                                # special case behaviors.
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   332
                                opensolaris_image = True
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   333
                                fmris, notfound, illegals = \
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   334
                                    self.img.installed_fmris_from_args(
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   335
                                        ["SUNWipkg", "SUNWcs"])
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   336
                                assert(len(illegals) == 0)
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   337
                                if notfound:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   338
                                        opensolaris_image = False
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   339
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   340
                                if opensolaris_image and not force:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   341
                                        try:
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 941
diff changeset
   342
                                                if not self.img.ipkg_is_up_to_date(
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   343
                                                    actual_cmd,
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   344
                                                    self.__check_cancelation,
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   345
                                                    noexecute,
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 941
diff changeset
   346
                                                    refresh_allowed=refresh_catalogs,
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 941
diff changeset
   347
                                                    progtrack=self.progresstracker):
1027
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
   348
                                                        error = api_errors.IpkgOutOfDateException()
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
   349
                                                        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
   350
                                                        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
   351
                                        except api_errors.ImageNotFoundException:
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 941
diff changeset
   352
                                                # Can't do anything in this
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 941
diff changeset
   353
                                                # case; so proceed.
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   354
                                                pass
655
6eef82185057 2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 625
diff changeset
   355
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
   356
                                pkg_list = [
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
   357
                                    ipkg.get_pkg_stem()
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
   358
                                    for ipkg in self.img.gen_installed_pkgs()
655
6eef82185057 2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 625
diff changeset
   359
                                ]
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   360
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   361
                                self.img.make_install_plan(pkg_list,
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   362
                                    self.progresstracker,
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   363
                                    self.__check_cancelation,
1158
78582c4403a9 8616 operations should use same publisher when only non-preferred has package
Shawn Walker <srw@sun.com>
parents: 1150
diff changeset
   364
                                    noexecute, verbose=verbose,
78582c4403a9 8616 operations should use same publisher when only non-preferred has package
Shawn Walker <srw@sun.com>
parents: 1150
diff changeset
   365
                                    multimatch_ignore=True)
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   366
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   367
                                assert self.img.imageplan
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   368
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   369
                                if self.__canceling:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   370
                                        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
   371
                                        raise api_errors.CanceledException()
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   372
                                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
   373
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   374
                                if not noexecute:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   375
                                        self.plan_type = self.__IMAGE_UPDATE
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   376
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   377
                                self.plan_desc = PlanDescription(
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   378
                                    self.img.imageplan)
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   379
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   380
                                if self.img.imageplan.nothingtodo() or \
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   381
                                    noexecute:
1027
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
   382
                                        self.log_operation_end(
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
   383
                                            result=history.RESULT_NOTHING_TO_DO)
598
c53f6107fdb6 2863 pkg install should have a way to disable indexing
Brock Pytlik <bpytlik@sun.com>
parents: 594
diff changeset
   384
                                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
   385
                                res = not self.img.imageplan.nothingtodo()
716
b836c1b14137 4639 history result info differs for install and uninstall of nonexistent packages
Brock Pytlik <bpytlik@sun.com>
parents: 707
diff changeset
   386
                        except api_errors.PlanCreationException, e:
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
   387
                                self.__set_history_PlanCreationException(e)
716
b836c1b14137 4639 history result info differs for install and uninstall of nonexistent packages
Brock Pytlik <bpytlik@sun.com>
parents: 707
diff changeset
   388
                                self.__reset_unlock()
b836c1b14137 4639 history result info differs for install and uninstall of nonexistent packages
Brock Pytlik <bpytlik@sun.com>
parents: 707
diff changeset
   389
                                raise
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   390
                        except api_errors.IpkgOutOfDateException:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   391
                                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
   392
                                raise
1027
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
   393
                        except Exception, e:
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
   394
                                self.log_operation_end(error=e)
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
   395
                                self.__reset_unlock()
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   396
                                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
   397
                        except:
ff3c6b09f430 8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents: 1027
diff changeset
   398
                                # 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
   399
                                # Exception.
ff3c6b09f430 8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents: 1027
diff changeset
   400
                                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
   401
                                    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
   402
ff3c6b09f430 8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents: 1027
diff changeset
   403
                                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
   404
                                self.__reset_unlock()
ff3c6b09f430 8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents: 1027
diff changeset
   405
                                raise
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   406
                finally:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   407
                        self.__activity_lock.release()
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
   408
598
c53f6107fdb6 2863 pkg install should have a way to disable indexing
Brock Pytlik <bpytlik@sun.com>
parents: 594
diff changeset
   409
                return res, opensolaris_image, exception_caught
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   410
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   411
        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
   412
                """Returns None if no plan is ready yet, otherwise returns
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   413
                a PlanDescription"""
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   414
                return self.plan_desc
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
   415
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   416
        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
   417
                """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
   418
                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
   419
                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
   420
                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
   421
                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
   422
                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
   423
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   424
                self.__activity_lock.acquire()
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   425
                self.__set_can_be_canceled(True)
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   426
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   427
                try:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   428
                        try:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   429
                                if not self.img.imageplan:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   430
                                        raise api_errors.PlanMissingException()
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   431
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   432
                                if self.prepared:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   433
                                        raise api_errors.AlreadyPreparedException()
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   434
                                assert self.plan_type == self.__INSTALL or \
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   435
                                    self.plan_type == self.__UNINSTALL or \
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   436
                                    self.plan_type == self.__IMAGE_UPDATE
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   437
                                try:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   438
                                        self.img.imageplan.preexecute()
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   439
                                except search_errors.ProblematicPermissionsIndexException, e:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   440
                                        self.img.cleanup_downloads()
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   441
                                        raise api_errors.ProblematicPermissionsIndexException(e)
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
                                except:
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   443
                                        self.img.cleanup_downloads()
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   444
                                        raise
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   445
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   446
                                if self.__canceling:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   447
                                        self.img.cleanup_downloads()
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   448
                                        raise api_errors.CanceledException()
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   449
                                self.prepared = True
1027
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
   450
                        except Exception, e:
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
   451
                                if self.img.history.operation_name:
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
   452
                                        # If an operation is in progress, log
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
   453
                                        # the error and mark its end.
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
   454
                                        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
   455
                                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
   456
                        except:
ff3c6b09f430 8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents: 1027
diff changeset
   457
                                # 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
   458
                                # Exception.
ff3c6b09f430 8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents: 1027
diff changeset
   459
                                if self.img.history.operation_name:
ff3c6b09f430 8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents: 1027
diff changeset
   460
                                        # If an operation is in progress, log
ff3c6b09f430 8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents: 1027
diff changeset
   461
                                        # the error and mark its end.
ff3c6b09f430 8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents: 1027
diff changeset
   462
                                        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
   463
                                            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
   464
                                        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
   465
                                raise
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   466
                finally:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   467
                        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
   468
                        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
   469
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   470
        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
   471
                """Executes the plan. This is uncancelable one it begins. It
1027
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
   472
                can raise CorruptedIndexException,
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   473
                ProblematicPermissionsIndexException, ImageplanStateException,
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   474
                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
   475
                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
   476
                called."""
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   477
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   478
                self.__activity_lock.acquire()
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   479
                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
   480
                try:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   481
                        if not self.img.imageplan:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   482
                                raise api_errors.PlanMissingException()
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   483
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   484
                        if not self.prepared:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   485
                                raise api_errors.PrematureExecutionException()
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   486
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   487
                        if self.executed:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   488
                                raise api_errors.AlreadyExecutedException()
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
   489
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   490
                        assert self.plan_type == self.__INSTALL or \
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   491
                            self.plan_type == self.__UNINSTALL or \
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   492
                            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
   493
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   494
                        try:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   495
                                be = bootenv.BootEnv(self.img.get_root())
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   496
                        except RuntimeError:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   497
                                be = bootenv.BootEnvNull(self.img.get_root())
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   498
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   499
                        if self.plan_type is self.__IMAGE_UPDATE:
1027
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
   500
                                try:
1102
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1100
diff changeset
   501
                                        be.init_image_recovery(self.img,
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1100
diff changeset
   502
                                            self.be_name)
1027
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
   503
                                except Exception, e:
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
   504
                                        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
   505
                                        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
   506
                                except:
1102
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1100
diff changeset
   507
                                        # 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
   508
                                        # 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
   509
                                        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
   510
                                            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
   511
                                        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
   512
                                        raise
1027
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
   513
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   514
                                if self.img.is_liveroot():
1027
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
   515
                                        e = api_errors.ImageUpdateOnLiveImageException()
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
   516
                                        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
   517
                                        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
   518
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   519
                        try:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   520
                                self.img.imageplan.execute()
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   521
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   522
                                if self.plan_type is self.__IMAGE_UPDATE:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   523
                                        be.activate_image()
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   524
                                else:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   525
                                        be.activate_install_uninstall()
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   526
                                ret_code = 0
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   527
                        except RuntimeError, e:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   528
                                if self.plan_type is self.__IMAGE_UPDATE:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   529
                                        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
   530
                                else:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   531
                                        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
   532
                                # 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
   533
                                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
   534
                                self.img.cleanup_downloads()
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   535
                                raise
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   536
                        except search_errors.ProblematicPermissionsIndexException, e:
1027
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
   537
                                error = api_errors.ProblematicPermissionsIndexException(e)
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
   538
                                self.log_operation_end(error=error)
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   539
                                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
   540
                                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
   541
                        except (search_errors.InconsistentIndexException,
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   542
                                search_errors.PartialIndexingException), e:
1027
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
   543
                                error = api_errors.CorruptedIndexException(e)
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
   544
                                self.log_operation_end(error=error)
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   545
                                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
   546
                                raise error
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
   547
                        except search_errors.MainDictParsingException, e:
1027
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
   548
                                error = api_errors.MainDictParsingException(e)
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
   549
                                self.log_operation_end(error=error)
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
   550
                                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
   551
                                raise error
1019
e61c57c724c9 7663 disable_fmri should be synchronous
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 996
diff changeset
   552
                        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
   553
                                # Won't happen during image-update
1019
e61c57c724c9 7663 disable_fmri should be synchronous
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 996
diff changeset
   554
                                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
   555
                                error = api_errors.ActuatorException(e)
1019
e61c57c724c9 7663 disable_fmri should be synchronous
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 996
diff changeset
   556
                                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
   557
                                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
   558
                                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
   559
                        except Exception, e:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   560
                                if self.plan_type is self.__IMAGE_UPDATE:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   561
                                        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
   562
                                else:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   563
                                        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
   564
                                # 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
   565
                                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
   566
                                self.img.cleanup_downloads()
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   567
                                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
   568
                        except:
ff3c6b09f430 8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents: 1027
diff changeset
   569
                                # 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
   570
                                # Exception.
ff3c6b09f430 8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents: 1027
diff changeset
   571
                                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
   572
                                    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
   573
ff3c6b09f430 8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents: 1027
diff changeset
   574
                                if self.plan_type is self.__IMAGE_UPDATE:
ff3c6b09f430 8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents: 1027
diff changeset
   575
                                        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
   576
                                else:
ff3c6b09f430 8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents: 1027
diff changeset
   577
                                        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
   578
                                # 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
   579
                                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
   580
                                self.img.cleanup_downloads()
ff3c6b09f430 8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents: 1027
diff changeset
   581
                                raise
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   582
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   583
                        if self.img.imageplan.state != EXECUTED_OK:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   584
                                if self.plan_type is self.__IMAGE_UPDATE:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   585
                                        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
   586
                                else:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   587
                                        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
   588
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
   589
                                error = api_errors.ImageplanStateException(
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   590
                                    self.img.imageplan.state)
1027
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
   591
                                # 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
   592
                                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
   593
                                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
   594
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   595
                        self.img.cleanup_downloads()
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   596
                        self.img.cleanup_cached_content()
1027
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
   597
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
   598
                        # If the end of the operation wasn't already logged
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
   599
                        # by one of the above operations, then log it as
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
   600
                        # ending now.
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
   601
                        if self.img.history.operation_name:
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
   602
                                self.log_operation_end()
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   603
                        self.executed = True
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   604
                finally:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   605
                        self.__activity_lock.release()
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
   606
1102
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1100
diff changeset
   607
        def __refresh(self, full_refresh=False, pubs=None, immediate=False,
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1100
diff changeset
   608
            validate=True):
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1100
diff changeset
   609
                """Private refresh method that exposes functionality not
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1100
diff changeset
   610
                suitable for external consumers."""
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1100
diff changeset
   611
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1100
diff changeset
   612
                self.__activity_lock.acquire()
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1100
diff changeset
   613
                self.__set_can_be_canceled(False)
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1100
diff changeset
   614
                try:
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1100
diff changeset
   615
                        self.img.refresh_publishers(full_refresh=full_refresh,
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1100
diff changeset
   616
                            immediate=immediate, pubs=pubs,
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1100
diff changeset
   617
                            progtrack=self.progresstracker, validate=validate)
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1100
diff changeset
   618
                        return self.img
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1100
diff changeset
   619
                finally:
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1100
diff changeset
   620
                        self.__activity_lock.release()
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1100
diff changeset
   621
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 941
diff changeset
   622
        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
   623
                """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
   624
                publishers.
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 941
diff changeset
   625
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 941
diff changeset
   626
                '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
   627
                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
   628
                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
   629
                True, 'immediate' is also set to True.
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
   630
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 941
diff changeset
   631
                '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
   632
                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
   633
                implies all publishers.
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
   634
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 941
diff changeset
   635
                'immediate' is an optional boolean value indicating whether the
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 941
diff changeset
   636
                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
   637
                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
   638
                interval period recorded in the image configuration has been
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 941
diff changeset
   639
                exceeded; ignored when 'full_refresh' is True.
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
   640
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
   641
                Currently returns an image object, allowing existing code to
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
   642
                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
   643
1102
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1100
diff changeset
   644
                return self.__refresh(full_refresh=full_refresh, pubs=pubs,
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1100
diff changeset
   645
                    immediate=immediate)
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   646
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   647
        def __licenses(self, mfst, local):
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   648
                """Private function. Returns the license info from the
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   649
                manifest mfst. Local controls whether the information is
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   650
                retrieved locally."""
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   651
                license_lst = []
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   652
                for lic in mfst.gen_actions_by_type("license"):
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   653
                        if not local:
1072
66ce6aa346d7 8132 __licenses should use StringIO
Rich Burridge <rich.burridge@sun.com>
parents: 1053
diff changeset
   654
                                s = StringIO.StringIO()
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   655
                                hash_val = misc.gunzip_from_stream(
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   656
                                    lic.get_remote_opener(self.img,
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 941
diff changeset
   657
                                    mfst.fmri)(), s)
1072
66ce6aa346d7 8132 __licenses should use StringIO
Rich Burridge <rich.burridge@sun.com>
parents: 1053
diff changeset
   658
                                text = s.getvalue()
66ce6aa346d7 8132 __licenses should use StringIO
Rich Burridge <rich.burridge@sun.com>
parents: 1053
diff changeset
   659
                                s.close()
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   660
                        else:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   661
                                text = lic.get_local_opener(self.img,
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   662
                                    mfst.fmri)().read()[:-1]
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   663
                        license_lst.append(LicenseInfo(text))
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   664
                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
   665
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
   666
        def info(self, fmri_strings, local, info_needed):
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
   667
                """Gathers information about fmris.  fmri_strings is a list
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
   668
                of fmri_names for which information is desired.  local
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
   669
                determines whether to retrieve the information locally.  It
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
   670
                returns a dictionary of lists.  The keys for the dictionary are
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
   671
                the constants specified in the class definition.  The values are
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
   672
                lists of PackageInfo objects or strings."""
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   673
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
   674
                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
   675
                if bad_opts:
eed22f430a9f 6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents: 884
diff changeset
   676
                        raise api_errors.UnrecognizedOptionsToInfo(bad_opts)
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
   677
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
   678
                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
   679
                self.img.load_catalogs(self.progresstracker)
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   680
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   681
                fmris = []
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   682
                notfound = []
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   683
                multiple_matches = []
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   684
                illegals = []
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
   685
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   686
                if local:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   687
                        fmris, notfound, illegals = \
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   688
                            self.img.installed_fmris_from_args(fmri_strings)
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   689
                        if not fmris and not notfound and not illegals:
1027
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
   690
                                self.log_operation_end(
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
   691
                                    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
   692
                                raise api_errors.NoPackagesInstalledException()
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   693
                else:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   694
                        # Verify validity of certificates before attempting
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
   695
                        # network operations.
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
   696
                        try:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
   697
                                self.img.check_cert_validity()
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
   698
                        except api_errors.ExpiringCertificate, e:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
   699
                                misc.emsg(e)
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
   700
                        except api_errors.CertificateError, e:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
   701
                                self.log_operation_end(error=e)
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
   702
                                raise
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
   703
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   704
                        # XXX This loop really needs not to be copied from
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   705
                        # Image.make_install_plan()!
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   706
                        for p in fmri_strings:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   707
                                try:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   708
                                        matches = list(self.img.inventory([ p ],
1045
62656c214151 8135 plan creation could be faster for install and uninstall
Shawn Walker <srw@sun.com>
parents: 1044
diff changeset
   709
                                            all_known=True, ordered=False))
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   710
                                except api_errors.InventoryException, e:
707
d37b19989de2 4878 pkg info traceback when given invalid input
Brock Pytlik <bpytlik@sun.com>
parents: 696
diff changeset
   711
                                        assert(len(e.notfound) == 1 or \
d37b19989de2 4878 pkg info traceback when given invalid input
Brock Pytlik <bpytlik@sun.com>
parents: 696
diff changeset
   712
                                            len(e.illegal) == 1)
d37b19989de2 4878 pkg info traceback when given invalid input
Brock Pytlik <bpytlik@sun.com>
parents: 696
diff changeset
   713
                                        if e.notfound:
d37b19989de2 4878 pkg info traceback when given invalid input
Brock Pytlik <bpytlik@sun.com>
parents: 696
diff changeset
   714
                                                notfound.append(e.notfound[0])
d37b19989de2 4878 pkg info traceback when given invalid input
Brock Pytlik <bpytlik@sun.com>
parents: 696
diff changeset
   715
                                        else:
d37b19989de2 4878 pkg info traceback when given invalid input
Brock Pytlik <bpytlik@sun.com>
parents: 696
diff changeset
   716
                                                illegals.append(e.illegal[0])
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   717
                                        err = 1
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   718
                                        continue
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   719
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   720
                                pnames = {}
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   721
                                pmatch = []
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   722
                                npnames = {}
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   723
                                npmatch = []
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   724
                                for m, state in matches:
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
   725
                                        if m.preferred_publisher():
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   726
                                                pnames[m.get_pkg_stem()] = 1
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   727
                                                pmatch.append(m)
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   728
                                        else:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   729
                                                npnames[m.get_pkg_stem()] = 1
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   730
                                                npmatch.append(m)
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   731
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   732
                                if len(pnames.keys()) > 1:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   733
                                        multiple_matches.append(
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   734
                                            (p, pnames.keys()))
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   735
                                        error = 1
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   736
                                        continue
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   737
                                elif len(pnames.keys()) < 1 and \
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   738
                                    len(npnames.keys()) > 1:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   739
                                        multiple_matches.append(
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   740
                                            (p, pnames.keys()))
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   741
                                        error = 1
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   742
                                        continue
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   743
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   744
                                # matches is a list reverse sorted by version,
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   745
                                # so take the first; i.e., the latest.
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   746
                                if len(pmatch) > 0:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   747
                                        fmris.append(pmatch[0])
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   748
                                else:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   749
                                        fmris.append(npmatch[0])
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   750
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   751
                pis = []
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   752
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   753
                for f in fmris:
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
   754
                        pub = name = version = release = None
917
eed22f430a9f 6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents: 884
diff changeset
   755
                        build_release = branch = packaging_date = None
eed22f430a9f 6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents: 884
diff changeset
   756
                        if PackageInfo.IDENTITY in info_needed:
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
   757
                                pub, name, version = f.tuple()
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
   758
                                pub = fmri.strip_pub_pfx(pub)
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
   759
                                release = version.release
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
   760
                                build_release = version.build_release
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
   761
                                branch = version.branch
1150
2b8aaf0b0b4e 4346 use of ctime() creates non-localized time strings
Rich Burridge <rich.burridge@sun.com>
parents: 1141
diff changeset
   762
                                packaging_date = \
2b8aaf0b0b4e 4346 use of ctime() creates non-localized time strings
Rich Burridge <rich.burridge@sun.com>
parents: 1141
diff changeset
   763
                                    version.get_timestamp().strftime("%c")
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
   764
                        pref_pub = None
938
eeb932b9b44e 7336 putback for 5871 missed a few vestiges of authority
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 926
diff changeset
   765
                        if PackageInfo.PREF_PUBLISHER in info_needed:
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
   766
                                pref_pub = False
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
   767
                                if f.preferred_publisher():
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
   768
                                        pref_pub = True
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
   769
                        state = None
eed22f430a9f 6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents: 884
diff changeset
   770
                        if PackageInfo.STATE in info_needed:
eed22f430a9f 6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents: 884
diff changeset
   771
                                if self.img.is_installed(f):
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
   772
                                        state = PackageInfo.INSTALLED
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
   773
                                else:
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
   774
                                        state = PackageInfo.NOT_INSTALLED
615
aeeeb9f31173 4114 Api.Info needs to provide more info
Brock Pytlik <bpytlik@sun.com>
parents: 610
diff changeset
   775
                        links = hardlinks = files = dirs = dependencies = None
917
eed22f430a9f 6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents: 884
diff changeset
   776
                        summary = size = licenses = cat_info = None
eed22f430a9f 6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents: 884
diff changeset
   777
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
   778
                        if (frozenset([PackageInfo.SIZE, PackageInfo.LICENSES,
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
   779
                            PackageInfo.SUMMARY, PackageInfo.CATEGORIES]) |
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
   780
                            PackageInfo.ACTION_OPTIONS) & info_needed:
eed22f430a9f 6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents: 884
diff changeset
   781
                                mfst = self.img.get_manifest(f)
1044
046981c42149 8102 pkg.client.api info reports size of zero for packages with cached manifests
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 1032
diff changeset
   782
                                excludes = self.img.list_excludes()
917
eed22f430a9f 6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents: 884
diff changeset
   783
                                if PackageInfo.SIZE in info_needed:
1044
046981c42149 8102 pkg.client.api info reports size of zero for packages with cached manifests
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 1032
diff changeset
   784
                                        size = mfst.get_size(excludes=excludes)
917
eed22f430a9f 6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents: 884
diff changeset
   785
                                if PackageInfo.LICENSES in info_needed:
eed22f430a9f 6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents: 884
diff changeset
   786
                                        licenses = self.__licenses(mfst, local)
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
   787
                                if PackageInfo.SUMMARY in info_needed:
1140
b2aee412ba0d 4395 Use pkg.summary for "pkg info" output
Rich Burridge <rich.burridge@sun.com>
parents: 1130
diff changeset
   788
                                        summary = mfst.get("pkg.summary",
b2aee412ba0d 4395 Use pkg.summary for "pkg info" output
Rich Burridge <rich.burridge@sun.com>
parents: 1130
diff changeset
   789
                                            mfst.get("description", ""))
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
   790
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
   791
                                if PackageInfo.ACTION_OPTIONS & info_needed:
eed22f430a9f 6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents: 884
diff changeset
   792
                                        if PackageInfo.LINKS in info_needed:
eed22f430a9f 6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents: 884
diff changeset
   793
                                                links = list(
eed22f430a9f 6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents: 884
diff changeset
   794
                                                    mfst.gen_key_attribute_value_by_type(
eed22f430a9f 6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents: 884
diff changeset
   795
                                                    "link", excludes))
eed22f430a9f 6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents: 884
diff changeset
   796
                                        if PackageInfo.HARDLINKS in info_needed:
eed22f430a9f 6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents: 884
diff changeset
   797
                                                hardlinks = list(
eed22f430a9f 6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents: 884
diff changeset
   798
                                                    mfst.gen_key_attribute_value_by_type(
eed22f430a9f 6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents: 884
diff changeset
   799
                                                    "hardlink", excludes))
eed22f430a9f 6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents: 884
diff changeset
   800
                                        if PackageInfo.FILES in info_needed:
eed22f430a9f 6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents: 884
diff changeset
   801
                                                files = list(
eed22f430a9f 6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents: 884
diff changeset
   802
                                                    mfst.gen_key_attribute_value_by_type(
eed22f430a9f 6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents: 884
diff changeset
   803
                                                    "file", excludes))
eed22f430a9f 6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents: 884
diff changeset
   804
                                        if PackageInfo.DIRS in info_needed:
eed22f430a9f 6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents: 884
diff changeset
   805
                                                dirs = list(
eed22f430a9f 6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents: 884
diff changeset
   806
                                                    mfst.gen_key_attribute_value_by_type(
eed22f430a9f 6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents: 884
diff changeset
   807
                                                    "dir", excludes))
eed22f430a9f 6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents: 884
diff changeset
   808
                                        if PackageInfo.DEPENDENCIES in \
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
   809
                                            info_needed:
eed22f430a9f 6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents: 884
diff changeset
   810
                                                dependencies = list(
eed22f430a9f 6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents: 884
diff changeset
   811
                                                    mfst.gen_key_attribute_value_by_type(
eed22f430a9f 6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents: 884
diff changeset
   812
                                                    "depend", excludes))
eed22f430a9f 6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents: 884
diff changeset
   813
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
   814
                                if PackageInfo.CATEGORIES in info_needed:
eed22f430a9f 6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents: 884
diff changeset
   815
                                        cat_info = [
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
   816
                                            PackageCategory(scheme, cat)
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
   817
                                            for ca
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
   818
                                            in mfst.gen_actions_by_type("set")
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
   819
                                            if ca.has_category_info()
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
   820
                                            for scheme, cat
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
   821
                                            in ca.parse_category_info()
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
   822
                                        ]
615
aeeeb9f31173 4114 Api.Info needs to provide more info
Brock Pytlik <bpytlik@sun.com>
parents: 610
diff changeset
   823
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   824
                        pis.append(PackageInfo(pkg_stem=name, summary=summary,
688
32a3ca40676e 4260 pkg info should print the classification
Brock Pytlik <bpytlik@sun.com>
parents: 685
diff changeset
   825
                            category_info_list=cat_info, state=state,
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
   826
                            publisher=pub, preferred_publisher=pref_pub,
917
eed22f430a9f 6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents: 884
diff changeset
   827
                            version=release, build_release=build_release,
eed22f430a9f 6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents: 884
diff changeset
   828
                            branch=branch, packaging_date=packaging_date,
eed22f430a9f 6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents: 884
diff changeset
   829
                            size=size, pfmri=str(f), licenses=licenses,
615
aeeeb9f31173 4114 Api.Info needs to provide more info
Brock Pytlik <bpytlik@sun.com>
parents: 610
diff changeset
   830
                            links=links, hardlinks=hardlinks, files=files,
aeeeb9f31173 4114 Api.Info needs to provide more info
Brock Pytlik <bpytlik@sun.com>
parents: 610
diff changeset
   831
                            dirs=dirs, dependencies=dependencies))
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   832
                if pis:
1027
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
   833
                        self.log_operation_end()
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   834
                elif illegals or multiple_matches:
1027
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
   835
                        self.log_operation_end(
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
   836
                            result=history.RESULT_FAILED_BAD_REQUEST)
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   837
                else:
1027
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
   838
                        self.log_operation_end(
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
   839
                            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
   840
                return {
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   841
                    self.INFO_FOUND: pis,
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   842
                    self.INFO_MISSING: notfound,
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   843
                    self.INFO_MULTI_MATCH: multiple_matches,
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   844
                    self.INFO_ILLEGALS: illegals
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   845
                }
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
   846
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   847
        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
   848
                """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
   849
                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
   850
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   851
        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
   852
                """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
   853
                cancelable state."""
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   854
                if self.__can_be_canceled != status:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   855
                        self.__can_be_canceled = status
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   856
                        if self.cancel_state_callable:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   857
                                self.cancel_state_callable(
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   858
                                    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
   859
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   860
        def reset(self):
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   861
                """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
   862
                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
   863
                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
   864
                the prepare method."""
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   865
                self.__activity_lock.acquire()
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   866
                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
   867
                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
   868
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   869
        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
   870
                """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
   871
                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
   872
                holds the activity lock."""
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   873
                self.img.imageplan = None
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   874
                self.plan_desc = None
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   875
                self.plan_type = None
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   876
                self.prepared = False
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   877
                self.executed = False
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   878
                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
   879
                self.__canceling = False
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   880
                self.progresstracker.reset()
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   881
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   882
        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
   883
                """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
   884
                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
   885
                canceled."""
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   886
                return self.__canceling
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
   887
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   888
        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
   889
                """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
   890
                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
   891
                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
   892
                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
   893
                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
   894
                Plan execution cannot be canceled. A call to this method blocks
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   895
                until the canelation has happened. Note: this does not
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   896
                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
   897
                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
   898
                prepare method."""
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   899
                if not 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
   900
                        return False
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   901
                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
   902
                self.__canceling = True
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   903
                # The lock is taken here to make the call block, until
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   904
                # the activity has been canceled.
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   905
                self.__activity_lock.acquire()
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   906
                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
   907
                self.__canceling = False
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   908
                return True
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   909
716
b836c1b14137 4639 history result info differs for install and uninstall of nonexistent packages
Brock Pytlik <bpytlik@sun.com>
parents: 707
diff changeset
   910
        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
   911
                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
   912
                    e.missing_matches or e.illegal:
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
   913
                        self.log_operation_end(error=e,
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
   914
                            result=history.RESULT_FAILED_BAD_REQUEST)
716
b836c1b14137 4639 history result info differs for install and uninstall of nonexistent packages
Brock Pytlik <bpytlik@sun.com>
parents: 707
diff changeset
   915
                elif e.constraint_violations:
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
   916
                        self.log_operation_end(error=e,
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
   917
                            result=history.RESULT_FAILED_CONSTRAINED)
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
   918
                else:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
   919
                        self.log_operation_end(error=e)
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
   920
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
   921
        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
   922
                """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
   923
                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
   924
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
   925
                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
   926
                        l = query_p.QueryLexer()
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
   927
                        l.build()
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
   928
                        qp = query_p.QueryParser(l)
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
   929
                        try:
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
   930
                                query = qp.parse(q.encoded_text())
1053
00fe9773d072 8098 parsing errors should not cause a stacktrace
Brock Pytlik <bpytlik@sun.com>
parents: 1051
diff changeset
   931
                        except query_p.BooleanQueryException, e:
00fe9773d072 8098 parsing errors should not cause a stacktrace
Brock Pytlik <bpytlik@sun.com>
parents: 1051
diff changeset
   932
                                raise api_errors.BooleanQueryException(e)
00fe9773d072 8098 parsing errors should not cause a stacktrace
Brock Pytlik <bpytlik@sun.com>
parents: 1051
diff changeset
   933
                        except query_p.ParseError, e:
00fe9773d072 8098 parsing errors should not cause a stacktrace
Brock Pytlik <bpytlik@sun.com>
parents: 1051
diff changeset
   934
                                raise api_errors.ParseError(e)
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
   935
                        self.img.update_index_dir()
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
   936
                        assert self.img.index_dir
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
   937
                        try:
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
   938
                                query.set_info(q.num_to_return, q.start_point,
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
   939
                                    self.img.index_dir,
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
   940
                                    self.img.get_manifest_path,
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
   941
                                    self.img.gen_installed_pkg_names,
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
   942
                                    q.case_sensitive)
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
   943
                                excludes = [variant.Variants(
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
   944
                                    {"variant.arch": self.img.get_arch()}
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
   945
                                    ).allow_action]
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
   946
                                res = query.search(self.img.gen_installed_pkgs,
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
   947
                                    self.img.get_manifest_path, excludes)
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
   948
                        except search_errors.InconsistentIndexException, e:
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
   949
                                raise api_errors.InconsistentIndexException(e)
1100
22a8b08d460a 7364 documentation and code comments needed for fix for 6175
Brock Pytlik <bpytlik@sun.com>
parents: 1087
diff changeset
   950
                        # 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
   951
                        # 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
   952
                        # publisher being searched against.
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
   953
                        return ((i, None, r) for r in res)
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
   954
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
   955
        @staticmethod
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
   956
        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
   957
                """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
   958
                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
   959
                (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
   960
                
22a8b08d460a 7364 documentation and code comments needed for fix for 6175
Brock Pytlik <bpytlik@sun.com>
parents: 1087
diff changeset
   961
                "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
   962
                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
   963
                request."""
22a8b08d460a 7364 documentation and code comments needed for fix for 6175
Brock Pytlik <bpytlik@sun.com>
parents: 1087
diff changeset
   964
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
   965
                line = line.strip()
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
   966
                fields = line.split(None, 3)
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
   967
                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
   968
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
   969
        @staticmethod
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
   970
        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
   971
                """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
   972
                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
   973
                (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
   974
                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
   975
                ServerReturnError."""
22a8b08d460a 7364 documentation and code comments needed for fix for 6175
Brock Pytlik <bpytlik@sun.com>
parents: 1087
diff changeset
   976
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
   977
                fields = line.split(None, 2)
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
   978
                if len(fields) != 3:
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
   979
                        raise api_errors.ServerReturnError(line)
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
   980
                try:
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
   981
                        return_type = int(fields[1])
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
   982
                except ValueError:
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
   983
                        raise api_errors.ServerReturnError(line)
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
   984
                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
   985
                        subfields = fields[2].split(None, 2)
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
   986
                        return (fields[0], pub, (v, return_type,
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
   987
                            (subfields[0], urllib.unquote(subfields[1]),
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
   988
                            subfields[2])))
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
   989
                elif return_type == Query.RETURN_PACKAGES:
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
   990
                        return (fields[0], pub, (v, return_type, fields[2]))
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
   991
                else:
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
   992
                        raise api_errors.ServerReturnError(line)
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
   993
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
   994
        def remote_search(self, query_str_and_args_lst, servers=None):
1100
22a8b08d460a 7364 documentation and code comments needed for fix for 6175
Brock Pytlik <bpytlik@sun.com>
parents: 1087
diff changeset
   995
                """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
   996
                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
   997
                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
   998
                servers are provided, the search is conducted against all
22a8b08d460a 7364 documentation and code comments needed for fix for 6175
Brock Pytlik <bpytlik@sun.com>
parents: 1087
diff changeset
   999
                active servers known by the image."""
22a8b08d460a 7364 documentation and code comments needed for fix for 6175
Brock Pytlik <bpytlik@sun.com>
parents: 1087
diff changeset
  1000
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1001
                failed = []
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1002
                invalid = []
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 941
diff changeset
  1003
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1004
                if not servers:
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1005
                        servers = self.img.gen_publishers()
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1006
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1007
                single = True
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 941
diff changeset
  1008
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1009
                if not len(query_str_and_args_lst) == 1:
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1010
                        single = False
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1011
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1012
                allow_version_zero = single
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1013
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1014
                version_list = [1]
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 941
diff changeset
  1015
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1016
                if single:
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1017
                        method = "GET"
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1018
                        q = query_str_and_args_lst[0]
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1019
                        qs = [urllib.quote(str(q), safe='')]
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1020
                        version_1_data = None
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1021
                        l = query_p.QueryLexer()
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1022
                        l.build()
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1023
                        qp = query_p.QueryParser(l)
1100
22a8b08d460a 7364 documentation and code comments needed for fix for 6175
Brock Pytlik <bpytlik@sun.com>
parents: 1087
diff changeset
  1024
                        # Parse the query to determine whether it can be
22a8b08d460a 7364 documentation and code comments needed for fix for 6175
Brock Pytlik <bpytlik@sun.com>
parents: 1087
diff changeset
  1025
                        # represented in search/0 syntax.
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1026
                        try:
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1027
                                query = qp.parse(q.encoded_text())
1053
00fe9773d072 8098 parsing errors should not cause a stacktrace
Brock Pytlik <bpytlik@sun.com>
parents: 1051
diff changeset
  1028
                        except query_p.BooleanQueryException, e:
00fe9773d072 8098 parsing errors should not cause a stacktrace
Brock Pytlik <bpytlik@sun.com>
parents: 1051
diff changeset
  1029
                                raise api_errors.BooleanQueryException(e)
00fe9773d072 8098 parsing errors should not cause a stacktrace
Brock Pytlik <bpytlik@sun.com>
parents: 1051
diff changeset
  1030
                        except query_p.ParseError, e:
00fe9773d072 8098 parsing errors should not cause a stacktrace
Brock Pytlik <bpytlik@sun.com>
parents: 1051
diff changeset
  1031
                                raise api_errors.ParseError(e)
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1032
                        if query.allow_version(0):
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1033
                                version_list.append(0)
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1034
                                qs.append(urllib.quote(q.ver_0(), safe=''))
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 941
diff changeset
  1035
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1036
                else:
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1037
                        method = "POST"
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1038
                        qs = None
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1039
                        version_1_data = urllib.urlencode(
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1040
                            [(i, str(q))
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1041
                            for i, q in enumerate(query_str_and_args_lst)])
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1042
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1043
                for pub in servers:
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1044
                        prefix = None
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1045
                        uuid = None
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1046
                        if not isinstance(pub, publisher.Publisher):
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1047
                                origin = pub["origin"]
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1048
                                try:
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1049
                                        pub = self.img.get_publisher(
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1050
                                            origin=origin)
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1051
                                except api_errors.UnknownPublisher:
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1052
                                        pass
1081
0cc3e524ea7f 8318 search v1 not sending uuid
Brock Pytlik <bpytlik@sun.com>
parents: 1080
diff changeset
  1053
                        # This cannot be an else statment to the previous if
0cc3e524ea7f 8318 search v1 not sending uuid
Brock Pytlik <bpytlik@sun.com>
parents: 1080
diff changeset
  1054
                        # clause because it needs to work on the value of pub
0cc3e524ea7f 8318 search v1 not sending uuid
Brock Pytlik <bpytlik@sun.com>
parents: 1080
diff changeset
  1055
                        # after it has been set by self.img.get_publisher.
0cc3e524ea7f 8318 search v1 not sending uuid
Brock Pytlik <bpytlik@sun.com>
parents: 1080
diff changeset
  1056
                        if isinstance(pub, publisher.Publisher):
0cc3e524ea7f 8318 search v1 not sending uuid
Brock Pytlik <bpytlik@sun.com>
parents: 1080
diff changeset
  1057
                                repo = pub.selected_repository
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1058
                                origin = pub.selected_repository.origins[0]
1081
0cc3e524ea7f 8318 search v1 not sending uuid
Brock Pytlik <bpytlik@sun.com>
parents: 1080
diff changeset
  1059
                                prefix = pub.prefix
0cc3e524ea7f 8318 search v1 not sending uuid
Brock Pytlik <bpytlik@sun.com>
parents: 1080
diff changeset
  1060
                                uuid = pub.client_uuid
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1061
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1062
                        ssl_key = None
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1063
                        ssl_cert = None
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1064
                        if isinstance(origin, publisher.RepositoryURI):
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1065
                                ssl_key = origin.ssl_key
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1066
                                ssl_cert = origin.ssl_cert
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1067
                                origin = origin.uri
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1068
                        if ssl_cert:
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1069
                                try:
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 941
diff changeset
  1070
                                        misc.validate_ssl_cert(ssl_cert,
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 941
diff changeset
  1071
                                            prefix=prefix, uri=origin)
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1072
                                except api_errors.CertificateError, e:
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1073
                                        failed.append((pub, e))
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1074
                                        continue
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1075
                        ssl_tuple = (ssl_key, ssl_cert)
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1076
                        try:
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1077
                                res, v = versioned_urlopen(origin,
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1078
                                    "search", version_list, tail=qs,
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1079
                                    data=version_1_data,
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1080
                                    ssl_creds=ssl_tuple, imgtype=self.img.type,
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1081
                                    method=method, uuid=uuid)
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1082
                        except urllib2.HTTPError, e:
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1083
                                if e.code != httplib.NOT_FOUND and \
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1084
                                    e.code != httplib.NO_CONTENT:
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1085
                                        failed.append((pub, e))
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1086
                                continue
1051
6b47b42fddcc 7367 search needs to catch more possible exceptions from transport
Brock Pytlik <bpytlik@sun.com>
parents: 1045
diff changeset
  1087
                        except (urllib2.URLError, httplib.BadStatusLine,
6b47b42fddcc 7367 search needs to catch more possible exceptions from transport
Brock Pytlik <bpytlik@sun.com>
parents: 1045
diff changeset
  1088
                            httplib.IncompleteRead, RuntimeError,
6b47b42fddcc 7367 search needs to catch more possible exceptions from transport
Brock Pytlik <bpytlik@sun.com>
parents: 1045
diff changeset
  1089
                            ValueError), e:
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1090
                                failed.append((pub, e))
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1091
                                continue
1051
6b47b42fddcc 7367 search needs to catch more possible exceptions from transport
Brock Pytlik <bpytlik@sun.com>
parents: 1045
diff changeset
  1092
                        except KeyboardInterrupt:
6b47b42fddcc 7367 search needs to catch more possible exceptions from transport
Brock Pytlik <bpytlik@sun.com>
parents: 1045
diff changeset
  1093
                                raise
6b47b42fddcc 7367 search needs to catch more possible exceptions from transport
Brock Pytlik <bpytlik@sun.com>
parents: 1045
diff changeset
  1094
                        except Exception, e:
6b47b42fddcc 7367 search needs to catch more possible exceptions from transport
Brock Pytlik <bpytlik@sun.com>
parents: 1045
diff changeset
  1095
                                failed.append((pub, "Could not perform search."
6b47b42fddcc 7367 search needs to catch more possible exceptions from transport
Brock Pytlik <bpytlik@sun.com>
parents: 1045
diff changeset
  1096
                                    "\nException: str:%s repr:%r" % (e, e)))
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1097
                                continue
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1098
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1099
                        try:
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1100
                                if v == 0:
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1101
                                        for line in res:
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 941
diff changeset
  1102
                                                yield self.__parse_v_0(line,
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 941
diff changeset
  1103
                                                    pub, v)
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1104
                                else:
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1105
                                        if not self.validate_response(res, v):
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1106
                                                invalid.append(pub)
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1107
                                                continue
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1108
                                        for line in res:
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 941
diff changeset
  1109
                                                yield self.__parse_v_1(line,
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 941
diff changeset
  1110
                                                    pub, v)
1051
6b47b42fddcc 7367 search needs to catch more possible exceptions from transport
Brock Pytlik <bpytlik@sun.com>
parents: 1045
diff changeset
  1111
                        except (socket.timeout, socket.error, ValueError,
6b47b42fddcc 7367 search needs to catch more possible exceptions from transport
Brock Pytlik <bpytlik@sun.com>
parents: 1045
diff changeset
  1112
                            httplib.IncompleteRead,
6b47b42fddcc 7367 search needs to catch more possible exceptions from transport
Brock Pytlik <bpytlik@sun.com>
parents: 1045
diff changeset
  1113
                            api_errors.ServerReturnError), e:
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1114
                                failed.append((pub, e))
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1115
                                continue
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1116
                if failed or invalid:
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1117
                        raise api_errors.ProblematicSearchServers(failed,
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1118
                            invalid)
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1119
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1120
        def rebuild_search_index(self):
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1121
                """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
  1122
                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
  1123
                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
  1124
                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
  1125
                been corrupted."""
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1126
                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
  1127
                self.log_operation_start("rebuild-index")
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1128
                if not os.path.isdir(self.img.index_dir):
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1129
                        self.img.mkdirs()
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1130
                try:
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1131
                        excludes = [variant.Variants(
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1132
                            {"variant.arch": self.img.get_arch()}).allow_action]
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1133
                        ind = indexer.Indexer(self.img, self.img.get_manifest,
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1134
                            self.img.get_manifest_path,
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1135
                            self.progresstracker, excludes)
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1136
                        ind.rebuild_index_from_scratch(
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1137
                            self.img.gen_installed_pkgs())
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1138
                except search_errors.ProblematicPermissionsIndexException, e:
1027
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
  1139
                        error = api_errors.ProblematicPermissionsIndexException(e)
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
  1140
                        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
  1141
                        raise error
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1142
                except search_errors.MainDictParsingException, e:
1027
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
  1143
                        error = api_errors.MainDictParsingException(e)
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
  1144
                        self.log_operation_end(error=error)
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1145
                        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
  1146
                        raise error
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1147
                else:
1027
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
  1148
                        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
  1149
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1150
        @staticmethod
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1151
        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
  1152
                """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
  1153
                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
  1154
                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
  1155
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1156
                try:
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1157
                        s = res.next()
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1158
                        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
  1159
                except StopIteration:
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1160
                        return False
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1161
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1162
        def add_publisher(self, pub, refresh_allowed=True):
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1163
                """Add the provided publisher object to the image
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1164
                configuration."""
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 941
diff changeset
  1165
                self.img.add_publisher(pub, refresh_allowed=refresh_allowed,
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 941
diff changeset
  1166
                    progtrack=self.progresstracker)
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1167
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1168
        def get_preferred_publisher(self):
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1169
                """Returns the preferred publisher object for the image."""
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1170
                return self.get_publisher(
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1171
                    prefix=self.img.get_preferred_publisher())
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1172
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1173
        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
  1174
                """Retrieves a publisher object matching the provided prefix
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1175
                (name) or alias.
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1176
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1177
                'duplicate' is an optional boolean value indicating whether
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1178
                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
  1179
                of the original.
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1180
                """
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1181
                pub = self.img.get_publisher(prefix=prefix, alias=alias)
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1182
                if duplicate:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1183
                        # Never return the original so that changes to the
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1184
                        # retrieved object are not reflected until
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1185
                        # update_publisher is called.
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1186
                        return copy.copy(pub)
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1187
                return pub
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1188
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1189
        def get_publishers(self, duplicate=False):
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1190
                """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
  1191
                image.
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1192
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1193
                'duplicate' is an optional boolean value indicating whether
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1194
                copies of the publisher objects should be returned instead
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1195
                of the originals.
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1196
                """
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1197
                if duplicate:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1198
                        # 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
  1199
                        # are not reflected until update_publisher is called.
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1200
                        pubs = [
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1201
                            copy.copy(p)
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1202
                            for p in self.img.get_publishers().values()
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1203
                        ]
716
b836c1b14137 4639 history result info differs for install and uninstall of nonexistent packages
Brock Pytlik <bpytlik@sun.com>
parents: 707
diff changeset
  1204
                else:
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1205
                        pubs = self.img.get_publishers().values()
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1206
                return misc.get_sorted_publishers(pubs,
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1207
                    preferred=self.img.get_preferred_publisher())
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1208
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1209
        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
  1210
                """Returns a datetime object representing the last time the
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1211
                catalog for a publisher was modified or None."""
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1212
                if alias:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1213
                        prefix = self.get_publisher(alias=alias).prefix
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1214
                dt = None
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1215
                self.__activity_lock.acquire()
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1216
                try:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1217
                        self.__set_can_be_canceled(True)
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1218
                        try:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1219
                                dt = self.img.get_publisher_last_update_time(
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1220
                                    prefix)
1032
ff3c6b09f430 8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents: 1027
diff changeset
  1221
                        except:
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1222
                                self.__reset_unlock()
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1223
                                raise
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1224
                finally:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1225
                        self.__activity_lock.release()
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1226
                return dt
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1227
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1228
        def has_publisher(self, prefix=None, alias=None):
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1229
                """Retrieves a publisher object matching the provided prefix
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1230
                (name) or alias."""
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1231
                return self.img.has_publisher(prefix=prefix, alias=alias)
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1232
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1233
        def remove_publisher(self, prefix=None, alias=None):
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1234
                """Removes a publisher object matching the provided prefix
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1235
                (name) or alias."""
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  1236
                self.img.remove_publisher(prefix=prefix, alias=alias,
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  1237
                    progtrack=self.progresstracker)
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1238
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1239
        def set_preferred_publisher(self, prefix=None, alias=None):
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1240
                """Sets the preferred publisher for the image."""
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1241
                self.img.set_preferred_publisher(prefix=prefix, alias=alias)
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1242
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1243
        def update_publisher(self, pub, refresh_allowed=True):
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1244
                """Replaces an existing publisher object with the provided one
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1245
                using the _source_object_id identifier set during copy.
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1246
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1247
                'refresh_allowed' is an optional boolean value indicating
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1248
                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
  1249
                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
  1250
                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
  1251
                made to retrieve publisher metadata."""
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1252
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1253
                self.log_operation_start("update-publisher")
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1254
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1255
                if pub.disabled and \
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1256
                    pub.prefix == self.img.get_preferred_publisher():
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1257
                        raise api_errors.SetPreferredPublisherDisabled(
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1258
                            pub.prefix)
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1259
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1260
                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
  1261
                        if newo.disabled:
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  1262
                                # 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
  1263
                                # should be performed.
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  1264
                                return False
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  1265
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1266
                        if oldo.disabled and not newo.disabled:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1267
                                # The publisher has been re-enabled, so
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1268
                                # retrieve the catalog.
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1269
                                return True
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1270
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1271
                        if len(newo.repositories) != len(oldo.repositories):
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1272
                                # If there are an unequal number of repositories
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1273
                                # then some have been added or removed.
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1274
                                return True
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1275
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1276
                        matched = 0
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1277
                        for oldr in oldo.repositories:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1278
                                for newr in newo.repositories:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1279
                                        if newr._source_object_id == id(oldr):
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1280
                                                matched += 1
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1281
                                                if oldr.origins != newr.origins:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1282
                                                        return True
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1283
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1284
                        if matched != len(newo.repositories):
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1285
                                # If not all of the repositories match up, then
1102
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1100
diff changeset
  1286
                                # one has been added or removed.
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1287
                                return True
1102
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1100
diff changeset
  1288
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1289
                        return False
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1290
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 941
diff changeset
  1291
                refresh_catalog = False
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1292
                updated = False
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  1293
                disable = False
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  1294
                orig_pub = None
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1295
                publishers = self.img.get_publishers()
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1296
                for key, old in publishers.iteritems():
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1297
                        if pub._source_object_id == id(old):
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1298
                                if need_refresh(old, pub):
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1299
                                        refresh_catalog = True
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  1300
                                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
  1301
                                        disable = True
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  1302
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  1303
                                # Store the new publisher's id and the old
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  1304
                                # publisher object so it can be restored if the
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  1305
                                # update operation fails.
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  1306
                                orig_pub = (id(pub), publishers[key])
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  1307
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  1308
                                # Now remove the old publisher object using the
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  1309
                                # iterator key since the prefix might be
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  1310
                                # different for the new publisher object.
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  1311
                                updated = True
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1312
                                del publishers[key]
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  1313
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  1314
                                # Finally, add the new publisher object.
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1315
                                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
  1316
                                break
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1317
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1318
                if not updated:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1319
                        # If a matching publisher couldn't be found and
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1320
                        # replaced, something is wrong (client api usage
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1321
                        # error).
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1322
                        e = api_errors.UnknownPublisher(pub)
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1323
                        self.log_operation_end(e)
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1324
                        raise e
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1325
1102
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1100
diff changeset
  1326
                def cleanup():
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1100
diff changeset
  1327
                        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
  1328
                        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
  1329
                                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
  1330
                                        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
  1331
                                        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
  1332
                                        break
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1100
diff changeset
  1333
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  1334
                try:
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  1335
                        if disable:
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  1336
                                # 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
  1337
                                # 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
  1338
                                # 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
  1339
                                # 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
  1340
                                # refresh() will do the right thing.
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  1341
                                self.img.remove_publisher_metadata(pub)
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  1342
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  1343
                                # Now reload the catalogs so that in-memory and
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  1344
                                # on-disk state will reflect the removal.
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  1345
                                self.img.load_catalogs(self.progresstracker,
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  1346
                                    force=True)
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  1347
                        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
  1348
                                refresh_catalog = pub.needs_refresh
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1349
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  1350
                        if refresh_catalog:
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  1351
                                if refresh_allowed:
1102
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1100
diff changeset
  1352
                                        # One of the publisher's repository
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1100
diff changeset
  1353
                                        # origins may have changed, so the
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1100
diff changeset
  1354
                                        # publisher needs to be revalidated.
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1100
diff changeset
  1355
                                        self.img.valid_publisher_test(pub)
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1100
diff changeset
  1356
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1100
diff changeset
  1357
                                        # Because the more strict test above
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1100
diff changeset
  1358
                                        # was performed, there is no point in
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1100
diff changeset
  1359
                                        # having refresh perform additional
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1100
diff changeset
  1360
                                        # validation before attempting metadata
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1100
diff changeset
  1361
                                        # retrieval.
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1100
diff changeset
  1362
                                        self.__refresh(pubs=[pub],
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1100
diff changeset
  1363
                                            immediate=True, validate=False)
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  1364
                                else:
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  1365
                                        # Something has changed (such as a
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  1366
                                        # repository origin) for the publisher,
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  1367
                                        # so a refresh should occur, but isn't
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  1368
                                        # currently allowed.  As such, clear the
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  1369
                                        # last_refreshed time so that the next
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  1370
                                        # time the client checks to see if a
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  1371
                                        # refresh is needed and is allowed, one
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  1372
                                        # will be performed.
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  1373
                                        pub.last_refreshed = None
1102
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1100
diff changeset
  1374
                except Exception, e:
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1100
diff changeset
  1375
                        # If any of the above fails, the original publisher
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1100
diff changeset
  1376
                        # information needs to be restored so that state is
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1100
diff changeset
  1377
                        # consistent.
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1100
diff changeset
  1378
                        cleanup()
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1100
diff changeset
  1379
                        self.log_operation_end(error=e)
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1100
diff changeset
  1380
                        raise
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  1381
                except:
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  1382
                        # 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
  1383
                        # 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
  1384
                        # consistent.
1102
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1100
diff changeset
  1385
                        cleanup()
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1100
diff changeset
  1386
                        exc_type, exc_value, exc_traceback = \
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1100
diff changeset
  1387
                            sys.exc_info()
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1100
diff changeset
  1388
                        self.log_operation_end(error=exc_type)
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  1389
                        raise
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1390
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 941
diff changeset
  1391
                # Successful; so save configuration.
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1392
                self.img.save_config()
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1393
                self.log_operation_end()
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1394
                return
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1395
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1396
        def log_operation_end(self, error=None, result=None):
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1397
                """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
  1398
                history.
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1399
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1400
                'result' should be a pkg.client.history constant value
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1401
                representing the outcome of an operation.  If not provided,
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1402
                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
  1403
                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
  1404
                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
  1405
                provided, success is assumed."""
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1406
                self.img.history.log_operation_end(error=error, result=result)
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1407
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1408
        def log_operation_error(self, error):
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1409
                """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
  1410
                history for the current opreation."""
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1411
                self.img.history.log_operation_error(error)
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1412
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1413
        def log_operation_start(self, name):
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1414
                """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
  1415
                history."""
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1416
                self.img.history.log_operation_start(name)
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1417
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1418
        def parse_p5i(self, fileobj=None, location=None):
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1419
                """Reads the pkg(5) publisher json formatted data at 'location'
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1420
                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
  1421
                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
  1422
                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
  1423
                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
  1424
                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
  1425
                pkg_names).
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1426
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1427
                '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
  1428
                'read' method for retrieving data.
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1429
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1430
                '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
  1431
                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
  1432
                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
  1433
                'ftp', 'http', and 'https'.
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1434
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1435
                'fileobj' or 'location' must be provided."""
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1436
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1437
                if location is None and fileobj is None:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1438
                        raise api_errors.InvalidResourceLocation(location)
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1439
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1440
                if location:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1441
                        if location.startswith(os.path.sep):
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1442
                                location = os.path.abspath(location)
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1443
                                location = "file://" + location
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1444
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1445
                        try:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1446
                                fileobj = urllib2.urlopen(location)
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1447
                        except (EnvironmentError, ValueError,
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1448
                            urllib2.HTTPError), e:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1449
                                raise api_errors.RetrievalError(e,
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1450
                                    location=location)
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1451
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1452
                try:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1453
                        dump_struct = json.load(fileobj)
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1454
                except (EnvironmentError, urllib2.HTTPError), e:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1455
                        raise api_errors.RetrievalError(e)
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1456
                except ValueError, e:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1457
                        # Not a valid json file.
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1458
                        raise api_errors.InvalidP5IFile(e)
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1459
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1460
                try:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1461
                        ver = int(dump_struct["version"])
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1462
                except KeyError:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1463
                        raise api_errors.InvalidP5IFile(_("missing version"))
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1464
                except ValueError:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1465
                        raise api_errors.InvalidP5IFile(_("invalid version"))
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1466
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1467
                if ver > CURRENT_P5I_VERSION:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1468
                        raise api_errors.UnsupportedP5IFile()
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1469
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1470
                result = []
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1471
                try:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1472
                        plist = dump_struct.get("publishers", [])
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1473
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1474
                        for p in plist:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1475
                                alias = p.get("alias", None)
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1476
                                prefix = p.get("name", None)
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1477
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1478
                                if not prefix:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1479
                                        prefix = "Unknown"
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1480
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1481
                                pub = publisher.Publisher(prefix, alias=alias)
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1482
                                pkglist = p.get("packages", [])
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1483
                                result.append((pub, pkglist))
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1484
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1485
                                for r in p.get("repositories", []):
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1486
                                        rargs = {}
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1487
                                        for prop in ("collection_type",
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1488
                                            "description", "name",
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1489
                                            "refresh_seconds",
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1490
                                            "registration_uri"):
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1491
                                                val = r.get(prop, None)
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1492
                                                if val is None or val == "None":
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1493
                                                        continue
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1494
                                                rargs[prop] = val
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1495
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1496
                                        for prop in ("legal_uris", "mirrors",
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1497
                                            "origins", "related_uris"):
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1498
                                                val = r.get(prop, [])
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1499
                                                if not isinstance(val, list):
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1500
                                                        continue
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1501
                                                rargs[prop] = val
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1502
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1503
                                        if rargs.get("origins", None):
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1504
                                                repo = publisher.Repository(
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1505
                                                    **rargs)
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1506
                                                pub.add_repository(repo)
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1507
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1508
                        pkglist = dump_struct.get("packages", [])
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1509
                        if pkglist:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1510
                                result.append((None, pkglist))
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1511
                except (api_errors.PublisherError, TypeError, ValueError), e:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1512
                        raise api_errors.InvalidP5IFile(str(e))
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1513
                return result
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1514
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1515
        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
  1516
                """Writes the publisher, repository, and provided package names
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1517
                to the provided file-like object 'fileobj' in json p5i format.
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1518
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1519
                '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
  1520
                data to be written as a parameter.
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1521
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1522
                '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
  1523
                publisher prefix that contain package names, FMRI strings, or
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1524
                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
  1525
                that are not specific to a publisher.
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1526
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1527
                '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
  1528
                objects.  If not provided, the information for all publishers
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1529
                (excluding those disabled) will be output."""
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1530
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1531
                dump_struct = {
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1532
                    "packages": [],
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1533
                    "publishers": [],
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1534
                    "version": CURRENT_P5I_VERSION,
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1535
                }
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1536
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1537
                if not pubs:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1538
                        plist = [
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1539
                            p for p in self.get_publishers()
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1540
                            if not p.disabled
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1541
                        ]
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1542
                else:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1543
                        plist = []
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1544
                        for p in pubs:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1545
                                if not isinstance(p, publisher.Publisher):
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1546
                                        plist.append(self.img.get_publisher(
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1547
                                            prefix=p, alias=p))
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1548
                                else:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1549
                                        plist.append(p)
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1550
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1551
                if pkg_names is None:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1552
                        pkg_names = {}
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1553
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1554
                def copy_pkg_names(source, dest):
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1555
                        for entry in source:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1556
                                # Publisher information is intentionally
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1557
                                # omitted as association with this specific
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1558
                                # publisher is implied by location in the
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1559
                                # output.
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1560
                                if isinstance(entry, PackageInfo):
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1561
                                        dest.append(entry.fmri.get_fmri(
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1562
                                            anarchy=True))
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1563
                                elif isinstance(entry, fmri.PkgFmri):
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1564
                                        dest.append(entry.get_fmri(
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1565
                                            anarchy=True))
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1566
                                else:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1567
                                        dest.append(str(entry))
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1568
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1569
                dpubs = dump_struct["publishers"]
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1570
                for p in plist:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1571
                        dpub = {
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1572
                            "alias": p.alias,
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1573
                            "name": p.prefix,
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1574
                            "packages": [],
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1575
                            "repositories": []
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1576
                        }
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1577
                        dpubs.append(dpub)
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1578
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1579
                        try:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1580
                                copy_pkg_names(pkg_names[p.prefix],
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1581
                                    dpub["packages"])
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1582
                        except KeyError:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1583
                                pass
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1584
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1585
                        drepos = dpub["repositories"]
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1586
                        for r in p.repositories:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1587
                                reg_uri = ""
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1588
                                if r.registration_uri:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1589
                                        reg_uri = r.registration_uri.uri
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1590
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1591
                                drepos.append({
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1592
                                    "collection_type": r.collection_type,
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1593
                                    "description": r.description,
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1594
                                    "legal_uris": [u.uri for u in r.legal_uris],
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1595
                                    "mirrors": [u.uri for u in r.mirrors],
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1596
                                    "name": r.name,
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1597
                                    "origins": [u.uri for u in r.origins],
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1598
                                    "refresh_seconds": r.refresh_seconds,
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1599
                                    "registration_uri": reg_uri,
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1600
                                    "related_uris": [
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1601
                                        u.uri for u in r.related_uris
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1602
                                    ],
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1603
                                })
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1604
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1605
                try:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1606
                        copy_pkg_names(pkg_names[""], dump_struct["packages"])
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1607
                except KeyError:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1608
                        pass
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1609
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1610
                return json.dump(dump_struct, fileobj, ensure_ascii=False,
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1611
                    allow_nan=False, indent=2, sort_keys=True)
716
b836c1b14137 4639 history result info differs for install and uninstall of nonexistent packages
Brock Pytlik <bpytlik@sun.com>
parents: 707
diff changeset
  1612
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1613
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1614
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
  1615
        """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
  1616
        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
  1617
        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
  1618
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1619
        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
  1620
            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
  1621
                if return_actions:
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1622
                        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
  1623
                else:
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1624
                        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
  1625
                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
  1626
                    num_to_return, start_point)
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1627
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  1628
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1629
class PlanDescription(object):
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1630
        """A class which describes the changes the plan will make. It
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1631
        provides a list of tuples of PackageInfo's. The first item in the
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1632
        tuple is the package that is being changed. The second item in the
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1633
        tuple is the package that will be in the image after the change."""
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1634
        def __init__(self, imageplan):
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1635
                self.__pkgs = \
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1636
                        [ (PackageInfo.build_from_fmri(pp.origin_fmri),
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1637
                          PackageInfo.build_from_fmri(pp.destination_fmri))
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1638
                          for pp
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1639
                          in imageplan.pkg_plans ]
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1640
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1641
        def get_changes(self):
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1642
                return self.__pkgs
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1643
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1644
class LicenseInfo(object):
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1645
        """A class representing the license information a package
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1646
        provides."""
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1647
        def __init__(self, text):
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1648
                self.__text = text
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1649
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1650
        def get_text(self):
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1651
                return self.__text
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1652
610
09641d85df90 4132 Info --license no longer displays a license
Brock Pytlik <bpytlik@sun.com>
parents: 598
diff changeset
  1653
        def __str__(self):
09641d85df90 4132 Info --license no longer displays a license
Brock Pytlik <bpytlik@sun.com>
parents: 598
diff changeset
  1654
                return self.__text
09641d85df90 4132 Info --license no longer displays a license
Brock Pytlik <bpytlik@sun.com>
parents: 598
diff changeset
  1655
688
32a3ca40676e 4260 pkg info should print the classification
Brock Pytlik <bpytlik@sun.com>
parents: 685
diff changeset
  1656
class PackageCategory(object):
32a3ca40676e 4260 pkg info should print the classification
Brock Pytlik <bpytlik@sun.com>
parents: 685
diff changeset
  1657
        def __init__(self, scheme, category):
32a3ca40676e 4260 pkg info should print the classification
Brock Pytlik <bpytlik@sun.com>
parents: 685
diff changeset
  1658
                self.scheme = scheme
32a3ca40676e 4260 pkg info should print the classification
Brock Pytlik <bpytlik@sun.com>
parents: 685
diff changeset
  1659
                self.category = category
32a3ca40676e 4260 pkg info should print the classification
Brock Pytlik <bpytlik@sun.com>
parents: 685
diff changeset
  1660
32a3ca40676e 4260 pkg info should print the classification
Brock Pytlik <bpytlik@sun.com>
parents: 685
diff changeset
  1661
        def __str__(self, verbose=False):
32a3ca40676e 4260 pkg info should print the classification
Brock Pytlik <bpytlik@sun.com>
parents: 685
diff changeset
  1662
                if verbose:
32a3ca40676e 4260 pkg info should print the classification
Brock Pytlik <bpytlik@sun.com>
parents: 685
diff changeset
  1663
                        return "%s (%s)" % (self.category, self.scheme)
32a3ca40676e 4260 pkg info should print the classification
Brock Pytlik <bpytlik@sun.com>
parents: 685
diff changeset
  1664
                else:
32a3ca40676e 4260 pkg info should print the classification
Brock Pytlik <bpytlik@sun.com>
parents: 685
diff changeset
  1665
                        return "%s" % self.category
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1666
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1667
class PackageInfo(object):
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1668
        """A class capturing the information about packages that a client
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1669
        could need. The fmri is guaranteed to be set. All other values may
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1670
        be None, depending on how the PackageInfo instance was created."""
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1671
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1672
        # Possible package installation states
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1673
        INSTALLED = 1
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1674
        NOT_INSTALLED = 2
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
  1675
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
  1676
        __NUM_PROPS = 12
938
eeb932b9b44e 7336 putback for 5871 missed a few vestiges of authority
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 926
diff changeset
  1677
        IDENTITY, SUMMARY, CATEGORIES, STATE, PREF_PUBLISHER, SIZE, LICENSES, \
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
  1678
            LINKS, HARDLINKS, FILES, DIRS, DEPENDENCIES = range(__NUM_PROPS)
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
  1679
        ALL_OPTIONS = frozenset(range(__NUM_PROPS))
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
  1680
        ACTION_OPTIONS = frozenset([LINKS, HARDLINKS, FILES, DIRS,
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
  1681
            DEPENDENCIES])
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1682
688
32a3ca40676e 4260 pkg info should print the classification
Brock Pytlik <bpytlik@sun.com>
parents: 685
diff changeset
  1683
        def __init__(self, pfmri, pkg_stem=None, summary=None,
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1684
            category_info_list=None, state=None, publisher=None,
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1685
            preferred_publisher=None, version=None, build_release=None,
688
32a3ca40676e 4260 pkg info should print the classification
Brock Pytlik <bpytlik@sun.com>
parents: 685
diff changeset
  1686
            branch=None, packaging_date=None, size=None, licenses=None,
32a3ca40676e 4260 pkg info should print the classification
Brock Pytlik <bpytlik@sun.com>
parents: 685
diff changeset
  1687
            links=None, hardlinks=None, files=None, dirs=None,
32a3ca40676e 4260 pkg info should print the classification
Brock Pytlik <bpytlik@sun.com>
parents: 685
diff changeset
  1688
            dependencies=None):
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1689
                self.pkg_stem = pkg_stem
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1690
                self.summary = summary
688
32a3ca40676e 4260 pkg info should print the classification
Brock Pytlik <bpytlik@sun.com>
parents: 685
diff changeset
  1691
                if category_info_list is None:
32a3ca40676e 4260 pkg info should print the classification
Brock Pytlik <bpytlik@sun.com>
parents: 685
diff changeset
  1692
                        category_info_list = []
32a3ca40676e 4260 pkg info should print the classification
Brock Pytlik <bpytlik@sun.com>
parents: 685
diff changeset
  1693
                self.category_info_list = category_info_list
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1694
                self.state = state
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1695
                self.publisher = publisher
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1696
                self.preferred_publisher = preferred_publisher
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1697
                self.version = version
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1698
                self.build_release = build_release
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1699
                self.branch = branch
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1700
                self.packaging_date = packaging_date
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1701
                self.size = size
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1702
                self.fmri = pfmri
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1703
                self.licenses = licenses
615
aeeeb9f31173 4114 Api.Info needs to provide more info
Brock Pytlik <bpytlik@sun.com>
parents: 610
diff changeset
  1704
                self.links = links
aeeeb9f31173 4114 Api.Info needs to provide more info
Brock Pytlik <bpytlik@sun.com>
parents: 610
diff changeset
  1705
                self.hardlinks = hardlinks
aeeeb9f31173 4114 Api.Info needs to provide more info
Brock Pytlik <bpytlik@sun.com>
parents: 610
diff changeset
  1706
                self.files = files
aeeeb9f31173 4114 Api.Info needs to provide more info
Brock Pytlik <bpytlik@sun.com>
parents: 610
diff changeset
  1707
                self.dirs = dirs
aeeeb9f31173 4114 Api.Info needs to provide more info
Brock Pytlik <bpytlik@sun.com>
parents: 610
diff changeset
  1708
                self.dependencies = dependencies
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1709
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1710
        def __str__(self):
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1711
                return self.fmri
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1712
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1713
        @staticmethod
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1714
        def build_from_fmri(f):
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1715
                if not f:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1716
                        return f
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1717
                pub, name, version = f.tuple()
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1718
                pub = fmri.strip_pub_pfx(pub)
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1719
                return PackageInfo(pkg_stem=name, publisher=pub,
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1720
                    version=version.release,
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  1721
                    build_release=version.build_release, branch=version.branch,
1150
2b8aaf0b0b4e 4346 use of ctime() creates non-localized time strings
Rich Burridge <rich.burridge@sun.com>
parents: 1141
diff changeset
  1722
                    packaging_date=version.get_timestamp().strftime("%c"),
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  1723
                    pfmri=str(f))