def ini_file(mode, section, file_name , key, option = 'None'): try: config = configparser.ConfigParser() exit_str = (separator_arguments + separator_string).join(["Ini: %s" %(file_name), "mode: %s" %(mode),"section: %s"%section, "key: %s" %(key), "option: %s"%(option)]) if mode == 'r': config.readfp(open(file_name, "r")) config.get(section,key) exit_str += separator_string.join([separator_arguments, 'exit', 'code: %s'% str(enum_code_ini.ECI_EXIST_FILE_IN_LIST_MD5)]) print(exit_str) return enum_code_ini.ECI_EXIST_FILE_IN_LIST_MD5 elif mode == 'w': if(os.path.exists(file_name)): config.readfp(open(file_name, "r")) else: config.add_section(section_files_ini_file) config.add_section(section_folders_ini_file) config.set(section, key, option) config.write(open(file_name, "w")) exit_str += separator_string.join([separator_arguments, 'exit', 'code: %s'% str(enum_code_ini.NONE)]) print(exit_str) return enum_code_ini.NONE except configparser.Error as err: exit_str+= separator_string.join([separator_arguments, 'exit', 'code: %s'% str(enum_code_ini.ERROR)]) print(os.path.basename(__file__),"%s:"%type(err).__name__,err, exit_str, file=sys.stderr,sep =separator_string) return enum_code_ini.ERROR except OSError as err: exit_str+= separator_string.join([separator_arguments, 'exit', 'code: %s'% str(enum_code_ini.ECI_NOT_INI_FILE)]) print("NOT") print(os.path.basename(__file__),"%s:"%type(err).__name__,err, exit_str, file=sys.stderr,sep =separator_string) return enum_code_ini.ECI_NOT_INI_FILE except IOError as err: exit_str+= separator_string.join([separator_arguments, 'exit', 'code: %s'% str(enum_code_ini.ECI_NOT_INI_FILE)]) print(os.path.basename(__file__),"%s:"%type(err).__name__,err, exit_str, file=sys.stderr,sep =separator_string) return enum_code_ini.ECI_NOT_INI_FILE
saveout = sys.stdout saveerr = sys.stderr if options.stream_log_out_file_name: stream_log_out_file = open( options.stream_log_out_file_name, 'w') sys.stdout = stream_log_out_file sys.stderr = stream_log_out_file if options.stream_log_err_file_name: stream_log_err_file = open( options.stream_log_err_file_name, 'w') sys.stderr = stream_log_err_file global old_ini_dict old_ini_dict = IniFile.ini_file_dict('r', os.path.join(temp_folder_name,old_info_ini_name)) print(old_info_ini_name,"%s:"% old_ini_dict.__class__.__name__, old_ini_dict, sep =separator_string) print(separator_primary_block) print('Parsing', resources_xml_file_name,"...",sep = separator_string) print(separator_primary_block) sys.stdout = saveout #создал для того, чтобы восстановить поток, так как он перенаправлен на файл sys.stderr = saveerr #
вот лог выполнения:
#################################################################################################### old_info.ini int: 6 #################################################################################################### Parsing resources1.xml ... #################################################################################################### IniFile.py IOError: [Errno 2] No such file or directory: 'temp_resources1\\old_info.ini' Ini: temp_resources1\old_info.ini, mode: r, dict: None, exit code: 6