Updating build systems: folder release/bpydata/ moved to release/scripts/bpydata/
[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         scriptpath = "%s%s" % (startdir, "\\dist\\.blender\\scripts")
54         scriptdir = os.listdir(scriptpath)
55         for scriptitem in scriptdir:
56                 scriptfile = "%s\\%s" % (scriptpath, scriptitem)
57                 if os.path.isdir(scriptfile) == 0:
58                         scriptlist.append("File %s" % scriptfile)
59         scriptstring = string.join(scriptlist, "\n  ")
60         scriptstring += "\n\n"
61         nsis_cnt = string.replace(nsis_cnt, "[SCRIPTCONTS]", scriptstring)
62
63         # do scripts\bpymodules
64         bpymodlist = []
65         bpymodpath = "%s%s" % (startdir, "\\dist\\.blender\\scripts\\bpymodules")
66         bpymoddir = os.listdir(bpymodpath)
67         for bpymoditem in bpymoddir:
68                 bpymodfile = "%s\\%s" % (bpymodpath, bpymoditem)
69                 if os.path.isdir(bpymodfile) == 0:
70                         bpymodlist.append("File %s" % bpymodfile)
71         bpymodstring = string.join(bpymodlist, "\n  ")
72         bpymodstring += "\n\n"
73         nsis_cnt = string.replace(nsis_cnt, "[SCRIPTMODCONTS]", bpymodstring)
74
75         # do scripts\bpydata
76         bpydatalist = []
77         bpydatapath = "%s%s" % (startdir, "\\dist\\.blender\\scripts\\bpydata")
78         bpydatadir = os.listdir(bpydatapath)
79         for bpydataitem in bpydatadir:
80                 bpydatafile = "%s\\%s" % (bpydatapath, bpydataitem)
81                 if os.path.isdir(bpydatafile) == 0:
82                         bpydatalist.append("File %s" % bpydatafile)
83         bpydatastring = string.join(bpydatalist, "\n  ")
84         bpydatastring += "\n\n"
85         nsis_cnt = string.replace(nsis_cnt, "[SCRIPTDATACONTS]", bpydatastring)
86
87         # do scripts\bpydata\config
88         cfglist = []
89         cfgpath = "%s%s" % (startdir, "\\dist\\.blender\\scripts\\bpydata\\config")
90         cfgdir = os.listdir(cfgpath)
91         for cfgitem in cfgdir:
92                 cfgfile = "%s\\%s" % (cfgpath, cfgitem)
93                 if os.path.isdir(cfgfile) == 0:
94                         cfglist.append("File %s" % cfgfile)
95         cfgstring = string.join(cfglist, "\n  ")
96         cfgstring += "\n\n"
97         nsis_cnt = string.replace(nsis_cnt, "[SCRIPTDATACFGCONTS]", cfgstring)
98
99         # do dotblender
100         dotblendlist = []
101         dotblenddir = os.listdir(startdir+"\\dist\\.blender")
102         for dotblenditem in dotblenddir:
103                 if os.path.isdir(startdir + "\\dist\\.blender\\" + dotblenditem) == 0:
104                         dotblendlist.append("File " + startdir + "\\dist\\.blender\\" + dotblenditem)
105         dotblendstring = string.join(dotblendlist, "\n  ")
106         dotblendstring += "\n\n"
107         nsis_cnt = string.replace(nsis_cnt, "[DOTBLENDERCONTS]", dotblendstring)
108         
109         # do language files
110         langlist = []
111         langfiles = []
112         langdir = os.listdir(startdir + "\\dist\\.blender\\locale")
113         for langitem in langdir:
114                 if os.path.isdir(startdir + "\\dist\\.blender\\locale\\" + langitem) == 1:
115                         langfiles.append("SetOutPath $BLENDERHOME\\.blender\\locale\\" + langitem + "\\LC_MESSAGES")
116                         langfiles.append("File " + startdir + "\\dist\\.blender\\locale\\" + langitem + "\\LC_MESSAGES\\blender.mo")
117         langstring = string.join(langfiles, "\n  ")
118         langstring += "\n\n"
119         nsis_cnt = string.replace(nsis_cnt, "[LANGUAGECONTS]", langstring)
120         
121         # var replacements
122         nsis_cnt = string.replace(nsis_cnt, "DISTDIR", startdir + "\\dist")
123         nsis_cnt = string.replace(nsis_cnt, "SHORTVER", bs_globals.shortversion)
124         nsis_cnt = string.replace(nsis_cnt, "VERSION", bs_globals.version)
125         
126         new_nsis = open("00.blender_tmp.nsi", 'w')
127         new_nsis.write(nsis_cnt)
128         new_nsis.close()
129         
130         sys.stdout = os.popen("makensis 00.blender_tmp.nsi", 'w')
131         
132         os.chdir(startdir)
133         
134 def BlenderNSIS(target):
135         """
136         Entry for creating Windows installer
137         """
138         if sys.platform == 'win32':
139                 inst_env = bs_globals.init_env.Copy()
140                 nsis_inst = inst_env.Command('nsisinstaller', 'blender$PROGSUFFIX', donsis)
141                 if bs_globals.user_options_dict['BUILD_BLENDER_PLAYER'] == 1:
142                         inst_env.Depends(nsis_inst, 'blenderplayer$PROGSUFFIX')
143                 inst_env.Alias("wininst", nsis_inst)