source: sasview/installers/installer_generator.py @ b685c7b

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalc
Last change on this file since b685c7b was 0595bb7, checked in by Piotr Rozyczko <rozyczko@…>, 7 years ago

Constraint validator - initial implementation + tests. SASVIEW-844

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