46
|
1 #
|
|
2 # release
|
|
3 #
|
|
4
|
|
5 from os.path import join, isdir, isfile, dirname, basename, normpath
|
|
6
|
|
7 import tempfile
|
|
8 import os
|
|
9 import sys
|
|
10 import shutil
|
|
11 import zipfile
|
|
12 import datetime
|
|
13
|
|
14 def relative_walk(path):
|
|
15 for root, folders, files in os.walk(path):
|
|
16 for filename in files:
|
|
17 yield join(root, filename)[len(path)+1:]
|
|
18
|
|
19 def release_project(root, location, project, target=None, build='Build'):
|
|
20 if target:
|
|
21 executable = join(root, project, 'bin', target, project + '.exe')
|
|
22
|
|
23 else:
|
|
24 executable = join(root, project, 'bin', 'release', project + '.exe')
|
|
25 if not isfile(executable):
|
|
26 executable = join(root, project, 'bin', 'debug', project + '.exe')
|
|
27
|
|
28 if not isfile(executable):
|
|
29 raise Exception('Error: Could not locate executable')
|
|
30
|
|
31 data = join(root, 'data')
|
49
|
32 extern = join(root, 'extern')
|
46
|
33
|
|
34 if not isdir(data):
|
|
35 raise Exception('Error: Could not locate data folder')
|
|
36
|
|
37 if isdir(build):
|
|
38 shutil.rmtree(build, True)
|
|
39
|
|
40 os.makedirs(build)
|
|
41
|
|
42 shutil.copyfile(executable, join(build, basename(executable)))
|
|
43
|
|
44 for filename in relative_walk(data):
|
49
|
45 filepath = join(build, 'Data', filename)
|
46
|
46
|
|
47 if not isdir(dirname(filepath)):
|
|
48 os.makedirs(dirname(filepath))
|
|
49
|
|
50 shutil.copyfile(join(data, filename), filepath)
|
|
51
|
49
|
52 for filename in relative_walk(extern):
|
|
53 filepath = join(build, filename)
|
|
54
|
|
55 if not isdir(dirname(filepath)):
|
|
56 os.makedirs(dirname(filepath))
|
|
57
|
|
58 shutil.copyfile(join(extern, filename), filepath)
|
|
59
|
46
|
60 if not isdir(location):
|
|
61 os.makedirs(location)
|
|
62
|
47
|
63 with zipfile.ZipFile(join(location, project + datetime.datetime.now().strftime('%Y%m%d%I%M%p') + '.zip'), 'w') as handle:
|
46
|
64 for filename in relative_walk(build):
|
|
65 handle.write(join(build, filename), filename)
|
|
66
|
|
67 if __name__ == '__main__':
|
|
68 root = normpath(join(dirname(sys.argv[0]), '..'))
|
|
69
|
|
70 release_project(root, '..\Release', 'LightClone') |