# -*- python -*-

# This file is only useful for SMARTDATA's build system

import os, re

multicompile = 0

native = 1

description = ''' PicoGUI python interface '''

license = ''' GNU LGPL '''

help = """
Provides the PicoGUI Python client interface
"""

prefix = '/usr'

def listdir (dir, pattern):
    content = []
  
    for f in os.listdir (dir or '.'):
        if dir: f = os.path.join (dir, f)
  
        if os.path.isdir (f):
            content = content + listdir (f, pattern)
        else:
            if re.search (pattern, f) is not None:
                content.append (f)
  
    return content

def package_contents (module, platform, project):
    path = module.path ['dfl']
    old  = os.getcwd ()
    os.chdir (path)
    # select the dir to list
    ret = listdir ('lib', 'pyc')
    os.chdir (old)
    return ret

def package_contents (module, platform, project):
    path = module.path ['dfl']
    old  = os.getcwd ()
    os.chdir (path)
    # select the dir to list
    ret = listdir ('lib', 'pyc$')
    os.chdir (old)
    return ret

def sample_contents (module, platform, project):
    path = module.path ['dfl']
    old  = os.getcwd ()
    os.chdir (path)
    # select the dir to list
    ret = listdir ('share', 'py$')
    os.chdir (old)
    return ret

runtime = [
    Runtime ('install', 'Install PicoGUI python interface',
             content = package_contents,
             depends = [ 'python/modules/utf-8',
                         'python/modules/network',
                         ]),
    
    Runtime ('samples', 'Install PicoGUI python interface',
             content = sample_contents,
             depends = [ 'picoguipython/install' ])
    ]

def clean (module, platform, project):
    sequence ("python2.2 setup.py clean")
    return

def prepare (module, platform, project):
    message ("checking your python installation")

    failed = 0
    
    for mod in (('distutils', 'python2.2-dev'),
                ('xml',       'python2.2-xml')):
        try:
            sequence ("python2.2 -c 'import %s' 2> /dev/null" % mod [0])
        except BeeError:
            warning ("please install %s" % mod [1])
            failed = 1

    if failed:
        raise BeeError ("incomplete python2.2 installation (see above)")
    
    return

def compile (module, platform, project):
    sequence ("python2.2 setup.py build")
    return

def install (module, platform, project):
    sequence ('python2.2 setup.py install --prefix=%s' % module.path ['dfl'])
    return

def linkinfo (module, platform, project):

    path = os.path.join (module.path ['dfl'],
                         'lib', 'python2.2', 'site-packages')
    
    return { 'library' : { 'path' : path }}
