OSDN Git Service

revise database generator for seed1 decision & threshold2 & inishie
[amulettoolsmh4/main.git] / make.py
1 # -*- coding:utf-8 -*-
2
3 # generate pyinstaller's spec file & modify .spec file
4 # 2013/12/07 written by kei9
5
6 import subprocess
7 import tempfile
8 import os
9 import os.path
10 import shutil
11
12 import convertcoding
13 func = lambda path_list: os.path.join(convertcoding.convert_unicode(
14     os.path.dirname(os.path.abspath(__file__))), *path_list)
15 """
16 BUNDLE_RESOURCES = [(r"view/mainframe.xrc", r"d:\\Git\\AmuletToolsMH4\\view\\mainframe.xrc"),
17        (r"view/gaugedialog.xrc", r"d:\\Git\\AmuletToolsMH4\\view\\gaugedialog.xrc")]
18 """
19 BUNDLE_RESOURCES = [(ur"view/mainframe.xrc", func([u"view", u"mainframe.xrc"])),
20        (ur"view/gaugedialog.xrc", func([u"view", u"gaugedialog.xrc"]))]
21 MOVE_FILES = [u"data.zip", u"readme.txt", u"license.txt"]
22
23
24 SCRIPTFILE = u"amulettool.py"
25 APPNAME = u"AmuletToolsMH4"
26
27 MAKESPEC = u"pyi-makespec"
28 PYINSTALLER = u"pyinstaller"
29
30 SPECOPTIONS = [u"--onefile", u"--windowed", u"--name=" + APPNAME]
31
32 def get_insert_lines():
33     result = []
34     for item in BUNDLE_RESOURCES:
35         result.append(ur'a.datas += [("{0}", r"{1}", "DATA")]'.format(item[0], item[1]) + "\n")
36     return result
37
38 if __name__ == "__main__":
39     print u"file path: ", os.path.dirname(os.path.abspath(__file__))
40     
41     cmd = [MAKESPEC] + SPECOPTIONS + [SCRIPTFILE]
42     print " ".join(cmd)
43     out = subprocess.check_output(cmd)
44     print out
45
46
47     # insert bundle data line to .spec
48     print "insert bundle resources to .spec file"
49     specfile = APPNAME + ".spec"
50     with tempfile.NamedTemporaryFile(delete=False) as tmp_file:
51         tmpname = tmp_file.name
52         with open(specfile, "r") as f:
53             for line in f:
54                 if line.startswith("pyz"):
55                     for l in get_insert_lines():
56                         tmp_file.write(l)
57                 tmp_file.write(line)
58
59     os.remove(specfile)
60     os.rename(tmpname, specfile)
61
62
63     # conduct pyinstall
64     cmd = [PYINSTALLER, specfile]
65     print " ".join(cmd)
66     out = subprocess.check_output(cmd)
67     print out
68
69     # copy file to dist 
70     file_dir = os.path.dirname(os.path.abspath(__file__))
71     for f in MOVE_FILES:
72         abs_path = os.path.abspath(f)
73         relative_path = os.path.relpath(abs_path, file_dir)
74         shutil.copy(abs_path, os.path.join("dist", relative_path))
75
76     print "Finished"