source: sasview/sasview/installer_generator.py @ 899e084

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

build console app as well as gui

  • Property mode set to 100644
File size: 16.4 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"""
[899e084]6import os
7import sys
[fa597990]8import string
9
[899e084]10root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
11sys.path.insert(0, os.path.join(root, 'sasview-install', 'Lib', 'site-packages'))
12from sas.sasview import local_config
13
[fa597990]14REG_PROGRAM = """{app}\MYPROG.EXE"" ""%1"""
15APPLICATION = str(local_config.__appname__ )+ '.exe'
[50282f8]16AppName = str(local_config.__appname__ )
[fa597990]17AppVerName = str(local_config.__appname__ )+'-'+ str(local_config.__version__)
18Dev = ''
[899e084]19if 'dev' in AppVerName.lower():
[fa597990]20    Dev = '-Dev'
21AppPublisher = local_config._copyright
22AppPublisherURL = local_config._homepage
23AppSupportURL = local_config._homepage
24AppUpdatesURL = local_config._homepage
25ChangesEnvironment = 'true'
26DefaultDirName = os.path.join("{pf}" , AppName+Dev) 
27DefaultGroupName = os.path.join(local_config.DefaultGroupName, AppVerName)
28                               
29OutputBaseFilename = local_config.OutputBaseFilename
[efe730d]30SetupIconFile = local_config.SetupIconFile_win
[fa597990]31LicenseFile = 'license.txt'
32DisableProgramGroupPage = 'yes'
33Compression = 'lzma'
34SolidCompression = 'yes'
35PrivilegesRequired = 'none'
[e040eb1b]36INSTALLER_FILE = 'installer'
[fa597990]37
38icon_path =  local_config.icon_path
39media_path = local_config.media_path
40test_path = local_config.test_path
41
42def find_extension():
43    """
44    Describe the extensions that can be read by the current application
45    """
[50282f8]46    list_data = []
47    list_app =[]
[fa597990]48    try:
[50282f8]49       
[fa597990]50        #(ext, type, name, flags)
[b699768]51        from sas.sascalc.dataloader.loader import Loader
[fa597990]52        wild_cards = Loader().get_wildcards()
53        for item in wild_cards:
54            #['All (*.*)|*.*']
55            file_type, ext = string.split(item, "|*", 1)
[50282f8]56            if ext.strip() not in ['.*', ''] and ext.strip() not in list_data:
57                list_data.append((ext, 'string', file_type))
[fa597990]58    except:
59        pass
60    try:
61        file_type, ext = string.split(local_config.APPLICATION_WLIST, "|*", 1)
[50282f8]62        if ext.strip() not in ['.', ''] and ext.strip() not in list_app:
63            list_app.append((ext, 'string', file_type))
[fa597990]64    except:
65        pass
66    try:
67        for item in local_config.PLUGINS_WLIST:
68            file_type, ext = string.split(item, "|*", 1)
[50282f8]69            if ext.strip() not in ['.', ''] and ext.strip() not in list_app:
70                list_app.append((ext, 'string', file_type)) 
[fa597990]71    except:
72        pass
[50282f8]73    return list_data, list_app
74DATA_EXTENSION, APP_EXTENSION = find_extension()
75
76def write_registry(data_extension=None, app_extension=None):
[fa597990]77    """
78    create file association for windows.
79    Allow open file on double click
80    """
81    msg = ""
[50282f8]82    if data_extension is not None and data_extension:
83        openwithlist = "OpenWithList\%s" % str(APPLICATION)
[fa597990]84        msg = "\n\n[Registry]\n"
[50282f8]85        for (ext, type, _) in data_extension:
86            list = os.path.join(ext, openwithlist)
87            msg +=  """Root: HKCR;\tSubkey: "%s";\t""" % str(list)
88            msg += """ Flags: %s""" % str('uninsdeletekey noerror')
89            msg += "\n"
90        #list the file on right-click
91        msg += """Root: HKCR; Subkey: "applications\%s\shell\open\command";\t"""\
92                              %  str(APPLICATION)
93        msg += """ValueType: %s; """ % str('string')
94        msg += """ValueName: "%s";\t""" %str('') 
95        msg += """ValueData: \"""{app}\%s""  ""%s1\"""; \t"""% (str(APPLICATION),
96                                                          str('%'))   
97        msg += """ Flags: %s""" % str('uninsdeletevalue noerror')
98        msg += "\n"
99        user_list = "Software\Classes" 
100        for (ext, type, _) in data_extension:
101            list = os.path.join(user_list, ext, openwithlist)
102            msg +=  """Root: HKCU;\tSubkey: "%s";\t""" % str(list)
103            msg += """ Flags: %s""" % str('uninsdeletekey noerror')
104            msg += "\n"
105        #list the file on right-click
106        user_list = os.path.join("Software", "Classes", "applications")
[c648414]107        msg += """Root: HKCU; Subkey: "%s\%s\shell\open\command";\t"""\
[50282f8]108                              %  (str(user_list), str(APPLICATION))
109        msg += """ValueType: %s; """ % str('string')
110        msg += """ValueName: "%s";\t""" %str('') 
111        msg += """ValueData: \"""{app}\%s""  ""%s1\"""; \t"""% (str(APPLICATION),
112                                                          str('%'))   
113        msg += """ Flags: %s""" % str('uninsdeletevalue noerror')
114        msg += "\n"       
115    if app_extension is not None and app_extension:
116        for (ext, type, _) in app_extension:
[fa597990]117            msg +=  """Root: HKCR;\tSubkey: "%s";\t""" % str(ext)
118            msg += """ValueType: %s;\t""" % str(type)
119            #file type empty set the current application as the default
120            #reader for this file. change the value of file_type to another
121            #string modify the default reader
122            file_type = ''
123            msg += """ValueName: "%s";\t""" % str('')
124            msg += """ValueData: "{app}\%s";\t""" % str(APPLICATION)
[dd16ad6]125            msg += """ Flags: %s""" % str('uninsdeletevalue  noerror')
[fa597990]126            msg += "\n"
[50282f8]127    msg += """Root: HKCR; Subkey: "{app}\%s";\t""" % str(APPLICATION)
128    msg += """ValueType: %s; """ % str('string')
129    msg += """ValueName: "%s";\t""" % str('') 
[c329f4d]130    msg += """ValueData: "{app}\%s";\t""" % str("SasView File") 
[dd16ad6]131    msg += """ Flags: %s \t""" % str("uninsdeletekey  noerror")
[50282f8]132    msg += "\n"
[fa597990]133       
[50282f8]134    #execute the file on double-click
135    msg += """Root: HKCR; Subkey: "{app}\%s\shell\open\command";\t"""  %  str(APPLICATION)
136    msg += """ValueType: %s; """ % str('string')
137    msg += """ValueName: "%s";\t""" %str('') 
138    msg += """ValueData: \"""{app}\%s""  ""%s1\""";\t"""% (str(APPLICATION),
139                                                          str('%')) 
140    msg += """ Flags: %s \t""" % str("uninsdeletevalue noerror")
141    msg += "\n"                                                     
142    #create default icon
143    msg += """Root: HKCR; Subkey: "{app}\%s";\t""" % str(SetupIconFile)
144    msg += """ValueType: %s; """ % str('string')
145    msg += """ValueName: "%s";\t""" % str('') 
[dd16ad6]146    msg += """ValueData: "{app}\%s,0";\t""" % str(APPLICATION)
147    msg += """ Flags: %s \t""" % str("uninsdeletevalue noerror")
148    msg += "\n" 
[50282f8]149
150   
[3a39c2e]151    #SASVIEWPATH
[50282f8]152    msg += """Root: HKLM; Subkey: "%s";\t"""  %  str('SYSTEM\CurrentControlSet\Control\Session Manager\Environment')
153    msg += """ValueType: %s; """ % str('expandsz')
[3a39c2e]154    msg += """ValueName: "%s";\t""" % str('SASVIEWPATH') 
[50282f8]155    msg += """ValueData: "{app}";\t"""
[dd16ad6]156    msg += """ Flags: %s""" % str('uninsdeletevalue noerror')
[50282f8]157    msg += "\n"
158   
159    #PATH
160    msg += """; Write to PATH (below) is disabled; need more tests\n"""
161    msg += """;Root: HKCU; Subkey: "%s";\t"""  %  str('Environment')
162    msg += """ValueType: %s; """ % str('expandsz')
163    msg += """ValueName: "%s";\t""" % str('PATH') 
[3a39c2e]164    msg += """ValueData: "%s;{olddata}";\t""" % str('%SASVIEWPATH%')
[50282f8]165    msg += """ Check: %s""" % str('NeedsAddPath()')
166    msg += "\n"
[fa597990]167       
168    return msg
169
170def write_language(language=['english'], msfile="compiler:Default.isl"): 
171    """
172    define the language of the application
173    """ 
174    msg = ''
175    if language:
176        msg = "\n\n[Languages]\n"
177        for lang in language:
178            msg += """Name: "%s";\tMessagesFile: "%s"\n""" % (str(lang), 
179                                                           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"""
[aade98e]189    msg += """Name: "quicklaunchicon"; Description: "{cm:CreateQuickLaunchIcon}";\t"""
190    msg += """GroupDescription: "{cm:AdditionalIcons}";\n"""
[fa597990]191    return msg
192
[50282f8]193dist_path = "dist"
[fa597990]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"""
[ddf571d]203    msg += """Source: "dist\plugin_models\*";\tDestDir: "{userdesktop}\..\.sasview\plugin_models";\t"""
204    msg += """Flags: recursesubdirs createallsubdirs\n""" 
[6a698c0]205    msg += """Source: "dist\compiled_models\*";\tDestDir: "{userdesktop}\..\.sasmodels\compiled_models";\t"""
[aade98e]206    msg += """Flags: recursesubdirs createallsubdirs\n"""
[0f382d7]207    msg += """Source: "dist\config\custom_config.py";\tDestDir: "{userdesktop}\..\.sasview\config";\t""" 
[aade98e]208    msg += """Flags: recursesubdirs createallsubdirs\n"""
[27b7acc]209    msg += """Source: "dist\default_categories.json";    DestDir: "{userdesktop}\..\.sasview";\t""" 
[50008e3]210    msg += """DestName: "categories.json";\n"""
[fa597990]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)
[aade98e]221    msg += """WorkingDir: "{app}"; IconFilename: "{app}\images\\ball.ico" \n"""
[fa597990]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)
[aade98e]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"""
[fa597990]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"""
[aade98e]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"""
[fa597990]255    return msg
256
[e7281fd]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
[fa597990]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"""
[aade98e]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"""
[fa597990]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"""
[3a39c2e]288    msg += """  newpath := '%SASVIEWPATH%';\n"""
[fa597990]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
[aade98e]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
[fa597990]329
[d73a274]330def generate_installer():
331    """
332    """
[fa597990]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)
[e3ef8dd4]354    TEMPLATE += "UsePreviousAppDir=no\n"
[fa597990]355   
[50282f8]356    TEMPLATE += write_registry(data_extension=DATA_EXTENSION,
357                                app_extension=APP_EXTENSION)
[fa597990]358    TEMPLATE += write_language()
359    TEMPLATE += write_tasks()
360    TEMPLATE += write_file()
361    TEMPLATE += write_icon()
362    TEMPLATE += write_run()
[e7281fd]363    TEMPLATE += write_dirs()
[fa597990]364    TEMPLATE += write_code()
[aade98e]365    TEMPLATE += write_uninstalldelete()
[fa597990]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"
[d73a274]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.