source: sasview/sasview/installer_generator.py @ f9fbe99

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 f9fbe99 was 6a698c0, checked in by Paul Kienzle <pkienzle@…>, 8 years ago

refactor support for precompiled models in windows

  • Property mode set to 100644
File size: 16.2 KB
RevLine 
[fa597990]1"""
[5c3aafa]2This module generates .iss file according to the local config of
[fa597990]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'
[50282f8]12AppName = str(local_config.__appname__ )
[fa597990]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
[aade98e]26SetupIconFile = "images\\ball.ico"
[fa597990]27LicenseFile = 'license.txt'
28DisableProgramGroupPage = 'yes'
29Compression = 'lzma'
30SolidCompression = 'yes'
31PrivilegesRequired = 'none'
[e040eb1b]32INSTALLER_FILE = 'installer'
[fa597990]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    """
[50282f8]42    list_data = []
43    list_app =[]
[fa597990]44    try:
[50282f8]45       
[fa597990]46        #(ext, type, name, flags)
[b699768]47        from sas.sascalc.dataloader.loader import Loader
[fa597990]48        wild_cards = Loader().get_wildcards()
49        for item in wild_cards:
50            #['All (*.*)|*.*']
51            file_type, ext = string.split(item, "|*", 1)
[50282f8]52            if ext.strip() not in ['.*', ''] and ext.strip() not in list_data:
53                list_data.append((ext, 'string', file_type))
[fa597990]54    except:
55        pass
56    try:
57        file_type, ext = string.split(local_config.APPLICATION_WLIST, "|*", 1)
[50282f8]58        if ext.strip() not in ['.', ''] and ext.strip() not in list_app:
59            list_app.append((ext, 'string', file_type))
[fa597990]60    except:
61        pass
62    try:
63        for item in local_config.PLUGINS_WLIST:
64            file_type, ext = string.split(item, "|*", 1)
[50282f8]65            if ext.strip() not in ['.', ''] and ext.strip() not in list_app:
66                list_app.append((ext, 'string', file_type)) 
[fa597990]67    except:
68        pass
[50282f8]69    return list_data, list_app
70DATA_EXTENSION, APP_EXTENSION = find_extension()
71
72def write_registry(data_extension=None, app_extension=None):
[fa597990]73    """
74    create file association for windows.
75    Allow open file on double click
76    """
77    msg = ""
[50282f8]78    if data_extension is not None and data_extension:
79        openwithlist = "OpenWithList\%s" % str(APPLICATION)
[fa597990]80        msg = "\n\n[Registry]\n"
[50282f8]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")
[c648414]103        msg += """Root: HKCU; Subkey: "%s\%s\shell\open\command";\t"""\
[50282f8]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:
[fa597990]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)
[dd16ad6]121            msg += """ Flags: %s""" % str('uninsdeletevalue  noerror')
[fa597990]122            msg += "\n"
[50282f8]123    msg += """Root: HKCR; Subkey: "{app}\%s";\t""" % str(APPLICATION)
124    msg += """ValueType: %s; """ % str('string')
125    msg += """ValueName: "%s";\t""" % str('') 
[c329f4d]126    msg += """ValueData: "{app}\%s";\t""" % str("SasView File") 
[dd16ad6]127    msg += """ Flags: %s \t""" % str("uninsdeletekey  noerror")
[50282f8]128    msg += "\n"
[fa597990]129       
[50282f8]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('') 
[dd16ad6]142    msg += """ValueData: "{app}\%s,0";\t""" % str(APPLICATION)
143    msg += """ Flags: %s \t""" % str("uninsdeletevalue noerror")
144    msg += "\n" 
[50282f8]145
146   
[3a39c2e]147    #SASVIEWPATH
[50282f8]148    msg += """Root: HKLM; Subkey: "%s";\t"""  %  str('SYSTEM\CurrentControlSet\Control\Session Manager\Environment')
149    msg += """ValueType: %s; """ % str('expandsz')
[3a39c2e]150    msg += """ValueName: "%s";\t""" % str('SASVIEWPATH') 
[50282f8]151    msg += """ValueData: "{app}";\t"""
[dd16ad6]152    msg += """ Flags: %s""" % str('uninsdeletevalue noerror')
[50282f8]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') 
[3a39c2e]160    msg += """ValueData: "%s;{olddata}";\t""" % str('%SASVIEWPATH%')
[50282f8]161    msg += """ Check: %s""" % str('NeedsAddPath()')
162    msg += "\n"
[fa597990]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"""
[aade98e]185    msg += """Name: "quicklaunchicon"; Description: "{cm:CreateQuickLaunchIcon}";\t"""
186    msg += """GroupDescription: "{cm:AdditionalIcons}";\n"""
[fa597990]187    return msg
188
[50282f8]189dist_path = "dist"
[fa597990]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"""
[ddf571d]199    msg += """Source: "dist\plugin_models\*";\tDestDir: "{userdesktop}\..\.sasview\plugin_models";\t"""
200    msg += """Flags: recursesubdirs createallsubdirs\n""" 
[6a698c0]201    msg += """Source: "dist\compiled_models\*";\tDestDir: "{userdesktop}\..\.sasmodels\compiled_models";\t"""
[aade98e]202    msg += """Flags: recursesubdirs createallsubdirs\n"""
[0f382d7]203    msg += """Source: "dist\config\custom_config.py";\tDestDir: "{userdesktop}\..\.sasview\config";\t""" 
[aade98e]204    msg += """Flags: recursesubdirs createallsubdirs\n"""
[27b7acc]205    msg += """Source: "dist\default_categories.json";    DestDir: "{userdesktop}\..\.sasview";\t""" 
[50008e3]206    msg += """DestName: "categories.json";\n"""
[fa597990]207    msg += """;\tNOTE: Don't use "Flags: ignoreversion" on any shared system files"""
208    return msg
209
210def write_icon():
211    """
212    Create application icon
213    """
214    msg = """\n\n[Icons]\n"""
215    msg += """Name: "{group}\%s";\t""" % str(AppName)
216    msg += """Filename: "{app}\%s";\t"""  % str(APPLICATION)
[aade98e]217    msg += """WorkingDir: "{app}"; IconFilename: "{app}\images\\ball.ico" \n"""
[fa597990]218    msg += """Name: "{group}\{cm:UninstallProgram, %s}";\t""" % str(AppName)
219    msg += """ Filename: "{uninstallexe}" \n"""
220    msg += """Name: "{commondesktop}\%s";\t""" % str(AppVerName)
221    msg += """Filename: "{app}\%s";\t""" % str(APPLICATION)
[aade98e]222    msg += """Tasks: desktopicon; WorkingDir: "{app}" ; IconFilename: "{app}\images\\ball.ico" \n"""
223    msg += """Name: "{userappdata}\Microsoft\Internet Explorer\Quick Launch\%s";\t""" % str(AppVerName)
224    msg += """Filename: "{app}\%s";\t""" % str(APPLICATION)
225    msg += """Tasks: quicklaunchicon; WorkingDir: "{app}"; IconFilename: "{app}\images\\ball.ico" \n"""
[fa597990]226    return msg
227
228def write_run():
229    """
230    execute some file
231    """
232    msg = """\n\n[Run]\n"""
233    msg += """Filename: "{app}\%s";\t""" % str(APPLICATION)
234    msg += """Description: "{cm:LaunchProgram, %s}";\t""" %str(AppName) 
235    msg += """Flags: nowait postinstall skipifsilent\n"""
[aade98e]236    msg += """; Install the Microsoft C++ DLL redistributable package if it is """
237    msg += """provided and the DLLs are not present on the target system.\n"""
238    msg += """; Note that the redistributable package is included if the app was """
239    msg += """built using Python 2.6 or 2.7, but not with 2.5.\n"""
240    msg += """; Parameter options:\n"""
241    msg += """; - for silent install use: "/q"\n"""
242    msg += """; - for silent install with progress bar use: "/qb"\n"""
243    msg += """; - for silent install with progress bar but disallow """
244    msg += """cancellation of operation use: "/qb!"\n"""
245    msg += """; Note that we do not use the postinstall flag as this would """
246    msg += """display a checkbox and thus require the user to decide what to do.\n"""
247    msg += """;Filename: "{app}\\vcredist_x86.exe"; Parameters: "/qb!"; """
248    msg += """WorkingDir: "{tmp}"; StatusMsg: "Installing Microsoft Visual """
249    msg += """C++ 2008 Redistributable Package ..."; Check: InstallVC90CRT(); """
250    msg += """Flags: skipifdoesntexist waituntilterminated\n"""
[fa597990]251    return msg
252
[e7281fd]253def write_dirs():
254    """
255    Define Dir permission
256    """
257    msg = """\n\n[Dirs]\n"""
258    msg += """Name: "{app}\%s";\t""" % str('')
259    msg += """Permissions: everyone-modify\t""" 
260    msg += """\n""" 
261    return msg
262
[fa597990]263def write_code():
264    """
265    Code that checks the existing path and snaviewpath
266    in the environmental viriables/PATH
267    """
268    msg = """\n\n[Code]\n"""
[aade98e]269    msg += """function InstallVC90CRT(): Boolean;\n""" 
270    msg += """begin\n"""
271    msg += """    Result := not DirExists('C:\WINDOWS\WinSxS\\x86_Microsoft.VC90."""
272    msg += """CRT_1fc8b3b9a1e18e3b_9.0.21022.8_x-ww_d08d0375');\n"""
273    msg += """end;\n\n"""
[fa597990]274    msg += """function NeedsAddPath(): boolean;\n""" 
275    msg += """var\n""" 
276    msg += """  oldpath: string;\n"""
277    msg += """  newpath: string;\n""" 
278    msg += """  pathArr:    TArrayOfString;\n""" 
279    msg += """  i:        Integer;\n""" 
280    msg += """begin\n""" 
281    msg += """  RegQueryStringValue(HKEY_CURRENT_USER,'Environment',"""
282    msg += """'PATH', oldpath)\n"""
283    msg += """  oldpath := oldpath + ';';\n"""
[3a39c2e]284    msg += """  newpath := '%SASVIEWPATH%';\n"""
[fa597990]285    msg += """  i := 0;\n"""
286    msg += """  while (Pos(';', oldpath) > 0) do begin\n"""
287    msg += """    SetArrayLength(pathArr, i+1);\n"""
288    msg += """    pathArr[i] := Copy(oldpath, 0, Pos(';', oldpath)-1);\n"""
289    msg += """    oldpath := Copy(oldpath, Pos(';', oldpath)+1,"""
290    msg += """ Length(oldpath));\n"""
291    msg += """    i := i + 1;\n"""
292    msg += """    // Check if current directory matches app dir\n"""
293    msg += """    if newpath = pathArr[i-1] \n"""
294    msg += """    then begin\n"""
295    msg += """      Result := False;\n"""
296    msg += """      exit;\n"""
297    msg += """    end;\n"""
298    msg += """  end;\n"""
299    msg += """  Result := True;\n"""
300    msg += """end;\n"""
301    msg += """\n"""
302    return msg
303
[aade98e]304def write_uninstalldelete():
305    """
306    Define uninstalldelete
307    """
308    msg = """\n[UninstallDelete]\n"""
309    msg += """; Delete directories and files that are dynamically created by """
310    msg += """the application (i.e. at runtime).\n"""
311    msg += """Type: filesandordirs; Name: "{app}\.matplotlib"\n"""
312    msg += """Type: files; Name: "{app}\*.*"\n"""
313    msg += """; The following is a workaround for the case where the """
314    msg += """application is installed and uninstalled but the\n"""
315    msg += """;{app} directory is not deleted because it has user files.  """
316    msg += """Then the application is installed into the\n"""
317    msg += """; existing directory, user files are deleted, and the """
318    msg += """application is un-installed again.  Without the\n"""
319    msg += """; directive below, {app} will not be deleted because Inno Setup """
320    msg += """did not create it during the previous\n"""
321    msg += """; installation.\n"""
322    msg += """Type: dirifempty; Name: "{app}"\n"""
323    msg += """\n""" 
324    return msg
[fa597990]325
[d73a274]326def generate_installer():
327    """
328    """
[fa597990]329    TEMPLATE = "\n; Script generated by the Inno Setup Script Wizard\n"
330    TEMPLATE += "\n; and local_config.py located in this directory.\n "
331    TEMPLATE += "; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!"
332    TEMPLATE += "\n[Setup]\n\n" 
333    TEMPLATE += "ChangesAssociations=%s\n" %str('yes')
334    TEMPLATE += "AppName=%s\n" % str(AppName)
335    TEMPLATE += "AppVerName=%s\n" % str(AppVerName)
336    TEMPLATE += "AppPublisher=%s\n" % str(AppPublisher)
337    TEMPLATE += "AppPublisherURL=%s\n" % str(AppPublisherURL)
338    TEMPLATE += "AppSupportURL=%s\n" % str(AppSupportURL)
339    TEMPLATE += "AppUpdatesURL=%s \n" % str(AppUpdatesURL)
340    TEMPLATE += "ChangesEnvironment=%s \n" % str(ChangesEnvironment)
341    TEMPLATE += "DefaultDirName=%s\n" % str(DefaultDirName)
342    TEMPLATE += "DefaultGroupName=%s\n" % str(DefaultGroupName)
343    TEMPLATE += "DisableProgramGroupPage=%s\n" % str(DisableProgramGroupPage)
344    TEMPLATE += "LicenseFile=%s\n" % str(LicenseFile)
345    TEMPLATE += "OutputBaseFilename=%s\n" % str(OutputBaseFilename)
346    TEMPLATE += "SetupIconFile=%s\n" % str(SetupIconFile)
347    TEMPLATE += "Compression=%s\n" % str(Compression)
348    TEMPLATE += "SolidCompression=%s\n" % str(SolidCompression)
349    TEMPLATE += "PrivilegesRequired=%s\n" % str(PrivilegesRequired)
[e3ef8dd4]350    TEMPLATE += "UsePreviousAppDir=no\n"
[fa597990]351   
[50282f8]352    TEMPLATE += write_registry(data_extension=DATA_EXTENSION,
353                                app_extension=APP_EXTENSION)
[fa597990]354    TEMPLATE += write_language()
355    TEMPLATE += write_tasks()
356    TEMPLATE += write_file()
357    TEMPLATE += write_icon()
358    TEMPLATE += write_run()
[e7281fd]359    TEMPLATE += write_dirs()
[fa597990]360    TEMPLATE += write_code()
[aade98e]361    TEMPLATE += write_uninstalldelete()
[fa597990]362    path = '%s.iss' % str(INSTALLER_FILE)
363    f = open(path,'w') 
364    f.write(TEMPLATE)
365    f.close()
366    print "Generate Inno setup installer script complete"
[d73a274]367    print "A new file %s.iss should be created.Please refresh your directory" % str(INSTALLER_FILE)
368   
369if __name__ == "__main__":
370    generate_installer()
Note: See TracBrowser for help on using the repository browser.