summaryrefslogtreecommitdiffstats
path: root/dsextras.py
diff options
context:
space:
mode:
authorJohan Dahlin <zilch@src.gnome.org>2003-02-27 00:35:05 +0000
committerJohan Dahlin <zilch@src.gnome.org>2003-02-27 00:35:05 +0000
commit0ec6ea37b32dc9a588fe91593108a3dd8a53d4a9 (patch)
treee2c04471720ec868ab6e7c342a246835644224ef /dsextras.py
parenta7401b6bee5ff2a2fd8cb40f135a10d7c68c1a8a (diff)
downloadpygobject-0ec6ea37b32dc9a588fe91593108a3dd8a53d4a9.tar.gz
pygobject-0ec6ea37b32dc9a588fe91593108a3dd8a53d4a9.tar.xz
pygobject-0ec6ea37b32dc9a588fe91593108a3dd8a53d4a9.zip
Added win32 support and some rearrangements. Largely based upon patch by
* setup.py, dsextras.py: Added win32 support and some rearrangements. Largely based upon patch by Cedric Gustin.
Diffstat (limited to 'dsextras.py')
-rw-r--r--dsextras.py121
1 files changed, 72 insertions, 49 deletions
diff --git a/dsextras.py b/dsextras.py
index 387d3dc..22eda7b 100644
--- a/dsextras.py
+++ b/dsextras.py
@@ -4,7 +4,7 @@
# TODO:
# Make it possible to import codegen from another dir
#
-from commands import getoutput, getstatusoutput
+
from distutils.command.build_ext import build_ext
from distutils.command.install_lib import install_lib
from distutils.extension import Extension
@@ -16,6 +16,77 @@ import sys
GLOBAL_INC = []
GLOBAL_MACROS = []
+def getoutput(cmd):
+ """Return output (stdout or stderr) of executing cmd in a shell."""
+ return getstatusoutput(cmd)[1]
+
+def getstatusoutput(cmd):
+ """Return (status, output) of executing cmd in a shell."""
+ if sys.platform == 'win32':
+ pipe = os.popen(cmd, 'r')
+ text = pipe.read()
+ sts = pipe.close() or 0
+ if text[-1] == '\n':
+ text = text[:-1]
+ return sts, text
+ else:
+ from commands import getstatusoutput
+ return getstatusoutput(cmd)
+
+def have_pkgconfig():
+ """Checks for the existence of pkg-config"""
+ if (sys.platform == 'win32' and
+ os.system('pkg-config --version > NUL') == 0):
+ return 1
+ else:
+ if getstatusoutput('pkg-config')[0] == 256:
+ return 1
+
+def list_files(dir):
+ """List all files in a dir, with filename match support:
+ for example: glade/*.glade will return all files in the glade directory
+ that matches *.glade. It also looks up the full path"""
+ if dir.find(os.sep) != -1:
+ parts = dir.split(os.sep)
+ dir = string.join(parts[:-1], os.sep)
+ pattern = parts[-1]
+ else:
+ pattern = dir
+ dir = '.'
+
+ dir = os.path.abspath(dir)
+ retval = []
+ for file in os.listdir(dir):
+ if fnmatch.fnmatch(file, pattern):
+ retval.append(os.path.join(dir, file))
+ return retval
+
+def pkgc_version_check(name, longname, req_version):
+ is_installed = not os.system('pkg-config --exists %s' % name)
+ if not is_installed:
+ print "Could not find %s" % longname
+ return 0
+
+ orig_version = getoutput('pkg-config --modversion %s' % name)
+ version = map(int, orig_version.split('.'))
+ pkc_version = map(int, req_version.split('.'))
+
+ if version >= pkc_version:
+ return 1
+ else:
+ print "Warning: Too old version of %s" % longname
+ print " Need %s, but %s is installed" % \
+ (self.pkc_version, orig_version)
+ self.can_build_ok = 0
+ return 0
+
+class BuildExt(build_ext):
+ def build_extension(self, ext):
+ # Generate eventual templates before building
+ if hasattr(ext, 'generate'):
+ ext.generate()
+ build_ext.build_extension(self, ext)
+
class InstallLib(install_lib):
local_outputs = []
local_inputs = []
@@ -61,25 +132,6 @@ class InstallLib(install_lib):
def get_inputs(self):
return install_lib.get_inputs(self) + self.local_inputs
-def pkgc_version_check(name, longname, req_version):
- is_installed = not os.system('pkg-config --exists %s' % name)
- if not is_installed:
- print "Could not find %s" % longname
- return 0
-
- orig_version = getoutput('pkg-config --modversion %s' % name)
- version = map(int, orig_version.split('.'))
- pkc_version = map(int, req_version.split('.'))
-
- if version >= pkc_version:
- return 1
- else:
- print "Warning: Too old version of %s" % longname
- print " Need %s, but %s is installed" % \
- (self.pkc_version, orig_version)
- self.can_build_ok = 0
- return 0
-
class PkgConfigExtension(Extension):
can_build_ok = None
def __init__(self, **kwargs):
@@ -220,34 +272,5 @@ class TemplateExtension(PkgConfigExtension):
def generate(self):
map(lambda x: x.generate(), self.templates)
-class BuildExt(build_ext):
- def build_extension(self, ext):
- # Generate eventual templates before building
- if hasattr(ext, 'generate'):
- ext.generate()
- build_ext.build_extension(self, ext)
-def list_files(dir):
- """List all files in a dir, with filename match support:
- for example: glade/*.glade will return all files in the glade directory
- that matches *.glade. It also looks up the full path"""
- if dir.find(os.sep) != -1:
- parts = dir.split(os.sep)
- dir = string.join(parts[:-1], os.sep)
- pattern = parts[-1]
- else:
- pattern = dir
- dir = '.'
-
- dir = os.path.abspath(dir)
- retval = []
- for file in os.listdir(dir):
- if fnmatch.fnmatch(file, pattern):
- retval.append(os.path.join(dir, file))
- return retval
-def have_pkgconfig():
- """Checks for the existence of pkg-config"""
- status = getstatusoutput('pkg-config')[0]
- if status == 256:
- return 1