=== added file 'jhbuild/modtypes/binary.py'
--- jhbuild/modtypes/binary.py	1970-01-01 00:00:00 +0000
+++ jhbuild/modtypes/binary.py	2007-12-15 00:06:59 +0000
@@ -0,0 +1,155 @@
+# jhbuild - a build script for GNOME 1.x and 2.x
+# Copyright (C) 2007  John Stowers
+#
+#   binary.py: A binary module for executing scripts and installing
+#   modules which do not have a configure/autogen/make step
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+import os
+
+from jhbuild.errors import FatalError, CommandError, BuildStateError
+from jhbuild.modtypes import Package, register_module_type, get_dependencies
+from jhbuild.utils.unpack import unpack_archive
+from jhbuild.modtypes.tarball import Tarball
+
+class Binary(Tarball):
+    """Represents a binary distributed module which may need to have aditional
+    actions operate on it post download"""
+    type = 'binary'
+    STATE_DOWNLOAD  = 'download'
+    STATE_UNPACK    = 'unpack'
+    STATE_CONFIGURE = 'configure'
+    STATE_BUILD     = 'build'
+    STATE_INSTALL   = 'install'
+    def __init__(self, name, version, source_url='', source_size='', source_md5=None,uri=[],
+                 configure_commands=[], build_commands=[], install_commands=[], 
+                 dependencies=[], after=[]):
+        Tarball.__init__(self, name, version, source_url, source_size, source_md5,
+                         uri, patches=[], checkoutdir=None,autogenargs='', makeargs='',
+                         dependencies=dependencies,after=after,supports_non_srcdir_builds=False)
+
+        self.configure_commands = configure_commands
+        self.build_commands = build_commands
+        self.install_commands = install_commands
+
+    def _exec_commands(self, buildscript, commands):
+        #Commands can contain a number of special placeholders.
+        PLACEHOLDERS = {
+            "@@PREFIX@@"    :   buildscript.config.prefix,
+            "@@SRCDIR@@"    :   self.get_srcdir(buildscript)
+            }
+
+        for cmd in commands:
+            for i in range(0,len(cmd)):
+                for k,v in PLACEHOLDERS.items():
+                    cmd[i] = cmd[i].replace(k,v)
+
+            buildscript.execute(cmd)
+
+    def get_srcdir(self, buildscript):
+        #Binary tarballs can have random formats so always unpack into their own dir
+        srcdir = os.path.abspath(os.path.join(
+                                        buildscript.config.checkoutroot,
+                                        "%s-%s-binary" % (self.name, self.version)))
+        if not os.path.exists(srcdir):
+            os.makedirs(srcdir)
+        return srcdir
+
+    def do_start(self, buildscript):
+        if buildscript.packagedb.check(self.name, self.version):
+            return (Package.STATE_DONE, None, None)
+        if self.source_url != '':
+            return (self.STATE_DOWNLOAD, None, None)
+        return (self.STATE_CONFIGURE, None, None)
+
+    def do_unpack(self, buildscript):
+        if self.source_url != None:
+            #unpack the binary into its own custom folder
+            localfile = self.get_localfile(buildscript)
+            srcdir = self.get_srcdir(buildscript)
+            buildscript.set_action('Unpacking', self)
+            try:
+                unpack_archive(buildscript, localfile, self.get_srcdir(buildscript))
+            except:
+                raise BuildStateError('could not unpack tarball %s' % srcdir)
+    do_unpack.next_state = STATE_CONFIGURE
+    do_unpack.error_states = []
+            
+    def do_configure(self, buildscript):
+        buildscript.set_action('Configure', self)
+        self._exec_commands(buildscript, self.configure_commands)
+    do_configure.next_state = STATE_BUILD
+    do_configure.error_states = []
+
+    def do_build(self, buildscript):
+        buildscript.set_action('Building', self)
+        self._exec_commands(buildscript, self.build_commands)
+    do_build.next_state = STATE_INSTALL
+    do_build.error_states = []
+
+    def do_install(self, buildscript):
+        buildscript.set_action('Installing', self)
+        self._exec_commands(buildscript, self.install_commands)
+        buildscript.packagedb.add(self.name, self.version or '')
+    do_install.next_state = Package.STATE_DONE
+    do_install.error_states = []
+
+def parse_binary(node, config, uri, repositories, default_repo):
+    name = node.getAttribute('id')
+    version = node.getAttribute('version')
+    source_url = ''
+    source_size = ''
+    source_md5 = None
+    checkoutdir = None
+    configure_commands = []
+    build_commands = []
+    install_commands = []
+
+    def parse_command(node):
+        execute = node.getAttribute('execute')
+        return eval(execute)
+
+    for childnode in node.childNodes:
+        if childnode.nodeType != childnode.ELEMENT_NODE: continue
+        if childnode.nodeName == 'source':
+            source_url = childnode.getAttribute('href')
+            if childnode.hasAttribute('size'):
+                source_size = int(childnode.getAttribute('size'))
+            if childnode.hasAttribute('md5sum'):
+                source_md5 = childnode.getAttribute('md5sum')
+        elif childnode.nodeName == 'configure':
+            for cmd in childnode.childNodes:
+                if cmd.nodeType != cmd.ELEMENT_NODE: continue
+                if cmd.nodeName == 'cmd':
+                    configure_commands.append( parse_command(cmd) )
+        elif childnode.nodeName == 'build':
+            for cmd in childnode.childNodes:
+                if cmd.nodeType != cmd.ELEMENT_NODE: continue
+                if cmd.nodeName == 'cmd':
+                    build_commands.append( parse_command(cmd) )
+        elif childnode.nodeName == 'install':
+            for cmd in childnode.childNodes:
+                if cmd.nodeType != cmd.ELEMENT_NODE: continue
+                if cmd.nodeName == 'cmd':
+                    install_commands.append( parse_command(cmd) )
+
+    dependencies, after = get_dependencies(node)
+
+    return Binary(name, version, source_url, source_size, source_md5,uri,
+                  configure_commands, build_commands, install_commands,
+                  dependencies, after)
+
+register_module_type('binary', parse_binary)

