|
From: <ba...@us...> - 2007-02-22 00:19:50
|
Revision: 444
http://svn.sourceforge.net/omc/?rev=444&view=rev
Author: bartw
Date: 2007-02-21 16:19:49 -0800 (Wed, 21 Feb 2007)
Log Message:
-----------
fixed stringarray properties and parameters so that array elements can include commas
Modified Paths:
--------------
tools/trunk/yawn/yawn.py
Modified: tools/trunk/yawn/yawn.py
===================================================================
--- tools/trunk/yawn/yawn.py 2007-02-20 21:59:16 UTC (rev 443)
+++ tools/trunk/yawn/yawn.py 2007-02-22 00:19:49 UTC (rev 444)
@@ -60,7 +60,10 @@
for item in x:
if item is not x[0]:
rval+= ', '
- rval+= _val2str(item)
+ strItem = _val2str(item)
+ if type(item) in types.StringTypes:
+ strItem = '"' + strItem + '"'
+ rval+= strItem
rval+= '}'
return rval
elif type(x) == datetime:
@@ -759,10 +762,15 @@
if metaProp.is_array:
if type(propVal) is not list:
propVal = propVal.strip()
- propVal = propVal.strip('{}')
+ propVal = propVal.strip('{}[]')
propVal = propVal.strip()
- propVal = propVal.split(',')
- propVal = [x.strip() for x in propVal]
+ if len(propVal) > 2 and dt == 'string' \
+ and propVal[0] == '"' and propVal[-1] == '"' :
+ propVal = '['+propVal+']'
+ propVal = eval(propVal)
+ else:
+ propVal = propVal.split(",")
+ propVal = [x.strip() for x in propVal]
propVal = [pywbem.tocimobj(dt, x) for x in propVal]
inst.properties[propName] = propVal
else:
@@ -933,7 +941,10 @@
else:
ht+= '<input type=text size=50 name="'+fPropName+'"'
if oldVal is not None:
- ht+= ' value="'+_val2str(oldVal)+'"'
+ strValue = _val2str(oldVal)
+ if isinstance(oldVal,list):
+ strValue = strValue.replace('"','"')
+ ht+= ' value="'+strValue+'"'
ht+= '>'
ht+= '</td></tr>'
@@ -1025,10 +1036,15 @@
if metaParm.is_array:
if type(paramVal) is not list:
paramVal = paramVal.strip()
- paramVal = paramVal.strip('{}')
+ paramVal = paramVal.strip('{}[]')
paramVal = paramVal.strip()
- paramVal = paramVal.split(',')
- paramVal = [x.strip() for x in paramVal]
+ if len(paramVal) > 2 and dt == 'string' \
+ and paramVal[0] == '"' and paramVal[-1] == '"' :
+ paramVal = '['+paramVal+']'
+ paramVal = eval(paramVal)
+ else:
+ paramVal = paramVal.split(",")
+ paramVal = [x.strip() for x in paramVal]
if metaParm.reference_class is not None:
paramVal = [_decodeObject(x) for x in paramVal]
else:
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ba...@us...> - 2007-02-27 00:42:19
|
Revision: 445
http://svn.sourceforge.net/omc/?rev=445&view=rev
Author: bartw
Date: 2007-02-26 16:42:17 -0800 (Mon, 26 Feb 2007)
Log Message:
-----------
adding link to return to namespace on top; clickable method REF out params
Modified Paths:
--------------
tools/trunk/yawn/yawn.py
Modified: tools/trunk/yawn/yawn.py
===================================================================
--- tools/trunk/yawn/yawn.py 2007-02-22 00:19:49 UTC (rev 444)
+++ tools/trunk/yawn/yawn.py 2007-02-27 00:42:17 UTC (rev 445)
@@ -65,7 +65,7 @@
strItem = '"' + strItem + '"'
rval+= strItem
rval+= '}'
- return rval
+ return cgi.escape(rval)
elif type(x) == datetime:
#http://windowssdk.msdn.microsoft.com/en-us/library/ms739696.aspx
rval = x.strftime('%Y%m%d%H%M%S')
@@ -87,7 +87,7 @@
while len(uoff) < 3:
uoff = '0'+uoff
uoff = neg and '-'+uoff or '+'+uoff
- return rval + uoff
+ return cgi.escape(rval + uoff)
elif type(x) == timedelta:
#http://windowssdk.msdn.microsoft.com/en-us/library/ms744132.aspx
mss = str(x.microseconds)
@@ -108,10 +108,10 @@
days = str(x.days)
while len(days) < 8:
days = '0'+days
- return days + hours + mins + secs + '.' + mss + ':000'
+ return cgi.escape(days + hours + mins + secs + '.' + mss + ':000')
else:
- return str(x)
+ return cgi.escape(str(x))
##############################################################################
_status_codes = [('', '')
@@ -221,9 +221,11 @@
') : ' + arg[1] + '</i>')
req.write( '</body></html>')
return;
- req.write( _printHead('Deleted Instance of '+instName.classname))
- urlargs = {}
- req.write('Deleted Instance of ' + instName.classname)
+ urlargs = {'ns':ns,'url':url}
+ req.write( _printHead('Deleted Instance of '+instName.classname,
+ urlargs=urlargs))
+ req.write('Deleted Instance of ' + _makeHref(req, 'GetClass',
+ urlargs, instName.classname))
_printInstanceNames(req, urlargs, [instName], omitGetLink=True)
return '</body></html>'
@@ -265,7 +267,7 @@
class_urlargs["className"] = instName.classname
ht = 'Objects associated with instance of '
ht+= _makeHref(req, 'GetClass', class_urlargs, instName.classname)
- ht = _printHead('ReferenceNames '+instName.classname, ht, req)
+ ht = _printHead('ReferenceNames '+instName.classname, ht, req, urlargs)
req.write(ht)
_printInstanceNames(req, urlargs, [instName])
@@ -359,7 +361,7 @@
urlargs['url'] = url
instName = _decodeObject(instPath)
refs = None
- req.write( _printHead(assocCall+' '+instName.classname))
+ req.write( _printHead(assocCall+' '+instName.classname,urlargs=urlargs))
class_urlargs = urlargs.copy()
class_urlargs["className"] = instName.classname
@@ -440,7 +442,7 @@
urlargs['url'] = url
instName = _decodeObject(instPath)
assocs = _ex(req,conn.AssociatorNames,ObjectName=instName)
- ht = _printHead('AssociatorNames '+instName.classname)
+ ht = _printHead('AssociatorNames '+instName.classname, urlargs=urlargs)
groupedAssocs = {}
for assoc in assocs:
if assoc.classname not in groupedAssocs.keys():
@@ -464,7 +466,7 @@
class_urlargs['ns'] = ns
class_urlargs['url'] = url
class_urlargs["className"] = instName.classname
- ht = _printHead('Filtered ReferenceNames Dialog... (Coming...)')
+ ht = _printHead('Filtered ReferenceNames Dialog... (Coming...)', urlargs=urlargs)
ht+= '<h1>Filtered References on Class '+_makeHref(req, 'GetClass', class_urlargs, instName.classname)+'</h1>'
req.write(ht)
_printInstanceNames(req, class_urlargs, [instName])
@@ -626,7 +628,7 @@
inst = None
klass = _ex(req,conn.GetClass,ClassName=instName.classname, LocalOnly = False, IncludeQualifiers = True)
inst = _ex(req,conn.GetInstance,InstanceName=instName, LocalOnly = False)
- ht = _printHead('Instance of '+instName.classname, req=req)
+ ht = _printHead('Instance of '+instName.classname, req=req, urlargs=urlargs)
ht+= _displayInstance(req, inst, instName, klass, urlargs)
return ht + '</body></html>'
@@ -721,7 +723,7 @@
urlargs['ns'] = ns
urlargs['url'] = url
insts = _ex(req,conn.EnumerateInstances,ClassName = className, LocalOnly = False)
- ht = _printHead('Instances of '+className, 'Instances of '+className, req)
+ ht = _printHead('Instances of '+className, 'Instances of '+className, req, urlargs=urlargs)
numInsts = len(insts)
msgStart = 'Showing '+`numInsts`+' Instances<br />'
if numInsts == 0:
@@ -811,7 +813,7 @@
def CreateInstancePrep(req, url, ns, className):
conn = _frontMatter(req, url, ns)
klass = _ex(req, conn.GetClass, ClassName = className, LocalOnly = False, IncludeQualifiers = True)
- ht = _printHead('Create Instances of '+className,'Create Instances of '+className, req)
+ ht = _printHead('Create Instances of '+className,'Create Instances of '+className, req, urlargs={'ns':ns, 'url':url})
ht+= _displayInstanceMod(req, conn, url, ns, klass)
return ht + '</body></html>'
@@ -820,7 +822,7 @@
conn = _frontMatter(req, url, ns)
instPathDec = _decodeObject(instPath)
klass = _ex(req,conn.GetClass,ClassName=instPathDec.classname, LocalOnly = False, IncludeQualifiers = True)
- ht = _printHead('Modify Instances of '+instPathDec.classname,'Modify Instances of '+instPathDec.classname, req)
+ ht = _printHead('Modify Instances of '+instPathDec.classname,'Modify Instances of '+instPathDec.classname, req, urlargs={'ns':ns, 'url':url})
ht+= _displayInstanceMod(req, conn, url, ns, klass, (instPath, instPathDec))
return ht + '</body></html>'
@@ -980,7 +982,7 @@
class_urlargs["className"] = className
ht+= ' of '
ht+= _makeHref(req, 'GetClass', class_urlargs, className) + '</h1>'
- ht = _printHead('Instances of '+className, ht, req)
+ ht = _printHead('Instances of '+className, ht, req, urlargs=urlargs)
req.write(ht)
_printInstanceNames(req, urlargs, instNames)
ht = '<p>'
@@ -1013,7 +1015,7 @@
ht = 'Invoked method '+_makeHref(req, 'GetClass', urlargs, className)
ht+= '::'+_makeHref(req, 'GetClass', urlargs, method, '#'+method.lower())
ht+= '()'
- ht = _printHead('Results of Method '+className+'::'+method, ht, req)
+ ht = _printHead('Results of Method '+className+'::'+method, ht, req, urlargs=urlargs)
cimmethod = klass.methods[method]
inParms = {}
@@ -1065,8 +1067,12 @@
ht+= '<th>Data Type</th><th>Param Name</th><th>Value</th></tr>'
for parmName, parm in outParms.items():
metaParm = cimmethod.parameters[parmName]
+ isRef = False
if metaParm.reference_class is not None:
- dt = metaParm.reference_class
+ isRef = True
+ urlargs['className'] = metaParm.reference_class
+ dt = _makeHref(req, 'GetClass', urlargs,
+ metaParm.reference_class)
else:
dt = metaParm.type
ht+= '<tr><td>'+dt+'</td><td>'+metaParm.name+'</td><td>'
@@ -1080,7 +1086,10 @@
display = display + ' ('+valuesQual[valIdx]+')'
ht+= display
else:
- ht+= _val2str(parm)
+ if isRef:
+ ht+= _makeGetInstLink(req, urlargs, parm, _val2str(parm))
+ else:
+ ht+= _val2str(parm)
ht+= '</td></tr>'
ht+= '</table>'
@@ -1118,12 +1127,12 @@
outParms.append(param)
- ht = _printHead('Method '+className+'::'+method)
classUrlArgs = urlargs.copy()
classUrlArgs['className'] = className
ht = 'Invoke method '+_makeHref(req, 'GetClass', classUrlArgs, className)
ht+= '::'+_makeHref(req, 'GetClass', classUrlArgs, method, '#'+method.lower())+'()'
- ht = _printHead('Method '+className+'::'+method, ht, req)
+ # note, ht passed in as param.
+ ht = _printHead('Method '+className+'::'+method, ht, req, urlargs=urlargs)
if isinstance(lobjPath, pywbem.CIMInstanceName):
ht+= 'on instance'
req.write(ht,0)
@@ -1277,7 +1286,7 @@
urlargs['ns'] = ns
urlargs['url'] = url
klass = _ex(req, conn.GetClass, ClassName = className, LocalOnly = "false", IncludeClassOrigin = "true")
- ht = _printHead('Class '+className, 'Class '+className, req)
+ ht = _printHead('Class '+className, 'Class '+className, req, urlargs=urlargs)
instUrlArgs = urlargs.copy()
instUrlArgs['className'] = className
ht+= '<table border=0><tr><td>'
@@ -1316,7 +1325,7 @@
ht+= ', '
ht+= qual.name
if qual.name not in ["Composition", "Association", "Aggregation"]:
- ht+= ' ("'+cgi.escape(_val2str(qual.value))+'") '
+ ht+= ' ("'+_val2str(qual.value)+'") '
ht+= '</td></tr>'
ht+= '<tr><td align="center" bgcolor="#C0C0C0" colspan="3"><b>'
ht+= 'Parameters (local in grey)</b></td></tr>'
@@ -1765,7 +1774,7 @@
return "</table></body></html>"
##############################################################################
-def _printHead(title = None, heading = None, req = None):
+def _printHead(title = None, heading = None, req = None, urlargs = None):
ht = '\n<html><head><title>YAWN: CIM'
if title is not None:
ht+= ' ' + title
@@ -1777,7 +1786,13 @@
ht+= '<table border=0 cellpadding=0 cellspacing=0 vspace=0><tr><td nowrap width=100% valign=top>'
if heading is not None:
ht+= '<h1>'+heading+'</h1>'
- ht+= '</td><td valign=top nowrap align=right><font size=-1><i>'
+ ht+= '</td>'
+ if urlargs and 'ns' in urlargs.keys() and 'url' in urlargs.keys():
+ lurlargs = {'ns':urlargs['ns'], 'url':urlargs['url']}
+ ht+= '<td valign=top nowrap align=right><font size=-1><i>'
+ ht+= _makeHref(req, 'EnumClassNames', lurlargs, lurlargs['ns'])
+ ht+= ' </i></td>'
+ ht+= '<td valign=top nowrap align=right><font size=-1><i>'
ht+= '<a href="'+_baseScript(req)+'/Logout">Logout >></a></i>'
ht+= '</td></tr></table>'
return ht
@@ -1841,6 +1856,8 @@
ht+= 'Unable to enumerate Namespaces. Return to the '
ht+= '<a href="'+_baseScript(req)+'">Login page</a> and specify a '
ht+= 'Namespace.'
+ if req.conn.last_reply is not None:
+ ht+= '<pre>'+cgi.escape(req.conn.last_reply)+'</pre>'
return ht + '</body></html>'
urlargs = {}
urlargs['url'] = url
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ba...@us...> - 2007-03-09 03:57:55
|
Revision: 446
http://svn.sourceforge.net/omc/?rev=446&view=rev
Author: bartw
Date: 2007-03-08 19:57:56 -0800 (Thu, 08 Mar 2007)
Log Message:
-----------
fixed typo
Modified Paths:
--------------
tools/trunk/yawn/yawn.py
Modified: tools/trunk/yawn/yawn.py
===================================================================
--- tools/trunk/yawn/yawn.py 2007-02-27 00:42:17 UTC (rev 445)
+++ tools/trunk/yawn/yawn.py 2007-03-09 03:57:56 UTC (rev 446)
@@ -1051,7 +1051,7 @@
paramVal = [_decodeObject(x) for x in paramVal]
else:
paramVal = [pywbem.tocimobj(dt, x) for x in paramVal]
- inParams[paramName] = paramVal
+ inParms[paramName] = paramVal
else:
if metaParm.reference_class is not None:
inParms[paramName] = _decodeObject(paramVal)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ba...@us...> - 2007-03-30 16:28:56
|
Revision: 450
http://svn.sourceforge.net/omc/?rev=450&view=rev
Author: bartw
Date: 2007-03-30 09:28:56 -0700 (Fri, 30 Mar 2007)
Log Message:
-----------
bug fix
Modified Paths:
--------------
tools/trunk/yawn/yawn.py
Modified: tools/trunk/yawn/yawn.py
===================================================================
--- tools/trunk/yawn/yawn.py 2007-03-28 00:31:08 UTC (rev 449)
+++ tools/trunk/yawn/yawn.py 2007-03-30 16:28:56 UTC (rev 450)
@@ -466,7 +466,7 @@
class_urlargs['ns'] = ns
class_urlargs['url'] = url
class_urlargs["className"] = instName.classname
- ht = _printHead('Filtered ReferenceNames Dialog... (Coming...)', urlargs=urlargs)
+ ht = _printHead('Filtered ReferenceNames Dialog... (Coming...)', urlargs=class_urlargs)
ht+= '<h1>Filtered References on Class '+_makeHref(req, 'GetClass', class_urlargs, instName.classname)+'</h1>'
req.write(ht)
_printInstanceNames(req, class_urlargs, [instName])
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ba...@us...> - 2007-04-17 20:50:43
|
Revision: 452
http://svn.sourceforge.net/omc/?rev=452&view=rev
Author: bartw
Date: 2007-04-17 13:50:09 -0700 (Tue, 17 Apr 2007)
Log Message:
-----------
fixing utcoffset problem
Modified Paths:
--------------
tools/trunk/yawn/yawn.py
Modified: tools/trunk/yawn/yawn.py
===================================================================
--- tools/trunk/yawn/yawn.py 2007-04-02 17:34:49 UTC (rev 451)
+++ tools/trunk/yawn/yawn.py 2007-04-17 20:50:09 UTC (rev 452)
@@ -73,11 +73,12 @@
while len(mss) < 6:
mss = '0' + mss
rval += '.'+mss
- uoff = x.utcoffset()
+ uoff = x.utcoffset()
if uoff is None:
uoff = '+000'
else:
# make it fit in three digits
+ uoff = uoff.days*24*60 + uoff.seconds/60
if uoff < -(60*12):
uoff = 24*60 + uoff
if uoff > (60*12):
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ba...@us...> - 2007-04-30 20:56:38
|
Revision: 455
http://svn.sourceforge.net/omc/?rev=455&view=rev
Author: bartw
Date: 2007-04-30 13:56:35 -0700 (Mon, 30 Apr 2007)
Log Message:
-----------
fixed missing param in a link
Modified Paths:
--------------
tools/trunk/yawn/yawn.py
Modified: tools/trunk/yawn/yawn.py
===================================================================
--- tools/trunk/yawn/yawn.py 2007-04-26 22:22:35 UTC (rev 454)
+++ tools/trunk/yawn/yawn.py 2007-04-30 20:56:35 UTC (rev 455)
@@ -222,7 +222,7 @@
') : ' + arg[1] + '</i>')
req.write( '</body></html>')
return;
- urlargs = {'ns':ns,'url':url}
+ urlargs = {'ns':ns,'url':url,'className':instName.classname}
req.write( _printHead('Deleted Instance of '+instName.classname,
urlargs=urlargs))
req.write('Deleted Instance of ' + _makeHref(req, 'GetClass',
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ba...@us...> - 2007-05-09 22:56:42
|
Revision: 456
http://svn.sourceforge.net/omc/?rev=456&view=rev
Author: bartw
Date: 2007-05-09 15:56:36 -0700 (Wed, 09 May 2007)
Log Message:
-----------
changed to match new datetime functionality in pywbem
Modified Paths:
--------------
tools/trunk/yawn/yawn.py
Modified: tools/trunk/yawn/yawn.py
===================================================================
--- tools/trunk/yawn/yawn.py 2007-04-30 20:56:35 UTC (rev 455)
+++ tools/trunk/yawn/yawn.py 2007-05-09 22:56:36 UTC (rev 456)
@@ -29,7 +29,7 @@
# @author Norm Paxton <np...@no...>
from mod_python import Cookie, apache
-from datetime import datetime, timedelta
+from datetime import timedelta
import pywbem
import cgi
import types
@@ -66,31 +66,9 @@
rval+= strItem
rval+= '}'
return cgi.escape(rval)
- elif type(x) == datetime:
- #http://windowssdk.msdn.microsoft.com/en-us/library/ms739696.aspx
- rval = x.strftime('%Y%m%d%H%M%S')
- mss = str(x.microsecond)
- while len(mss) < 6:
- mss = '0' + mss
- rval += '.'+mss
- uoff = x.utcoffset()
- if uoff is None:
- uoff = '+000'
- else:
- # make it fit in three digits
- uoff = uoff.days*24*60 + uoff.seconds/60
- if uoff < -(60*12):
- uoff = 24*60 + uoff
- if uoff > (60*12):
- uoff = uoff - 60*24
- neg = uoff < 0
- uoff = str(abs(uoff))
- while len(uoff) < 3:
- uoff = '0'+uoff
- uoff = neg and '-'+uoff or '+'+uoff
- return cgi.escape(rval + uoff)
elif type(x) == timedelta:
- #http://windowssdk.msdn.microsoft.com/en-us/library/ms744132.aspx
+ #http://msdn2.microsoft.com/en-us/library/aa387237.aspx
+ #http://msdn2.microsoft.com/en-us/library/aa390895.aspx
mss = str(x.microseconds)
while len(mss) < 6:
mss = '0' + mss
@@ -413,7 +391,8 @@
req.write('<hr><h2>Objects of Class: ' + assocInstPath.classname + '</h2>')
_printInstanceNames(req, urlargs, [assocInstPath])
elif assocCall=='References':
- refs = conn.References(instName, **params)#, properties)
+ refs = _ex(req,conn.References,ObjectName=instName,
+ **params)#, properties)
req.write('Showing ' + `len(refs)` + ' resulting object(s). <br><br>')
for ref in refs:
assocInstPath = ref.path
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ba...@us...> - 2007-05-12 00:26:13
|
Revision: 457
http://svn.sourceforge.net/omc/?rev=457&view=rev
Author: bartw
Date: 2007-05-11 17:26:15 -0700 (Fri, 11 May 2007)
Log Message:
-----------
Added ability to generate python provider stubs for CIM classes
Modified Paths:
--------------
tools/trunk/yawn/yawn.py
Modified: tools/trunk/yawn/yawn.py
===================================================================
--- tools/trunk/yawn/yawn.py 2007-05-09 22:56:36 UTC (rev 456)
+++ tools/trunk/yawn/yawn.py 2007-05-12 00:26:15 UTC (rev 457)
@@ -1273,7 +1273,8 @@
ht+= '<div align=center>View '+_makeHref(req, 'EnumInstanceNames', instUrlArgs, 'Instance Names')
ht+= ' or '+_makeHref(req, 'EnumInstances', instUrlArgs, 'Instances')
ht+= ' or '+_makeHref(req, 'AssociatedClasses', instUrlArgs, 'Associated Classes')
- ht+= ' of this class.</div>'
+ ht+= ' of this class. '+_makeHref(req,
+ 'ProviderTemplate', instUrlArgs, 'Provider Template')+'</div>'
ht+= '<table border="1" cellpadding="2">'
if klass.qualifiers.has_key('aggregation'):
titleBGColor = "green"
@@ -1657,6 +1658,7 @@
return '</table></body></html>'
##############################################################################
+##############################################################################
def AssociatedClasses(req, url, ns, className):
conn = _frontMatter(req, url, ns)
classNames = None
@@ -1903,6 +1905,314 @@
return ht
##############################################################################
+##############################################################################
+##############################################################################
+def _providerTemplate (cc):
+ #################
+ def format_desc (obj):
+ txt = ''
+ try:
+ raw = obj.qualifiers['description'].value
+ beg = 0
+ end = 0
+ while beg < len(raw):
+ beg = end
+ end += 65
+ while beg < len(raw) and raw[beg] in string.whitespace:
+ beg = beg+1
+ while end < len(raw) and end > beg \
+ and raw[end] not in string.whitespace:
+ end = end-1
+ line = raw[beg:end]
+ line = line.replace('\n',' ')
+ txt +='''
+ %s''' % line
+ except KeyError:
+ pass
+ return txt
+
+ #################
+ def type_str (obj):
+ tx = obj.type
+ if tx == 'reference':
+ tx = 'REF %s (CIMInstanceName)' % obj.reference_class
+ if obj.is_array:
+ tx += '[]'
+ return tx
+ #################
+ def is_required (obj):
+ try:
+ if obj.qualifiers['required'].value:
+ return '(Required)'
+ else:
+ return ''
+ except KeyError:
+ return ''
+ #################
+
+ mappings = {'classname':cc.classname,
+ }
+ isAssoc = 'association' in cc.qualifiers
+
+ code = '''"""Python Provider for %(classname)s
+
+Instruments the CIM class %(classname)s
+"""
+
+import pywbem
+
+class %(classname)sProvider:
+ """Instrument the CIM class %(classname)s
+''' % mappings
+ code+= format_desc(cc)
+ code+= '''
+ """
+
+ #########################################################################
+ def __init__ (self):
+ pass
+
+ #########################################################################
+ def get_instance (self, env, model, cim_class):
+ """Return an instance of %(classname)s
+
+ Keyword arguments:
+ env -- Provider Environment
+ model -- A template of the CIMInstance to be returned. The key
+ properties are set on this instance to correspond to the
+ instanceName that was requested. The properties of the model
+ are already filtered according to the PropertyList from the
+ request.
+ cim_class -- The CIMClass %(classname)s
+
+ """
+''' % mappings
+ keyProps = [p for p in cc.properties.values() \
+ if 'key' in p.qualifiers]
+ for prop in cc.properties.values():
+ if 'key' in prop.qualifiers:
+ continue
+ code+= '''
+ if '%(pname)s' in model.properties:
+ model['%(pname)s'] = # TODO (type = %(ptype)s) %(required)s''' \
+ % { 'pname': prop.name, 'ptype': type_str(prop),
+ 'required':is_required(prop) }
+
+ code+= '''
+ return model
+
+ #########################################################################
+ def enum_instances(self, env, model, cim_class, keys_only):
+ """ Enumerate instances of %(classname)s
+ The WBEM operations EnumerateInstances and EnumerateInstanceNames
+ are both mapped to this method.
+ This method is a python generator
+
+ Keyword arguments:
+ env -- Provider Environment
+ model -- A template of the CIMInstances to be generated. The
+ properties of the model are already filtered according to the
+ PropertyList from the request.
+ cim_class -- The CIMClass %(classname)s
+ keys_only -- A boolean. True if only the key properties should be
+ set on the generated instances.
+
+ """
+
+ while False: # TODO more instances?
+ # TODO fetch system resource
+ # Key properties''' % mappings
+ for kp in keyProps:
+ code+='''
+ model['%(pname)s'] = # TODO (type = %(ptype)s)''' \
+ % { 'pname':kp.name, 'ptype':type_str(kp) }
+ code+='''
+ if keys_only:
+ yield model
+ else:
+ try:
+ yield self.get_instance(env, model, cim_class)
+ except pywbem.CIMError, (num, msg):
+ if num in (pywbem.CIM_ERR_NOT_FOUND,
+ pywbem.CIM_ERR_ACCESS_DENIED):
+ pass # EnumerateInstances shouldn't return these
+ else:
+ raise
+'''
+
+ code+='''
+ #########################################################################
+ def set_instance(self, env, instance, previous_instance, cim_class):
+ """ Return a newly created or modified instance of %(classname)s
+
+ Keyword arguments:
+ env -- Provider Environment
+ instance -- The new CIMInstance. If modifying an existing instance,
+ the properties on this instance have been filtered by the
+ PropertyList from the request.
+ previous_instance -- The previous instance if modifying an existing
+ instance. None if creating a new instance.
+ cim_class -- The CIMClass %(classname)s
+
+ Return the new instance. The keys must be set on the new instance.
+
+ """
+
+ # TODO create or modify the instance
+ return instance
+
+ #########################################################################
+ def delete_instance(self, env, instance_name):
+ """ Delete an instance of %(classname)s
+
+ Keyword arguments:
+ env -- Provider Environment
+ instance_name -- A CIMInstanceName specifying the instance of
+ %(classname)s to delete.
+
+ """ ''' % mappings
+
+ for method in cc.methods.values():
+ inParms = [ p for p in method.parameters.values() if \
+ 'in' in p.qualifiers and p.qualifiers['in'].value ]
+ outParms = [ p for p in method.parameters.values() if \
+ 'out' in p.qualifiers and p.qualifiers['out'].value ]
+ code+= '''
+ #########################################################################
+ def cim_method_%s(self, env, object_name, method''' % method.name.lower()
+ for p in inParms:
+ code+= ''',
+ param_%s''' % p.name.lower()
+ code+= '''):
+ """Implements %s.%s()
+''' % (cc.classname, method.name)
+ code+= format_desc(method)
+
+ code+= '''
+ Keyword arguments:
+ env -- Provider Environment
+ object_name -- A CIMInstanceName or CIMCLassName specifying the
+ object on which the method %(mname)s should be invoked
+ method -- A CIMMethod representing the method meta-data'''
+
+ for p in inParms:
+ code+= '''
+ param_%s -- The input parameter %s (type %s) %s''' \
+ % (p.name.lower(), p.name, type_str(p), is_required(p))
+ code+= format_desc(p)
+
+ code+='''
+
+ Returns a two-tuple containing the return value (type %s)
+ and a dictionary with the out-parameters
+
+ Output parameters:''' %(method.return_type)
+
+ if not outParms:
+ code+= ' none'
+ else:
+ for p in outParms:
+ code+='''
+ %s -- (type %s) %s''' % (p.name, type_str(p), is_required(p))
+ code+= format_desc(p)
+
+
+ code+='''
+
+ """
+
+ # TODO do something
+ out_params = {}'''
+
+ for p in outParms:
+ code+='''
+ out_params['%s'] = # TODO (type %s)''' % (p.name.lower(), type_str(p))
+
+ code+='''
+ rval = # TODO (type %s)
+ return (rval, out_params)
+ ''' % method.return_type
+
+ if isAssoc:
+ code+= '''
+ #########################################################################
+ def references(self, env, object_name, model, assoc_class,
+ result_class_name, role, result_role):
+ """Instrument %(classname)s Associations.
+ All four association-related operations (Associators, AssociatorNames,
+ References, ReferenceNames) are mapped to this method.
+ This method is a python generator
+
+ Keyword arguments:
+ env -- Provider Environment
+ object_name -- A CIMInstanceName that defines the source CIM Object
+ whose associated Objects are to be returned.
+ model -- A template CIMInstance of %(classname)s to serve as a model
+ of the objects to be returned. Only properties present on this
+ model need to be returned.
+ assoc_class -- The CIMClass %(classname)s
+ result_class_name -- If not None, acts as a filter on the returned set
+ of Objects by mandating that each returned Object MUST be either
+ an Instance of this Class (or one of its subclasses) or be this
+ Class (or one of its subclasses).
+ role -- If not None, acts as a filter on the returned set of Objects
+ by mandating that each returned Object MUST be associated to the
+ source Object via an Association in which the source Object plays
+ the specified role (i.e. the name of the Property in the
+ Association Class that refers to the source Object MUST match
+ the value of this parameter).
+ result_role -- If not None, acts as a filter on the returned set of
+ Objects by mandating that each returned Object MUST be associated
+ to the source Object via an Association in which the returned
+ Object plays the specified role (i.e. the name of the Property in
+ the Association Class that refers to the returned Object MUST
+ match the value of this parameter).
+ """
+
+''' % mappings
+
+ code+= '''
+
+## end of class %(classname)sProvider
+
+_prov = %(classname)sProvider() # initialize provider
+py_providers = {'%(classname)s: _prov} # register provider
+''' % mappings
+
+ ptypes = ['1', 'Instance']
+ if isAssoc:
+ ptypes[0]+= ',3'
+ ptypes[1]+= ', Associator'
+ if cc.methods:
+ ptypes[0]+= ',6'
+ ptypes[1]+= ', Method'
+ code+='''
+"""// Provider registration MOF for %(classname)s
+instance of OpenWBEM_PyProviderRegistration
+{
+ InstanceID = "<org:product:unique_id>"; // TODO
+ NamespaceNames = {"root/cimv2"};
+ ClassName = "%(classname)s";
+ ProviderTypes = {%(ptypeNums)s}; // %(ptypeStrs)s
+ ModulePath = "/some/path/%(classname)sProvider.py";
+};
+"""
+''' % {'classname': cc.classname,
+ 'ptypeNums': ptypes[0],
+ 'ptypeStrs': ptypes[1]}
+
+ return code
+
+def ProviderTemplate(req, url, ns, className):
+ conn = _frontMatter(req, url, ns)
+ req.content_type = 'text/plain'
+ klass = _ex(req, conn.GetClass, ClassName = className, LocalOnly = "false",
+ IncludeClassOrigin = "true")
+ return _providerTemplate(klass)
+
+
+##############################################################################
+##############################################################################
# TODO
"""
- Make GetClass links on REF type fields for properties and parameters.
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ba...@us...> - 2007-05-13 02:12:48
|
Revision: 458
http://svn.sourceforge.net/omc/?rev=458&view=rev
Author: bartw
Date: 2007-05-12 19:12:50 -0700 (Sat, 12 May 2007)
Log Message:
-----------
provider codegen fixes
Modified Paths:
--------------
tools/trunk/yawn/yawn.py
Modified: tools/trunk/yawn/yawn.py
===================================================================
--- tools/trunk/yawn/yawn.py 2007-05-12 00:26:15 UTC (rev 457)
+++ tools/trunk/yawn/yawn.py 2007-05-13 02:12:50 UTC (rev 458)
@@ -1274,7 +1274,7 @@
ht+= ' or '+_makeHref(req, 'EnumInstances', instUrlArgs, 'Instances')
ht+= ' or '+_makeHref(req, 'AssociatedClasses', instUrlArgs, 'Associated Classes')
ht+= ' of this class. '+_makeHref(req,
- 'ProviderTemplate', instUrlArgs, 'Provider Template')+'</div>'
+ 'Provider', instUrlArgs, 'Python Provider')+'</div>'
ht+= '<table border="1" cellpadding="2">'
if klass.qualifiers.has_key('aggregation'):
titleBGColor = "green"
@@ -1769,7 +1769,7 @@
if heading is not None:
ht+= '<h1>'+heading+'</h1>'
ht+= '</td>'
- if urlargs and 'ns' in urlargs.keys() and 'url' in urlargs.keys():
+ if urlargs and 'ns' in urlargs and 'url' in urlargs:
lurlargs = {'ns':urlargs['ns'], 'url':urlargs['url']}
ht+= '<td valign=top nowrap align=right><font size=-1><i>'
ht+= _makeHref(req, 'EnumClassNames', lurlargs, lurlargs['ns'])
@@ -1951,7 +1951,7 @@
#################
mappings = {'classname':cc.classname,
- }
+ 'classname_l':cc.classname.lower()}
isAssoc = 'association' in cc.qualifiers
code = '''"""Python Provider for %(classname)s
@@ -2175,8 +2175,8 @@
## end of class %(classname)sProvider
-_prov = %(classname)sProvider() # initialize provider
-py_providers = {'%(classname)s: _prov} # register provider
+_%(classname_l)s_prov = %(classname)sProvider() # initialize provider
+py_providers = {'%(classname)s': _%(classname_l)s_prov} # register provider
''' % mappings
ptypes = ['1', 'Instance']
@@ -2186,29 +2186,38 @@
if cc.methods:
ptypes[0]+= ',6'
ptypes[1]+= ', Method'
- code+='''
-"""// Provider registration MOF for %(classname)s
+ mof ='''
+// Provider registration for %(classname)s
instance of OpenWBEM_PyProviderRegistration
{
InstanceID = "<org:product:unique_id>"; // TODO
NamespaceNames = {"root/cimv2"};
ClassName = "%(classname)s";
ProviderTypes = {%(ptypeNums)s}; // %(ptypeStrs)s
- ModulePath = "/some/path/%(classname)sProvider.py";
+ ModulePath = "/some/path/%(classname)sProvider.py"; // TODO
};
-"""
''' % {'classname': cc.classname,
'ptypeNums': ptypes[0],
'ptypeStrs': ptypes[1]}
- return code
+ return code, mof
-def ProviderTemplate(req, url, ns, className):
+def Provider(req, url, ns, className):
conn = _frontMatter(req, url, ns)
- req.content_type = 'text/plain'
klass = _ex(req, conn.GetClass, ClassName = className, LocalOnly = "false",
IncludeClassOrigin = "true")
- return _providerTemplate(klass)
+ code, mof = _providerTemplate(klass)
+ title = 'Python Provider for %s' % className
+ ht = _printHead(title, req)
+ ht+= '<font size=+1><b>%s</b></font>' % title
+ ht+= '<table bgcolor="#f9f9f9" cellspacing=0 cellpadding=10 border=1>'
+ ht+= '<tr><td><pre>'+code+'</pre>'
+ ht+= '</td></tr></table>'
+ ht+= '<font size=+1><b>Provider Registration MOF</b></font>'
+ ht+= '<table bgcolor="#f9f9f9" cellspacing=0 cellpadding=10 border=1>'
+ ht+= '<tr><td><pre>'+mof+'</pre>'
+ ht+= '</td></tr></table>'
+ return ht
##############################################################################
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ba...@us...> - 2007-05-14 16:41:32
|
Revision: 459
http://svn.sourceforge.net/omc/?rev=459&view=rev
Author: bartw
Date: 2007-05-14 09:41:32 -0700 (Mon, 14 May 2007)
Log Message:
-----------
need to escape the generated code
Modified Paths:
--------------
tools/trunk/yawn/yawn.py
Modified: tools/trunk/yawn/yawn.py
===================================================================
--- tools/trunk/yawn/yawn.py 2007-05-13 02:12:50 UTC (rev 458)
+++ tools/trunk/yawn/yawn.py 2007-05-14 16:41:32 UTC (rev 459)
@@ -2211,11 +2211,11 @@
ht = _printHead(title, req)
ht+= '<font size=+1><b>%s</b></font>' % title
ht+= '<table bgcolor="#f9f9f9" cellspacing=0 cellpadding=10 border=1>'
- ht+= '<tr><td><pre>'+code+'</pre>'
+ ht+= '<tr><td><pre>'+cgi.escape(code)+'</pre>'
ht+= '</td></tr></table>'
ht+= '<font size=+1><b>Provider Registration MOF</b></font>'
ht+= '<table bgcolor="#f9f9f9" cellspacing=0 cellpadding=10 border=1>'
- ht+= '<tr><td><pre>'+mof+'</pre>'
+ ht+= '<tr><td><pre>'+cgi.escape(mof)+'</pre>'
ht+= '</td></tr></table>'
return ht
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ba...@us...> - 2007-05-14 17:37:06
|
Revision: 460
http://svn.sourceforge.net/omc/?rev=460&view=rev
Author: bartw
Date: 2007-05-14 10:37:08 -0700 (Mon, 14 May 2007)
Log Message:
-----------
added link to namespace list
Modified Paths:
--------------
tools/trunk/yawn/yawn.py
Modified: tools/trunk/yawn/yawn.py
===================================================================
--- tools/trunk/yawn/yawn.py 2007-05-14 16:41:32 UTC (rev 459)
+++ tools/trunk/yawn/yawn.py 2007-05-14 17:37:08 UTC (rev 460)
@@ -1551,7 +1551,7 @@
classNames = _ex(req, conn.EnumerateClassNames,
DeepInheritance = mode=='flat')
- ht = _printHead('Classes in '+ns,'Classes in '+url+'/'+ns, req)
+ ht = _printHead('Classes in '+ns,'Classes in '+url+'/'+ns, req, {'url':url})
urlargs = {'ns': ns, 'url': url}
ecn_urlargs = urlargs.copy()
ecn_urlargs['mode'] = mode
@@ -1774,6 +1774,11 @@
ht+= '<td valign=top nowrap align=right><font size=-1><i>'
ht+= _makeHref(req, 'EnumClassNames', lurlargs, lurlargs['ns'])
ht+= ' </i></td>'
+ if urlargs and 'url' in urlargs:
+ ht+= '<td valign=top nowrap align=right><font size=-1><i>'
+ ht+= _makeHref(req, 'EnumNamespaces', {'url':urlargs['url']},
+ 'Namespaces')
+ ht+= ' </i></td>'
ht+= '<td valign=top nowrap align=right><font size=-1><i>'
ht+= '<a href="'+_baseScript(req)+'/Logout">Logout >></a></i>'
ht+= '</td></tr></table>'
@@ -1798,15 +1803,8 @@
return __file__[drlen:-3]
##############################################################################
-def Login(req, scheme, host, port, ns):
- url = scheme + '://'+host
- if not ((scheme == 'https' and port == '5989') or (scheme == 'http' and port == '5988')):
- url += ':'+port
- if ns:
- EnumClassNames(req, url, ns)
- return ' '
-
- conn = _frontMatter(req, url, ns)
+def EnumNamespaces(req, url):
+ conn = _frontMatter(req, url, '')
nsinsts = []
try:
for nsclass in ['CIM_Namespace', '__Namespace']:
@@ -1860,6 +1858,17 @@
return ht + '</body></html>'
##############################################################################
+def Login(req, scheme, host, port, ns):
+ url = scheme + '://'+host
+ if not ((scheme == 'https' and port == '5989') or (scheme == 'http' and port == '5988')):
+ url += ':'+port
+ if ns:
+ return EnumClassNames(req, url, ns)
+ return EnumNamespaces(req, url)
+
+
+
+##############################################################################
def Logout(req):
req.add_common_vars()
req.content_type = "Text/HTML"
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ba...@us...> - 2007-05-15 16:13:25
|
Revision: 461
http://svn.sourceforge.net/omc/?rev=461&view=rev
Author: bartw
Date: 2007-05-15 09:13:24 -0700 (Tue, 15 May 2007)
Log Message:
-----------
bug fixes in bool handling
Modified Paths:
--------------
tools/trunk/yawn/yawn.py
Modified: tools/trunk/yawn/yawn.py
===================================================================
--- tools/trunk/yawn/yawn.py 2007-05-14 17:37:08 UTC (rev 460)
+++ tools/trunk/yawn/yawn.py 2007-05-15 16:13:24 UTC (rev 461)
@@ -57,8 +57,9 @@
elif isinstance(x,list):
rval = '{'
if x:
- for item in x:
- if item is not x[0]:
+ for i in range(0, len(x)):
+ item = x[i]
+ if i > 0:
rval+= ', '
strItem = _val2str(item)
if type(item) in types.StringTypes:
@@ -908,8 +909,8 @@
else:
if oldVal is not None and propIsKey:
ht+= _val2str(oldVal)
- elif prop.type == 'boolean':
- ht+= '<select name="'+fPropName+'"'
+ elif prop.type == 'boolean' and not prop.is_array:
+ ht+= '<select name="'+fPropName+'">'
ht+= '<option value='""'>'
ht+= '<option value="True"'
if oldVal is not None and oldVal:
@@ -1186,7 +1187,7 @@
ht+= '</select>'
elif param.type == 'boolean':
- ht+= '<select name="'+parmName+'"'
+ ht+= '<select name="'+parmName+'">'
ht+= '<option value='""'>'
ht+= '<option value="True">True'
ht+= '<option value="False">False'
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ba...@us...> - 2007-05-16 20:26:41
|
Revision: 462
http://svn.sourceforge.net/omc/?rev=462&view=rev
Author: bartw
Date: 2007-05-16 13:26:31 -0700 (Wed, 16 May 2007)
Log Message:
-----------
changed formatting of errors. makes stack traces from python providers look pretty
Modified Paths:
--------------
tools/trunk/yawn/yawn.py
Modified: tools/trunk/yawn/yawn.py
===================================================================
--- tools/trunk/yawn/yawn.py 2007-05-15 16:13:24 UTC (rev 461)
+++ tools/trunk/yawn/yawn.py 2007-05-16 20:26:31 UTC (rev 462)
@@ -1245,7 +1245,8 @@
except pywbem.CIMError, arg:
ht = _printHead('Error')
details = _code2string(arg[0])
- ht+= '<p><i>'+details[0]+': '+details[1]+': '+cgi.escape(arg[1])+'</i>'
+ ht+= '<p><i>'+details[0]+': ' + details[1]+'</i>'
+ ht+= '<pre>'+cgi.escape(arg[1])+'</pre>'
ht+= '<hr>'
if req.conn.debug:
if req.conn.last_request is not None:
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ba...@us...> - 2007-05-22 15:26:08
|
Revision: 466
http://svn.sourceforge.net/omc/?rev=466&view=rev
Author: bartw
Date: 2007-05-22 08:26:08 -0700 (Tue, 22 May 2007)
Log Message:
-----------
changed codegen a bit
Modified Paths:
--------------
tools/trunk/yawn/yawn.py
Modified: tools/trunk/yawn/yawn.py
===================================================================
--- tools/trunk/yawn/yawn.py 2007-05-21 22:53:49 UTC (rev 465)
+++ tools/trunk/yawn/yawn.py 2007-05-22 15:26:08 UTC (rev 466)
@@ -1237,6 +1237,33 @@
return '</body></html>'
##############################################################################
+def PrepMofComp(req, url):
+ conn = _frontMatter(req, url, 'root/cimv2')
+ ht = _printHead("MOF", "MOF", req, {'url':url})
+ ht+= '<form action="'+_baseScript(req)+'/MofComp" '
+ ht+= 'enctype="multipart/form-data" METHOD=POST>'
+ ht+= '<input type=hidden name="url" value="'+url+'"/>'
+ ht+= '<input type=hidden name="ns" value="'+'root/cimv2'+'"/>'
+ ht+= '<input id="file" name="file" size="70" type="file" />'
+ ht+= '<p><textarea cols="80" id="text" name="text" rows="40">'
+ ht+= '</textarea>'
+ ht+= '<p><input name="commit" type="submit" value="Submit" />'
+ ht+= '</form>'
+ return ht + '</body></html>'
+
+##############################################################################
+def MofComp(req, url, ns, file, text):
+ conn = _frontMatter(req, url, 'root/cimv2')
+ ht = _printHead("MOF", "MOF", req, {'url':url})
+ ht+= "file:<pre>"
+ ht+= cgi.escape(file.value)
+ ht+= '</pre>'
+ ht+= 'text:<pre>'
+ ht+= cgi.escape(text)
+ ht+= '</pre>'
+ return ht + '</body></html>'
+
+##############################################################################
def _ex(req, method, **params):
try:
return method(**params)
@@ -1971,8 +1998,9 @@
"""
import pywbem
+from cimprovider import CIMProvider
-class %(classname)sProvider:
+class %(classname)sProvider(CIMProvider):
"""Instrument the CIM class %(classname)s
''' % mappings
code+= format_desc(cc)
@@ -2044,10 +2072,8 @@
try:
yield self.get_instance(env, model, cim_class)
except pywbem.CIMError, (num, msg):
- if num in (pywbem.CIM_ERR_NOT_FOUND,
- pywbem.CIM_ERR_ACCESS_DENIED):
- pass # EnumerateInstances shouldn't return these
- else:
+ if num not in (pywbem.CIM_ERR_NOT_FOUND,
+ pywbem.CIM_ERR_ACCESS_DENIED):
raise
'''
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ba...@us...> - 2007-05-23 05:03:32
|
Revision: 467
http://svn.sourceforge.net/omc/?rev=467&view=rev
Author: bartw
Date: 2007-05-22 22:03:33 -0700 (Tue, 22 May 2007)
Log Message:
-----------
moved python provider generator to cimprovider
Modified Paths:
--------------
tools/trunk/yawn/yawn.py
Modified: tools/trunk/yawn/yawn.py
===================================================================
--- tools/trunk/yawn/yawn.py 2007-05-22 15:26:08 UTC (rev 466)
+++ tools/trunk/yawn/yawn.py 2007-05-23 05:03:33 UTC (rev 467)
@@ -1302,8 +1302,15 @@
ht+= '<div align=center>View '+_makeHref(req, 'EnumInstanceNames', instUrlArgs, 'Instance Names')
ht+= ' or '+_makeHref(req, 'EnumInstances', instUrlArgs, 'Instances')
ht+= ' or '+_makeHref(req, 'AssociatedClasses', instUrlArgs, 'Associated Classes')
- ht+= ' of this class. '+_makeHref(req,
- 'Provider', instUrlArgs, 'Python Provider')+'</div>'
+ ht+= ' of this class.'
+ try:
+ # see if code generator is available
+ from cimprovider import provider_template
+ ht+= ' '+ _makeHref(req,
+ 'Provider', instUrlArgs, 'Python Provider')
+ except ImportError:
+ pass
+ ht+= '</div>'
ht+= '<table border="1" cellpadding="2">'
if klass.qualifiers.has_key('aggregation'):
titleBGColor = "green"
@@ -1945,305 +1952,13 @@
##############################################################################
##############################################################################
##############################################################################
-def _providerTemplate (cc):
- #################
- def format_desc (obj):
- txt = ''
- try:
- raw = obj.qualifiers['description'].value
- beg = 0
- end = 0
- while beg < len(raw):
- beg = end
- end += 65
- while beg < len(raw) and raw[beg] in string.whitespace:
- beg = beg+1
- while end < len(raw) and end > beg \
- and raw[end] not in string.whitespace:
- end = end-1
- line = raw[beg:end]
- line = line.replace('\n',' ')
- txt +='''
- %s''' % line
- except KeyError:
- pass
- return txt
- #################
- def type_str (obj):
- tx = obj.type
- if tx == 'reference':
- tx = 'REF %s (CIMInstanceName)' % obj.reference_class
- if obj.is_array:
- tx += '[]'
- return tx
- #################
- def is_required (obj):
- try:
- if obj.qualifiers['required'].value:
- return '(Required)'
- else:
- return ''
- except KeyError:
- return ''
- #################
-
- mappings = {'classname':cc.classname,
- 'classname_l':cc.classname.lower()}
- isAssoc = 'association' in cc.qualifiers
-
- code = '''"""Python Provider for %(classname)s
-
-Instruments the CIM class %(classname)s
-"""
-
-import pywbem
-from cimprovider import CIMProvider
-
-class %(classname)sProvider(CIMProvider):
- """Instrument the CIM class %(classname)s
-''' % mappings
- code+= format_desc(cc)
- code+= '''
- """
-
- #########################################################################
- def __init__ (self):
- pass
-
- #########################################################################
- def get_instance (self, env, model, cim_class):
- """Return an instance of %(classname)s
-
- Keyword arguments:
- env -- Provider Environment
- model -- A template of the CIMInstance to be returned. The key
- properties are set on this instance to correspond to the
- instanceName that was requested. The properties of the model
- are already filtered according to the PropertyList from the
- request.
- cim_class -- The CIMClass %(classname)s
-
- """
-''' % mappings
- keyProps = [p for p in cc.properties.values() \
- if 'key' in p.qualifiers]
- for prop in cc.properties.values():
- if 'key' in prop.qualifiers:
- continue
- code+= '''
- if '%(pname)s' in model.properties:
- model['%(pname)s'] = # TODO (type = %(ptype)s) %(required)s''' \
- % { 'pname': prop.name, 'ptype': type_str(prop),
- 'required':is_required(prop) }
-
- code+= '''
- return model
-
- #########################################################################
- def enum_instances(self, env, model, cim_class, keys_only):
- """ Enumerate instances of %(classname)s
- The WBEM operations EnumerateInstances and EnumerateInstanceNames
- are both mapped to this method.
- This method is a python generator
-
- Keyword arguments:
- env -- Provider Environment
- model -- A template of the CIMInstances to be generated. The
- properties of the model are already filtered according to the
- PropertyList from the request.
- cim_class -- The CIMClass %(classname)s
- keys_only -- A boolean. True if only the key properties should be
- set on the generated instances.
-
- """
-
- while False: # TODO more instances?
- # TODO fetch system resource
- # Key properties''' % mappings
- for kp in keyProps:
- code+='''
- model['%(pname)s'] = # TODO (type = %(ptype)s)''' \
- % { 'pname':kp.name, 'ptype':type_str(kp) }
- code+='''
- if keys_only:
- yield model
- else:
- try:
- yield self.get_instance(env, model, cim_class)
- except pywbem.CIMError, (num, msg):
- if num not in (pywbem.CIM_ERR_NOT_FOUND,
- pywbem.CIM_ERR_ACCESS_DENIED):
- raise
-'''
-
- code+='''
- #########################################################################
- def set_instance(self, env, instance, previous_instance, cim_class):
- """ Return a newly created or modified instance of %(classname)s
-
- Keyword arguments:
- env -- Provider Environment
- instance -- The new CIMInstance. If modifying an existing instance,
- the properties on this instance have been filtered by the
- PropertyList from the request.
- previous_instance -- The previous instance if modifying an existing
- instance. None if creating a new instance.
- cim_class -- The CIMClass %(classname)s
-
- Return the new instance. The keys must be set on the new instance.
-
- """
-
- # TODO create or modify the instance
- return instance
-
- #########################################################################
- def delete_instance(self, env, instance_name):
- """ Delete an instance of %(classname)s
-
- Keyword arguments:
- env -- Provider Environment
- instance_name -- A CIMInstanceName specifying the instance of
- %(classname)s to delete.
-
- """ ''' % mappings
-
- for method in cc.methods.values():
- inParms = [ p for p in method.parameters.values() if \
- 'in' in p.qualifiers and p.qualifiers['in'].value ]
- outParms = [ p for p in method.parameters.values() if \
- 'out' in p.qualifiers and p.qualifiers['out'].value ]
- code+= '''
- #########################################################################
- def cim_method_%s(self, env, object_name, method''' % method.name.lower()
- for p in inParms:
- code+= ''',
- param_%s''' % p.name.lower()
- code+= '''):
- """Implements %s.%s()
-''' % (cc.classname, method.name)
- code+= format_desc(method)
-
- code+= '''
- Keyword arguments:
- env -- Provider Environment
- object_name -- A CIMInstanceName or CIMCLassName specifying the
- object on which the method %(mname)s should be invoked
- method -- A CIMMethod representing the method meta-data'''
-
- for p in inParms:
- code+= '''
- param_%s -- The input parameter %s (type %s) %s''' \
- % (p.name.lower(), p.name, type_str(p), is_required(p))
- code+= format_desc(p)
-
- code+='''
-
- Returns a two-tuple containing the return value (type %s)
- and a dictionary with the out-parameters
-
- Output parameters:''' %(method.return_type)
-
- if not outParms:
- code+= ' none'
- else:
- for p in outParms:
- code+='''
- %s -- (type %s) %s''' % (p.name, type_str(p), is_required(p))
- code+= format_desc(p)
-
-
- code+='''
-
- """
-
- # TODO do something
- out_params = {}'''
-
- for p in outParms:
- code+='''
- out_params['%s'] = # TODO (type %s)''' % (p.name.lower(), type_str(p))
-
- code+='''
- rval = # TODO (type %s)
- return (rval, out_params)
- ''' % method.return_type
-
- if isAssoc:
- code+= '''
- #########################################################################
- def references(self, env, object_name, model, assoc_class,
- result_class_name, role, result_role):
- """Instrument %(classname)s Associations.
- All four association-related operations (Associators, AssociatorNames,
- References, ReferenceNames) are mapped to this method.
- This method is a python generator
-
- Keyword arguments:
- env -- Provider Environment
- object_name -- A CIMInstanceName that defines the source CIM Object
- whose associated Objects are to be returned.
- model -- A template CIMInstance of %(classname)s to serve as a model
- of the objects to be returned. Only properties present on this
- model need to be returned.
- assoc_class -- The CIMClass %(classname)s
- result_class_name -- If not None, acts as a filter on the returned set
- of Objects by mandating that each returned Object MUST be either
- an Instance of this Class (or one of its subclasses) or be this
- Class (or one of its subclasses).
- role -- If not None, acts as a filter on the returned set of Objects
- by mandating that each returned Object MUST be associated to the
- source Object via an Association in which the source Object plays
- the specified role (i.e. the name of the Property in the
- Association Class that refers to the source Object MUST match
- the value of this parameter).
- result_role -- If not None, acts as a filter on the returned set of
- Objects by mandating that each returned Object MUST be associated
- to the source Object via an Association in which the returned
- Object plays the specified role (i.e. the name of the Property in
- the Association Class that refers to the returned Object MUST
- match the value of this parameter).
- """
-
-''' % mappings
-
- code+= '''
-
-## end of class %(classname)sProvider
-
-_%(classname_l)s_prov = %(classname)sProvider() # initialize provider
-py_providers = {'%(classname)s': _%(classname_l)s_prov} # register provider
-''' % mappings
-
- ptypes = ['1', 'Instance']
- if isAssoc:
- ptypes[0]+= ',3'
- ptypes[1]+= ', Associator'
- if cc.methods:
- ptypes[0]+= ',6'
- ptypes[1]+= ', Method'
- mof ='''
-// Provider registration for %(classname)s
-instance of OpenWBEM_PyProviderRegistration
-{
- InstanceID = "<org:product:unique_id>"; // TODO
- NamespaceNames = {"root/cimv2"};
- ClassName = "%(classname)s";
- ProviderTypes = {%(ptypeNums)s}; // %(ptypeStrs)s
- ModulePath = "/some/path/%(classname)sProvider.py"; // TODO
-};
-''' % {'classname': cc.classname,
- 'ptypeNums': ptypes[0],
- 'ptypeStrs': ptypes[1]}
-
- return code, mof
-
def Provider(req, url, ns, className):
conn = _frontMatter(req, url, ns)
klass = _ex(req, conn.GetClass, ClassName = className, LocalOnly = "false",
IncludeClassOrigin = "true")
- code, mof = _providerTemplate(klass)
+ from cimprovider import provider_template
+ code, mof = provider_template(klass)
title = 'Python Provider for %s' % className
ht = _printHead(title, req)
ht+= '<font size=+1><b>%s</b></font>' % title
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ba...@us...> - 2007-05-24 17:41:43
|
Revision: 468
http://svn.sourceforge.net/omc/?rev=468&view=rev
Author: bartw
Date: 2007-05-24 10:41:45 -0700 (Thu, 24 May 2007)
Log Message:
-----------
fix display of null and array params in InvokeMethod
Modified Paths:
--------------
tools/trunk/yawn/yawn.py
Modified: tools/trunk/yawn/yawn.py
===================================================================
--- tools/trunk/yawn/yawn.py 2007-05-23 05:03:33 UTC (rev 467)
+++ tools/trunk/yawn/yawn.py 2007-05-24 17:41:45 UTC (rev 468)
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
#**************************************************************************
#|
#| Copyright (c) 2006 Novell, Inc.
@@ -334,7 +334,8 @@
return '</body></html>'
##############################################################################
-def FilteredReferenceNames(req, url, ns, instPath, assocClass, resultClass, role, resultRole, assocCall, properties):
+def FilteredReferenceNames(req, url, ns, instPath, assocClass, resultClass,
+ role, resultRole, assocCall, properties):
conn = _frontMatter(req, url, ns)
urlargs = {}
urlargs['ns'] = ns
@@ -1000,6 +1001,18 @@
cimmethod = klass.methods[method]
inParms = {}
+
+ def type_str (meta_parm):
+ if meta_parm.reference_class is not None:
+ urlargs['className'] = metaParm.reference_class
+ dt = 'REF ' + _makeHref(req, 'GetClass', urlargs,
+ metaParm.reference_class)
+ else:
+ dt = metaParm.type
+ if metaParm.is_array:
+ dt+= '[]'
+ return dt
+
if params:
# Remove 'MethParm.' prefix from param names.
params = dict ([(x[9:],y) for (x, y) in params.items()])
@@ -1008,10 +1021,7 @@
ht+= ' <tr bgcolor="#CCCCCC"><th>Data Type</th><th>Param Name</th><th>Value</th></tr>'
for paramName, paramVal in params.items():
metaParm = cimmethod.parameters[paramName]
- if metaParm.reference_class is not None:
- dt = metaParm.reference_class
- else:
- dt = metaParm.type
+ dt = type_str(metaParm)
ht+= ' <tr><td>'+dt+'</td>'
ht+= ' <td>'+paramName+'</td>'
ht+= ' <td>'+_val2str(paramVal)+'</td></tr>'
@@ -1048,14 +1058,8 @@
ht+= '<th>Data Type</th><th>Param Name</th><th>Value</th></tr>'
for parmName, parm in outParms.items():
metaParm = cimmethod.parameters[parmName]
- isRef = False
- if metaParm.reference_class is not None:
- isRef = True
- urlargs['className'] = metaParm.reference_class
- dt = _makeHref(req, 'GetClass', urlargs,
- metaParm.reference_class)
- else:
- dt = metaParm.type
+ isRef = metaParm.reference_class is not None
+ dt = type_str(metaParm)
ht+= '<tr><td>'+dt+'</td><td>'+metaParm.name+'</td><td>'
if metaParm.qualifiers.has_key('values') and metaParm.qualifiers.has_key('valuemap'):
display = str(parm)
@@ -1067,7 +1071,7 @@
display = display + ' ('+valuesQual[valIdx]+')'
ht+= display
else:
- if isRef:
+ if isRef and parm is not None:
ht+= _makeGetInstLink(req, urlargs, parm, _val2str(parm))
else:
ht+= _val2str(parm)
@@ -1305,7 +1309,7 @@
ht+= ' of this class.'
try:
# see if code generator is available
- from cimprovider import provider_template
+ from cimprovider import codegen
ht+= ' '+ _makeHref(req,
'Provider', instUrlArgs, 'Python Provider')
except ImportError:
@@ -1957,8 +1961,8 @@
conn = _frontMatter(req, url, ns)
klass = _ex(req, conn.GetClass, ClassName = className, LocalOnly = "false",
IncludeClassOrigin = "true")
- from cimprovider import provider_template
- code, mof = provider_template(klass)
+ from cimprovider import codegen
+ code, mof = codegen(klass)
title = 'Python Provider for %s' % className
ht = _printHead(title, req)
ht+= '<font size=+1><b>%s</b></font>' % title
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ba...@us...> - 2007-06-04 02:08:16
|
Revision: 469
http://svn.sourceforge.net/omc/?rev=469&view=rev
Author: bartw
Date: 2007-06-03 19:08:18 -0700 (Sun, 03 Jun 2007)
Log Message:
-----------
renamed cimprovider -> pycim
Modified Paths:
--------------
tools/trunk/yawn/yawn.py
Modified: tools/trunk/yawn/yawn.py
===================================================================
--- tools/trunk/yawn/yawn.py 2007-05-24 17:41:45 UTC (rev 468)
+++ tools/trunk/yawn/yawn.py 2007-06-04 02:08:18 UTC (rev 469)
@@ -1309,7 +1309,7 @@
ht+= ' of this class.'
try:
# see if code generator is available
- from cimprovider import codegen
+ from pycim import codegen
ht+= ' '+ _makeHref(req,
'Provider', instUrlArgs, 'Python Provider')
except ImportError:
@@ -1961,7 +1961,7 @@
conn = _frontMatter(req, url, ns)
klass = _ex(req, conn.GetClass, ClassName = className, LocalOnly = "false",
IncludeClassOrigin = "true")
- from cimprovider import codegen
+ from pycim import codegen
code, mof = codegen(klass)
title = 'Python Provider for %s' % className
ht = _printHead(title, req)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|