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

# Source Code for Module Products.ZenModel.Software

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