"""Parse override definitions file.
It is possible to override methods definitions in classes.
+
+ It returns a tuple
+ (code, overriden_methods, docstring)
"""
- res={}
+ code={}
data=[]
current=None
if m:
# Dump old data
if current is not None:
- res[current]="\n".join(data)
+ code[current]="".join(data)
current=m.group(1)
data=[]
continue
data.append(l)
- res[current]="\n".join(data)
+ code[current]="".join(data)
f.close()
- return res
+
+ docstring={}
+ for k, v in code.iteritems():
+ if v.lstrip().startswith('"""'):
+ # Starting comment. Use it as docstring.
+ dummy, docstring[k], code[k]=v.split('"""', 2)
+
+ # Not robust wrt. internal methods, but this works for the moment.
+ overridden_methods=dict( (k, re.findall('^\s+def\s+(\w+)', v, re.MULTILINE)) for (k, v) in code.iteritems() )
+
+ return code, overridden_methods, docstring
def fix_python_comment(c):
"""Fix comment by removing first and last parameters (self and exception)
),
key=operator.itemgetter(0))
- overrides=parse_override('override.py')
+ overrides, overriden_methods, docstring=parse_override('override.py')
for classname, el in itertools.groupby(elements, key=operator.itemgetter(0)):
+ print """class %(name)s(object):""" % {'name': classname}
+ if classname in docstring:
+ print ' """%s\n """' % docstring[classname]
+
print """
-class %(name)s(object):
def __new__(cls, pointer=None):
'''Internal method used for instanciating wrappers from ctypes.
'''
# Strip prefix
name=method.replace(prefix, '').replace('libvlc_', '')
ret.add(method)
+ if name in overriden_methods.get(cl, []):
+ # Method already defined in override.py
+ continue
+
if params:
params[0]=(params[0][0], 'self')
if params and params[-1][0] in ('libvlc_exception_t*', 'mediacontrol_Exception*'):
args=", ".join( p[1] for p in params )
print " def %s(%s):" % (name, args)
- print ' """%s\n"""' % fix_python_comment(comment)
+ print ' """%s\n """' % fix_python_comment(comment)
if params and params[-1][0] == 'libvlc_exception_t*':
# Exception handling
print " e=VLCException()"