~ubuntu-branches/ubuntu/raring/pybik/raring

« back to all changes in this revision

Viewing changes to tools/create-gl-pxd.py

  • Committer: Package Import Robot
  • Author(s): B. Clausius
  • Date: 2013-02-03 17:35:32 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20130203173532-a71ulf5b07fcul37
Tags: 1.0.1-1
* New upstream release
  + Improved user interface.
  + Added Towers and Bricks (non cubic puzzles).
  + Added an option to show the back faces.
  + The cube can be manipulated with the keyboard.
  + Animation is faster and rendering more beautiful.
  + Added more pretty patterns.
  + Added a new solver.
  + Added new translations.
* More generic watch file based on the proposal by Bart Martens
* Updated debhelper dependency and compat to 9
* Updated Standards-Version to 3.9.4, no changes needed
* debian/copyright:
  + Updated Format URL for final copyright format 1.0
  + Added paragraphs for image files
* Updated Build-Depends: new: python-numpy, python-qt4, help2man
* Updated Depends for transitions:
  + GTK2/GConf -> Qt4 (PySide or PyQt4)
  + GtkGlExt -> QtOpenGL (PySide or PyQt4)
* Suggests python-opengl (unusual usage) and gconf2 (config transition)
* Splittet into an arch dependent and an arch independent package
  (increased size and build time)
* Enabled parallel build for the architecture independent part
* Install autogenerated README file without install paragraph
* Replace the license file (displayed in the about box) by a link
  to usr/share/common-licenses/GPL-3 and add lintian override

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
# -*- coding: utf-8 -*-
 
3
 
 
4
#  Copyright © 2012  B. Clausius <barcc@gmx.de>
 
5
#
 
6
#  This program is free software: you can redistribute it and/or modify
 
7
#  it under the terms of the GNU General Public License as published by
 
8
#  the Free Software Foundation, either version 3 of the License, or
 
9
#  (at your option) any later version.
 
10
#
 
11
#  This program is distributed in the hope that it will be useful,
 
12
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
#  GNU General Public License for more details.
 
15
#
 
16
#  You should have received a copy of the GNU General Public License
 
17
#  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
18
 
 
19
from __future__ import print_function, division
 
20
 
 
21
import sys
 
22
import re
 
23
 
 
24
from bcpath import path
 
25
 
 
26
srcdir = path('/usr/include/GL')
 
27
dstdir = path('pybiklib')
 
28
filenames = ['gl.h', #'glext.h'
 
29
]
 
30
dstfilename = dstdir / 'gl.pxd'
 
31
 
 
32
def convert_file(*psrc):
 
33
    src = [(_psrc, _psrc.text()) for _psrc in psrc]
 
34
    yield '\n\n# from {}:\n'.format(psrc[0])
 
35
    yield "cdef extern from '{}/{}':".format(psrc[0].dirname.basename, psrc[0].basename)
 
36
    for match in re.finditer(r'^\#define[ \t]+(\w+).*?$', src[0][1], re.MULTILINE | re.DOTALL):
 
37
        if match.group(1).startswith('GL_'):
 
38
            yield match.expand(r'    enum: \1')
 
39
            
 
40
    for psrc, tsrc in src:
 
41
        yield '\n\n# from {}:\n'.format(psrc)
 
42
        for match in re.finditer(r'^(typedef[\s\w]*);.*?$', tsrc, re.MULTILINE | re.DOTALL):
 
43
            mg1 = match.group(1)
 
44
            if mg1.find('_t') == -1 and not (mg1[-2:].isalpha() and mg1[-2:].isupper()):
 
45
                yield match.expand(r'c\1')
 
46
            
 
47
    for psrc, tsrc in src:
 
48
        yield '\n\n# from {} with:\n'.format(psrc)
 
49
        yield "cdef extern from '{}/{}':".format(psrc.dirname.basename, psrc.basename)
 
50
        for match in re.finditer(r'^GLAPI([\s\w*]*?)G?L?APIENTRY([^(]*)\(([^)]*)\);(.*?)$', tsrc,
 
51
                                                            re.MULTILINE | re.DOTALL):
 
52
            mg2s2 = match.group(2).strip()[-2:]
 
53
            if mg2s2.isalpha() and mg2s2.isupper():
 
54
                continue
 
55
            for mgf in (match.group(1).find, match.group(3).find):
 
56
                if not mgf('GLsizeiptr') == mgf('GLintptr') == mgf('64') == mgf('GLsync') == -1:
 
57
                    break
 
58
            else:
 
59
                if match.group(3).strip() == 'void':
 
60
                    template = r'    cdef\1\2()\4'
 
61
                else:
 
62
                    template = r'    cdef\1\2(\3)\4'
 
63
                yield match.expand(template).replace('const ', '').replace(' in,', ' in_,').replace('/*', '#/*')
 
64
                
 
65
def main():
 
66
    pdst = dstfilename
 
67
    with open(pdst, 'w') as fdst:
 
68
        print('# {}'.format(pdst), file=fdst)
 
69
        print('# generated with {}'.format(sys.argv[0]), file=fdst)
 
70
        psrc = srcdir / 'gl.h'
 
71
        psrcext = srcdir / 'glext.h'
 
72
        for token in convert_file(psrc, psrcext):
 
73
            print(token, file=fdst)
 
74
            
 
75
 
 
76
if __name__ == '__main__':
 
77
    main()
 
78
    
 
79