本文整理汇总了Python中pygments.console.colorize方法的典型用法代码示例。如果您正苦于以下问题:Python console.colorize方法的具体用法?Python console.colorize怎么用?Python console.colorize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pygments.console
的用法示例。
在下文中一共展示了console.colorize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from pygments import console [as 别名]
# 或者: from pygments.console import colorize [as 别名]
def __init__(self, **options):
Formatter.__init__(self, **options)
# We ignore self.encoding if it is set, since it gets set for lexer
# and formatter if given with -Oencoding on the command line.
# The RawTokenFormatter outputs only ASCII. Override here.
self.encoding = 'ascii' # let pygments.format() do the right thing
self.compress = get_choice_opt(options, 'compress',
['', 'none', 'gz', 'bz2'], '')
self.error_color = options.get('error_color', None)
if self.error_color is True:
self.error_color = 'red'
if self.error_color is not None:
try:
colorize(self.error_color, '')
except KeyError:
raise ValueError("Invalid color %r specified" %
self.error_color)
示例2: i18n_validate_gettext
# 需要导入模块: from pygments import console [as 别名]
# 或者: from pygments.console import colorize [as 别名]
def i18n_validate_gettext():
"""
Make sure GNU gettext utilities are available
"""
returncode = subprocess.call(['which', 'xgettext'])
if returncode != 0:
msg = colorize(
'red',
"Cannot locate GNU gettext utilities, which are "
"required by django for internationalization.\n (see "
"https://docs.djangoproject.com/en/dev/topics/i18n/"
"translation/#message-files)\nTry downloading them from "
"http://www.gnu.org/software/gettext/ \n"
)
sys.stderr.write(msg)
sys.exit(1)
示例3: i18n_validate_transifex_config
# 需要导入模块: from pygments import console [as 别名]
# 或者: from pygments.console import colorize [as 别名]
def i18n_validate_transifex_config():
"""
Make sure config file with username/password exists
"""
home = path('~').expanduser()
config = home / '.transifexrc'
if not config.isfile or config.getsize == 0:
msg = colorize(
'red',
"Cannot connect to Transifex, config file is missing"
" or empty: {config} \nSee "
"http://help.transifex.com/features/client/#transifexrc \n".format(
config=config,
)
)
sys.stderr.write(msg)
sys.exit(1)
示例4: run_bokchoy
# 需要导入模块: from pygments import console [as 别名]
# 或者: from pygments.console import colorize [as 别名]
def run_bokchoy(**opts):
"""
Runs BokChoyTestSuite with the given options.
If a default store is not specified, runs the test suite for 'split' as the default store.
"""
if opts['default_store'] not in ['draft', 'split']:
msg = colorize(
'red',
'No modulestore specified, running tests for split.'
)
print(msg)
stores = ['split']
else:
stores = [opts['default_store']]
for store in stores:
opts['default_store'] = store
test_suite = BokChoyTestSuite('bok-choy', **opts)
test_suite.run()
示例5: bokchoy_coverage
# 需要导入模块: from pygments import console [as 别名]
# 或者: from pygments.console import colorize [as 别名]
def bokchoy_coverage():
"""
Generate coverage reports for bok-choy tests
"""
Env.BOK_CHOY_REPORT_DIR.makedirs_p()
coveragerc = Env.BOK_CHOY_COVERAGERC
msg = colorize('green', "Combining coverage reports")
print(msg)
sh("coverage combine --rcfile={}".format(coveragerc))
msg = colorize('green', "Generating coverage reports")
print(msg)
sh("coverage html --rcfile={}".format(coveragerc))
sh("coverage xml --rcfile={}".format(coveragerc))
sh("coverage report --rcfile={}".format(coveragerc))
示例6: format
# 需要导入模块: from pygments import console [as 别名]
# 或者: from pygments.console import colorize [as 别名]
def format(self, tokensource, outfile):
try:
outfile.write(b'')
except TypeError:
raise TypeError('The raw tokens formatter needs a binary '
'output file')
if self.compress == 'gz':
import gzip
outfile = gzip.GzipFile('', 'wb', 9, outfile)
def write(text):
outfile.write(text.encode())
flush = outfile.flush
elif self.compress == 'bz2':
import bz2
compressor = bz2.BZ2Compressor(9)
def write(text):
outfile.write(compressor.compress(text.encode()))
def flush():
outfile.write(compressor.flush())
outfile.flush()
else:
def write(text):
outfile.write(text.encode())
flush = outfile.flush
if self.error_color:
for ttype, value in tokensource:
line = "%s\t%r\n" % (ttype, value)
if ttype is Token.Error:
write(colorize(self.error_color, line))
else:
write(line)
else:
for ttype, value in tokensource:
write("%s\t%r\n" % (ttype, value))
flush()
示例7: wait_for_test_servers
# 需要导入模块: from pygments import console [as 别名]
# 或者: from pygments.console import colorize [as 别名]
def wait_for_test_servers():
"""
Wait until we get a successful response from the servers or time out
"""
for service, info in Env.BOK_CHOY_SERVERS.iteritems():
ready = wait_for_server("0.0.0.0", info['port'])
if not ready:
msg = colorize(
"red",
"Could not contact {} test server".format(service)
)
print(msg)
sys.exit(1)
示例8: check_mongo
# 需要导入模块: from pygments import console [as 别名]
# 或者: from pygments.console import colorize [as 别名]
def check_mongo():
"""
Check that mongo is running
"""
if not is_mongo_running():
msg = colorize('red', "Mongo is not running locally.")
print(msg)
sys.exit(1)
示例9: check_mysql
# 需要导入模块: from pygments import console [as 别名]
# 或者: from pygments.console import colorize [as 别名]
def check_mysql():
"""
Check that mysql is running
"""
if not is_mysql_running():
msg = colorize('red', "MySQL is not running locally.")
print(msg)
sys.exit(1)
示例10: __exit__
# 需要导入模块: from pygments import console [as 别名]
# 或者: from pygments.console import colorize [as 别名]
def __exit__(self, exc_type, exc_value, traceback):
super(BokChoyTestSuite, self).__exit__(exc_type, exc_value, traceback)
msg = colorize('green', "Cleaning up databases...")
print(msg)
# Clean up data we created in the databases
sh("./manage.py lms --settings bok_choy flush --traceback --noinput")
bokchoy_utils.clear_mongo()
示例11: run_test
# 需要导入模块: from pygments import console [as 别名]
# 或者: from pygments.console import colorize [as 别名]
def run_test(self):
"""
Runs a self.cmd in a subprocess and waits for it to finish.
It returns False if errors or failures occur. Otherwise, it
returns True.
"""
cmd = self.cmd
sys.stdout.write(cmd)
msg = colorize(
'green',
'\n{bar}\n Running tests for {suite_name} \n{bar}\n'.format(suite_name=self.root, bar='=' * 40),
)
sys.stdout.write(msg)
sys.stdout.flush()
kwargs = {'shell': True, 'cwd': None}
process = None
try:
process = subprocess.Popen(cmd, **kwargs)
process.communicate()
except KeyboardInterrupt:
kill_process(process)
sys.exit(1)
else:
return (process.returncode == 0)
示例12: report_test_results
# 需要导入模块: from pygments import console [as 别名]
# 或者: from pygments.console import colorize [as 别名]
def report_test_results(self):
"""
Writes a list of failed_suites to sys.stderr
"""
if len(self.failed_suites) > 0:
msg = colorize('red', "\n\n{bar}\nTests failed in the following suites:\n* ".format(bar="=" * 48))
msg += colorize('red', '\n* '.join([s.root for s in self.failed_suites]) + '\n\n')
else:
msg = colorize('green', "\n\n{bar}\nNo test failures ".format(bar="=" * 48))
print(msg)
示例13: format
# 需要导入模块: from pygments import console [as 别名]
# 或者: from pygments.console import colorize [as 别名]
def format(self, tokensource, outfile):
try:
outfile.write(b'')
except TypeError:
raise TypeError('The raw tokens formatter needs a binary '
'output file')
if self.compress == 'gz':
import gzip
outfile = gzip.GzipFile('', 'wb', 9, outfile)
def write(text):
outfile.write(text.encode())
flush = outfile.flush
elif self.compress == 'bz2':
import bz2
compressor = bz2.BZ2Compressor(9)
def write(text):
outfile.write(compressor.compress(text.encode()))
def flush():
outfile.write(compressor.flush())
outfile.flush()
else:
def write(text):
outfile.write(text.encode())
flush = outfile.flush
if self.error_color:
for ttype, value in tokensource:
line = "%s\t%r\n" % (ttype, value)
if ttype is Token.Error:
write(colorize(self.error_color, line))
else:
write(line)
else:
for ttype, value in tokensource:
write("%s\t%r\n" % (ttype, value))
flush()
示例14: test_console_functions
# 需要导入模块: from pygments import console [as 别名]
# 或者: from pygments.console import colorize [as 别名]
def test_console_functions():
assert console.reset_color() == console.codes['reset']
assert console.colorize('blue', 'text') == \
console.codes['blue'] + 'text' + console.codes['reset']
示例15: coverage
# 需要导入模块: from pygments import console [as 别名]
# 或者: from pygments.console import colorize [as 别名]
def coverage(options):
"""
Build the html, xml, and diff coverage reports
"""
compare_branch = getattr(options, 'compare_branch', 'origin/master')
for directory in Env.LIB_TEST_DIRS + ['cms', 'lms']:
report_dir = Env.REPORT_DIR / directory
if (report_dir / '.coverage').isfile():
# Generate the coverage.py HTML report
sh("coverage html --rcfile={dir}/.coveragerc".format(dir=directory))
# Generate the coverage.py XML report
sh("coverage xml -o {report_dir}/coverage.xml --rcfile={dir}/.coveragerc".format(
report_dir=report_dir,
dir=directory
))
# Find all coverage XML files (both Python and JavaScript)
xml_reports = []
for filepath in Env.REPORT_DIR.walk():
if filepath.basename() == 'coverage.xml':
xml_reports.append(filepath)
if not xml_reports:
err_msg = colorize(
'red',
"No coverage info found. Run `paver test` before running `paver coverage`.\n"
)
sys.stderr.write(err_msg)
else:
xml_report_str = ' '.join(xml_reports)
diff_html_path = os.path.join(Env.REPORT_DIR, 'diff_coverage_combined.html')
# Generate the diff coverage reports (HTML and console)
sh(
"diff-cover {xml_report_str} --compare-branch={compare_branch} "
"--html-report {diff_html_path}".format(
xml_report_str=xml_report_str,
compare_branch=compare_branch,
diff_html_path=diff_html_path,
)
)
print("\n")