3 # generate pyinstaller's spec file & modify .spec file
4 # 2013/12/07 written by kei9
12 BUNDLE_RESOURCES = [(r"view/mainframe.xrc", r"d:\\Git\\AmuletToolsMH4\\view\\mainframe.xrc"),
13 (r"view/gaugedialog.xrc", r"d:\\Git\\AmuletToolsMH4\\view\\gaugedialog.xrc")]
14 MOVE_FILES = ["data.zip", "readme.txt", "license.txt"]
17 SCRIPTFILE = "amulettool.py"
18 APPNAME = "AmuletToolsMH4"
20 MAKESPEC = "pyi-makespec"
21 PYINSTALLER = "pyinstaller"
23 SPECOPTIONS = ["--onefile", "--windowed", "--name=" + APPNAME]
25 def get_insert_lines():
27 for item in BUNDLE_RESOURCES:
28 result.append(r'a.datas += [("{0}", "{1}", "DATA")]'.format(item[0], item[1]) + "\n")
31 if __name__ == "__main__":
32 cmd = [MAKESPEC] + SPECOPTIONS + [SCRIPTFILE]
34 out = subprocess.check_output(cmd)
37 # insert bundle data line to .spec
38 print "insert bundle resources to .spec file"
39 specfile = APPNAME + ".spec"
40 with tempfile.NamedTemporaryFile(delete=False) as tmp_file:
41 tmpname = tmp_file.name
42 with open(specfile, "r") as f:
44 if line.startswith("pyz"):
45 for l in get_insert_lines():
50 os.rename(tmpname, specfile)
53 cmd = [PYINSTALLER, specfile]
55 out = subprocess.check_output(cmd)
59 file_dir = os.path.dirname(os.path.abspath(__file__))
61 abs_path = os.path.abspath(f)
62 relative_path = os.path.relpath(abs_path, file_dir)
63 shutil.copy(abs_path, os.path.join("dist", relative_path))