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