view LightTools/release.py @ 74:40c0b5305de8

Work on removing ScreenManager
author koryspansel
date Tue, 18 Oct 2011 11:56:49 -0700
parents 48705dc6e568
children
line wrap: on
line source

#
# release
#

from os.path import join, isdir, isfile, dirname, basename, normpath

import tempfile
import os
import sys
import shutil
import zipfile
import datetime

def relative_walk(path):
    for root, folders, files in os.walk(path):
        for filename in files:
            yield join(root, filename)[len(path)+1:]

def release_project(root, location, project, target=None, build='Build'):
    if target:
        executable = join(root, project, 'bin', target, project + '.exe')

    else:
        executable = join(root, project, 'bin', 'release', project + '.exe')
        if not isfile(executable):
            executable = join(root, project, 'bin', 'debug', project + '.exe')
        
    if not isfile(executable):
        raise Exception('Error: Could not locate executable')

    data = join(root, 'data')
    extern = join(root, 'extern')

    if not isdir(data):
        raise Exception('Error: Could not locate data folder')
        
    if isdir(build):
        shutil.rmtree(build, True)

    os.makedirs(build)

    shutil.copyfile(executable, join(build, basename(executable)))
        
    for filename in relative_walk(data):
        filepath = join(build, 'Data', filename)

        if not isdir(dirname(filepath)):
            os.makedirs(dirname(filepath))

        shutil.copyfile(join(data, filename), filepath)
        
    for filename in relative_walk(extern):
        filepath = join(build, filename)
        
        if not isdir(dirname(filepath)):
            os.makedirs(dirname(filepath))
            
        shutil.copyfile(join(extern, filename), filepath)
        
    if not isdir(location):
        os.makedirs(location)
        
    with zipfile.ZipFile(join(location, project + datetime.datetime.now().strftime('%Y%m%d%I%M%p') + '.zip'), 'w') as handle:
        for filename in relative_walk(build):
            handle.write(join(build, filename), filename)

if __name__ == '__main__':
    root = normpath(join(dirname(sys.argv[0]), '..'))
    
    release_project(root, '..\Release', 'LightClone')