Package Products :: Package ZenModel :: Module Software |
[hide private]
[frames] | no frames]

# Source Code for Module Products.ZenModel.Software

      1  ##############################################################################
      2  #
      3  # Copyright (C) Zenoss, Inc. 2007, all rights reserved.
      4  #
      5  # This content is made available according to terms specified in
      6  # License.zenoss under the directory where your Zenoss product is installed.
      7  #
      8  ##############################################################################
      9
     10
     11  __doc__="""Software
     12
     13  Software represents a software vendor's product.
     14
     15  $Id: Software.py,v 1.5 2003/03/08 18:34:24 edahl Exp $"""
     16
     17  __version__ = "$Revision: 1.5 $"[11:-2]
     18
     19  from Globals import DTMLFile
     20  from Globals import InitializeClass
     21  from AccessControl import ClassSecurityInfo
     22
     23  from AccessControl import Permissions as permissions
     24  from Products.ZenModel.ZenossSecurity import *
     25
     26  from Products.ZenRelations.RelSchema import *
     27  from Products.ZenWidgets import messaging
     28
     29  from MEProduct import MEProduct
     30  from ZenDate import ZenDate
     31
     32 -def manage_addSoftware(context, id, title = None, REQUEST = None):
     33      """make a Software"""
     34      d = Software(id, title)
     35      context._setObject(id, d)
     36      if REQUEST is not None:
     37          REQUEST['RESPONSE'].redirect(context.absolute_url()+'/manage_main')
     38
     39
     40  addSoftware = DTMLFile('dtml/addSoftware',globals())
     41
     42
     43 -class Software(MEProduct):
     44      """Software object"""
     45      portal_type = meta_type = 'Software'
     46
     47      procRegex = ""
     48      monitorProc = False
     49
     50      _properties = (
     51          {'id':'procRegex', 'type':'string', 'mode':'w'},
     52          {'id':'monitorProc', 'type':'boolean', 'mode':'w'},
     53          {'id':'installDate', 'type':'date', 'mode':''},
     54      )
     55
     56      _relations = MEProduct._relations + (
     57          ("os", ToOne(ToManyCont, "Products.ZenModel.OperatingSystem", "software")),
     58      )
     59
     60      factory_type_information = (
     61          {
     62              'id'             : 'Software',
     63              'meta_type'      : 'Software',
     64              'description'    : """Class to manage product information""",
     65              'icon'           : 'Software_icon.gif',
     66              'product'        : 'ZenModel',
     67              'factory'        : 'manage_addSoftware',
     68              'immediate_view' : 'viewProductOverview',
     69              'actions'        :
     70              (
     71                  { 'id'            : 'overview'
     72                  , 'name'          : 'Overview'
     73                  , 'action'        : 'viewSoftwareOverview'
     74                  , 'permissions'   : (
     75                    permissions.view, )
     76                  },
     77              )
     78            },
     79          )
     80
     81      security = ClassSecurityInfo()
     82
     83 -    def __init__(self, id, title=""):
     84          MEProduct.__init__(self, id, title)
     85          self._installDate = ZenDate("1968/1/8")
     86
     87
     88 -    def __getattr__(self, name):
     89          if name == 'installDate':
     90              return self._installDate.getDate()
     91          else:
     92              raise AttributeError, name
     93
     94
     95 -    def _setPropValue(self, id, value):
     96          """override from PropertyManager to handle checks and ip creation"""
     97          self._wrapperCheck(value)
     98          if id == 'installDate':
     99              self.setInstallDate(value)
    100          else:
    101              MEProduct._setPropValue(self, id, value)
    102
    103
    104      security.declareProtected('Change Device', 'setProduct')
    105 -    def setProduct(self, productName,  manufacturer="Unknown",
    106                      newProductName="", REQUEST=None, **kwargs):
    107          """Set the product class of this software.
    108          """
    109          if not manufacturer: manufacturer = "Unknown"
    110          if newProductName: productName = newProductName
    111          prodobj = self.getDmdRoot("Manufacturers").createSoftwareProduct(
    112                                      productName, manufacturer, **kwargs)
    113          self.productClass.addRelation(prodobj)
    114          if REQUEST:
    115              messaging.IMessageSender(self).sendToBrowser(
    116                  'Product Set',
    117                  ("Set Manufacturer %s and Product %s."
    118                                      % (manufacturer, productName))
    119              )
    120              return self.callZenScreen(REQUEST)
    121
    122
    123 -    def setProductKey(self, prodKey, manufacturer=None):
    124          """Set the product class of this software by its productKey.
    125          """
    126          if prodKey:
    127              # Store these so we can return the proper value from getProductKey
    128              self._prodKey = prodKey
    129              self._manufacturer = manufacturer
    130
    131              if manufacturer is None:
    132                  manufacturer = 'Unknown'
    133
    134              manufs = self.getDmdRoot("Manufacturers")
    135              prodobj = manufs.createSoftwareProduct(prodKey, manufacturer, isOS=True)
    136              self.productClass.addRelation(prodobj)
    137          else:
    138              self.productClass.removeRelation()
    139
    140
    141 -    def name(self):
    142          """Return the name of this software (from its softwareClass)
    143          """
    144          pclass = self.productClass()
    145          if pclass: return pclass.name
    146          return ""
    147
    148
    149 -    def version(self):
    150          """Return the version of this software (from its softwareClass)
    151          """
    152          pclass = self.productClass()
    153          if pclass: return pclass.version
    154          return ""
    155
    156
    157 -    def build(self):
    158          """Return the build of this software (from its softwareClass)
    159          """
    160          pclass = self.productClass()
    161          if pclass: return pclass.build
    162          return ""
    163
    164
    165 -    def getInstallDateObj(self):
    166          """Return the install date as a DateTime object.
    167          """
    168          return self._installDate.getDate()
    169
    170
    171 -    def getInstallDate(self):
    172          """Return the install date in the form 'YYYY/MM/DD HH:MM:SS'
    173          """
    174          #1968/01/08 00:00:00.000
    175          if self._installDate.getStringSecsResolution() != "1968/01/08 00:00:00":
    176              return self._installDate.getStringSecsResolution()
    177          else:
    178              return "Unknown"
    179
    180
    181 -    def setInstallDate(self, value):
    182          """Set the install date should be string in form 'YYYY/MM/DD HH:MM:SS'
    183          """
    184          self._installDate.setDate(value)
    185
    186
    187 -    def device(self):
    188          """Return our Device for DeviceResultInt.
    189          """
    190          return self.os().device()
    191
    192
    193  InitializeClass(Software)
    194