source: sasview/sasview/installer_generator.py @ aaf5e49

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.2.2ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since aaf5e49 was a1b8fee, checked in by andyfaff, 7 years ago

MAINT: from future import print_function

  • Property mode set to 100644
File size: 15.9 KB
Line 
1"""
2This module generates .iss 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"""
6from __future__ import print_function
7
8import local_config
9import os 
10import string
11
12
13REG_PROGRAM = """{app}\MYPROG.EXE"" ""%1"""
14APPLICATION = str(local_config.__appname__ )+ '.exe'
15AppName = str(local_config.__appname__ )
16AppVerName = str(local_config.__appname__ )+'-'+ str(local_config.__version__)
17Dev = ''
18if AppVerName.lower().count('dev') > 0:
19    Dev = '-Dev'
20AppPublisher = local_config._copyright
21AppPublisherURL = local_config._homepage
22AppSupportURL = local_config._homepage
23AppUpdatesURL = local_config._homepage
24ChangesEnvironment = 'true'
25DefaultDirName = os.path.join("{pf}" , AppName+Dev) 
26DefaultGroupName = os.path.join(local_config.DefaultGroupName, AppVerName)
27                               
28OutputBaseFilename = local_config.OutputBaseFilename
29SetupIconFile = "images\\ball.ico"
30LicenseFile = 'license.txt'
31DisableProgramGroupPage = 'yes'
32Compression = 'lzma'
33SolidCompression = 'yes'
34PrivilegesRequired = 'none'
35INSTALLER_FILE = 'installer'
36
37icon_path =  local_config.icon_path
38media_path = local_config.media_path
39test_path = local_config.test_path
40
41def find_extension():
42    """
43    Describe the extensions that can be read by the current application
44    """
45    list_data = []
46    list_app =[]
47    try:
48       
49        #(ext, type, name, flags)
50        from sas.sascalc.dataloader.loader import Loader
51        wild_cards = Loader().get_wildcards()
52        for item in wild_cards:
53            #['All (*.*)|*.*']
54            file_type, ext = string.split(item, "|*", 1)
55            if ext.strip() not in ['.*', ''] and ext.strip() not in list_data:
56                list_data.append((ext, 'string', file_type))
57    except:
58        pass
59    try:
60        file_type, ext = string.split(local_config.APPLICATION_WLIST, "|*", 1)
61        if ext.strip() not in ['.', ''] and ext.strip() not in list_app:
62            list_app.append((ext, 'string', file_type))
63    except:
64        pass
65    try:
66        for item in local_config.PLUGINS_WLIST:
67            file_type, ext = string.split(item, "|*", 1)
68            if ext.strip() not in ['.', ''] and ext.strip() not in list_app:
69                list_app.append((ext, 'string', file_type)) 
70    except:
71        pass
72    return list_data, list_app
73DATA_EXTENSION, APP_EXTENSION = find_extension()
74
75def write_registry(data_extension=None, app_extension=None):
76    """
77    create file association for windows.
78    Allow open file on double click
79    """
80    msg = ""
81    if data_extension is not None and data_extension:
82        openwithlist = "OpenWithList\%s" % str(APPLICATION)
83        msg = "\n\n[Registry]\n"
84        for (ext, type, _) in data_extension:
85            list = os.path.join(ext, openwithlist)
86            msg +=  """Root: HKCR;\tSubkey: "%s";\t""" % str(list)
87            msg += """ Flags: %s""" % str('uninsdeletekey noerror')
88            msg += "\n"
89        #list the file on right-click
90        msg += """Root: HKCR; Subkey: "applications\%s\shell\open\command";\t"""\
91                              %  str(APPLICATION)
92        msg += """ValueType: %s; """ % str('string')
93        msg += """ValueName: "%s";\t""" %str('') 
94        msg += """ValueData: \"""{app}\%s""  ""%s1\"""; \t"""% (str(APPLICATION),
95                                                          str('%'))   
96        msg += """ Flags: %s""" % str('uninsdeletevalue noerror')
97        msg += "\n"
98        user_list = "Software\Classes" 
99        for (ext, type, _) in data_extension:
100            list = os.path.join(user_list, ext, openwithlist)
101            msg +=  """Root: HKCU;\tSubkey: "%s";\t""" % str(list)
102            msg += """ Flags: %s""" % str('uninsdeletekey noerror')
103            msg += "\n"
104        #list the file on right-click
105        user_list = os.path.join("Software", "Classes", "applications")
106        msg += """Root: HKCU; Subkey: "%s\%s\shell\open\command";\t"""\
107                              %  (str(user_list), str(APPLICATION))
108        msg += """ValueType: %s; """ % str('string')
109        msg += """ValueName: "%s";\t""" %str('') 
110        msg += """ValueData: \"""{app}\%s""  ""%s1\"""; \t"""% (str(APPLICATION),
111                                                          str('%'))   
112        msg += """ Flags: %s""" % str('uninsdeletevalue noerror')
113        msg += "\n"       
114    if app_extension is not None and app_extension:
115        for (ext, type, _) in app_extension:
116            msg +=  """Root: HKCR;\tSubkey: "%s";\t""" % str(ext)
117            msg += """ValueType: %s;\t""" % str(type)
118            #file type empty set the current application as the default
119            #reader for this file. change the value of file_type to another
120            #string modify the default reader
121            file_type = ''
122            msg += """ValueName: "%s";\t""" % str('')
123            msg += """ValueData: "{app}\%s";\t""" % str(APPLICATION)
124            msg += """ Flags: %s""" % str('uninsdeletevalue  noerror')
125            msg += "\n"
126    msg += """Root: HKCR; Subkey: "{app}\%s";\t""" % str(APPLICATION)
127    msg += """ValueType: %s; """ % str('string')
128    msg += """ValueName: "%s";\t""" % str('') 
129    msg += """ValueData: "{app}\%s";\t""" % str("SasView File") 
130    msg += """ Flags: %s \t""" % str("uninsdeletekey  noerror")
131    msg += "\n"
132       
133    #execute the file on double-click
134    msg += """Root: HKCR; Subkey: "{app}\%s\shell\open\command";\t"""  %  str(APPLICATION)
135    msg += """ValueType: %s; """ % str('string')
136    msg += """ValueName: "%s";\t""" %str('') 
137    msg += """ValueData: \"""{app}\%s""  ""%s1\""";\t"""% (str(APPLICATION),
138                                                          str('%')) 
139    msg += """ Flags: %s \t""" % str("uninsdeletevalue noerror")
140    msg += "\n"                                                     
141    #create default icon
142    msg += """Root: HKCR; Subkey: "{app}\%s";\t""" % str(SetupIconFile)
143    msg += """ValueType: %s; """ % str('string')
144    msg += """ValueName: "%s";\t""" % str('') 
145    msg += """ValueData: "{app}\%s,0";\t""" % str(APPLICATION)
146    msg += """ Flags: %s \t""" % str("uninsdeletevalue noerror")
147    msg += "\n" 
148
149   
150    #SASVIEWPATH
151    msg += """Root: HKLM; Subkey: "%s";\t"""  %  str('SYSTEM\CurrentControlSet\Control\Session Manager\Environment')
152    msg += """ValueType: %s; """ % str('expandsz')
153    msg += """ValueName: "%s";\t""" % str('SASVIEWPATH') 
154    msg += """ValueData: "{app}";\t"""
155    msg += """ Flags: %s""" % str('uninsdeletevalue noerror')
156    msg += "\n"
157   
158    #PATH
159    msg += """; Write to PATH (below) is disabled; need more tests\n"""
160    msg += """;Root: HKCU; Subkey: "%s";\t"""  %  str('Environment')
161    msg += """ValueType: %s; """ % str('expandsz')
162    msg += """ValueName: "%s";\t""" % str('PATH') 
163    msg += """ValueData: "%s;{olddata}";\t""" % str('%SASVIEWPATH%')
164    msg += """ Check: %s""" % str('NeedsAddPath()')
165    msg += "\n"
166       
167    return msg
168
169def write_language(language=['english'], msfile="compiler:Default.isl"): 
170    """
171    define the language of the application
172    """ 
173    msg = ''
174    if language:
175        msg = "\n\n[Languages]\n"
176        for lang in language:
177            msg += """Name: "%s";\tMessagesFile: "%s"\n""" % (str(lang), 
178                                                           str(msfile))
179    return msg
180
181def write_tasks():
182    """
183    create desktop icon
184    """
185    msg = """\n\n[Tasks]\n"""
186    msg += """Name: "desktopicon";\tDescription: "{cm:CreateDesktopIcon}";\t"""
187    msg += """GroupDescription: "{cm:AdditionalIcons}";\tFlags: unchecked\n"""
188    msg += """Name: "quicklaunchicon"; Description: "{cm:CreateQuickLaunchIcon}";\t"""
189    msg += """GroupDescription: "{cm:AdditionalIcons}";\n"""
190    return msg
191
192dist_path = "dist"
193def write_file():
194    """
195    copy some data files
196    """
197    msg = "\n\n[Files]\n"
198    msg += """Source: "%s\%s";\t""" % (dist_path, str(APPLICATION))
199    msg += """DestDir: "{app}";\tFlags: ignoreversion\n"""
200    msg += """Source: "dist\*";\tDestDir: "{app}";\t"""
201    msg += """Flags: ignoreversion recursesubdirs createallsubdirs\n"""
202    msg += """Source: "dist\plugin_models\*";\tDestDir: "{userdesktop}\..\.sasview\plugin_models";\t"""
203    msg += """Flags: recursesubdirs createallsubdirs\n""" 
204    msg += """Source: "dist\compiled_models\*";\tDestDir: "{userdesktop}\..\.sasmodels\compiled_models";\t"""
205    msg += """Flags: recursesubdirs createallsubdirs\n"""
206    msg += """Source: "dist\config\custom_config.py";\tDestDir: "{userdesktop}\..\.sasview\config";\t""" 
207    msg += """Flags: recursesubdirs createallsubdirs\n"""
208    #msg += """Source: "dist\default_categories.json";    DestDir: "{userdesktop}\..\.sasview";\t"""
209    #msg += """DestName: "categories.json";\n"""
210    msg += """;\tNOTE: Don't use "Flags: ignoreversion" on any shared system files"""
211    return msg
212
213def write_icon():
214    """
215    Create application icon
216    """
217    msg = """\n\n[Icons]\n"""
218    msg += """Name: "{group}\%s";\t""" % str(AppName)
219    msg += """Filename: "{app}\%s";\t"""  % str(APPLICATION)
220    msg += """WorkingDir: "{app}"; IconFilename: "{app}\images\\ball.ico" \n"""
221    msg += """Name: "{group}\{cm:UninstallProgram, %s}";\t""" % str(AppName)
222    msg += """ Filename: "{uninstallexe}" \n"""
223    msg += """Name: "{commondesktop}\%s";\t""" % str(AppVerName)
224    msg += """Filename: "{app}\%s";\t""" % str(APPLICATION)
225    msg += """Tasks: desktopicon; WorkingDir: "{app}" ; IconFilename: "{app}\images\\ball.ico" \n"""
226    msg += """Name: "{userappdata}\Microsoft\Internet Explorer\Quick Launch\%s";\t""" % str(AppVerName)
227    msg += """Filename: "{app}\%s";\t""" % str(APPLICATION)
228    msg += """Tasks: quicklaunchicon; WorkingDir: "{app}"; IconFilename: "{app}\images\\ball.ico" \n"""
229    return msg
230
231def write_run():
232    """
233    execute some file
234    """
235    msg = """\n\n[Run]\n"""
236    msg += """Filename: "{app}\%s";\t""" % str(APPLICATION)
237    msg += """Description: "{cm:LaunchProgram, %s}";\t""" %str(AppName) 
238    msg += """Flags: nowait postinstall skipifsilent\n"""
239    msg += """; Install the Microsoft C++ DLL redistributable package if it is """
240    msg += """provided and the DLLs are not present on the target system.\n"""
241    msg += """; Note that the redistributable package is included if the app was """
242    msg += """built using Python 2.6 or 2.7, but not with 2.5.\n"""
243    msg += """; Parameter options:\n"""
244    msg += """; - for silent install use: "/q"\n"""
245    msg += """; - for silent install with progress bar use: "/qb"\n"""
246    msg += """; - for silent install with progress bar but disallow """
247    msg += """cancellation of operation use: "/qb!"\n"""
248    msg += """; Note that we do not use the postinstall flag as this would """
249    msg += """display a checkbox and thus require the user to decide what to do.\n"""
250    msg += """;Filename: "{app}\\vcredist_x86.exe"; Parameters: "/qb!"; """
251    msg += """WorkingDir: "{tmp}"; StatusMsg: "Installing Microsoft Visual """
252    msg += """C++ 2008 Redistributable Package ..."; Check: InstallVC90CRT(); """
253    msg += """Flags: skipifdoesntexist waituntilterminated\n"""
254    return msg
255
256def write_dirs():
257    """
258    Define Dir permission
259    """
260    msg = """\n\n[Dirs]\n"""
261    msg += """Name: "{app}\%s";\t""" % str('')
262    msg += """Permissions: everyone-modify\t""" 
263    msg += """\n""" 
264    return msg
265
266def write_code():
267    """
268    Code that checks the existing path and snaviewpath
269    in the environmental viriables/PATH
270    """
271    msg = """\n\n[Code]\n"""
272    msg += """function InstallVC90CRT(): Boolean;\n""" 
273    msg += """begin\n"""
274    msg += """    Result := not DirExists('C:\WINDOWS\WinSxS\\x86_Microsoft.VC90."""
275    msg += """CRT_1fc8b3b9a1e18e3b_9.0.21022.8_x-ww_d08d0375');\n"""
276    msg += """end;\n\n"""
277    msg += """function NeedsAddPath(): boolean;\n""" 
278    msg += """var\n""" 
279    msg += """  oldpath: string;\n"""
280    msg += """  newpath: string;\n""" 
281    msg += """  pathArr:    TArrayOfString;\n""" 
282    msg += """  i:        Integer;\n""" 
283    msg += """begin\n""" 
284    msg += """  RegQueryStringValue(HKEY_CURRENT_USER,'Environment',"""
285    msg += """'PATH', oldpath)\n"""
286    msg += """  oldpath := oldpath + ';';\n"""
287    msg += """  newpath := '%SASVIEWPATH%';\n"""
288    msg += """  i := 0;\n"""
289    msg += """  while (Pos(';', oldpath) > 0) do begin\n"""
290    msg += """    SetArrayLength(pathArr, i+1);\n"""
291    msg += """    pathArr[i] := Copy(oldpath, 0, Pos(';', oldpath)-1);\n"""
292    msg += """    oldpath := Copy(oldpath, Pos(';', oldpath)+1,"""
293    msg += """ Length(oldpath));\n"""
294    msg += """    i := i + 1;\n"""
295    msg += """    // Check if current directory matches app dir\n"""
296    msg += """    if newpath = pathArr[i-1] \n"""
297    msg += """    then begin\n"""
298    msg += """      Result := False;\n"""
299    msg += """      exit;\n"""
300    msg += """    end;\n"""
301    msg += """  end;\n"""
302    msg += """  Result := True;\n"""
303    msg += """end;\n"""
304    msg += """\n"""
305    return msg
306
307def write_uninstalldelete():
308    """
309    Define uninstalldelete
310    """
311    msg = """\n[UninstallDelete]\n"""
312    msg += """; Delete directories and files that are dynamically created by """
313    msg += """the application (i.e. at runtime).\n"""
314    msg += """Type: filesandordirs; Name: "{app}\.matplotlib"\n"""
315    msg += """Type: files; Name: "{app}\*.*"\n"""
316    msg += """; The following is a workaround for the case where the """
317    msg += """application is installed and uninstalled but the\n"""
318    msg += """;{app} directory is not deleted because it has user files.  """
319    msg += """Then the application is installed into the\n"""
320    msg += """; existing directory, user files are deleted, and the """
321    msg += """application is un-installed again.  Without the\n"""
322    msg += """; directive below, {app} will not be deleted because Inno Setup """
323    msg += """did not create it during the previous\n"""
324    msg += """; installation.\n"""
325    msg += """Type: dirifempty; Name: "{app}"\n"""
326    msg += """\n""" 
327    return msg
328
329def generate_installer():
330    """
331    """
332    TEMPLATE = "\n; Script generated by the Inno Setup Script Wizard\n"
333    TEMPLATE += "\n; and local_config.py located in this directory.\n "
334    TEMPLATE += "; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!"
335    TEMPLATE += "\n[Setup]\n\n" 
336    TEMPLATE += "ChangesAssociations=%s\n" %str('yes')
337    TEMPLATE += "AppName=%s\n" % str(AppName)
338    TEMPLATE += "AppVerName=%s\n" % str(AppVerName)
339    TEMPLATE += "AppPublisher=%s\n" % str(AppPublisher)
340    TEMPLATE += "AppPublisherURL=%s\n" % str(AppPublisherURL)
341    TEMPLATE += "AppSupportURL=%s\n" % str(AppSupportURL)
342    TEMPLATE += "AppUpdatesURL=%s \n" % str(AppUpdatesURL)
343    TEMPLATE += "ChangesEnvironment=%s \n" % str(ChangesEnvironment)
344    TEMPLATE += "DefaultDirName=%s\n" % str(DefaultDirName)
345    TEMPLATE += "DefaultGroupName=%s\n" % str(DefaultGroupName)
346    TEMPLATE += "DisableProgramGroupPage=%s\n" % str(DisableProgramGroupPage)
347    TEMPLATE += "LicenseFile=%s\n" % str(LicenseFile)
348    TEMPLATE += "OutputBaseFilename=%s\n" % str(OutputBaseFilename)
349    TEMPLATE += "SetupIconFile=%s\n" % str(SetupIconFile)
350    TEMPLATE += "Compression=%s\n" % str(Compression)
351    TEMPLATE += "SolidCompression=%s\n" % str(SolidCompression)
352    TEMPLATE += "PrivilegesRequired=%s\n" % str(PrivilegesRequired)
353    TEMPLATE += "UsePreviousAppDir=no\n"
354   
355    TEMPLATE += write_registry(data_extension=DATA_EXTENSION,
356                                app_extension=APP_EXTENSION)
357    TEMPLATE += write_language()
358    TEMPLATE += write_tasks()
359    TEMPLATE += write_file()
360    TEMPLATE += write_icon()
361    TEMPLATE += write_run()
362    TEMPLATE += write_dirs()
363    TEMPLATE += write_code()
364    TEMPLATE += write_uninstalldelete()
365    path = '%s.iss' % str(INSTALLER_FILE)
366    f = open(path,'w') 
367    f.write(TEMPLATE)
368    f.close()
369    print("Generate Inno setup installer script complete")
370    print("A new file %s.iss should be created.Please refresh your directory" % str(INSTALLER_FILE))
371   
372if __name__ == "__main__":
373    generate_installer()
Note: See TracBrowser for help on using the repository browser.