1 | """ |
---|
2 | This module generates .ss file according to the local config of |
---|
3 | the current application. Please make sure a file named "local_config.py" |
---|
4 | exists in the current directory. Edit local_config.py according to your needs. |
---|
5 | """ |
---|
6 | import local_config |
---|
7 | import os |
---|
8 | import string |
---|
9 | |
---|
10 | REG_PROGRAM = """{app}\MYPROG.EXE"" ""%1""" |
---|
11 | APPLICATION = str(local_config.__appname__ )+ '.exe' |
---|
12 | AppName = str(local_config.__appname__ ) |
---|
13 | AppVerName = str(local_config.__appname__ )+'-'+ str(local_config.__version__) |
---|
14 | Dev = '' |
---|
15 | if AppVerName.lower().count('dev') > 0: |
---|
16 | Dev = '-Dev' |
---|
17 | AppPublisher = local_config._copyright |
---|
18 | AppPublisherURL = local_config._homepage |
---|
19 | AppSupportURL = local_config._homepage |
---|
20 | AppUpdatesURL = local_config._homepage |
---|
21 | ChangesEnvironment = 'true' |
---|
22 | DefaultDirName = os.path.join("{pf}" , AppName+Dev) |
---|
23 | DefaultGroupName = os.path.join(local_config.DefaultGroupName, AppVerName) |
---|
24 | |
---|
25 | OutputBaseFilename = local_config.OutputBaseFilename |
---|
26 | SetupIconFile = local_config.SetupIconFile_win |
---|
27 | LicenseFile = 'license.txt' |
---|
28 | DisableProgramGroupPage = 'yes' |
---|
29 | Compression = 'lzma' |
---|
30 | SolidCompression = 'yes' |
---|
31 | PrivilegesRequired = 'none' |
---|
32 | INSTALLER_FILE = 'installer_new' |
---|
33 | |
---|
34 | icon_path = local_config.icon_path |
---|
35 | media_path = local_config.media_path |
---|
36 | test_path = local_config.test_path |
---|
37 | |
---|
38 | def find_extension(): |
---|
39 | """ |
---|
40 | Describe the extensions that can be read by the current application |
---|
41 | """ |
---|
42 | list_data = [] |
---|
43 | list_app =[] |
---|
44 | try: |
---|
45 | |
---|
46 | #(ext, type, name, flags) |
---|
47 | from sans.dataloader.loader import Loader |
---|
48 | wild_cards = Loader().get_wildcards() |
---|
49 | for item in wild_cards: |
---|
50 | #['All (*.*)|*.*'] |
---|
51 | file_type, ext = string.split(item, "|*", 1) |
---|
52 | if ext.strip() not in ['.*', ''] and ext.strip() not in list_data: |
---|
53 | list_data.append((ext, 'string', file_type)) |
---|
54 | except: |
---|
55 | pass |
---|
56 | try: |
---|
57 | file_type, ext = string.split(local_config.APPLICATION_WLIST, "|*", 1) |
---|
58 | if ext.strip() not in ['.', ''] and ext.strip() not in list_app: |
---|
59 | list_app.append((ext, 'string', file_type)) |
---|
60 | except: |
---|
61 | pass |
---|
62 | try: |
---|
63 | for item in local_config.PLUGINS_WLIST: |
---|
64 | file_type, ext = string.split(item, "|*", 1) |
---|
65 | if ext.strip() not in ['.', ''] and ext.strip() not in list_app: |
---|
66 | list_app.append((ext, 'string', file_type)) |
---|
67 | except: |
---|
68 | pass |
---|
69 | return list_data, list_app |
---|
70 | DATA_EXTENSION, APP_EXTENSION = find_extension() |
---|
71 | |
---|
72 | def write_registry(data_extension=None, app_extension=None): |
---|
73 | """ |
---|
74 | create file association for windows. |
---|
75 | Allow open file on double click |
---|
76 | """ |
---|
77 | msg = "" |
---|
78 | if data_extension is not None and data_extension: |
---|
79 | openwithlist = "OpenWithList\%s" % str(APPLICATION) |
---|
80 | msg = "\n\n[Registry]\n" |
---|
81 | for (ext, type, _) in data_extension: |
---|
82 | list = os.path.join(ext, openwithlist) |
---|
83 | msg += """Root: HKCR;\tSubkey: "%s";\t""" % str(list) |
---|
84 | msg += """ Flags: %s""" % str('uninsdeletekey noerror') |
---|
85 | msg += "\n" |
---|
86 | #list the file on right-click |
---|
87 | msg += """Root: HKCR; Subkey: "applications\%s\shell\open\command";\t"""\ |
---|
88 | % str(APPLICATION) |
---|
89 | msg += """ValueType: %s; """ % str('string') |
---|
90 | msg += """ValueName: "%s";\t""" %str('') |
---|
91 | msg += """ValueData: \"""{app}\%s"" ""%s1\"""; \t"""% (str(APPLICATION), |
---|
92 | str('%')) |
---|
93 | msg += """ Flags: %s""" % str('uninsdeletevalue noerror') |
---|
94 | msg += "\n" |
---|
95 | user_list = "Software\Classes" |
---|
96 | for (ext, type, _) in data_extension: |
---|
97 | list = os.path.join(user_list, ext, openwithlist) |
---|
98 | msg += """Root: HKCU;\tSubkey: "%s";\t""" % str(list) |
---|
99 | msg += """ Flags: %s""" % str('uninsdeletekey noerror') |
---|
100 | msg += "\n" |
---|
101 | #list the file on right-click |
---|
102 | user_list = os.path.join("Software", "Classes", "applications") |
---|
103 | msg += """Root: HKCU; Subkey: "%s\%s\shell\open\command";\t"""\ |
---|
104 | % (str(user_list), str(APPLICATION)) |
---|
105 | msg += """ValueType: %s; """ % str('string') |
---|
106 | msg += """ValueName: "%s";\t""" %str('') |
---|
107 | msg += """ValueData: \"""{app}\%s"" ""%s1\"""; \t"""% (str(APPLICATION), |
---|
108 | str('%')) |
---|
109 | msg += """ Flags: %s""" % str('uninsdeletevalue noerror') |
---|
110 | msg += "\n" |
---|
111 | if app_extension is not None and app_extension: |
---|
112 | for (ext, type, _) in app_extension: |
---|
113 | msg += """Root: HKCR;\tSubkey: "%s";\t""" % str(ext) |
---|
114 | msg += """ValueType: %s;\t""" % str(type) |
---|
115 | #file type empty set the current application as the default |
---|
116 | #reader for this file. change the value of file_type to another |
---|
117 | #string modify the default reader |
---|
118 | file_type = '' |
---|
119 | msg += """ValueName: "%s";\t""" % str('') |
---|
120 | msg += """ValueData: "{app}\%s";\t""" % str(APPLICATION) |
---|
121 | msg += """ Flags: %s""" % str('uninsdeletevalue noerror') |
---|
122 | msg += "\n" |
---|
123 | msg += """Root: HKCR; Subkey: "{app}\%s";\t""" % str(APPLICATION) |
---|
124 | msg += """ValueType: %s; """ % str('string') |
---|
125 | msg += """ValueName: "%s";\t""" % str('') |
---|
126 | msg += """ValueData: "{app}\%s";\t""" % str("SansView File") |
---|
127 | msg += """ Flags: %s \t""" % str("uninsdeletekey noerror") |
---|
128 | msg += "\n" |
---|
129 | |
---|
130 | #execute the file on double-click |
---|
131 | msg += """Root: HKCR; Subkey: "{app}\%s\shell\open\command";\t""" % str(APPLICATION) |
---|
132 | msg += """ValueType: %s; """ % str('string') |
---|
133 | msg += """ValueName: "%s";\t""" %str('') |
---|
134 | msg += """ValueData: \"""{app}\%s"" ""%s1\""";\t"""% (str(APPLICATION), |
---|
135 | str('%')) |
---|
136 | msg += """ Flags: %s \t""" % str("uninsdeletevalue noerror") |
---|
137 | msg += "\n" |
---|
138 | #create default icon |
---|
139 | msg += """Root: HKCR; Subkey: "{app}\%s";\t""" % str(SetupIconFile) |
---|
140 | msg += """ValueType: %s; """ % str('string') |
---|
141 | msg += """ValueName: "%s";\t""" % str('') |
---|
142 | msg += """ValueData: "{app}\%s,0";\t""" % str(APPLICATION) |
---|
143 | msg += """ Flags: %s \t""" % str("uninsdeletevalue noerror") |
---|
144 | msg += "\n" |
---|
145 | |
---|
146 | |
---|
147 | #SANSVIEWPATH |
---|
148 | msg += """Root: HKLM; Subkey: "%s";\t""" % str('SYSTEM\CurrentControlSet\Control\Session Manager\Environment') |
---|
149 | msg += """ValueType: %s; """ % str('expandsz') |
---|
150 | msg += """ValueName: "%s";\t""" % str('SANSVIEWPATH') |
---|
151 | msg += """ValueData: "{app}";\t""" |
---|
152 | msg += """ Flags: %s""" % str('uninsdeletevalue noerror') |
---|
153 | msg += "\n" |
---|
154 | |
---|
155 | #PATH |
---|
156 | msg += """; Write to PATH (below) is disabled; need more tests\n""" |
---|
157 | msg += """;Root: HKCU; Subkey: "%s";\t""" % str('Environment') |
---|
158 | msg += """ValueType: %s; """ % str('expandsz') |
---|
159 | msg += """ValueName: "%s";\t""" % str('PATH') |
---|
160 | msg += """ValueData: "%s;{olddata}";\t""" % str('%SANSVIEWPATH%') |
---|
161 | msg += """ Check: %s""" % str('NeedsAddPath()') |
---|
162 | msg += "\n" |
---|
163 | |
---|
164 | return msg |
---|
165 | |
---|
166 | def write_language(language=['english'], msfile="compiler:Default.isl"): |
---|
167 | """ |
---|
168 | define the language of the application |
---|
169 | """ |
---|
170 | msg = '' |
---|
171 | if language: |
---|
172 | msg = "\n\n[Languages]\n" |
---|
173 | for lang in language: |
---|
174 | msg += """Name: "%s";\tMessagesFile: "%s"\n""" % (str(lang), |
---|
175 | str(msfile)) |
---|
176 | return msg |
---|
177 | |
---|
178 | def write_tasks(): |
---|
179 | """ |
---|
180 | create desktop icon |
---|
181 | """ |
---|
182 | msg = """\n\n[Tasks]\n""" |
---|
183 | msg += """Name: "desktopicon";\tDescription: "{cm:CreateDesktopIcon}";\t""" |
---|
184 | msg += """GroupDescription: "{cm:AdditionalIcons}";\tFlags: unchecked\n""" |
---|
185 | return msg |
---|
186 | |
---|
187 | dist_path = "dist" |
---|
188 | def write_file(): |
---|
189 | """ |
---|
190 | copy some data files |
---|
191 | """ |
---|
192 | msg = "\n\n[Files]\n" |
---|
193 | msg += """Source: "%s\%s";\t""" % (dist_path, str(APPLICATION)) |
---|
194 | msg += """DestDir: "{app}";\tFlags: ignoreversion\n""" |
---|
195 | msg += """Source: "dist\*";\tDestDir: "{app}";\t""" |
---|
196 | msg += """Flags: ignoreversion recursesubdirs createallsubdirs\n""" |
---|
197 | msg += """Source: "%s\*";\tDestDir: "{app}\%s";\t""" % (str(icon_path), str("images")) |
---|
198 | msg += """Flags: ignoreversion recursesubdirs createallsubdirs\n""" |
---|
199 | msg += """Source: "%s\*";\tDestDir: "{app}\%s";\t""" % (str(test_path), str("test")) |
---|
200 | msg += """Flags: ignoreversion recursesubdirs createallsubdirs\n""" |
---|
201 | msg += """Source: "%s\*";\tDestDir: "{app}\%s";\t""" % (str(media_path), str("media")) |
---|
202 | msg += """Flags: ignoreversion recursesubdirs createallsubdirs\n""" |
---|
203 | msg += """;\tNOTE: Don't use "Flags: ignoreversion" on any shared system files""" |
---|
204 | return msg |
---|
205 | |
---|
206 | def write_icon(): |
---|
207 | """ |
---|
208 | Create application icon |
---|
209 | """ |
---|
210 | msg = """\n\n[Icons]\n""" |
---|
211 | msg += """Name: "{group}\%s";\t""" % str(AppName) |
---|
212 | msg += """Filename: "{app}\%s";\t""" % str(APPLICATION) |
---|
213 | msg += """WorkingDir: "{app}" \n""" |
---|
214 | msg += """Name: "{group}\{cm:UninstallProgram, %s}";\t""" % str(AppName) |
---|
215 | msg += """ Filename: "{uninstallexe}" \n""" |
---|
216 | msg += """Name: "{commondesktop}\%s";\t""" % str(AppVerName) |
---|
217 | msg += """Filename: "{app}\%s";\t""" % str(APPLICATION) |
---|
218 | msg += """Tasks: desktopicon; WorkingDir: "{app}" \n""" |
---|
219 | return msg |
---|
220 | |
---|
221 | def write_run(): |
---|
222 | """ |
---|
223 | execute some file |
---|
224 | """ |
---|
225 | msg = """\n\n[Run]\n""" |
---|
226 | msg += """Filename: "{app}\%s";\t""" % str(APPLICATION) |
---|
227 | msg += """Description: "{cm:LaunchProgram, %s}";\t""" %str(AppName) |
---|
228 | msg += """Flags: nowait postinstall skipifsilent\n""" |
---|
229 | return msg |
---|
230 | |
---|
231 | def write_code(): |
---|
232 | """ |
---|
233 | Code that checks the existing path and snaviewpath |
---|
234 | in the environmental viriables/PATH |
---|
235 | """ |
---|
236 | msg = """\n\n[Code]\n""" |
---|
237 | msg += """function NeedsAddPath(): boolean;\n""" |
---|
238 | msg += """var\n""" |
---|
239 | msg += """ oldpath: string;\n""" |
---|
240 | msg += """ newpath: string;\n""" |
---|
241 | msg += """ pathArr: TArrayOfString;\n""" |
---|
242 | msg += """ i: Integer;\n""" |
---|
243 | msg += """begin\n""" |
---|
244 | msg += """ RegQueryStringValue(HKEY_CURRENT_USER,'Environment',""" |
---|
245 | msg += """'PATH', oldpath)\n""" |
---|
246 | msg += """ oldpath := oldpath + ';';\n""" |
---|
247 | msg += """ newpath := '%SANSVIEWPATH%';\n""" |
---|
248 | msg += """ i := 0;\n""" |
---|
249 | msg += """ while (Pos(';', oldpath) > 0) do begin\n""" |
---|
250 | msg += """ SetArrayLength(pathArr, i+1);\n""" |
---|
251 | msg += """ pathArr[i] := Copy(oldpath, 0, Pos(';', oldpath)-1);\n""" |
---|
252 | msg += """ oldpath := Copy(oldpath, Pos(';', oldpath)+1,""" |
---|
253 | msg += """ Length(oldpath));\n""" |
---|
254 | msg += """ i := i + 1;\n""" |
---|
255 | msg += """ // Check if current directory matches app dir\n""" |
---|
256 | msg += """ if newpath = pathArr[i-1] \n""" |
---|
257 | msg += """ then begin\n""" |
---|
258 | msg += """ Result := False;\n""" |
---|
259 | msg += """ exit;\n""" |
---|
260 | msg += """ end;\n""" |
---|
261 | msg += """ end;\n""" |
---|
262 | msg += """ Result := True;\n""" |
---|
263 | msg += """end;\n""" |
---|
264 | msg += """\n""" |
---|
265 | |
---|
266 | |
---|
267 | |
---|
268 | |
---|
269 | return msg |
---|
270 | |
---|
271 | |
---|
272 | if __name__ == "__main__": |
---|
273 | TEMPLATE = "\n; Script generated by the Inno Setup Script Wizard\n" |
---|
274 | TEMPLATE += "\n; and local_config.py located in this directory.\n " |
---|
275 | TEMPLATE += "; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!" |
---|
276 | TEMPLATE += "\n[Setup]\n\n" |
---|
277 | TEMPLATE += "ChangesAssociations=%s\n" %str('yes') |
---|
278 | TEMPLATE += "AppName=%s\n" % str(AppName) |
---|
279 | TEMPLATE += "AppVerName=%s\n" % str(AppVerName) |
---|
280 | TEMPLATE += "AppPublisher=%s\n" % str(AppPublisher) |
---|
281 | TEMPLATE += "AppPublisherURL=%s\n" % str(AppPublisherURL) |
---|
282 | TEMPLATE += "AppSupportURL=%s\n" % str(AppSupportURL) |
---|
283 | TEMPLATE += "AppUpdatesURL=%s \n" % str(AppUpdatesURL) |
---|
284 | TEMPLATE += "ChangesEnvironment=%s \n" % str(ChangesEnvironment) |
---|
285 | TEMPLATE += "DefaultDirName=%s\n" % str(DefaultDirName) |
---|
286 | TEMPLATE += "DefaultGroupName=%s\n" % str(DefaultGroupName) |
---|
287 | TEMPLATE += "DisableProgramGroupPage=%s\n" % str(DisableProgramGroupPage) |
---|
288 | TEMPLATE += "LicenseFile=%s\n" % str(LicenseFile) |
---|
289 | TEMPLATE += "OutputBaseFilename=%s\n" % str(OutputBaseFilename) |
---|
290 | TEMPLATE += "SetupIconFile=%s\n" % str(SetupIconFile) |
---|
291 | TEMPLATE += "Compression=%s\n" % str(Compression) |
---|
292 | TEMPLATE += "SolidCompression=%s\n" % str(SolidCompression) |
---|
293 | TEMPLATE += "PrivilegesRequired=%s\n" % str(PrivilegesRequired) |
---|
294 | |
---|
295 | TEMPLATE += write_registry(data_extension=DATA_EXTENSION, |
---|
296 | app_extension=APP_EXTENSION) |
---|
297 | TEMPLATE += write_language() |
---|
298 | TEMPLATE += write_tasks() |
---|
299 | TEMPLATE += write_file() |
---|
300 | TEMPLATE += write_icon() |
---|
301 | TEMPLATE += write_run() |
---|
302 | TEMPLATE += write_code() |
---|
303 | path = '%s.iss' % str(INSTALLER_FILE) |
---|
304 | f = open(path,'w') |
---|
305 | f.write(TEMPLATE) |
---|
306 | f.close() |
---|
307 | print "Generate Inno setup installer script complete" |
---|
308 | print "A new file %s.iss should be created.Please refresh your directory" % str(INSTALLER_FILE) |
---|