Commit dc0b86e9 authored by Sven Brauch's avatar Sven Brauch

(incomplete) attempt to support more Qt/KDE modules

parent 031badc3
This diff is collapsed.
This diff is collapsed.
python2.7 sip_to_xml.py QtGui QtCore
python2.7 xml_to_py.py QtGui.xml QtCore.xml
cp QtCore.py QtGui.py ../../documentation_files/PyQt4/
pyqt=($(ls /usr/share/sip/PyQt4))
element_count=${#pyqt[@]}
for index in $(seq $element_count); do
python2.7 sip_to_xml.py ${pyqt[$index]}
python2.7 xml_to_py.py ${pyqt[$index]}.xml
cp ${pyqt[$index]}.py ../../documentation_files/PyQt4/
done
mkdir -p ../../documentation_files/PyKDE4
pykde=($(ls /usr/share/sip/python2-PyKDE4))
element_count=${#pykde[@]}
for index in $(seq $element_count); do
python2.7 sip_to_xml.py python2-PyKDE4/${pykde[$index]}
python2.7 xml_to_py.py ${pykde[$index]}.xml
cp ${pykde[$index]}.py ../../documentation_files/PyKDE4/
done
\ No newline at end of file
......@@ -11,18 +11,31 @@ from PyQt4 import pyqtconfig
config = pyqtconfig.Configuration() # Get the PyQt configuration information.
def convertSipToXML(inFilePath, outFilePath):
command = [config.sip_bin, '-m', outFilePath, '-I', config.pyqt_sip_dir]
command.extend(config.pyqt_sip_flags.split())
command.append(inFilePath)
print '\nConverting sip to xml:\n%s' % ' '.join(command)
try:
print subprocess.check_output(command, stderr = subprocess.STDOUT)
except subprocess.CalledProcessError as e:
print 'There was an error when running the command:'
print e.output
print 'Opening and parsing XML document...'
if not os.path.exists(outFilePath):
command = [config.sip_bin, '-m', outFilePath, '-I', config.pyqt_sip_dir, '-I', config.pyqt_sip_dir+'/python2-PyKDE4']
command.extend(config.pyqt_sip_flags.split())
command.append(inFilePath)
print '\nConverting sip to xml:\n%s' % ' '.join(command)
try:
print subprocess.check_output(command, stderr = subprocess.STDOUT)
except subprocess.CalledProcessError as e:
print 'There was an error when running the command:'
print e.output
print 'Opening and parsing XML document...'
# replace the invalid "&"s which are used by pykde to indicate shortcuts
# they would need to be escaped, but oh well
f = open(outFilePath, 'r')
data = f.read()
f.close()
data = data.replace('&', '')
data = data.replace('("', '')
data = data.replace('")', '')
data = data.replace('""', '"')
f = open(outFilePath, 'w')
f.write(data)
f.close()
xmlDoc = minidom.parse(outFilePath)
module = xmlDoc.firstChild
......@@ -54,7 +67,8 @@ def convertSipToXML(inFilePath, outFilePath):
if dotsCount == 1:
childClasses[name] = node
else:
raise Exception('More than 2 dots in name of a class: %s' % name)
print Exception('More than 2 dots in name of a class: %s' % name)
continue
print 'Reparenting classes...'
for name, node in childClasses.iteritems():
......@@ -76,9 +90,9 @@ if not os.path.isdir(sipDir):
modules = sys.argv[1:] # ['QtGui.xml', 'QtCore.xml'] # files to convert
for moduleName in modules:
sipFilePath = os.path.join(sipDir, moduleName, moduleName + 'mod.sip')
sipFilePath = os.path.join(sipDir, moduleName, moduleName.split('/')[-1] + 'mod.sip')
xmlFilePath = moduleName + '.xml'
if os.path.isfile(sipFilePath):
convertSipToXML(sipFilePath, xmlFilePath)
if os.path.isfile(sipFilePath) or os.path.exists(xmlFilePath.split('/')[-1]):
convertSipToXML(sipFilePath, xmlFilePath.split('/')[-1])
else:
print 'Input sip file does not exist: %s' % sipFilePath
......@@ -79,7 +79,7 @@ def parseFunction(functionNode):
# function parameters in function defintion
paramsStr = ['self'] if functionNode.parentNode.nodeName == 'Class' else [] # add `self` first parameter for methods
namesUsed = set(['self', 'exec', 'print', 'from', 'in', 'def', 'if', 'for', 'while', 'return']) # reserved words which cannot be used as argument names
namesUsed = set(['self', 'exec', 'print', 'from', 'in', 'def', 'if', 'for', 'while', 'return', 'raise']) # reserved words which cannot be used as argument names
hadDefault = False # there has been a default argument previously
for _, argName, defaultValue in params:
while argName in namesUsed: # some function arguments have same names...
......@@ -89,7 +89,7 @@ def parseFunction(functionNode):
if defaultValue is NoDefaultValue and not hadDefault:
paramsStr.append(argName)
else:
if defaultValue is NoDefaultValue:
if defaultValue is NoDefaultValue or not defaultValue.replace('(','').replace(')','').isalnum():
defaultValue = "None"
paramsStr.append('{} = {}'.format(argName, defaultValue))
hadDefault = True
......
[Containments][1]
activity=kdev-python
activityId=
desktop=-1
formfactor=0
geometry=0,0,1146,766
immutability=1
lastDesktop=-1
lastScreen=0
location=0
plugin=newspaper
screen=0
wallpaperplugin=color
wallpaperpluginmode=
zvalue=0
[Containments][1][Applets][2]
immutability=1
plugin=plasma_kdev_projectfileelement
[Containments][1][Applets][2][Configuration]
Share=false
relativePath=DESIGN
[Containments][1][Applets][2][LayoutInformation]
Column=0
Order=0
[Containments][1][Configuration]
ActionPluginsSource=Global
activity=kdev-python
activityId=
desktop=-1
formfactor=0
geometry=0,0,1146,766
immutability=1
lastDesktop=-1
lastScreen=0
location=0
orientation=2
plugin=newspaper
screen=0
wallpaperplugin=color
wallpaperpluginmode=
zvalue=0
[Containments][1][Configuration][Applets][2]
geometry=7.58219147723574e-316,6.9533518363725e-310,284,235.5
immutability=1
plugin=plasma_kdev_projectfileelement
zvalue=16
[Containments][1][Configuration][Applets][2][Configuration]
Share=false
relativePath=DESIGN
[Containments][1][Configuration][Wallpaper][color]
backgroundMode=0
color1=255,255,255
color2=0,0,0
[Containments][1][Wallpaper][color]
backgroundMode=0
color1=255,255,255
color2=0,0,0
[Project]
Manager=KDevCMakeManager
Name=kdev-python
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment