def do_diff(self, *args): '''Open a CodeInput with git diff ''' diff = self.repo.git.diff() designer = get_designer() designer_content = designer.designer_content tabs = designer_content.tab_pannel # check if diff is visible on tabbed panel. # if so, update the text content for i, code_input in enumerate(tabs.list_py_code_inputs): if code_input == self.diff_code_input: tabs.switch_to(tabs.tab_list[len(tabs.tab_list) - i - 2]) code_input.text = diff return # if not displayed, create or add it to the screen if self.diff_code_input is None: panel_item = DesignerTabbedPanelItem(text='Git diff') scroll = PyScrollView() _py_code_input = scroll.code_input _py_code_input.rel_file_path = 'designer.DesigerGit.diff_code_input' _py_code_input.text = diff _py_code_input.readonly = True _py_code_input.lexer = DiffLexer() tabs.list_py_code_inputs.append(_py_code_input) panel_item.content = scroll self.diff_code_input = panel_item else: self.diff_code_input.content.code_input.text = diff tabs.add_widget(self.diff_code_input) tabs.switch_to(tabs.tab_list[0])
def __init__(self): super().__init__() self.show_context_menu = False self.sh = self.modes.append( modes.PygmentsSH(self.document(), DiffLexer())) self.lines = self.panels.append(panels.LineNumberPanel(), panels.LineNumberPanel.Position.LEFT) self.setReadOnly(True) self.syntax_highlighter.color_scheme = api.ColorScheme( settings.color_scheme())
def create_diff(original_source: str, processed_source: str, source_file: str, highlight=False) -> str: diff_text = "".join( difflib.unified_diff( original_source.splitlines(keepends=True), processed_source.splitlines(keepends=True), fromfile=source_file, tofile=source_file, )) if highlight: diff_text = highlight_source(diff_text, DiffLexer(), Terminal256Formatter()) return diff_text
def lexer(self): def strip(lex): return [x[2:] for x in lex.filenames] if self.extension in strip(RenpyLexer): return RenpyLexer() elif self.extension in strip(DiffLexer): return DiffLexer() elif self.extension in strip(JsonLexer): return JsonLexer() elif self.extension in strip(YamlLexer): return YamlLexer() elif self.extension in strip(MarkdownLexer): return MarkdownLexer() elif self.extension in strip(XmlLexer): return XmlLexer() else: return NullLexer()
def do_diff(self, *args): '''Open a CodeInput with git diff ''' diff = self.repo.git.diff() if not diff: diff = 'Empty diff' d = get_designer() panel = d.designer_content.tab_pannel inputs = d.code_inputs # check if diff is visible on tabbed panel. # if so, update the text content for i, code_input in enumerate(panel.tab_list): if code_input == self.diff_code_input: panel.switch_to(panel.tab_list[len(panel.tab_list) - i - 2]) code_input.content.code_input.text = diff return # if not displayed, create or add it to the screen if self.diff_code_input is None: panel_item = DesignerCloseableTab(title='Git diff') panel_item.bind(on_close=panel.on_close_tab) scroll = PyScrollView() _py_code_input = scroll.code_input _py_code_input.text = diff _py_code_input.path = '' _py_code_input.readonly = True _py_code_input.lexer = DiffLexer() _py_code_input.saved = True panel_item.content = scroll panel_item.rel_path = '' self.diff_code_input = panel_item else: self.diff_code_input.content.code_input.text = diff panel.add_widget(self.diff_code_input) panel.switch_to(panel.tab_list[0])
def highlight_diff(diff): from pygments import highlight from pygments.lexers.diff import DiffLexer from pygments.formatters import HtmlFormatter return highlight(diff, DiffLexer(stripnl=False), HtmlFormatter())
'6pl': Perl6Lexer(), 'p6l': Perl6Lexer(), 'pl6': Perl6Lexer(), 'p6m': Perl6Lexer(), 'pm6': Perl6Lexer(), 't': Perl6Lexer(), 'rb': RubyLexer(), 'rbw': RubyLexer(), 'rake': RubyLexer(), 'rbx': RubyLexer(), 'duby': RubyLexer(), 'gemspec': RubyLexer(), 'ini': IniLexer(), 'init': IniLexer(), 'sh': BashLexer(), 'diff': DiffLexer(), 'patch': DiffLexer(), 'cs': CSharpLexer(), 'md': MarkdownLexer(), # WAIT: Virker dårlig } known_extensions = list(lexer_from_ext.keys()) # class EditorFrame(ScrollableNotebook): class EditorFrame(tk.ttk.Frame): """ A container for the notebook, including bottom console """ def __init__( self, parent,
def pretty(self) -> str: lines = list(self.lines) lines[0] += f" {self.target}" # include target name in comments return pygments.highlight("\n".join(lines), DiffLexer(), TerminalFormatter())
def colorize(): print(Colorize().set_lexer(DiffLexer()).highlight(stdin.read()))
def patch(): for obj in kalc_state_objects: if isinstance(obj, Deployment): # print("patch for ", obj.metadata_name) print(highlight(obj.get_patch(), DiffLexer(), TerminalFormatter()))
def __init__(self, fmt=None, datefmt=None, colors=None): if DiffLexer: self.lex = DiffLexer() self.formatter = TerminalFormatter() super(DiffLogFormatter, self).__init__(fmt, datefmt, colors)
def do_filter_part(self, text, html, mime_type, is_patch): """ Filter the part and output safe HTML. Search for code tags (``` or <code>), or determine if part is a patch. Syntax highlight the relevant parts and use the html part for the rest. """ ## Try to figure out if part is a patch if is_patch: from pygments.lexers.diff import DiffLexer return highlight(text, DiffLexer(), HtmlFormatter(noclasses=True)) ## Look for code segments between code-tags starttags = ['```', '<code>'] endtags = ['```', '</code>'] if mime_type == 'text/html': for tag, antitag in zip(starttags, endtags): i = 0 def tags(): nonlocal i i = html.find(tag, i) if i != -1: i += len(tag) yield i for j in tags(): e = html.find(antitag, i) if e != -1: segment = self.high(html[i:e]) html = html[:i - len(tag)] + segment + html[e + len(antitag):] i += len(segment) - len(tag) else: break return html elif mime_type == 'text/plain': # The GMime filter has created the HTML line-for-line. So if we find the # code tag on a line, it matches the same line in the HTML part. text_lines = text.split('\n') html_lines = html.split('\n') no = 0 offset = 0 # offset between HTML and TEXT part after syntax highlighting a segment while no < len(text_lines): l = text_lines[no] for tag, antitag in zip(starttags, endtags): it = l.find(tag) if it > -1: ih = html_lines[no + offset].find(tag) # find end for eno, el in enumerate(text_lines[no:]): iet = el.find(antitag) ieh = html_lines[no + eno + offset].find(antitag) if (eno > 0 and iet > -1) or (eno == 0 and iet > it): # found end tag segment = text_lines[no:no + eno + 1] segment[0] = segment[0][it + len(tag):] segment[-1] = segment[-1][:iet] html_segment = self.high( '\n'.join(segment)).split('\n') html_segment[0] = html_lines[ no + offset][ih + len(tag):] + html_segment[0] html_segment[ -1] = html_segment[-1] + html_lines[ no + eno + offset][ieh + len(antitag):] html_lines = html_lines[:no + offset] + html_segment + html_lines[ no + eno + offset + 1:] offset += len(html_segment) - len(segment) no += eno break break no += 1 return '\n'.join(html_lines) else: return html
def highlight(text): # this seems to append a newline, so remove it return pygments.highlight(text, DiffLexer(), _formatter()).rstrip('\n')
pass if extens == "py" or extens == "pyw" or extens == "sc" or extens == "sage" or extens == "tac": ui_core = CoreUI(lexer=PythonLexer()) elif extens == "txt" or extens == "README" or extens == "text": ui_core = CoreUI(lexer=TextLexer()) elif extens == "htm" or extens == "html" or extens == "css" or extens == "js" or extens == "md": ui_core = CoreUI(lexer=HtmlLexer()) elif extens == "xml" or extens == "xsl" or extens == "rss" or extens == "xslt" or extens == "xsd" or extens == "wsdl" or extens == "wsf": ui_core = CoreUI(lexer=XmlLexer()) elif extens == "php" or extens == "php5": ui_core = CoreUI(lexer=HtmlPhpLexer()) elif extens == "pl" or extens == "pm" or extens == "nqp" or extens == "p6" or extens == "6pl" or extens == "p6l" or extens == "pl6" or extens == "pm" or extens == "p6m" or extens == "pm6" or extens == "t": ui_core = CoreUI(lexer=Perl6Lexer()) elif extens == "rb" or extens == "rbw" or extens == "rake" or extens == "rbx" or extens == "duby" or extens == "gemspec": ui_core = CoreUI(lexer=RubyLexer()) elif extens == "ini" or extens == "init": ui_core = CoreUI(lexer=IniLexer()) elif extens == "conf" or extens == "cnf" or extens == "config": ui_core = CoreUI(lexer=ApacheConfLexer()) elif extens == "sh" or extens == "cmd" or extens == "bashrc" or extens == "bash_profile": ui_core = CoreUI(lexer=BashLexer()) elif extens == "diff" or extens == "patch": ui_core = CoreUI(lexer=DiffLexer()) elif extens == "cs": ui_core = CoreUI(lexer=CSharpLexer()) elif extens == "sql": ui_core = CoreUI(lexer=MySqlLexer()) else: ui_core = CoreUI(lexer=PythonLexer()) # default (no extension) lexer is python ui_core.mainloop()
def historyView(id): if request.method == 'GET': global ConfigParser if ConfigParser is None: import ConfigParser config = ConfigParser.ConfigParser() # SVN 설정 정보 로딩 config.read('config.ini') pSvnId = request.args.get('svnid', '') pFlag = request.args.get('flag', '') pOffset = int(request.args.get('offset', 0)) if pOffset < 0: pOffset = 0 result = mongo.db.tblBranch.find_one({"_id": ObjectId(id)}) print result # path_info = g.db.execute('select * from svn_info where s_path_id=?', [pSID]).fetchall() svnrooturl = '' if result['product'] == 'MF2' or result['product'] == 'AE': svnrooturl = config.get('svn', result['product'] + '.url') svnurl = svnrooturl + result['url'] else: svnrooturl = config.get('svn', result['product'] + '.url') svnurl = svnrooturl + result['url'] s = svncheck(svnrooturl, result['url'], '', '', config.get('svn', 'uid'), config.get('svn', 'upass')) # 마지막 리비전 조회 last_revision = s.getLastRevision() resultlist = [] print int(result['trev']), last_revision # DB에 저장된 최종 리비전이 리파지토리 최종 리비전 보다 작을 경우 변경 로그 조회 if int(result['trev']) < last_revision: # cur = g.db.cursor() # cur.execute('update svn_info set s_last_revision=? where s_path_url=?', [last_revision, path_info[0][1]]) log = s.diffrence(int(result['trev']) + 1, last_revision) tmpUpdateRevision = result['trev'] for info in log: print info tmpUpdateRevision = info.revision.number result = mongo.db.tblHistory.insert_one({ 'tblBranchKey': ObjectId(id), 'revision': info.revision.number, 'svnid': info.author, 'date': time.ctime(info.date), 'comment': info.message.decode('utf8'), 'paths': [] }) pathlist = [] for pathinfo in info.changed_paths: difftext = None # 파일 수정 if pathinfo.action == 'M': # 인코딩 에러가 발생할 경우 빈값으로 셋팅 try: difftext = s.getDiffText(info.revision.number, pathinfo.path).decode('utf-8') except: difftext = '' # 파일 추가 elif pathinfo.action == 'A': # 인코딩 에러가 발생할 경우 빈값으로 셋팅 try: difftext = pathinfo.action + ' ' + s.getText( info.revision.number, pathinfo.path).decode('utf-8') except: difftext = '' # 파일 삭제 elif pathinfo.action == 'D': difftext = pathinfo.action + ' ' + pathinfo.path if difftext: difftext = highlight(difftext.decode("utf-8"), DiffLexer(), HtmlFormatter()) tmpPath = pathinfo.path.decode('utf-8') mongo.db.tblHistory.update_one( {'_id': ObjectId(result.inserted_id)}, { '$push': { 'paths': { 'action': pathinfo.action, 'file': tmpPath, 'diff': difftext } } }) result = mongo.db.tblBranch.find_one_and_update( {"_id": ObjectId(id)}, {"$set": { "trev": last_revision }}) if pFlag == 'n': pOffset += 10 elif pFlag == 'p': pOffset -= 10 else: pOffset = 0 print pSvnId if pSvnId: result = mongo.db.tblHistory.find({ 'tblBranchKey': ObjectId(id), "svnid": { '$regex': pSvnId } }).skip(pOffset).limit(10) else: result = mongo.db.tblHistory.find({ 'tblBranchKey': ObjectId(id) }).skip(pOffset).limit(10) param = {'svnurl': svnurl, 'sid': id, 'offset': pOffset} return render_template('history/historyView.html', data=result, param=param)