def isolation_print_command(cmd, path=None, add_env=None): cprint( blue_arrow + " " + sanitize(cmd) + "@|" + (" @!@{kf}in@| '@!" + sanitize(path) + "@|'" if path else "") + (" @!@{kf}with@| '@!" + " ".join(["%s=%s" % (k, v) for k, v in add_env.items()]) + "@|'" if add_env else "") )
def test_terminal_colors(self): test = '@_This is underlined@|' rslt = '\033[4mThis is underlined\033[0m\033[0m' assert fmt(test) == rslt test = 'This has bad stuff @! @/ @_ @| OK!' test = sanitize(test) rslt = 'This has bad stuff @! @/ @_ @| OK!\033[0m' assert fmt(test) == rslt test = char(2018) test = sanitize(test) rslt = char(2018) assert test == rslt
def test_terminal_colors(self): test = '@_This is underlined@|' rslt = '\033[4mThis is underlined\033[0m\033[0m' assert fmt(test) == rslt test = 'This has bad stuff @! @/ @_ @| OK!' test = sanitize(test) rslt = 'This has bad stuff @! @/ @_ @| OK!\033[0m' assert fmt(test) == rslt test = u'\u2018@' test = sanitize(test) rslt = u'\u2018@@' assert test == rslt
def print_command_banner(cmd, cwd, color): if color: # Prepare for printing cmd_str = sanitize(' '.join(cmd)) cwd_str = sanitize(cwd) # Print command notice cprint('@{bf}####') cprint('@{bf}#### Running command: @!"%s"@|@{bf} in @!"%s"' % (cmd_str, cwd_str)) cprint('@{bf}####') else: print('####') print('#### Running command: "%s" in "%s"' % (' '.join(cmd), cwd)) print('####')
def test_terminal_colors(self): # since other test might disable ansi colors # we need to ensure it is enabled enable_ANSI_colors() assert ansi('reset') != '' test = '@_This is underlined@|' rslt = '\033[4mThis is underlined\033[0m\033[0m' assert fmt(test) == rslt test = 'This has bad stuff @! @/ @_ @| OK!' test = sanitize(test) rslt = 'This has bad stuff @! @/ @_ @| OK!\033[0m' assert fmt(test) == rslt test = char(2018) test = sanitize(test) rslt = char(2018) assert test == rslt
def colorize_line(line): cline = sanitize(line) cline = cline.replace( '-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~', '-- @{pf}~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~@|') if line.startswith('-- ~~'): # -- ~~ - cline = cline.replace('~~ ', '@{pf}~~ @|') cline = cline.replace(' - ', ' - @!@{bf}') cline = cline.replace('(', '@|(') cline = cline.replace('(plain cmake)', '@|(@{rf}plain cmake@|)') cline = cline.replace('(unknown)', '@|(@{yf}unknown@|)') if line.startswith('-- +++'): # -- +++ add_subdirectory(package) cline = cline.replace('+++', '@!@{gf}+++@|') cline = cline.replace('kin package: \'', 'kin package: \'@!@{bf}') cline = cline.replace(')', '@|)') cline = cline.replace('\'\n', '@|\'\n') cline = cline.replace('cmake package: \'', 'cmake package: \'@!@{bf}') cline = cline.replace('\'\n', '@|\'\n') if line.startswith('-- ==>'): cline = cline.replace('-- ==>', '-- @!@{bf}==>@|') if line.lower().startswith('warning'): # WARNING cline = ansi('yf') + cline if line.startswith('CMake Warning'): # CMake Warning... cline = cline.replace('CMake Warning', '@{yf}@!CMake Warning@|') if line.startswith('ERROR:'): # ERROR: cline = cline.replace('ERROR:', '@!@{rf}ERROR:@|') if line.startswith('[guoguo]'): # guoguo: cline = cline.replace('[guoguo]:', '@!@{rf}[guoguo]@|') if line.startswith('CMake Error'): # CMake Error... cline = cline.replace('CMake Error', '@{rf}@!CMake Error@|') if line.startswith('Call Stack (most recent call first):'): # CMake Call Stack cline = cline.replace('Call Stack (most recent call first):', '@{cf}@_Call Stack (most recent call first):@|') return fmt(cline)
def colorize_line(line): cline = sanitize(line) cline = cline.replace( '-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~', '-- @{pf}~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~@|' ) if line.startswith('-- ~~'): # -- ~~ - cline = cline.replace('~~ ', '@{pf}~~ @|') cline = cline.replace(' - ', ' - @!@{bf}') cline = cline.replace('(', '@|(') cline = cline.replace('(metapackage)', '@|(@{cf}metapackage@|)') cline = cline.replace('(plain cmake)', '@|(@{rf}plain cmake@|)') cline = cline.replace('(unknown)', '@|(@{yf}unknown@|)') if line.startswith('-- +++'): # -- +++ add_subdirectory(package) cline = cline.replace('+++', '@!@{gf}+++@|') cline = cline.replace('kin package: \'', 'kin package: \'@!@{bf}') cline = cline.replace(')', '@|)') cline = cline.replace('metapackage: \'', 'metapackage: \'@!@{bf}') cline = cline.replace('\'\n', '@|\'\n') cline = cline.replace('cmake package: \'', 'cmake package: \'@!@{bf}') cline = cline.replace('\'\n', '@|\'\n') if line.startswith('-- ==>'): cline = cline.replace('-- ==>', '-- @!@{bf}==>@|') if line.lower().startswith('warning'): # WARNING cline = ansi('yf') + cline if line.startswith('CMake Warning'): # CMake Warning... cline = cline.replace('CMake Warning', '@{yf}@!CMake Warning@|') if line.startswith('ERROR:'): # ERROR: cline = cline.replace('ERROR:', '@!@{rf}ERROR:@|') if line.startswith('CMake Error'): # CMake Error... cline = cline.replace('CMake Error', '@{rf}@!CMake Error@|') if line.startswith('Call Stack (most recent call first):'): # CMake Call Stack cline = cline.replace('Call Stack (most recent call first):', '@{cf}@_Call Stack (most recent call first):@|') return fmt(cline)
def colorize_line(line): cline = sanitize(line) cline = cline.replace( "-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~", "-- @{pf}~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~@|", ) if line.startswith("-- ~~"): # -- ~~ - cline = cline.replace("~~ ", "@{pf}~~ @|") cline = cline.replace(" - ", " - @!@{bf}") cline = cline.replace("(", "@|(") cline = cline.replace("(plain cmake)", "@|(@{rf}plain cmake@|)") cline = cline.replace("(unknown)", "@|(@{yf}unknown@|)") if line.startswith("-- +++"): # -- +++ add_subdirectory(package) cline = cline.replace("+++", "@!@{gf}+++@|") cline = cline.replace("kin package: '", "kin package: '@!@{bf}") cline = cline.replace(")", "@|)") cline = cline.replace("'\n", "@|'\n") cline = cline.replace("cmake package: '", "cmake package: '@!@{bf}") cline = cline.replace("'\n", "@|'\n") if line.startswith("-- ==>"): cline = cline.replace("-- ==>", "-- @!@{bf}==>@|") if line.lower().startswith("warning"): # WARNING cline = ansi("yf") + cline if line.startswith("CMake Warning"): # CMake Warning... cline = cline.replace("CMake Warning", "@{yf}@!CMake Warning@|") if line.startswith("ERROR:"): # ERROR: cline = cline.replace("ERROR:", "@!@{rf}ERROR:@|") if line.startswith("CMake Error"): # CMake Error... cline = cline.replace("CMake Error", "@{rf}@!CMake Error@|") if line.startswith("Call Stack (most recent call first):"): # CMake Call Stack cline = cline.replace("Call Stack (most recent call first):", "@{cf}@_Call Stack (most recent call first):@|") return fmt(cline)
def isolation_print_command(cmd, path=None, add_env=None): cprint(blue_arrow + " " + sanitize(cmd) + "@|" + (" @!@{kf}in@| '@!" + sanitize(path) + "@|'" if path else '') + (" @!@{kf}with@| '@!" + ' '.join(['%s=%s' % (k, v) for k, v in add_env.items()]) + "@|'" if add_env else ''))
def isolation_print_command(cmd, path=None): cprint(blue_arrow + " " + sanitize(cmd) + "@|" + (" @!@{kf}in@| '@!" + sanitize(path) + "@|'" if path else ''))
def isolation_print_command(cmd, path=None): cprint( blue_arrow + " " + sanitize(cmd) + "@|" + (" @!@{kf}in@| '@!" + sanitize(path) + "@|'" if path else '') )