Mercurial > LightClone
diff LightTools/release.py @ 46:a379bce1aeb1
Rename map.py to build.py; Add release script
author | koryspansel |
---|---|
date | Thu, 22 Sep 2011 14:35:35 -0700 |
parents | |
children | 81d413160824 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LightTools/release.py Thu Sep 22 14:35:35 2011 -0700 @@ -0,0 +1,65 @@ +# +# 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') + + 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, filename) + + if not isdir(dirname(filepath)): + os.makedirs(dirname(filepath)) + + shutil.copyfile(join(data, filename), filepath) + + if not isdir(location): + os.makedirs(location) + + current_date = datetime.datetime.now() + suffix = current_date.strftime('%Y%m%d%I%M%p') + print suffix + + with zipfile.ZipFile(join(location, project + '.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') \ No newline at end of file