yandex-tank/Tank/Plugins/TipsAndTricks.py

52 lines
1.5 KiB
Python
Raw Normal View History

2012-09-21 12:01:16 +00:00
'''
Plugin showing tool learning hints in console
'''
from Tank.Core import AbstractPlugin
from Tank.Plugins.ConsoleOnline import ConsoleOnlinePlugin, AbstractInfoWidget
import os
import random
import textwrap
class TipsAndTricksPlugin(AbstractPlugin, AbstractInfoWidget):
2012-09-21 12:01:16 +00:00
'''
Tips showing plugin
'''
2012-09-19 12:28:28 +00:00
SECTION = 'tips'
def __init__(self, core):
AbstractPlugin.__init__(self, core)
2012-09-21 12:01:16 +00:00
AbstractInfoWidget.__init__(self)
lines = open(os.path.dirname(__file__) + '/tips.txt').readlines()
2012-09-19 12:40:00 +00:00
line = random.choice(lines)
self.section = line[:line.index(':')]
2012-09-20 10:16:27 +00:00
self.tip = line[line.index(':') + 1:].strip()
2012-09-19 12:46:10 +00:00
self.disable = 0
@staticmethod
def get_key():
2012-09-19 12:46:10 +00:00
return __file__
def configure(self):
2012-09-19 12:28:28 +00:00
self.disable = int(self.get_option('disable', '0'))
def prepare_test(self):
2012-09-19 12:28:28 +00:00
if not self.disable:
try:
console = self.core.get_plugin_of_type(ConsoleOnlinePlugin)
2012-09-19 12:46:10 +00:00
except KeyError, ex:
2012-09-19 12:28:28 +00:00
self.log.debug("Console not found: %s", ex)
console = None
if console:
console.add_info_widget(self)
def get_index(self):
return 10000 # really last index
def render(self, screen):
line = screen.markup.WHITE + "Tips & Tricks => " + self.section + screen.markup.RESET + ":\n "
2012-09-20 10:16:27 +00:00
line += "\n ".join(textwrap.wrap(self.tip, screen.right_panel_width - 1))
return line