build_files.py 1.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
'''
Created on 20 oct. 2012

@author: coissac
'''

import os.path

from distutils.core import Command
from distutils import log

class build_files(Command):
            
    def initialize_options(self):
        self.files=None
        self.ctools=None
        self.build_temp=None
        self.build_cexe=None

    def finalize_options(self):
        
        self.set_undefined_options('build_ctools',
                                   ('ctools',  'ctools'),
                                   ('build_temp','build_temp'),
                                   ('build_cexe','build_cexe'),
                                   )
        
        self.files = {}
        
    def run(self):
31 32 33 34

        for cmd_name in self.get_sub_commands():
            self.run_command(cmd_name)

35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
        
        for dest,prog,command in self.distribution.files:
            destfile = os.path.join(self.build_temp,dest)
            if prog in self.ctools:
                progfile = os.path.join(self.build_cexe,prog)
            else:
                progfile = prog 
                
            log.info("Building file : %s" % dest)
            
            commandline = command % {'prog' : progfile,
                                     'dest' : destfile}

            log.info("    --> %s" % commandline)
            
            os.system(commandline)
            self.files[dest]=destfile
            
            log.info("Done.\n")
            
55 56 57 58 59 60
    def has_ctools(self):
        return self.distribution.has_ctools()


    sub_commands = [('build_ctools', has_ctools)] + \
                   Command.sub_commands
61 62 63