def save_result(branch_name, what_save): sets = iow.get_utf8_template() # Перевод в json sets['name'] = branch_name+'.json' sets['howOpen'] = 'w' sets['coding'] = 'utf_8' iow.list2file(sets, ['\r# Unrolled:\n']) sets['howOpen'] = 'a' to_json.save_process_result(what_save, sets, raw=False) iow.list2file(sets, ['\r# Packed:\n']) to_json.save_process_result(what_save, sets, raw=True)
def assignBranch(self, str_branch_name):#void """ Соединяет курсор с узлом. Если узла нет, создается.""" self._current_node_name = str_branch_name self._branch_cash = {} findex_name = self._get_real_branch_name()+'/'+self._kForwardIndexName sets = dal.get_utf8_template() sets['name'] = findex_name try: os.mkdir(self._get_real_branch_name()) sets['howOpen'] = 'w' dal.list2file(sets, ["{}"]) except OSError as e: print 'Branch is exist' # Загружаем индекс readed_list = dal.file2list(sets) branch_in_json = ' '.join(readed_list) # TODO(zaqwes): долгая операция(несколько секунд), как быть? self._branch_cash = json.loads(branch_in_json)
def saveBranchCash(self):#void to_file = [json.dumps(self._branch_cash, sort_keys=True, indent=2)] sets = dal.get_utf8_template() sets['name'] = self._get_real_branch_name()+'/'+self._kForwardIndexName sets['howOpen'] = 'w' dal.list2file(sets, to_file)
def _save_temp_file(fname, text_content): sets = get_utf8_template() sets['name'] = fname sets['howOpen'] = 'w' list2file(sets, text_content)
def write_result_file(result_list, fname): sets = dal.get_utf8_template() sets['howOpen'] = 'w' sets['name'] = fname dal.list2file(sets, result_list)
# Сохраняем код sets['howOpen'] = 'w' sets['name'] = '../src/to_text_jy_template.py' python_code.insert(0, '# coding: utf-8') python_code.insert(1, '# Autogenerated by script '+str(sys.argv[0])) # Импорт position = 2 for iface in ifaces: python_code.insert(position, 'from to_text import '+iface) position += 1 python_code.insert(position, '') # Пишем iow.list2file(sets, python_code) # Java code java_code = to_java.to_code(markered_code, open_comment_idx, close_comment_idx) for entity in java_code: print entity sets['howOpen'] = 'w' sets['name'] = '../src/to_text/'+entity+'.java' java_code[entity].insert(0, '// coding: utf-8') java_code[entity].insert(1, '// Autogenerated by script '+str(sys.argv[0])) java_code[entity].insert(2, 'package to_text;') java_code[entity].insert(3, '') java_code[entity].insert(4, '// Import') java_code[entity].insert(5, 'import java.util.List;') java_code[entity].insert(6, '')
def write_source(fname, list_lines): sets = iow.get_utf8_template() sets['name'] = fname sets['howOpen'] = 'w' iow.list2file(sets, list_lines)
# Кодогенерация code = [] for branch_name in result_branchs: code.append('\n// branch: '+branch_name) code.append('// Auto generate by: '+sys.argv[0]) code.append('function check_'+branch_name+'() {') code.append(' var correct = false;') branch = result_branchs[branch_name] for one_node in branch: if one_node[0] == 't': # Call code.append('\n // checker') #for one_node in branch: print one_node #code code.append(' var check_'+one_node+' = function(value) {\n return true;\n }') code.append(' correct = check_'+one_node+'(document.getElementById("'+one_node+'").value);'+ \ '\n if (!correct) {\n return "msg";\n }') code.append(' return "";\n} // '+'function check_'+branch_name) sets = iow.get_utf8_template() sets['name'] = "code.js" sets['howOpen'] = 'w' iow.list2file(sets, code) print 'Done'
result = [] content = dal.file2list(sets) insert_in_next_line = False for at in content: if 'p["' in at and '!=' in at: result.append( at+' \n// STR_PARAM [Autogenerated]:\n string msg = "Change_to :"+p["'+at.split('"')[1]+'"];') result.append( ' sampler_.journal.PutRecord(msg);') result.append( ' GSNMPJournal->SendWarning(msg, kSnmpOk);') result.append( '// Autogenerated\n') elif 'itmp = a' in at: result.append( at ) insert_in_next_line = True else: if insert_in_next_line: result.append( at+' \n// INT_PARAM [Autogenerated]:\n string msg = "Change_to: "+to_string('+"itmp"+");") result.append( ' sampler_.journal.PutRecord(msg);') result.append( ' GSNMPJournal->SendWarning(msg, kSnmpOk);') result.append( '// Autogenerated\n') insert_in_next_line = False else: result.append( at ) map(printer, result) sets['howOpen'] = 'w' sets['name'] = path+'ajax_set_settings_at.cc' sets['coding'] = 'cp1251' dal.list2file(sets, result)