view test-lily/test-binary.py @ 6481:c9f348420ef1

w32api: rename DATADIR to MINGW_DATADIR.
author Jan Nieuwenhuizen <janneke@gnu.org>
date Thu, 03 Feb 2011 19:55:51 +0100
parents 576d0a5a3b83
children
line wrap: on
line source

#! /usr/bin/env python

import sys
import os
import re
import time

def argv0_relocation ():
    import os, sys
    bindir = os.path.dirname (sys.argv[0])
    prefix = os.path.dirname (bindir)
    if not prefix:
        prefix = bindir + '/..'
    sys.path.insert (0, prefix)

argv0_relocation ()

#
from gub.syntax import printf

def system (c, ignore_error=False):
    printf ('executing' , c)
    s = os.system (c)
    if s and not ignore_error:
        raise Exception ('barf')




##
## format:
## 
## { "platform": ("login", "host", "directory", test-file") , ... }
##
test_settings = eval (open ('test-settings.py').read ())
    

platform_test_script_types = {
    'linux-x86': 'shar',
    'linux-64': 'shar',
    'darwin-ppc' : 'darwin',
    'darwin-x86' : 'darwin',
    'freebsd-x86': 'shar',
    'freebsd-64': 'shar',
}

def test_build (bin):
    if bin.find (':') < 0:
        bin = os.path.abspath (bin)

    base = os.path.split (bin)[1]
    platform = re.search ('lilypond-[0-9.]+-[0-9]+.([a-z0-9-]+).*', bin).group (1)
    viewer = 'evince'
    
    if not platform:
        printf ('unknown platform for', bin)
        return

    ending_found = 0 
    for e in ['.sh', '.zip', '.exe', 'tar.bz2']:
        ending_found = ending_found or bin.endswith  (e)

    if not ending_found:
        printf ('unknown extension for', base)
        return
    
    try:
        os.unlink ('typography-demo.pdf')
    except:
        pass

    printf ('testing platform %s' % platform)
    logdir = "log/"
    try:
        (uid, host, dir, test_file) = test_settings[platform]
    except KeyError:
        system ('touch %(logdir)s/%(base)s.test.pdf' % locals ())
        return
    
    if test_file == None:
        test_file = 'test-lily/typography-demo.ly' 

    base_test_file = os.path.split (test_file)[1]
    base_test_file_stem = os.path.splitext (base_test_file)[0]

    system ('ssh %(uid)s@%(host)s mkdir  %(dir)s' % locals (), ignore_error=True)
    system ('ssh %(uid)s@%(host)s rm  %(dir)s/%(base_test_file_stem)s.*' % locals (), ignore_error=True)

    test_platform_script = 'test-%s-gub.sh' % platform_test_script_types.get (platform, platform)
    system ('scp %(test_file)s test-lily/%(test_platform_script)s '
            ' %(bin)s '
            ' %(uid)s@%(host)s:%(dir)s/'
            % locals ())

    system ('ssh %(uid)s@%(host)s sh %(dir)s/%(test_platform_script)s %(dir)s %(base)s %(base_test_file)s'
            % locals ())
    system ('scp %(uid)s@%(host)s:%(dir)s/%(base_test_file_stem)s.pdf %(logdir)s/%(base)s.test.pdf'
            % locals ())
    system ('%(viewer)s %(logdir)s/%(base)s.test.pdf'
            % locals ())


pids = []
for a in sys.argv[1:]:
    pid = os.fork () 
    if not pid:
        test_build (a)
        sys.exit (0)
    else:
        pids.append (pid)

os.wait ()