source: sasview/installers/installer_generator.py @ a64f8f4

magnetic_scattrelease-4.2.2ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since a64f8f4 was a64f8f4, checked in by Piotr Rozyczko <rozyczko@…>, 6 years ago

Add arch specific keyword

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