df6dcdb1c08458a12974016d5cbea8bca7ed0de5
[blender.git] / tools / scons / bs / bs_nsis.py
1 # nsis target
2 #
3 # this file has the NSIS related functions
4
5 import os
6 import string
7 import sys
8
9 import bs_dirs
10 import bs_globals
11
12 def donsis(env, target, source):
13         """
14         Create a Windows installer with NSIS
15         """
16         print
17         print "Creating the Windows installer"
18         print
19         
20         startdir = os.getcwd()
21         
22         if bs_dirs.preparedist()==0:
23                 print "check output for error"
24                 return
25         
26         os.chdir("release/windows/installer")
27         
28         nsis = open("00.sconsblender.nsi", 'r')
29         nsis_cnt = str(nsis.read())
30         nsis.close()
31         
32         # do root
33         rootlist = []
34         rootdir = os.listdir(startdir + "\\dist")
35         for rootitem in rootdir:
36                 if os.path.isdir(startdir + "\\dist\\" + rootitem) == 0:
37                         rootlist.append("File " + startdir + "\\dist\\" + rootitem)
38         rootstring = string.join(rootlist, "\n  ")
39         rootstring += "\n\n"
40         nsis_cnt = string.replace(nsis_cnt, "[ROOTDIRCONTS]", rootstring)
41         
42         # do delete items
43         delrootlist = []
44         for rootitem in rootdir:
45                 if os.path.isdir(startdir + "\\dist\\" + rootitem) == 0:
46                         delrootlist.append("Delete $INSTDIR\\" + rootitem)
47         delrootstring = string.join(delrootlist, "\n ")
48         delrootstring += "\n"
49         nsis_cnt = string.replace(nsis_cnt, "[DELROOTDIRCONTS]", delrootstring)
50         
51         # do scripts
52         scriptlist = []
53         scriptdir = os.listdir(startdir + "\\dist\\.blender\\scripts")
54         for scriptitem in scriptdir:
55                 if os.path.isdir(startdir + "\\dist\\.blender\\scripts\\" + scriptitem) == 0:
56                         scriptlist.append("File " + startdir + "\\dist\\.blender\\scripts\\" + scriptitem)
57         scriptstring = string.join(scriptlist, "\n  ")
58         scriptstring += "\n\n"
59         nsis_cnt = string.replace(nsis_cnt, "[SCRIPTCONTS]", scriptstring)
60         
61         # do bpycontents
62         bpydatalist = []
63         bpydatadir = os.listdir(startdir + "\\dist\\.blender\\bpydata")
64         for bpydataitem in bpydatadir:
65                 if os.path.isdir(startdir + "\\dist\\.blender\\bpydata\\" + bpydataitem) == 0:
66                         bpydatalist.append("File " + startdir + "\\dist\\.blender\\bpydata\\" + bpydataitem)
67         bpydatastring = string.join(bpydatalist, "\n  ")
68         bpydatastring += "\n\n"
69         nsis_cnt = string.replace(nsis_cnt, "[BPYCONTS]", bpydatastring)
70         
71         # do dotblender
72         dotblendlist = []
73         dotblenddir = os.listdir(startdir+"\\dist\\.blender")
74         for dotblenditem in dotblenddir:
75                 if os.path.isdir(startdir + "\\dist\\.blender\\" + dotblenditem) == 0:
76                         dotblendlist.append("File " + startdir + "\\dist\\.blender\\" + dotblenditem)
77         dotblendstring = string.join(dotblendlist, "\n  ")
78         dotblendstring += "\n\n"
79         nsis_cnt = string.replace(nsis_cnt, "[DOTBLENDERCONTS]", dotblendstring)
80         
81         # do language files
82         langlist = []
83         langfiles = []
84         langdir = os.listdir(startdir + "\\dist\\.blender\\locale")
85         for langitem in langdir:
86                 if os.path.isdir(startdir + "\\dist\\.blender\\locale\\" + langitem) == 1:
87                         langfiles.append("SetOutPath $BLENDERHOME\\.blender\\locale\\" + langitem + "\\LC_MESSAGES")
88                         langfiles.append("File " + startdir + "\\dist\\.blender\\locale\\" + langitem + "\\LC_MESSAGES\\blender.mo")
89         langstring = string.join(langfiles, "\n  ")
90         langstring += "\n\n"
91         nsis_cnt = string.replace(nsis_cnt, "[LANGUAGECONTS]", langstring)
92         
93         # var replacements
94         nsis_cnt = string.replace(nsis_cnt, "DISTDIR", startdir + "\\dist")
95         nsis_cnt = string.replace(nsis_cnt, "SHORTVER", bs_globals.shortversion)
96         nsis_cnt = string.replace(nsis_cnt, "VERSION", bs_globals.version)
97         
98         new_nsis = open("00.blender_tmp.nsi", 'w')
99         new_nsis.write(nsis_cnt)
100         new_nsis.close()
101         
102         sys.stdout = os.popen("makensis 00.blender_tmp.nsi", 'w')
103         
104         os.chdir(startdir)
105         
106 def BlenderNSIS(target):
107         """
108         Entry for creating Windows installer
109         """
110         if sys.platform == 'win32':
111                 inst_env = bs_globals.init_env.Copy()
112                 nsis_inst = inst_env.Command('nsisinstaller', 'blender$PROGSUFFIX', donsis)
113                 if bs_globals.user_options_dict['BUILD_BLENDER_PLAYER'] == 1:
114                         inst_env.Depends(nsis_inst, 'blenderplayer$PROGSUFFIX')
115                 inst_env.Alias("wininst", nsis_inst)