source: sasview/sansview/installer_generator.py @ 7f291a3

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.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since 7f291a3 was 7f291a3, checked in by Jae Cho <jhjcho@…>, 13 years ago

implemented SANSVIEWPATH env.

  • Property mode set to 100644
File size: 10.2 KB
Line 
1"""
2This module generates .ss 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"""
6import local_config
7import os 
8import string
9
10REG_PROGRAM = """{app}\MYPROG.EXE"" ""%1"""
11APPLICATION = str(local_config.__appname__ )+ '.exe'
12AppName  = str(local_config.__appname__ ) # + '-'+ str(local_config.__version__)
13AppVerName = str(local_config.__appname__ ) + '-'+ str(local_config.__version__)
14Dev = ''
15if AppVerName.lower().count('dev') > 0:
16    Dev = '-Dev'
17AppPublisher = local_config._copyright
18AppPublisherURL = local_config._homepage
19AppSupportURL = local_config._homepage
20AppUpdatesURL = local_config._homepage
21ChangesEnvironment = 'true'
22DefaultDirName = os.path.join("{pf}" , AppName+Dev) 
23DefaultGroupName = os.path.join(local_config.DefaultGroupName, AppVerName)
24                               
25OutputBaseFilename = local_config.OutputBaseFilename
26SetupIconFile = local_config.SetupIconFile_win
27LicenseFile = 'license.txt'
28DisableProgramGroupPage = 'yes'
29Compression = 'lzma'
30SolidCompression = 'yes'
31PrivilegesRequired = 'none'
32INSTALLER_FILE = 'installer_new'
33#find extension for windows file assocation
34#extension list need to be modified for each application
35
36def find_extension():
37    """
38    Describe the extensions that can be read by the current application
39    """
40    try:
41        list = []
42        #(ext, type, name, flags)
43        from DataLoader.loader import Loader
44        wild_cards = Loader().get_wildcards()
45        for item in wild_cards:
46            #['All (*.*)|*.*']
47            file_type, ext = string.split(item, "|*", 1)
48            if ext.strip() not in ['.*', ''] and ext.strip() not in list:
49                list.append((ext, 'string', file_type))
50    except:
51        pass
52    try:
53        file_type, ext = string.split(local_config.APPLICATION_WLIST, "|*", 1)
54        if ext.strip() not in ['.', ''] and ext.strip() not in list:
55            list.append((ext, 'string', file_type))
56    except:
57        pass
58    try:
59        for item in local_config.PLUGINS_WLIST:
60            file_type, ext = string.split(item, "|*", 1)
61            if ext.strip() not in ['.', ''] and ext.strip() not in list:
62                list.append((ext, 'string', file_type)) 
63    except:
64        pass
65    return list
66EXTENSION = find_extension()
67   
68def write_registry(extension=None):
69    """
70    create file association for windows.
71    Allow open file on double click
72    """
73    msg = ""
74    if extension is not None and extension:
75        msg = "\n\n[Registry]\n"
76        for (ext, type, _) in extension:
77            msg +=  """Root: HKCR;\tSubkey: "%s";\t""" % str(ext)
78            msg += """ValueType: %s;\t""" % str(type)
79            #file type empty set the current application as the default
80            #reader for this file. change the value of file_type to another
81            #string modify the default reader
82            file_type = ''
83            msg += """ValueName: "%s";\t""" % str('')
84            msg += """ValueData: "{app}\%s";\t""" % str(APPLICATION)
85            msg += """ Flags: %s""" % str('uninsdeletevalue')
86            msg += "\n"
87     
88        #create default icon
89        msg += """Root: HKCR; Subkey: "{app}\%s";\t""" % str(SetupIconFile)
90        msg += """ValueType: %s; """ % str('string')
91        msg += """ValueName: "%s";\t""" % str('') 
92        msg += """ValueData: "{app}\%s,0"\n""" % str(APPLICATION)
93       
94        #execute the file on double-click
95        msg += """Root: HKCR; Subkey: "{app}\%s\shell\open\command";\t"""  %  str(APPLICATION)
96        msg += """ValueType: %s; """ % str('string')
97        msg += """ValueName: "%s";\t""" %str('') 
98        msg += """ValueData: \"""{app}\%s""  ""%s1\"""\n"""% (str(APPLICATION),
99                                                              str('%'))
100       
101        #SANSVIEWPATH
102        msg += """Root: HKCU; Subkey: "%s";\t"""  %  str('Environment')
103        msg += """ValueType: %s; """ % str('expandsz')
104        msg += """ValueName: "%s";\t""" % str('SANSVIEWPATH') 
105        msg += """ValueData: "{app}";\t"""
106        msg += """ Flags: %s""" % str('uninsdeletevalue')
107        msg += "\n"
108       
109        #PATH
110        msg += """; Write to PATH (below) is disabled; need more work\n"""
111        msg += """;Root: HKCU; Subkey: "%s";\t"""  %  str('Environment')
112        msg += """ValueType: %s; """ % str('expandsz')
113        msg += """ValueName: "%s";\t""" % str('PATH') 
114        msg += """ValueData: "%s;{olddata}";\t""" % str('%SANSVIEWPATH%')
115        msg += """ Check: %s""" % str('NeedsAddPath()')
116        msg += "\n"
117       
118    return msg
119
120def write_language(language=['english'], msfile="compiler:Default.isl"): 
121    """
122    define the language of the application
123    """ 
124    msg = ''
125    if language:
126        msg = "\n\n[Languages]\n"
127        for lang in language:
128            msg += """Name: "%s";\tMessagesFile: "%s"\n""" % (str(lang), 
129                                                           str(msfile))
130    return msg
131
132def write_tasks():
133    """
134    create desktop icon
135    """
136    msg = """\n\n[Tasks]\n"""
137    msg += """Name: "desktopicon";\tDescription: "{cm:CreateDesktopIcon}";\t"""
138    msg += """GroupDescription: "{cm:AdditionalIcons}";\tFlags: unchecked\n"""
139    return msg
140
141def write_file():
142    """
143    copy some data files
144    """
145    msg = "\n\n[Files]\n"
146    msg += """Source: "dist\%s";\t""" % str(APPLICATION)
147    msg += """DestDir: "{app}";\tFlags: ignoreversion\n"""
148    msg += """Source: "dist\*";\tDestDir: "{app}";\t"""
149    msg += """Flags: ignoreversion recursesubdirs createallsubdirs\n"""
150    msg += """Source: "images\*";\tDestDir: "{app}\%s";\t""" % str("images")
151    msg += """Flags: ignoreversion recursesubdirs createallsubdirs\n"""
152    msg += """Source: "test\*";\tDestDir: "{app}\%s";\t""" % str("test")
153    msg += """Flags: ignoreversion recursesubdirs createallsubdirs\n"""
154    msg += """;\tNOTE: Don't use "Flags: ignoreversion" on any shared system files"""
155    return msg
156
157def write_icon():
158    """
159    Create application icon
160    """
161    msg = """\n\n[Icons]\n"""
162    msg += """Name: "{group}\%s";\t""" % str(AppName)
163    msg += """Filename: "{app}\%s";\t"""  % str(APPLICATION)
164    msg += """WorkingDir: "{app}" \n"""
165    msg += """Name: "{group}\{cm:UninstallProgram, %s}";\t""" % str(AppName)
166    msg += """ Filename: "{uninstallexe}" \n"""
167    msg += """Name: "{commondesktop}\%s";\t""" % str(AppVerName)
168    msg += """Filename: "{app}\%s";\t""" % str(APPLICATION)
169    msg += """Tasks: desktopicon; WorkingDir: "{app}" \n"""
170    return msg
171
172def write_run():
173    """
174    execute some file
175    """
176    msg = """\n\n[Run]\n"""
177    msg += """Filename: "{app}\%s";\t""" % str(APPLICATION)
178    msg += """Description: "{cm:LaunchProgram, %s}";\t""" %str(AppName) 
179    msg += """Flags: nowait postinstall skipifsilent\n"""
180    return msg
181
182def write_code():
183    """
184    Code that checks the existing path and snaviewpath
185    in the environmental viriables/PATH
186    """
187    msg = """\n\n[Code]\n"""
188    msg += """function NeedsAddPath(): boolean;\n""" 
189    msg += """var\n""" 
190    msg += """  oldpath: string;\n"""
191    msg += """  newpath: string;\n""" 
192    msg += """  pathArr:    TArrayOfString;\n""" 
193    msg += """  i:        Integer;\n""" 
194    msg += """begin\n""" 
195    msg += """  RegQueryStringValue(HKEY_CURRENT_USER,'Environment',"""
196    msg += """'PATH', oldpath)\n"""
197    msg += """  oldpath := oldpath + ';';\n"""
198    msg += """  newpath := '%SANSVIEWPATH%';\n"""
199    msg += """  i := 0;\n"""
200    msg += """  while (Pos(';', oldpath) > 0) do begin\n"""
201    msg += """    SetArrayLength(pathArr, i+1);\n"""
202    msg += """    pathArr[i] := Copy(oldpath, 0, Pos(';', oldpath)-1);\n"""
203    msg += """    oldpath := Copy(oldpath, Pos(';', oldpath)+1,"""
204    msg += """ Length(oldpath));\n"""
205    msg += """    i := i + 1;\n"""
206    msg += """    // Check if current directory matches app dir\n"""
207    msg += """    if newpath = pathArr[i-1] \n"""
208    msg += """    then begin\n"""
209    msg += """      Result := False;\n"""
210    msg += """      exit;\n"""
211    msg += """    end;\n"""
212    msg += """  end;\n"""
213    msg += """  Result := True;\n"""
214    msg += """end;\n"""
215    msg += """\n"""
216   
217   
218   
219   
220    return msg
221
222
223if __name__ == "__main__":
224    TEMPLATE = "\n; Script generated by the Inno Setup Script Wizard\n"
225    TEMPLATE += "\n; and local_config.py located in this directory.\n "
226    TEMPLATE += "; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!"
227    TEMPLATE += "\n[Setup]\n\n" 
228    TEMPLATE += "ChangesAssociations=%s\n" %str('yes')
229    TEMPLATE += "AppName=%s\n" % str(AppName)
230    TEMPLATE += "AppVerName=%s\n" % str(AppVerName)
231    TEMPLATE += "AppPublisher=%s\n" % str(AppPublisher)
232    TEMPLATE += "AppPublisherURL=%s\n" % str(AppPublisherURL)
233    TEMPLATE += "AppSupportURL=%s\n" % str(AppSupportURL)
234    TEMPLATE += "AppUpdatesURL=%s \n" % str(AppUpdatesURL)
235    TEMPLATE += "ChangesEnvironment=%s \n" % str(ChangesEnvironment)
236    TEMPLATE += "DefaultDirName=%s\n" % str(DefaultDirName)
237    TEMPLATE += "DefaultGroupName=%s\n" % str(DefaultGroupName)
238    TEMPLATE += "DisableProgramGroupPage=%s\n" % str(DisableProgramGroupPage)
239    TEMPLATE += "LicenseFile=%s\n" % str(LicenseFile)
240    TEMPLATE += "OutputBaseFilename=%s\n" % str(OutputBaseFilename)
241    TEMPLATE += "SetupIconFile=%s\n" % str(SetupIconFile)
242    TEMPLATE += "Compression=%s\n" % str(Compression)
243    TEMPLATE += "SolidCompression=%s\n" % str(SolidCompression)
244    TEMPLATE += "PrivilegesRequired=%s\n" % str(PrivilegesRequired)
245   
246    TEMPLATE += write_registry(extension=EXTENSION)
247    TEMPLATE += write_language()
248    TEMPLATE += write_tasks()
249    TEMPLATE += write_file()
250    TEMPLATE += write_icon()
251    TEMPLATE += write_run()
252    TEMPLATE += write_code()
253    path = '%s.iss' % str(INSTALLER_FILE)
254    f = open(path,'w') 
255    f.write(TEMPLATE)
256    f.close()
257    print "Generate Inno setup installer script complete"
258    print "A new file %s.iss should be created.Please refresh your directory" % str(INSTALLER_FILE)
Note: See TracBrowser for help on using the repository browser.