Shawn,
I have designed a new action as per your suggestion, this action is similar to the license action.
It install's the content/file in the metadata area like the license action.

*Info Actions*
   The 'info' action represents the informational file associated with the
   package contents. For example, an icon for the package can be represented
   using this action. The payload of the info action will be delivered into
   the image metadata directory associated with the package.
        
        The following attributes are recognized:
        
type The keyword identifying the information type, for use in filter and query operations. The 'type' attribute is the key attribute for the info action.
        

At present, the only type value allowed is pkg.icon.24px but in future we can 
extend
this action to use other types of informational payloads.

Now the syntax is
*pkgsend add info* */home/rajkumar/package-24x24.png type=pkg.icon.24px
**
*metadata location*
.org.opensolaris,pkg/pkg/sample/1.0.1%2C5.1.2600%3A20090324T133153Z/info.pkg.icon.24px*

Manifest entry
*info cd8e2e19900beccecd829d37195e5f6b92e97394 chash=9d77be964b27e4b52fd17625facd25de138bf54c pkg.csize=4118 pkg.size=4095 type=pkg.icon.24px*

I think we need one more attribute to set the icon file type (svg or png ), but I think there is no need to expose this attribute to the user we can use internally in the code. This will be used by the client UI find the type of file and direct it to the corresponding loader.
Is there any other way to do this?

I have also attached the action file which I coded and it works fine.

Thoughts?

regards,
Rajkumar

Shawn Walker wrote:
Bart Smaalders wrote:
If you specify the icon by hash, the packagemanger is free to
cache it wherever it wants, and the publishers don't need to
care... and those of us using the command line won't need to
download the icons at all.

Except we don't currently support file actions that are payload only as far as I know (i.e. the path attribute is a required attribute at the moment). That leaves us with a few possible solutions (that I can think of at the moment):

* enhance the file action to not require a path attribute and assume such actions are payload only (this makes publication time verification problematic and the fact that the path is treated as the key attribute difficult)

* add a new 'data' action that is specifically for informational payloads to be served by the depot server via /file/0, but are ignored by client/imageplan as they are not intended to be installed to the user's target system.

If we chose the second option, the pkg.icon attribute would then be free to reference hash names of data or file actions (as appropriate). That would also allow other, future attributes to reference informational only payloads.

Thoughts?


#!/usr/bin/python2.4
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#

#
# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#

"""module describing a info packaging object

This module contains the InfoAction class, which represents a info
packaging object.  This contains a payload of the package extra information ,
and a single attribute, 'type', which is the type of the information. Info are
installed on the system in the package's directory."""

import os
import errno
from stat import S_IWRITE, S_IREAD

import generic
import pkg.misc as misc
import pkg.portable as portable

class InfoAction(generic.Action):
        """Class representing a info packaging object."""

        name = "info"
        key_attr = "type"

        def __init__(self, data=None, **attrs):
                generic.Action.__init__(self, data, **attrs)

        def preinstall(self, pkgplan, orig):
                # set attrs["path"] so filelist can handle this action
                # No leading / chars allowed
                #file_parts = self.attrs["value"].rsplit(".", 1)
                print self.attrs
                self.attrs["path"] = os.path.normpath(os.path.join(
                    pkgplan.image.img_prefix,
                    "pkg",
                    pkgplan.destination_fmri.get_dir_path(),
                    "info." + self.attrs["type"]))

        def install(self, pkgplan, orig):
                """Client-side method that installs the info."""
                mode = 0444
                owner = 0
                group = 0

                path = self.attrs["path"]
                stream = self.data()

                path = os.path.normpath(os.path.sep.join(
                    (pkgplan.image.get_root(), path)))

                # make sure the directory exists and the file is writable
                if not os.path.exists(os.path.dirname(path)):
                        self.makedirs(os.path.dirname(path), mode=0755)
                elif os.path.exists(path):
                        os.chmod(path, 0644)

                lfile = file(path, "wb")
                # XXX Should throw an exception if shasum doesn't match
                # self.hash
                shasum = misc.gunzip_from_stream(stream, lfile)

                lfile.close()
                stream.close()

                os.chmod(path, mode)

                try:
                        portable.chown(path, owner, group)
                except OSError, e:
                        if e.errno != errno.EPERM:
                                raise

        def needsdata(self, orig):
                # We always want to download the license
                return True

        def verify(self, img, pkg_fmri, **args):
                path = os.path.normpath(os.path.join(img.imgdir,
                    "pkg", pkg_fmri.get_dir_path(),
                    "info." + self.attrs["type"]))

                if args["forever"] == True:
                        try:
                                chash, cdata = misc.get_data_digest(path)
                        except EnvironmentError, e:
                                if e.errno == errno.ENOENT:
                                        return [_("Info file %s does not "
                                            "exist.") % path]
                                raise

                        if chash != self.hash:
                                return [_("Hash: '%(found)s' should be "
                                    "'%(expected)s'") % { "found": chash,
                                    "expected": self.hash}]
                return []

        #this method is introduced to keep in sync with the license action,
        #I am sure about the use of this method in license action.
        def remove(self, pkgplan):
                path = os.path.normpath(os.path.join(pkgplan.image.imgdir,
                    "pkg", pkgplan.origin_fmri.get_dir_path(),
                    "info." + self.attrs["type"]))

                try:
                        # Make file writable so it can be deleted
                        os.chmod(path, S_IWRITE|S_IREAD)
                        os.unlink(path)
                except OSError,e:
                        if e.errno != errno.ENOENT:
                                raise

        def get_local_opener(self, img, fmri):
                """Return an opener for the info file from the local disk."""
                path = os.path.normpath(os.path.join(img.imgdir, "pkg",
                    fmri.get_dir_path(), "info." + self.attrs["type"]))

                def opener():
                        # XXX Do we check to make sure that what's there is what
                        # we think is there (i.e., re-hash)?
                        return file(path, "rb")

                return opener
_______________________________________________
pkg-discuss mailing list
[email protected]
http://mail.opensolaris.org/mailman/listinfo/pkg-discuss

Reply via email to