本文整理汇总了Python中coalib.output.printers.LogPrinter.LogPrinter.warn方法的典型用法代码示例。如果您正苦于以下问题:Python LogPrinter.warn方法的具体用法?Python LogPrinter.warn怎么用?Python LogPrinter.warn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类coalib.output.printers.LogPrinter.LogPrinter
的用法示例。
在下文中一共展示了LogPrinter.warn方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from coalib.output.printers.LogPrinter import LogPrinter [as 别名]
# 或者: from coalib.output.printers.LogPrinter.LogPrinter import warn [as 别名]
def __init__(
self,
log_printer: LogPrinter,
project_dir: str,
flush_cache: bool=False):
"""
Initialize FileCache.
:param log_printer: A LogPrinter object to use for logging.
:param project_dir: The root directory of the project to be used
as a key identifier.
:param flush_cache: Flush the cache and rebuild it.
"""
self.log_printer = log_printer
self.project_dir = project_dir
self.current_time = int(time.time())
cache_data = pickle_load(log_printer, project_dir, {})
last_time = -1
if "time" in cache_data:
last_time = cache_data["time"]
if not flush_cache and last_time > self.current_time:
log_printer.warn("It seems like you went back in time - your "
"system time is behind the last recorded run "
"time on this project. The cache will "
"be force flushed.")
flush_cache = True
self.data = cache_data.get("files", {})
if flush_cache:
self.flush_cache()
示例2: test_logging
# 需要导入模块: from coalib.output.printers.LogPrinter import LogPrinter [as 别名]
# 或者: from coalib.output.printers.LogPrinter.LogPrinter import warn [as 别名]
def test_logging(self):
uut = LogPrinter(StringPrinter(), timestamp_format="")
uut.log_message(self.log_message, end="")
self.assertEqual(uut.printer.string, str(self.log_message))
uut = LogPrinter(StringPrinter(), log_level=LOG_LEVEL.DEBUG)
uut.log_message(self.log_message, end="")
self.assertEqual(
uut.printer.string,
"[ERROR][" + self.timestamp.strftime("%X") + "] " +
Constants.COMPLEX_TEST_STRING)
uut.printer.clear()
uut.log(LOG_LEVEL.ERROR,
Constants.COMPLEX_TEST_STRING,
timestamp=self.timestamp,
end="")
self.assertEqual(
uut.printer.string,
"[ERROR][" + self.timestamp.strftime("%X") + "] " +
Constants.COMPLEX_TEST_STRING)
uut.printer.clear()
uut.debug(Constants.COMPLEX_TEST_STRING,
"d",
timestamp=self.timestamp,
end="")
self.assertEqual(
uut.printer.string,
"[DEBUG][" + self.timestamp.strftime("%X") + "] " +
Constants.COMPLEX_TEST_STRING + " d")
uut.printer.clear()
uut.log_level = LOG_LEVEL.INFO
uut.debug(Constants.COMPLEX_TEST_STRING,
timestamp=self.timestamp,
end="")
self.assertEqual(uut.printer.string, "")
uut.printer.clear()
uut.info(Constants.COMPLEX_TEST_STRING,
"d",
timestamp=self.timestamp,
end="")
self.assertEqual(
uut.printer.string,
"[INFO][" + self.timestamp.strftime("%X") + "] " +
Constants.COMPLEX_TEST_STRING + " d")
uut.log_level = LOG_LEVEL.WARNING
uut.printer.clear()
uut.debug(Constants.COMPLEX_TEST_STRING,
timestamp=self.timestamp,
end="")
self.assertEqual(uut.printer.string, "")
uut.printer.clear()
uut.warn(Constants.COMPLEX_TEST_STRING,
"d",
timestamp=self.timestamp,
end="")
self.assertEqual(
uut.printer.string,
"[WARNING][" + self.timestamp.strftime("%X") + "] " +
Constants.COMPLEX_TEST_STRING + " d")
uut.printer.clear()
uut.err(Constants.COMPLEX_TEST_STRING,
"d",
timestamp=self.timestamp,
end="")
self.assertEqual(
uut.printer.string,
"[ERROR][" + self.timestamp.strftime("%X") + "] " +
Constants.COMPLEX_TEST_STRING + " d")
uut.log_level = LOG_LEVEL.DEBUG
uut.printer.clear()
uut.log_exception(
"Something failed.",
NotImplementedError(Constants.COMPLEX_TEST_STRING),
timestamp=self.timestamp)
self.assertTrue(uut.printer.string.startswith(
"[ERROR][" + self.timestamp.strftime("%X") +
"] Something failed.\n" +
"[DEBUG][" + self.timestamp.strftime("%X") +
"] Exception was:"))
uut.log_level = LOG_LEVEL.INFO
uut.printer.clear()
logged = uut.log_exception(
"Something failed.",
NotImplementedError(Constants.COMPLEX_TEST_STRING),
timestamp=self.timestamp,
end="")
self.assertTrue(uut.printer.string.startswith(
"[ERROR][" + self.timestamp.strftime("%X") +
"] Something failed."))
示例3: CoalaViewActivatable
# 需要导入模块: from coalib.output.printers.LogPrinter import LogPrinter [as 别名]
# 或者: from coalib.output.printers.LogPrinter.LogPrinter import warn [as 别名]
class CoalaViewActivatable(GObject.Object, Gedit.ViewActivatable):
"""
A class inherited from Gedit.ViewActivatable - it gets created for every
gedit view. This class has a property `view` which is the Gedit.View that
the class is related to. From the Gedit.View, the Gedit.Document associated
to it can be got using `view.get_buffer()`.
"""
__gtype_name__ = "CoalaViewActivatable"
view = GObject.Property(type=Gedit.View)
def __init__(self):
GObject.Object.__init__(self)
self.log_printer = LogPrinter(ConsolePrinter())
def do_activate(self):
"""
This function is called when the view is created - it will
be called only once in a lifetime of a view.
"""
self.register_marks()
self.view.get_buffer().connect("saved", lambda x: self.analyze())
def register_marks(self):
"""
Creates mark-attributes for all result severities.
"""
self.view.set_show_line_marks(True)
for name, val in RESULT_SEVERITY.str_dict.items():
attr = GtkSource.MarkAttributes()
attr.set_icon_name(RESULT_SEVERITY_ICONS[val])
attr.connect("query_tooltip_markup", self.show_mark_tooltip)
self.view.set_mark_attributes(get_mark_category(name), attr, 0)
self.log_printer.info("Mark attribute created for", name)
def show_mark_tooltip(self, mark_attr, mark):
result = getattr(mark, COALA_KEY + "Result")
return str(result.origin) + ": " + str(result.message)
def show_result(self, result):
"""
Takes a result and shows it in gedit's UI.
:param result: The result to display.
"""
document = self.view.get_buffer()
for sourcerange in result.affected_code:
_iter = document.get_iter_at_line(sourcerange.start.line-1)
mark = document.create_source_mark(
None,
get_mark_category(result.severity),
_iter)
setattr(mark, COALA_KEY + "Result", result)
self.log_printer.info("Created mark at", sourcerange.start.line)
def analyze(self):
"""
This function fetches the location of the file in this view
and runs coala on it.
"""
document = self.view.get_buffer()
location = document.get_location()
if location == None:
self.log_printer.warn("coala cannot run on unsaved files")
return
results = CoalaViewActivatable.run_coala(location.get_path())
document.remove_source_marks(document.get_start_iter(),
document.get_end_iter())
for section_results in results.values():
for result in section_results:
self.show_result(result)
@staticmethod
def run_coala(path):
"""
Run coala on the file at the given path. The config file is got using
the `find-config` option of coala.
:param path: The path of the file to analyze.
:return: The result dictionary from coala.
"""
results = {}
log_printer = LogPrinter(ConsolePrinter())
cwd = os.getcwd()
try:
os.chdir(os.path.dirname(path))
args = ["--find-config", "--limit-files", path, '-S',
'autoapply=false']
sections, local_bears, global_bears, targets = (
# Use `lambda *args: True` so that `gather_configuration` does
# nothing when it needs to request settings from user.
gather_configuration(lambda *args: True,
log_printer,
arg_list=args))
for section_name in sections:
#.........这里部分代码省略.........