def makeInifile(self, inifilename, iniSpec=None): """make in subdirectory inifiles_test a new inifile of this name """ inifilepath = os.path.join(thisDir, 'test_inifiles', inifilename) ini = inivars.IniVars(inifilepath) if iniSpec: ini.delete() ini.fromDict(iniSpec) return ini
def checkSpokenformsInifile(language): """copy if needed the correct inifile into the userDirectory print message if no valid file found and return False """ global currentlanguage, ini, inifile if language and language == currentlanguage and ini: return inifile # all OK ini = None currentlanguage = language filename = '%s_spokenforms.ini' % language if language == 'test': testDirectory = os.path.join(unimacroDirectory, 'unimacro_test', 'test_inifiles') print 'test spokenforms.ini from %s' % testDirectory inifile = os.path.join(testDirectory, '%s_spokenforms.ini' % language) print 'spokenforms, test inifile: %s' % inifile else: inifile = os.path.join(userDirectory, '%s_spokenforms.ini' % language) if not os.path.isfile(inifile): # now try to copy from the samples: print '---try to find spokenforms.ini file in old version (UserDirectory) or sample_ini directory' for sample in sampleDirectories: sampleinifile = os.path.join(sample, filename) if os.path.isfile(sampleinifile): print '---copy spokenforms.ini from\nsamples directory: %s\nto %s\n----' % ( sampleinifile, inifile) shutil.copyfile(sampleinifile, inifile) if os.path.isfile(inifile): break else: print 'cannot copy sample spokenforms inifile to: "%s"' % inifile inifile = None return else: print 'no valid sample "%s" file found in one of %s sample directories:\n|%s|'% \ (filename, len(sampleDirectories), sampleDirectories) return # now assume valid inifile: try: ini = inivars.IniVars(inifile, returnStrings=True) except inivars.IniError: print 'Error in spokenforms inifile: "%s"' % inifile m = str(sys.exc_info()[1]) print 'message: %s' % m print '\n\n===please edit %s (open by hand)' % inifile #win32api.ShellExecute(0, "open", inifile, None , "", 1) else: return inifile
def openInifile(inifilepath): global inifile, ini if os.path.isfile(inifilepath): inifile = inifilepath try: ini = inivars.IniVars(inifile) except inivars.IniError: print 'Error in numbers inifile: %s'% inifile m = str(sys.exc_info()[1]) print 'message: %s'% m pendingMessage = 'Please repair spokenforms.ini file\n\n' + m ini = None print 'please edit %s (open by hand)'% inifile #win32api.ShellExecute(0, "open", inifile, None , "", 1) else: return ini else: ini = inifile = None print 'no inifile spokenforms.ini found. Please repair'