2012-09-21 12:01:16 +00:00
|
|
|
'''
|
|
|
|
Plugin showing tool learning hints in console
|
|
|
|
'''
|
|
|
|
|
2015-02-06 13:35:16 +00:00
|
|
|
from pkg_resources import resource_stream
|
|
|
|
from yandextank.plugins.ConsoleOnline import \
|
|
|
|
ConsoleOnlinePlugin, AbstractInfoWidget
|
2015-02-02 17:24:32 +00:00
|
|
|
from yandextank.core import AbstractPlugin
|
2012-09-19 12:10:51 +00:00
|
|
|
import random
|
|
|
|
import textwrap
|
|
|
|
|
2015-02-05 11:46:45 +00:00
|
|
|
|
2012-09-19 12:10:51 +00:00
|
|
|
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'
|
2015-02-02 17:24:32 +00:00
|
|
|
|
2012-09-19 12:10:51 +00:00
|
|
|
def __init__(self, core):
|
|
|
|
AbstractPlugin.__init__(self, core)
|
2012-09-21 12:01:16 +00:00
|
|
|
AbstractInfoWidget.__init__(self)
|
2015-02-06 13:35:16 +00:00
|
|
|
lines = resource_stream(__name__, "config/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
|
2015-02-02 17:24:32 +00:00
|
|
|
|
2012-09-19 12:10:51 +00:00
|
|
|
@staticmethod
|
|
|
|
def get_key():
|
2012-09-19 12:46:10 +00:00
|
|
|
return __file__
|
2015-02-02 17:24:32 +00:00
|
|
|
|
2013-03-22 13:55:13 +00:00
|
|
|
def get_available_options(self):
|
|
|
|
return ["disable"]
|
2015-02-02 17:24:32 +00:00
|
|
|
|
2012-09-19 12:10:51 +00:00
|
|
|
def configure(self):
|
2012-09-19 12:28:28 +00:00
|
|
|
self.disable = int(self.get_option('disable', '0'))
|
2015-02-02 17:24:32 +00:00
|
|
|
|
2012-09-19 12:10:51 +00:00
|
|
|
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
|
2015-02-02 17:24:32 +00:00
|
|
|
|
|
|
|
if console:
|
|
|
|
console.add_info_widget(self)
|
|
|
|
|
2012-09-19 12:10:51 +00:00
|
|
|
def get_index(self):
|
2015-02-05 11:46:45 +00:00
|
|
|
return 10000 # really last index
|
2012-09-19 12:10:51 +00:00
|
|
|
|
|
|
|
def render(self, screen):
|
2012-09-19 13:19:57 +00:00
|
|
|
line = screen.markup.WHITE + "Tips & Tricks => " + self.section + screen.markup.RESET + ":\n "
|
2012-09-23 16:45:05 +00:00
|
|
|
line += "\n ".join(textwrap.wrap(self.tip, screen.right_panel_width - 2))
|
2012-09-19 12:10:51 +00:00
|
|
|
return line
|