source: sasview/sansview/installer_generator.py @ 6e10cff

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since 6e10cff was aade98e, checked in by Jae Cho <jhjcho@…>, 13 years ago

updated iss generator

  • Property mode set to 100644
File size: 15.8 KB
Line 
1"""
2This module generates .ss file according to the local config of
3the current application. Please make sure a file named "local_config.py"
4exists in the current directory. Edit local_config.py according to your needs.
5"""
6import local_config
7import os 
8import string
9
10REG_PROGRAM = """{app}\MYPROG.EXE"" ""%1"""
11APPLICATION = str(local_config.__appname__ )+ '.exe'
12AppName = str(local_config.__appname__ )
13AppVerName = str(local_config.__appname__ )+'-'+ str(local_config.__version__)
14Dev = ''
15if AppVerName.lower().count('dev') > 0:
16    Dev = '-Dev'
17AppPublisher = local_config._copyright
18AppPublisherURL = local_config._homepage
19AppSupportURL = local_config._homepage
20AppUpdatesURL = local_config._homepage
21ChangesEnvironment = 'true'
22DefaultDirName = os.path.join("{pf}" , AppName+Dev) 
23DefaultGroupName = os.path.join(local_config.DefaultGroupName, AppVerName)
24                               
25OutputBaseFilename = local_config.OutputBaseFilename
26SetupIconFile = "images\\ball.ico"
27LicenseFile = 'license.txt'
28DisableProgramGroupPage = 'yes'
29Compression = 'lzma'
30SolidCompression = 'yes'
31PrivilegesRequired = 'none'
32INSTALLER_FILE = 'installer_new'
33
34icon_path =  local_config.icon_path
35media_path = local_config.media_path
36test_path = local_config.test_path
37
38def 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
70DATA_EXTENSION, APP_EXTENSION = find_extension()
71
72def 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
166def 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
178def 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    msg += """Name: "quicklaunchicon"; Description: "{cm:CreateQuickLaunchIcon}";\t"""
186    msg += """GroupDescription: "{cm:AdditionalIcons}";\n"""
187    return msg
188
189dist_path = "dist"
190def write_file():
191    """
192    copy some data files
193    """
194    msg = "\n\n[Files]\n"
195    msg += """Source: "%s\%s";\t""" % (dist_path, str(APPLICATION))
196    msg += """DestDir: "{app}";\tFlags: ignoreversion\n"""
197    msg += """Source: "dist\*";\tDestDir: "{app}";\t"""
198    msg += """Flags: ignoreversion recursesubdirs createallsubdirs\n"""
199    msg += """Source: "dist\plugin_models\*";\tDestDir: "{userappdata}\..\.sansview\plugin_models";\t""" 
200    msg += """Flags: recursesubdirs createallsubdirs\n"""
201    msg += """Source: "dist\config\custom_config.py";\tDestDir: "{userappdata}\..\.sansview\config";\t""" 
202    msg += """Flags: recursesubdirs createallsubdirs\n"""
203    msg += """;\tNOTE: Don't use "Flags: ignoreversion" on any shared system files"""
204    return msg
205
206def 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}"; IconFilename: "{app}\images\\ball.ico" \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}" ; IconFilename: "{app}\images\\ball.ico" \n"""
219    msg += """Name: "{userappdata}\Microsoft\Internet Explorer\Quick Launch\%s";\t""" % str(AppVerName)
220    msg += """Filename: "{app}\%s";\t""" % str(APPLICATION)
221    msg += """Tasks: quicklaunchicon; WorkingDir: "{app}"; IconFilename: "{app}\images\\ball.ico" \n"""
222    return msg
223
224def write_run():
225    """
226    execute some file
227    """
228    msg = """\n\n[Run]\n"""
229    msg += """Filename: "{app}\%s";\t""" % str(APPLICATION)
230    msg += """Description: "{cm:LaunchProgram, %s}";\t""" %str(AppName) 
231    msg += """Flags: nowait postinstall skipifsilent\n"""
232    msg += """; Install the Microsoft C++ DLL redistributable package if it is """
233    msg += """provided and the DLLs are not present on the target system.\n"""
234    msg += """; Note that the redistributable package is included if the app was """
235    msg += """built using Python 2.6 or 2.7, but not with 2.5.\n"""
236    msg += """; Parameter options:\n"""
237    msg += """; - for silent install use: "/q"\n"""
238    msg += """; - for silent install with progress bar use: "/qb"\n"""
239    msg += """; - for silent install with progress bar but disallow """
240    msg += """cancellation of operation use: "/qb!"\n"""
241    msg += """; Note that we do not use the postinstall flag as this would """
242    msg += """display a checkbox and thus require the user to decide what to do.\n"""
243    msg += """;Filename: "{app}\\vcredist_x86.exe"; Parameters: "/qb!"; """
244    msg += """WorkingDir: "{tmp}"; StatusMsg: "Installing Microsoft Visual """
245    msg += """C++ 2008 Redistributable Package ..."; Check: InstallVC90CRT(); """
246    msg += """Flags: skipifdoesntexist waituntilterminated\n"""
247    return msg
248
249def write_dirs():
250    """
251    Define Dir permission
252    """
253    msg = """\n\n[Dirs]\n"""
254    msg += """Name: "{app}\%s";\t""" % str('')
255    msg += """Permissions: everyone-modify\t""" 
256    msg += """\n""" 
257    return msg
258
259def write_code():
260    """
261    Code that checks the existing path and snaviewpath
262    in the environmental viriables/PATH
263    """
264    msg = """\n\n[Code]\n"""
265    msg += """function InstallVC90CRT(): Boolean;\n""" 
266    msg += """begin\n"""
267    msg += """    Result := not DirExists('C:\WINDOWS\WinSxS\\x86_Microsoft.VC90."""
268    msg += """CRT_1fc8b3b9a1e18e3b_9.0.21022.8_x-ww_d08d0375');\n"""
269    msg += """end;\n\n"""
270    msg += """function NeedsAddPath(): boolean;\n""" 
271    msg += """var\n""" 
272    msg += """  oldpath: string;\n"""
273    msg += """  newpath: string;\n""" 
274    msg += """  pathArr:    TArrayOfString;\n""" 
275    msg += """  i:        Integer;\n""" 
276    msg += """begin\n""" 
277    msg += """  RegQueryStringValue(HKEY_CURRENT_USER,'Environment',"""
278    msg += """'PATH', oldpath)\n"""
279    msg += """  oldpath := oldpath + ';';\n"""
280    msg += """  newpath := '%SANSVIEWPATH%';\n"""
281    msg += """  i := 0;\n"""
282    msg += """  while (Pos(';', oldpath) > 0) do begin\n"""
283    msg += """    SetArrayLength(pathArr, i+1);\n"""
284    msg += """    pathArr[i] := Copy(oldpath, 0, Pos(';', oldpath)-1);\n"""
285    msg += """    oldpath := Copy(oldpath, Pos(';', oldpath)+1,"""
286    msg += """ Length(oldpath));\n"""
287    msg += """    i := i + 1;\n"""
288    msg += """    // Check if current directory matches app dir\n"""
289    msg += """    if newpath = pathArr[i-1] \n"""
290    msg += """    then begin\n"""
291    msg += """      Result := False;\n"""
292    msg += """      exit;\n"""
293    msg += """    end;\n"""
294    msg += """  end;\n"""
295    msg += """  Result := True;\n"""
296    msg += """end;\n"""
297    msg += """\n"""
298    return msg
299
300def write_uninstalldelete():
301    """
302    Define uninstalldelete
303    """
304    msg = """\n[UninstallDelete]\n"""
305    msg += """; Delete directories and files that are dynamically created by """
306    msg += """the application (i.e. at runtime).\n"""
307    msg += """Type: filesandordirs; Name: "{app}\.matplotlib"\n"""
308    msg += """Type: files; Name: "{app}\*.*"\n"""
309    msg += """; The following is a workaround for the case where the """
310    msg += """application is installed and uninstalled but the\n"""
311    msg += """;{app} directory is not deleted because it has user files.  """
312    msg += """Then the application is installed into the\n"""
313    msg += """; existing directory, user files are deleted, and the """
314    msg += """application is un-installed again.  Without the\n"""
315    msg += """; directive below, {app} will not be deleted because Inno Setup """
316    msg += """did not create it during the previous\n"""
317    msg += """; installation.\n"""
318    msg += """Type: dirifempty; Name: "{app}"\n"""
319    msg += """\n""" 
320    return msg
321
322if __name__ == "__main__":
323    TEMPLATE = "\n; Script generated by the Inno Setup Script Wizard\n"
324    TEMPLATE += "\n; and local_config.py located in this directory.\n "
325    TEMPLATE += "; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!"
326    TEMPLATE += "\n[Setup]\n\n" 
327    TEMPLATE += "ChangesAssociations=%s\n" %str('yes')
328    TEMPLATE += "AppName=%s\n" % str(AppName)
329    TEMPLATE += "AppVerName=%s\n" % str(AppVerName)
330    TEMPLATE += "AppPublisher=%s\n" % str(AppPublisher)
331    TEMPLATE += "AppPublisherURL=%s\n" % str(AppPublisherURL)
332    TEMPLATE += "AppSupportURL=%s\n" % str(AppSupportURL)
333    TEMPLATE += "AppUpdatesURL=%s \n" % str(AppUpdatesURL)
334    TEMPLATE += "ChangesEnvironment=%s \n" % str(ChangesEnvironment)
335    TEMPLATE += "DefaultDirName=%s\n" % str(DefaultDirName)
336    TEMPLATE += "DefaultGroupName=%s\n" % str(DefaultGroupName)
337    TEMPLATE += "DisableProgramGroupPage=%s\n" % str(DisableProgramGroupPage)
338    TEMPLATE += "LicenseFile=%s\n" % str(LicenseFile)
339    TEMPLATE += "OutputBaseFilename=%s\n" % str(OutputBaseFilename)
340    TEMPLATE += "SetupIconFile=%s\n" % str(SetupIconFile)
341    TEMPLATE += "Compression=%s\n" % str(Compression)
342    TEMPLATE += "SolidCompression=%s\n" % str(SolidCompression)
343    TEMPLATE += "PrivilegesRequired=%s\n" % str(PrivilegesRequired)
344   
345    TEMPLATE += write_registry(data_extension=DATA_EXTENSION,
346                                app_extension=APP_EXTENSION)
347    TEMPLATE += write_language()
348    TEMPLATE += write_tasks()
349    TEMPLATE += write_file()
350    TEMPLATE += write_icon()
351    TEMPLATE += write_run()
352    TEMPLATE += write_dirs()
353    TEMPLATE += write_code()
354    TEMPLATE += write_uninstalldelete()
355    path = '%s.iss' % str(INSTALLER_FILE)
356    f = open(path,'w') 
357    f.write(TEMPLATE)
358    f.close()
359    print "Generate Inno setup installer script complete"
360    print "A new file %s.iss should be created.Please refresh your directory" % str(INSTALLER_FILE)
Note: See TracBrowser for help on using the repository browser.