File build-examples.py of Package python-pyjamas

#!/usr/bin/python
import commands
import os
import sys
import tempfile

options = sys.argv[1:]
if not options:
    options = "-O"

buildroot = os.environ.get('RPM_BUILD_ROOT', '')


pyjsbuild_script = """#!/usr/bin/python

import os
import sys

buildroot = os.environ.get('RPM_BUILD_ROOT', '')

pyjsversion = r'0.6pre4'
pyjspth = buildroot + r'/usr/share/pyjamas'

for l in ('lib', 'lib64'):
    sys.path.insert(0, buildroot + os.path.join(sys.prefix, l, 'python'+sys.version[:3], 'site-packages'))
sys.path[0:0] = [buildroot + r'/usr/share/pyjamas']
import pyjs
pyjs.pyjspth = buildroot + r'/usr/share/pyjamas'
pyjs.path += [os.path.join(pyjspth, 'library'),
os.path.join(pyjspth, 'addons'),
]

import pyjs.browser
if __name__ == '__main__':
    if "--version" in sys.argv:
        print "Version:", pyjsversion
        sys.exit(0)
    pyjs.browser.build_script()
"""

pyjsbuild_script_file = tempfile.NamedTemporaryFile()
pyjsbuild_script_file.write(pyjsbuild_script)
pyjsbuild_script_file.flush()

def pyjsbuild(options, name):
    (ret, out) = commands.getstatusoutput("python %s %s %s" % (pyjsbuild_script_file.name, options, name))
    print ret, out


if __name__ == '__main__':
    for d in [x for x in os.listdir('.') if os.path.isdir(x)]:
        buildscript = os.path.join(d, 'build.sh')
        if os.path.exists(buildscript):
            os.chdir(d)
            buildscript = open('build.sh').read()
            name = [line.strip().split()[-1] for line in buildscript.split('\n') if 'bin/pyjsbuild' in line][0]
            pyjsbuild(options, name)
            os.chdir("..")

openSUSE Build Service is sponsored by