def open(self, file): html_desc = open(file) html = html_desc.read() html_desc.close() xml = minidom.parseString(html) pre = xml.getElementsByTagName('pre')[0].firstChild.data diff = Diff() return diff.restore(pre)
def open (self, file): html_desc = open(file) html = html_desc.read() html_desc.close() xml = minidom.parseString(html) pre = xml.getElementsByTagName ('pre')[0].firstChild.data diff = Diff () return diff.restore (pre)
def generate(self): self.html_file = self.make_file(self.result1, self.result2) self.html_file = ' '.join(self.html_file.split(' ')) txt_diff = Diff(self.result1, self.result2, self.junk) self.text_file = '''<br /><br /> <!-- %s --> <center><div class="umit" align="center">%s</div></center> <pre align="center">%s</pre> '''% (_("Changes to this file can make Umit unable to read it."),\ _('Regular Text Diff: '),\ ''.join(txt_diff.generate ())) return self.insert_banner()
def generate (self): self.html_file = self.make_file (self.result1, self.result2) self.html_file = ' '.join(self.html_file.split(' ')) txt_diff = Diff (self.result1, self.result2, self.junk) self.text_file = '''<br /><br /> <!-- %s --> <center><div class="umit" align="center">%s</div></center> <pre align="center">%s</pre> '''% (_("Changes to this file can make Umit unable to read it."),\ _('Regular Text Diff: '),\ ''.join(txt_diff.generate ())) return self.insert_banner ()
def __init__(self): super().__init__() # settings file self.settings = QSettings('martinopilia', 'wikied') # label for the permanent message in the status bar self.permanentMessage = QLabel('Disconnected') # window for the regex sandbox self.regexSandbox = RegexSandbox() # object for the connection to the site self.connection = Connection(self.settings) self.connection.statusMessage.connect(self.statusBar().showMessage) self.connection.permanentMessage.connect(self.permanentMessage.setText) # window for the account settings self.accountDialog = AccountDialog(self.settings) # add permanent widget to the status bar self.statusBar().addPermanentWidget(self.permanentMessage) # actions # quit exitAction = QAction( QIcon('icons/window-close'), 'Exit', self) exitAction.setStatusTip('Quit the application (Ctrl+Q)') exitAction.setShortcut('Ctrl+Q') exitAction.triggered.connect(self.close) # open RegexSandbox sandboxAction = QAction( QIcon('icons/code-context'), 'Regex sandbox', self) sandboxAction.setStatusTip( 'Open the regex test environment (Ctrl+Shif+S)') sandboxAction.setShortcut('Ctrl+Shift+S') sandboxAction.triggered.connect(self.regexSandbox.show) # connect connectAction = QAction( QIcon('icons/network-connect'), 'Connect', self) connectAction.setStatusTip('Connect to the project') connectAction.triggered.connect(self.connection.connect) # disconnect disconnectAction = QAction( QIcon('icons/network-disconnect'), 'Disconnect', self) disconnectAction.setStatusTip('Disconnect from the project') disconnectAction.triggered.connect(self.connection.disconnect) # set account setAccountAction = QAction( QIcon('icons/user-identity'), 'Set account', self) setAccountAction.setStatusTip('Manage the account settings') setAccountAction.triggered.connect(self.accountDialog.exec_) # central widget and docks diff = Diff() diff.setObjectName('Diff') diff.setVisible(False) self.addDockWidget(Qt.TopDockWidgetArea, diff) editorWidget = VoiceEditor(self.connection, diff) self.setCentralWidget(editorWidget) substWidget = FindAndReplace(editorWidget.pageContent) substWidget.setObjectName('Find and replace') substWidget.statusMessage.connect(self.statusBar().showMessage) self.addDockWidget(Qt.BottomDockWidgetArea, substWidget) voiceSelector = VoiceSelector(self.connection, editorWidget) voiceSelector.setObjectName('Select voices') voiceSelector.statusMessage.connect(self.statusBar().showMessage) self.addDockWidget(Qt.LeftDockWidgetArea, voiceSelector) # toolbars # Connection connectionToolbar = QToolBar('Connection') connectionToolbar.setObjectName('connectionToolbar') connectionToolbar.addActions( [connectAction, disconnectAction, setAccountAction]) self.addToolBar(connectionToolbar) # menu bar # File fileMenu = self.menuBar().addMenu('File') fileMenu.addAction(connectAction) fileMenu.addAction(disconnectAction) fileMenu.addAction(setAccountAction) fileMenu.addSeparator() fileMenu.addAction(exitAction) # Tools toolsMenu = self.menuBar().addMenu('Tools') toolsMenu.addAction(sandboxAction) # View viewMenu = self.menuBar().addMenu('View') viewMenu.addAction(voiceSelector.toggleViewAction()) viewMenu.addAction(substWidget.toggleViewAction()) viewMenu.addAction(connectionToolbar.toggleViewAction()) viewMenu.addAction(editorWidget.actionsToolbar.toggleViewAction()) viewMenu.addAction(diff.toggleViewAction()) viewMenu.addAction(editorWidget.editToolbar.toggleViewAction()) # view details self.setGeometry(200, 200, 1000, 800) self.setWindowTitle('WikiEd') self.setWindowIcon(QIcon('')) editorWidget.pageContent.setFocus() # restore state and geometry (lazy initialization) if (not self.settings.value('window/geometry') or not self.settings.value('window/state')): self.saveWindow() self.restoreGeometry(self.settings.value('window/geometry')) self.restoreState(self.settings.value('window/state')) self.show()
def analyze_between(self, another, cls): anls = self.anls another = another.oplist Diff.pos_oplist = self Diff.neg_oplist = another print("=================================================") print("Diff list: {}".format(len(Diff.get_diff_list(cls)))) Diff.update_diffs(cls) #dry_list = self.ops a_list = self.ops b_list = another.ops print("Start analysis...") def must_op_str(x, who): anls.oplist[who.name][x.name] = True def none_op_str(x, who): anls.oplist[who.name][x.name] = False def unkn_op_str(x): anls.unknown[tuple(x.bounds)] = x.diff # Round 1: remove known options: for op in a_list: if op.verified and not op.suspected: if op.set: must_op_str(op, self) else: none_op_str(op, self) for op in b_list: if op.verified and not op.suspected: if op.set: must_op_str(op, another) else: none_op_str(op, another) Diff.update_diffs(cls) print("Known members in {:7s}:{}".format(self.name, [ x.name for x in a_list if x.verified and x.set and not x.suspected ])) # sure existing members print("Known members in {:7s}:{}".format(another.name, [ x.name for x in b_list if x.verified and x.set and not x.suspected ])) # sure existing members # Round 2: if diff is larger than a specific value, then a config is confirmed # TODO None # Round 3: no options. If there's a difference then it is an unknown tag for diff in Diff.get_diff_list(cls): if len(diff.oplist) == 0: # no options unkn_op_str(diff) # Round 4: only has one option and size matches: elif len(diff.oplist) == 1: # one option opname = diff.oplist[0] op_a = self.get_option(opname) op_b = another.get_option(opname) # TODO: currently we assume op_a == op_b so we let op = op_a if diff.get_bytes(op_a) == abs(diff.diff): if diff.diff > 0: op = op_a st = self else: op = op_b st = another must_op_str(op, st) #diff.expected += op.get_bytes() #op.verified = True #op.set = True st.set_option(op.name) print("{} confirmed by round 4.".format(op.name)) eff = diff.get_eff(op_a) if len(eff.deps) == 1: op = eff.deps[0] #op.verified = True #op.set = True st.set_option(op.name) print("{} confirmed by round 4.".format(op.name)) else: unkn_op_str(diff) # Round 5: more than 2 options but only one option is below diff else: # TODO: remove self ref, and the implication of same options # print(diff.oplist) # gaps for paddings opnames = [ op for op in diff.oplist if diff.get_bytes(self.get_option(op)) > 0 and diff.get_bytes(self.get_option(op)) <= (abs(diff.diff) + 8) ] if len(opnames) == 1: sign = 1 if diff.diff > 0: st = self sign = 1 else: st = another sign = -1 op = st.get_option(opnames[0]) must_op_str(op, st) #diff.expected += sign*diff.get_bytes(self.get_option(op)) #op.verified = True #op.set = True st.set_option(op.name) Diff.update_diffs(cls)
return unkn_op_str, poss_op_str, add_details, set_diff, set_diff_str # Eradicated enough cases, now need to run a powerset # diff_list = [x for x in diff_list if x.expected != x.diff] a_dep_list = [ x for x in a_list if x.verified and x.set and not x.suspected ] # sure existing members b_dep_list = [ x for x in b_list if x.verified and x.set and not x.suspected ] # sure existing members a_list = [] b_list = [] print("Populating perm lists") for diff in Diff.get_merged_list(): for opname in diff.oplist: a_op = self.get_option(opname) b_op = another.get_option(opname) if a_op not in a_list and not (a_op.verified and not a_op.set ) and a_op not in a_dep_list: a_list.append(a_op) if b_op not in b_list and not (b_op.verified and not b_op.set ) and b_op not in b_dep_list: b_list.append(b_op) for cls in Diff.diff_list.keys(): print("{}:".format(cls.__name__)) print(Diff.get_diff_list(cls)) print("first round eradication done.") print("dep list {:7s}:{}".format(self.name,
def cmp(self, another): diff = 0 lastmem = "__beginning__" for idx, item in enumerate(type(self).Members): a = self.getOffset(idx) b = another.getOffset(idx) # deal with padding difference if item in type(self).PaddingList.keys(): pad_flag = False if type(self).PaddingList[item] == None: pad_flag = True else: opname = type(self).PaddingList[item] op_0 = self.oplist.get_option(opname) op_1 = another.oplist.get_option(opname) bool_0 = op_0.verified and op_0.set bool_1 = op_1.verified and op_1.set if bool_0 or bool_1: pad_flag = True if pad_flag: newdiff = diff olddiff = diff if diff != 0: if diff > 0: newdiff = diff // 8 * 8 elif diff < 0: newdiff = diff // (-8) * (-8) diff = newdiff print( "Smooth out padding at {}, old diff: {}, new diff: {}." .format(item, olddiff, newdiff)) else: print( "Neither side has member {}, skipping padding".format( item)) # both not defined if (a == UNDEF and b == UNDEF): #print("Skipping...: {} not tested.".format(item)) continue # only one has a member if (a == UNDEF and b != UNDEF) or (a != UNDEF and b == UNDEF): t = self s = another if (a == UNDEF): t = another s = self print("{} has member {} that {} doesn't.".format( t.name, item, s.name)) continue # both have a member but with different offsets # Logic: the difference will remain constant if no new diff is introduced, save for padding issues which can be resolved. new_diff = a - b if diff != new_diff: diff, true_diff = new_diff, new_diff - diff if true_diff < 0: missing = self.name else: missing = another.name last_idx = idx - 1 while last_idx >= 0 and (self.offsets[last_idx] == UNDEF or another.offsets[last_idx] == UNDEF): last_idx = last_idx - 1 print( "possible missing members in {} kernel, between {} and {}, offsets: {}, {}, diff: {}" .format(missing, type(self).Members[last_idx], type(self).Members[idx], hex(a), hex(b), true_diff)) lastmem = item Diff(type(self), true_diff, tuple((type(self).Members[last_idx], type(self).Members[idx])), oplist=self.oplist) else: #print("member registered in both kernel: {}, offset {}, {}.".format(type(self).Members[idx],hex(a), hex(b))) None return self.oplist.analyze_between(another, type(self))
pyhg_action = Shelved() elif options.action == 'restore': from Shelf import Restore pyhg_action = Restore() elif options.action == 'conflicts': from Shelf import Conflicts Conflicts(options) elif options.action == 'push': from Push import Push Push(options) elif options.action == 'mergeheads': from MergeHeads import MergeHeads MergeHeads(options) elif options.action == 'diff': from Diff import Diff Diff(options) elif options.action == 'switch': from Switch import Switch pyhg_action = Switch() if pyhg_action: if not pyhg_action.execute(options): print(pyhg_action.message, file=sys.stderr) result = 1 else: if not pyhg_action.cleanup(options): print(pyhg_action.message, file=sys.stderr) result = 1 if os.name != 'nt': # reset the console colors to defaults
def main(argv): TOKEN = 'tester:xxxxxxxxxxxxx' filepath = 'app_urls_diff.txt' fullpath = sys.path[0] + os.sep + 'urls' + os.sep + filepath resultFile = 'test.log' app_version1 = '' app_version2 = '' helpStr = '{} -v <online_version> -V <yf_version> -u <online_url> -U <yf_url>'.format( argv[0]) try: opts, args = getopt.getopt(argv[1:], "hv:V:u:U:", [ "help", "online_version=", "yf_version=", "online_url=", "yf_url=" ]) #print(opts,args) except getopt.GetoptError: #print(helpStr) sys.exit(2) for opt, arg in opts: if opt == '-h': #print(helpStr) sys.exit() #elif opt in ("-f", "--logFileName"): # filepath = arg elif opt in ("-v", "--appVersion1"): online_version = arg #print(online_version) elif opt in ("-V", "--appVersion2"): yf_version = arg #print(yf_version) elif opt in ("-u", "--online_url"): online_url = arg #print('online_url=%s'%online_url) elif opt in ("-U", "--yf_url"): yf_url = arg #print('yf_url=%s'%yf_url) else: print('Unrecognized paramters') print(helpStr) sys.exit(3) try: fw = open(resultFile, 'w', encoding='utf-8') f = open(fullpath) counter = 0 while True: #if counter > 10: # break line = f.readline() if not line: break line_param = line.strip('\n').split('\t') url1 = online_url + line_param[0] url2 = yf_url + line_param[0] param_body1 = json.loads(line_param[1]) param_body2 = json.loads(line_param[1]) param_body1['app_version'] = online_version param_body2['app_version'] = yf_version param_body1['t_token'] = TOKEN param_body2['t_token'] = TOKEN try: # resA = str(requests.post(url1, data=param_body).text) resA = requests.post( url1, data=param_body1) # request请求格式是url + json格式 time.sleep(1) # resB = str(requests.post(url2, data=param_body).text) resB = requests.post(url2, data=param_body2) time.sleep(1) #print(json.loads(str(resB.text).replace("\n", ""), encoding='UTF-8')) if resA.status_code != 200 or resB.status_code != 200: fw.write('{}\n{}\n{}\n'.format(counter, url1, resA.text)) fw.write('{}\n{}\n'.format(url2, resB.text)) fw.write('-' * 50) except: print("error, url is: " + "\n" + url1 + "\n") param_body1.pop('t_token') print(param_body1) pass counter += 1 print(counter) dif = Diff() #print(resA.text) #print(resB.text) resA_json = json.loads(str(resA.text).replace("\n", ""), encoding='UTF-8') resB_json = json.loads(str(resB.text).replace("\n", ""), encoding='UTF-8') #print(resA_json) #print(resB_json) print(json.loads(str(resA.text).replace("\n", ""))) print(json.loads(str(resB.text).replace("\n", ""))) dif.diff( json.loads(str(resA.text).replace("\n", ""), encoding='UTF-8'), json.loads(str(resB.text).replace("\n", ""), encoding='UTF-8')) # dif.diff(json.dumps(json.loads(resA.replace("\n", ""), encoding='UTF-8'),ensure_ascii=False),json.dumps(json.loads(resB.replace("\n", ""), encoding='UTF-8'),ensure_ascii=False)) a = dif.result() # diff 的结果 print(a) except Exception as e: print(e) finally: f.close() fw.close()