home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.6)
-
- __license__ = 'GPL v3'
- __copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
- __docformat__ = 'restructuredtext en'
- import os
- import textwrap
- import re
- import subprocess
- INC = '/usr/include/ImageMagick'
-
- def parse_enums(f):
- print '\nParsing:', f
- raw = open(os.path.join(INC, f)).read()
- raw = re.sub('(?s)/\\*.*?\\*/', '', raw)
- raw = re.sub('#.*', '', raw)
- for enum in re.findall('typedef\\s+enum\\s+\\{([^}]+)', raw):
- enum = re.sub('(?s)/\\*.*?\\*/', '', enum)
- for x in enum.splitlines():
- e = x.split(',')[0].strip().split(' ')[0]
- if e:
- val = get_value(e)
- print e, val
- yield (e, val)
- continue
-
-
-
-
- def get_value(const):
- t = '\n #include <wand/MagickWand.h>\n #include <stdio.h>\n int main(int argc, char **argv) {\n printf("%%d", %s);\n return 0;\n }\n ' % const
-
- try:
- f = _[1]
- f.write(t)
- finally:
- pass
-
- subprocess.check_call([
- 'gcc',
- '-I/usr/include/ImageMagick',
- '/tmp/ig.c',
- '-o',
- '/tmp/ig',
- '-lMagickWand'])
- return int(subprocess.Popen([
- '/tmp/ig'], stdout = subprocess.PIPE).communicate()[0].strip())
-
-
- def main():
- constants = []
- for x in ('resample', 'image', 'draw', 'distort', 'composite', 'geometry', 'colorspace'):
- constants += list(parse_enums('magick/%s.h' % x))
-
- base = os.path.dirname(__file__)
- constants = [ 'PyModule_AddIntConstant(m, "{0}", {1});'.format(c, v) for c, v in constants ]
- raw = textwrap.dedent(' // Generated by generate.py\n\n static void magick_add_module_constants(PyObject *m) {\n %s\n }\n ') % '\n '.join(constants)
-
- try:
- f = _[2]
- f.write(raw)
- finally:
- pass
-
-
- if __name__ == '__main__':
- main()
-
-