def main(): try: output = sp.check_output(["svn","diff"] + sys.argv[1:], shell = 0) except sp.CalledProcessError as e: sys.stdout.write(e.output) sys.exit(e.returncode) for line in output.split("\n"): if line.startswith("Index:") or line.startswith("==="): color = cc.YELLOW elif line.startswith("+++") or line.startswith("---"): color = cc.SKYBLUE elif line.startswith("@@"): color = cc.PURPLE elif line.startswith("-"): color = cc.RED elif line.startswith("+"): color = cc.GREEN elif line.startswith(" "): print(line) continue else: continue cc.output(line, color) print()
def main(): args = sys.argv[1:] if args and args[0] == "-s": single = True args = args[1:] else: single = False try: output = sp.check_output(["svn", "st"] + args, shell=0) except sp.CalledProcessError as e: sys.stdout.write(e.output) sys.exit(e.returncode) for line in output.split("\n"): if not line: continue if line.startswith("M"): color = cc.RED elif line.startswith("C"): color = cc.YELLOW elif line.startswith("A"): color = cc.PURPLE elif line.startswith("D"): color = cc.SKYBLUE else: print(line.split()[1] if single else line) continue cc.output(line.split()[1] if single else line, color) print()
def search(lines, fname): number = 0 if lines[-1] == "": lines = lines[:-1] for line in lines: number += 1 out = [] if ns.withfilename or not onlyone: out.append(fname) if ns.linenumber: out.append(str(number)) if ns.invertmatch: if not pattern.search(line): out.append(line) print ':'.join(out) else: if not ns.highlight: if not ns.separately: obj = pattern.search(line) if obj: if ns.onlymatching: line = obj.group(0) if ns.column: out.append(str(obj.start() + 1)) out.append(line) print ':'.join(out) else: for obj in pattern.finditer(line): if ns.column: print ':'.join(out + [str(obj.start() + 1), line]) else: print ':'.join(out + [line]) else: if not ns.separately: offset = 0 first = 1 for obj in pattern.finditer(line): if first: if ns.column: out.append(str(obj.start() + 1)) sys.stdout.write(':'.join(out)) if len(out): sys.stdout.write(':') first = 0 sys.stdout.write(line[offset:obj.start()]) cc.output(obj.group(0), cc.YELLOW) offset = obj.end() if not first: print line[offset:] else: for obj in pattern.finditer(line): if ns.column: sys.stdout.write(':'.join(out + [str(obj.start() + 1)])) sys.stdout.write(':') else: sys.stdout.write(':'.join(out)) if len(out): sys.stdout.write(':') sys.stdout.write(line[:obj.start()]) cc.output(obj.group(0), cc.YELLOW) print line[obj.end():]
def print_translations(xml, with_color, detailed): #print xml original_query = get_elements(xml, "original-query") queryword = get_text(original_query[0]) custom_translations = get_elements(xml, "custom-translation") cc.output(queryword, cc.YELLOW); print "" translated = False for cus in custom_translations: source = get_elements_by_path(cus, "source/name") cc.output("Translations from " + source[0].decode("utf-8").encode(SYSENC), cc.RED);print "" contents = get_elements_by_path(cus, "translation/content") if with_color: for content in contents[0:5]: cc.output(get_text(content), cc.GREEN);print "" else: for content in contents[0:5]: print get_text(content) translated = True yodao_translations = get_elements(xml, "yodao-web-dict") printed = False for trans in yodao_translations: webtrans = get_elements(trans, "web-translation") for web in webtrans[0:5]: if not printed: cc.output("Translations from yodao:", cc.RED);print "" printed = True keys = get_elements(web, "key") values = get_elements_by_path(web, "trans/value") summaries = get_elements_by_path(web, "trans/summary") key = keys[0].strip() value = values[0].strip() if with_color: cc.output(get_text(key) + ":\t", cc.YELLOW) cc.output(get_text(value), cc.GREEN);print "" else: print get_text(value)
def print_translations(xml, with_color, detailed): #print xml original_query = get_elements(xml, "original-query") queryword = get_text(original_query[0]) custom_translations = get_elements(xml, "custom-translation") cc.output(queryword, cc.YELLOW) print("") translated = False for cus in custom_translations: source = get_elements_by_path(cus, "source/name") cc.output( "Translations from " + source[0].decode("utf-8").encode(SYSENC), cc.RED) print("") contents = get_elements_by_path(cus, "translation/content") if with_color: for content in contents[0:5]: cc.output(get_text(content), cc.GREEN) print("") else: for content in contents[0:5]: print(get_text(content)) translated = True yodao_translations = get_elements(xml, "yodao-web-dict") printed = False for trans in yodao_translations: webtrans = get_elements(trans, "web-translation") for web in webtrans[0:5]: if not printed: cc.output("Translations from yodao:", cc.RED) print("") printed = True keys = get_elements(web, "key") values = get_elements_by_path(web, "trans/value") summaries = get_elements_by_path(web, "trans/summary") key = keys[0].strip() value = values[0].strip() if with_color: cc.output(get_text(key) + ":\t", cc.YELLOW) cc.output(get_text(value), cc.GREEN) print("") else: print(get_text(value))