source: sasview/installers/installer_generator.py @ 156203a

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalcmagnetic_scattrelease-4.2.2ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since 156203a was a67ec83, checked in by Paul Kienzle <pkienzle@…>, 7 years ago

lint

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