--- a/doc/client_api_versions.txt Tue Nov 11 15:07:27 2008 -0800
+++ b/doc/client_api_versions.txt Tue Nov 11 15:17:25 2008 -0800
@@ -1,3 +1,11 @@
+Version 7:
+Compatible with clients using versions 1-6.
+Changes:
+ Ignore the pkg_client_name parameter passed to api.ImageInterface() if
+ pkg.client.global_settings.client_name isn't None. This latter object
+ is now the preferred way to set the client name, and the
+ pkg_client_name parameter may be ignored or removed in the future.
+
Version 6:
Compatible with clients using versions 1-5
Changes:
--- a/src/client.py Tue Nov 11 15:07:27 2008 -0800
+++ b/src/client.py Tue Nov 11 15:17:25 2008 -0800
@@ -2006,9 +2006,10 @@
__img = None
def main_func():
+ global_settings.client_name = PKG_CLIENT_NAME
+
global __img
__img = img = image.Image()
- img.history.client_name = PKG_CLIENT_NAME
locale.setlocale(locale.LC_ALL, '')
gettext.install("pkg", "/usr/share/locale")
--- a/src/modules/client/__init__.py Tue Nov 11 15:07:27 2008 -0800
+++ b/src/modules/client/__init__.py Tue Nov 11 15:17:25 2008 -0800
@@ -22,7 +22,6 @@
# Copyright 2008 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
-#
__all__ = ["global_settings"]
@@ -33,5 +32,6 @@
def __init__(self):
object.__init__(self)
self.PKG_TIMEOUT_MAX = 4
+ self.client_name = None
global_settings = GlobalSettings()
--- a/src/modules/client/api.py Tue Nov 11 15:07:27 2008 -0800
+++ b/src/modules/client/api.py Tue Nov 11 15:17:25 2008 -0800
@@ -30,11 +30,12 @@
import pkg.misc as misc
import pkg.fmri as fmri
from pkg.client.imageplan import EXECUTED_OK
+from pkg.client import global_settings
import threading
-CURRENT_API_VERSION = 6
-
+CURRENT_API_VERSION = 7
+
class ImageInterface(object):
"""This class presents an interface to images that clients may use.
There is a specific order of methods which must be used to install
@@ -56,7 +57,7 @@
__INSTALL = 1
__UNINSTALL = 2
__IMAGE_UPDATE = 3
-
+
def __init__(self, img_path, version_id, progesstracker,
cancel_state_callable, pkg_client_name):
"""Constructs an ImageInterface. img_path should point to an
@@ -67,16 +68,21 @@
wishes to have called each time whether the operation can be
canceled changes. It can raise VersionException and
ImageNotFoundException."""
-
- compatible_versions = set([1, 2, 3, 4, 5, 6])
-
+
+ compatible_versions = set([1, 2, 3, 4, 5, 6, 7])
+
if version_id not in compatible_versions:
raise api_errors.VersionException(CURRENT_API_VERSION,
version_id)
+ # The image's History object will use client_name from
+ # global_settings, but if the program forgot to set it,
+ # we'll go ahead and do so here.
+ if global_settings.client_name is None:
+ global_settings.client_name = pkg_client_name
+
# These variables are private and not part of the API.
self.img = image.Image()
- self.img.history.client_name = pkg_client_name
self.img.find_root(img_path)
self.img.load_config()
self.progresstracker = progesstracker
--- a/src/modules/client/history.py Tue Nov 11 15:07:27 2008 -0800
+++ b/src/modules/client/history.py Tue Nov 11 15:17:25 2008 -0800
@@ -267,6 +267,10 @@
# bypass our setattr override by calling object.
object.__setattr__(self, "client_args", [])
+ # Initialize client_name to what the client thinks it is. This
+ # will be overridden if we load history entries off disk.
+ self.client_name = pkg.client.global_settings.client_name
+
self.root_dir = root_dir
if filename:
self.__load(filename)
--- a/src/modules/client/image.py Tue Nov 11 15:07:27 2008 -0800
+++ b/src/modules/client/image.py Tue Nov 11 15:17:25 2008 -0800
@@ -968,7 +968,7 @@
# are not negatively impacted by manifest caching. This should
# be removed by bug 4231 whenever a better way to handle caching
# is found.
- if self.history.client_name == "pkg":
+ if global_settings.client_name == "pkg":
if fmri in self.__manifest_cache:
m = self.__manifest_cache[fmri]
else:
--- a/src/modules/misc.py Tue Nov 11 15:07:27 2008 -0800
+++ b/src/modules/misc.py Tue Nov 11 15:17:25 2008 -0800
@@ -43,6 +43,7 @@
import pkg.urlhelpers as urlhelpers
import pkg.portable as portable
from pkg.client.imagetypes import img_type_names, IMG_NONE
+from pkg.client import global_settings
from pkg import VERSION
def time_to_timestamp(t):
@@ -76,7 +77,7 @@
return u
-_client_version = "pkg/%s (%s %s; %s %s; %%s)" % \
+_client_version = "pkg/%s (%s %s; %s %s; %%s; %%s)" % \
(VERSION, portable.util.get_canonical_os_name(), platform.machine(),
portable.util.get_os_release(), platform.version())
@@ -132,7 +133,8 @@
(operation, version))
headers["User-Agent"] = \
- _client_version % img_type_names[imgtype]
+ _client_version % (img_type_names[imgtype],
+ global_settings.client_name)
if uuid:
headers["X-IPkg-UUID"] = uuid
req = urllib2.Request(url = uri, headers = headers)
--- a/src/packagemanager.py Tue Nov 11 15:07:27 2008 -0800
+++ b/src/packagemanager.py Tue Nov 11 15:17:25 2008 -0800
@@ -92,6 +92,8 @@
# in the environment.
global_settings.PKG_TIMEOUT_MAX = int(os.environ.get("PKG_TIMEOUT_MAX",
global_settings.PKG_TIMEOUT_MAX))
+
+ global_settings.client_name = PKG_CLIENT_NAME
try:
self.application_dir = os.environ["PACKAGE_MANAGER_ROOT"]
--- a/src/pull.py Tue Nov 11 15:07:27 2008 -0800
+++ b/src/pull.py Tue Nov 11 15:17:25 2008 -0800
@@ -39,6 +39,7 @@
import pkg.catalog as catalog
import pkg.actions as actions
from pkg.misc import versioned_urlopen, gunzip_from_stream, msg, PipeError
+from pkg.client import global_settings
def usage(usage_error = None):
""" Emit a usage message and optionally prefix it with a more
@@ -253,6 +254,8 @@
# XXX /usr/lib/locale is OpenSolaris-specific.
gettext.install("pkgrecv", "/usr/lib/locale")
+ global_settings.client_name = "pkgrecv"
+
try:
opts, pargs = getopt.getopt(sys.argv[1:], "s:d:nk")
except getopt.GetoptError, e:
--- a/src/tests/cli/testutils.py Tue Nov 11 15:07:27 2008 -0800
+++ b/src/tests/cli/testutils.py Tue Nov 11 15:17:25 2008 -0800
@@ -111,6 +111,8 @@
if k.startswith("PKG_"):
del os.environ[k]
+ from pkg.client import global_settings
+ global_settings.client_name = "pkg"
topdivider = \
--- a/src/updatemanager.py Tue Nov 11 15:07:27 2008 -0800
+++ b/src/updatemanager.py Tue Nov 11 15:17:25 2008 -0800
@@ -50,6 +50,7 @@
import pkg.client.api_errors as api_errors
import pkg.client.progress as progress
import pkg.gui.beadmin as beadm
+from pkg.client import global_settings
# Put _() in the global namespace
import __builtin__
@@ -203,6 +204,8 @@
class Updatemanager:
def __init__(self):
+ global_settings.client_name = PKG_CLIENT_NAME
+
try:
self.application_dir = os.environ["UPDATE_MANAGER_ROOT"]
except KeyError: