yandex-tank/Tank/Plugins/TipsAndTricks.py

51 lines
1.5 KiB
Python
Raw Normal View History

from Tank.Core import AbstractPlugin
from Tank.Plugins.ConsoleOnline import ConsoleOnlinePlugin, AbstractInfoWidget
import os
import random
import textwrap
class TipsAndTricksPlugin(AbstractPlugin, AbstractInfoWidget):
2012-09-19 12:28:28 +00:00
SECTION = 'tips'
def __init__(self, core):
AbstractPlugin.__init__(self, core)
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(':')]
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 start_test(self):
pass
def end_test(self, retcode):
self.log.debug("End2")
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-19 12:40:00 +00:00
line += "\n ".join(textwrap.wrap(self.tip, screen.right_panel_width-1))
return line