22
23 #
24 # Copyright 2009 Sun Microsystems, Inc. All rights reserved.
25 # Use is subject to license terms.
26 #
27
28 """module describing a generic packaging object
29
30 This module contains the Action class, which represents a generic packaging
31 object."""
32
33 from cStringIO import StringIO
34 import errno
35 import os
36 try:
37 # Some versions of python don't have these constants.
38 os.SEEK_SET
39 except AttributeError:
40 os.SEEK_SET, os.SEEK_CUR, os.SEEK_END = range(3)
41 import pkg.actions
42 import pkg.client.retrieve as retrieve
43 import pkg.portable as portable
44
45 class Action(object):
46 """Class representing a generic packaging object.
47
48 An Action is a very simple wrapper around two dictionaries: a named set
49 of data streams and a set of attributes. Data streams generally
50 represent files on disk, and attributes represent metadata about those
51 files.
52 """
53
54 # 'name' is the name of the action, as specified in a manifest.
55 name = "generic"
56 # 'attributes' is a list of the known usable attributes. Or something.
57 # There probably isn't a good use for it.
58 attributes = ()
59 # 'key_attr' is the name of the attribute whose value must be unique in
60 # the namespace of objects represented by a particular action. For
61 # instance, a file's key_attr would be its pathname. Or a driver's
62 # key_attr would be the driver name. When 'key_attr' is None, it means
382
383 variants = []
384 facets = []
385
386 for k in self.attrs.iterkeys():
387 if k.startswith("variant."):
388 variants.append(k)
389 if k.startswith("facet."):
390 facets.append(k)
391 return variants, facets
392
393 def get_remote_opener(self, img, fmri):
394 """Return an opener for the action's datastream which pulls from
395 the server. The caller may have to decompress the
396 datastream."""
397
398 if not hasattr(self, "hash"):
399 return None
400
401 def opener():
402 return retrieve.get_datastream(img, fmri, self.hash)
403
404 return opener
405
406 def verify(self, img, **args):
407 """Returns an empty list if correctly installed in the given
408 image."""
409 return []
410
411 def needsdata(self, orig):
412 """Returns True if the action transition requires a
413 datastream."""
414 return False
415
416 def attrlist(self, name):
417 """return list containing value of named attribute."""
418 value = self.attrs.get(name, [])
419 if isinstance(value, list):
420 return value
421 else:
422 return [ value ]
|
22
23 #
24 # Copyright 2009 Sun Microsystems, Inc. All rights reserved.
25 # Use is subject to license terms.
26 #
27
28 """module describing a generic packaging object
29
30 This module contains the Action class, which represents a generic packaging
31 object."""
32
33 from cStringIO import StringIO
34 import errno
35 import os
36 try:
37 # Some versions of python don't have these constants.
38 os.SEEK_SET
39 except AttributeError:
40 os.SEEK_SET, os.SEEK_CUR, os.SEEK_END = range(3)
41 import pkg.actions
42 import pkg.portable as portable
43
44 class Action(object):
45 """Class representing a generic packaging object.
46
47 An Action is a very simple wrapper around two dictionaries: a named set
48 of data streams and a set of attributes. Data streams generally
49 represent files on disk, and attributes represent metadata about those
50 files.
51 """
52
53 # 'name' is the name of the action, as specified in a manifest.
54 name = "generic"
55 # 'attributes' is a list of the known usable attributes. Or something.
56 # There probably isn't a good use for it.
57 attributes = ()
58 # 'key_attr' is the name of the attribute whose value must be unique in
59 # the namespace of objects represented by a particular action. For
60 # instance, a file's key_attr would be its pathname. Or a driver's
61 # key_attr would be the driver name. When 'key_attr' is None, it means
381
382 variants = []
383 facets = []
384
385 for k in self.attrs.iterkeys():
386 if k.startswith("variant."):
387 variants.append(k)
388 if k.startswith("facet."):
389 facets.append(k)
390 return variants, facets
391
392 def get_remote_opener(self, img, fmri):
393 """Return an opener for the action's datastream which pulls from
394 the server. The caller may have to decompress the
395 datastream."""
396
397 if not hasattr(self, "hash"):
398 return None
399
400 def opener():
401 return img.transport.get_datastream(fmri, self.hash)
402
403 return opener
404
405 def verify(self, img, **args):
406 """Returns an empty list if correctly installed in the given
407 image."""
408 return []
409
410 def needsdata(self, orig):
411 """Returns True if the action transition requires a
412 datastream."""
413 return False
414
415 def attrlist(self, name):
416 """return list containing value of named attribute."""
417 value = self.attrs.get(name, [])
418 if isinstance(value, list):
419 return value
420 else:
421 return [ value ]
|