[python-win32] "Property '%s.%s' can not be set" on read/write attribute

Mark Hammond mhammond at skippinet.com.au
Wed Jan 30 01:39:01 CET 2008


I can't see docs for that property, but if it takes optional params, it might have been transformed to a SetRuleName() method.  You could try adding:

 

rule_obj. _print_details_()

 

and see what is dumped.  Finally, if you can use makepy, the generated file should make it clearer to see what is going on.

 

Cheers,

 

Mark

 

From: python-win32-bounces at python.org [mailto:python-win32-bounces at python.org] On Behalf Of Tim Johnson
Sent: Wednesday, 30 January 2008 11:18 AM
To: python-win32 at python.org
Subject: [python-win32] "Property '%s.%s' can not be set" on read/write attribute

 

So I'm trying to automate some tasks with SMS, and I've run into a roadblock when creating new collection membership rules.  The code below is a method of a Collection object.  It's a rough draft, so don't worry too much about the top half unless you think it might be screwing something up.  My problem is that I go to create a new SMS_CollectionRuleDirect object (at the bottom of the code provided) and I get the following error:

 

>>> coll.AddMembershipRule(rule)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "H:\p4rootw\lib\ops\sms.py", line 495, in AddMembershipRule
    rule_obj.RuleName = name
  File "C:\Python24\Lib\site-packages\win32com\client\dynamic.py", line 550, in __setattr__
    raise AttributeError, "Property '%s.%s' can not be set." % (self._username_, attr)

 

If you look in the SMS 2003 SDK v3.1 or here (http://www.microsoft.com/technet/prodtechnol/sms/sms2003/opsguide/ops_854m.mspx?mfr=true) you can see that the property is indeed Read/Write.  Is there any way to override this or some workaround that I can use to fix this?  I'm about ready to start hopping up and down in my office chair like an angry chimpanzee.

 

 

 

 

 

# This is a method of an sms.Collection object.

#

# self.parent.wmi_connection is an object created via wmi.WMI() with the 

#   namespace set to  <file:///\\server\root\sms\site_S01> \\server\root\sms\site_S01, 

#   and I can retrieve information fine, as well as add/edit Collection, 

#   advertisement, and other objects just fine.

#

# self.parent.db_connection is an object created via odbc.odbc(), connected to the SMS database

 

  def AddMembershipRule(self, rule):
    """Adds a membership rule using an sms.MemberShipRule object.
    
    Note: this method only supports adding System Resources through direct
          membership, not User or Group Resources.
    
    Args:
      rule: an sms.CollectionMembershipRule object
      
    Raises:
      TypeError: if rule is not an sms.CollectionMembershipRule object
      SmsUnsupportedResourceType: if a direct membership rule for a non-system
        resource type is passed
      
    Returns:
      True on Success
      None on Failure
      
    TODO: Remove object type limitation for direct membership rules
    """
    if not isinstance(rule, CollectionMembershipRule):
      raise TypeError
    
    self.parent.ConnectWmi()
    self.parent.ConnectDb()
    conn = self.parent.wmi_connection
    
    if rule.type == 'direct':
      if rule.resource_type != 5:
        raise SmsUnsupportedResourceType
      
      cursor = self.parent.db_connection.cursor()
      cursor.execute('SELECT Netbios_Name0, Name0 from v_R_System '
                     'WHERE ResourceID = %s' % rule.resource_id)
      names = cursor.fetchall()
      name = None
      
      if names[0]:
        name = names[0]
      else:
        name = names[1]

 

      # This is the problem section

      rule_obj = conn.Get('SMS_CollectionRuleDirect').SpawnInstance_()
      rule_obj.ResourceClassName = 'SMS_R_System'
      rule_obj.RuleName = name
      rule_obj.ResourceID = rule.resource_id
      coll_obj = conn.Get('SMS_Collection.CollectionID="%s"'
                          % self.collection_id)
      coll_obj.AddMembershipRule(rule_obj)

 



-- 
_____________________
Ceci n'est pas un email. 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/python-win32/attachments/20080130/b8cc5de0/attachment-0001.htm 


More information about the python-win32 mailing list