~ubuntu-branches/ubuntu/karmic/quodlibet/karmic

« back to all changes in this revision

Viewing changes to gdist/gobject.py

  • Committer: Bazaar Package Importer
  • Author(s): Luca Falavigna
  • Date: 2009-01-30 23:55:34 UTC
  • mfrom: (1.1.12 upstream)
  • Revision ID: james.westby@ubuntu.com-20090130235534-l4e72ulw0vqfo17w
Tags: 2.0-1ubuntu1
* Merge from Debian experimental (LP: #276856), remaining Ubuntu changes:
  + debian/patches/40-use-music-profile.patch:
    - Use the "Music and Movies" pipeline per default.
* Refresh the above patch for new upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright 2007 Joe Wreschnig
 
2
#
 
3
# This software and accompanying documentation, if any, may be freely
 
4
# used, distributed, and/or modified, in any form and for any purpose,
 
5
# as long as this notice is preserved. There is no warranty, either
 
6
# express or implied, for this software.
 
7
 
 
8
"""GObject extension support
 
9
 
 
10
This module contains commands and classes to support building
 
11
Python GObject wrappers.
 
12
"""
 
13
 
 
14
import os
 
15
 
 
16
from distutils.core import Extension
 
17
from distutils.command.build_ext import build_ext as distutils_build_ext
 
18
from gdist.core import GCommand
 
19
 
 
20
class GObjectExtension(Extension):
 
21
    """Generate and build GObject extensions
 
22
 
 
23
    This class will build GObject extensions much like the normal
 
24
    distutils Extension class builds normal CPython extensions.
 
25
    Its constructor takes two more arguments, the defs file and
 
26
    the override file.
 
27
    """
 
28
    def __init__(self, pkgname, defs, override, sources, *args, **kwargs):
 
29
        self._c_file = pkgname + "_py_codegen.c"
 
30
        self._override = override
 
31
        self._def_file = defs
 
32
        sources.append(self._c_file)
 
33
        Extension.__init__(self, pkgname, sources, *args, **kwargs)
 
34
 
 
35
class build_gobject_ext(distutils_build_ext, GCommand):
 
36
    """build Python GObject extensions
 
37
 
 
38
    This command builds Python GObject extensions by generating the
 
39
    appropriate source file with pygtk-codegen-2.0, getting the
 
40
    correct compiler flags with pkg-config, and then compiling
 
41
    everything with the default distutils extension commands.
 
42
    """
 
43
 
 
44
    description = "build Python GObject extensions"
 
45
 
 
46
    def finalize_options(self):
 
47
        distutils_build_ext.finalize_options(self)
 
48
        GCommand.finalize_options(self)
 
49
        self.extensions = self.distribution.gobject_modules
 
50
        self._defsdir = self.capture(
 
51
            ["pkg-config", "--variable", "defsdir", "pygtk-2.0"]).strip()
 
52
        self._cargs = self.capture(
 
53
            ["pkg-config", "--cflags", "gtk+-2.0", "pygtk-2.0"]).split()
 
54
        self._ldargs = self.capture(
 
55
            ["pkg-config", "--libs", "gtk+-2.0", "pygtk-2.0"]).split()
 
56
    
 
57
    def build_extension(self, ext):
 
58
        ext.extra_compile_args.extend(self._cargs)
 
59
        ext.extra_link_args.extend(self._ldargs)
 
60
        name = ext.name.split(".")[-1]
 
61
        data = self.capture(
 
62
            ["pygtk-codegen-2.0", "--prefix", name,
 
63
             "--register", os.path.join(self._defsdir, "gdk-types.defs"),
 
64
             "--register",  os.path.join(self._defsdir, "gtk-types.defs"),
 
65
             "--override", ext._override, ext._def_file])
 
66
        fileobj = file(ext._c_file, "w")
 
67
        fileobj.write(data)
 
68
        fileobj.close()
 
69
        distutils_build_ext.build_extension(self, ext)
 
70
 
 
71
        os.unlink(ext._c_file)
 
72
 
 
73
__all__ = ["build_gobject_ext"]