diff --git a/pytest_gui_status/status_gui/gui.py b/pytest_gui_status/status_gui/gui.py deleted file mode 100644 index e69de29..0000000 diff --git a/pytest_gui_status/status_gui/gui_backend.py b/pytest_gui_status/status_gui/gui_backend.py new file mode 100644 index 0000000..28a6d5c --- /dev/null +++ b/pytest_gui_status/status_gui/gui_backend.py @@ -0,0 +1,78 @@ +import htmlPy +from utils import render_template +import os +import redis +import dateutil.parser +from datetime import datetime +import humanfriendly +import os.path + + +env_redis_port = os.environ.get("pytest_status_port") +if env_redis_port: + REDIS_PORT = int(env_redis_port) +else: + REDIS_PORT = 5946 + + +class Controller(htmlPy.Object): + # GUI callable functions have to be inside a class. + # The class should be inherited from htmlPy.Object. + dict_state_desc = { + "start": "Starting Tests", + "collect": "Collecting Tests", + "runtest": "Running Tests", + "end": "Finished Tests" + } + + def __init__(self, app_gui): + super(Controller, self).__init__() + self.i = 0 + self.app_gui = app_gui + self.last_state = None + # Initialize the class here, if required. + + @htmlPy.Slot() + def redraw(self): + # from main import app as app_gui + print(self.app_gui.dir_name) + + redis_db = redis.StrictRedis(host='localhost', port=REDIS_PORT, db=0) + # make sure that this is correct redis db + try: + assert redis_db.get("PYTEST_STATUS_DB") == "1" + except AssertionError, e: + print("Got redis db, but it is not related to pytest status") + raise e + dir_name = self.app_gui.dir_name + hash_dir_name = redis_db.hget("directories_to_hash", dir_name) + + if hash_dir_name is None: + raise Exception("dir_name = {dir_name} not found in redis db".format( + dir_name=dir_name)) + + dict_state = {} + dict_state["dir_name"] = dir_name + dict_state["dir_name_topfolder"] = os.path.basename(dir_name) + + dict_state["state"] = redis_db.get("{hash_a}_state".format(hash_a=hash_dir_name)) + dict_state["state_desc"] = self.dict_state_desc[dict_state["state"]] + dict_state["last_updated"] = redis_db.get("{hash_a}_last_updated".format(hash_a=hash_dir_name)) + + dict_state["last_updated_obj"] = dateutil.parser.parse(dict_state["last_updated"]) + last_updated_rel = (datetime.now() - dict_state["last_updated_obj"]).seconds # in seconds + if last_updated_rel > 60: + # when >1 min, reolve only upto min + last_updated_rel = last_updated_rel - (last_updated_rel % 60) + dict_state["last_updated_friendly"] = humanfriendly.format_timespan(last_updated_rel) + + dict_state["collect"] = redis_db.lrange("{hash_a}_collect".format(hash_a=hash_dir_name), 0, -1) + dict_state["pass"] = redis_db.lrange("{hash_a}_pass".format(hash_a=hash_dir_name), 0, -1) + dict_state["fail"] = redis_db.lrange("{hash_a}_fail".format(hash_a=hash_dir_name), 0, -1) + dict_state["skip"] = redis_db.lrange("{hash_a}_skip".format(hash_a=hash_dir_name), 0, -1) + + if (not self.last_state) or (self.last_state != dict_state): + print("called redraw") + self.app_gui.html = render_template(self.app_gui, "index.html", dict_state) + + self.last_state = dict_state diff --git a/pytest_gui_status/status_gui/gui_frontend.py b/pytest_gui_status/status_gui/gui_frontend.py new file mode 100644 index 0000000..e1edbcb --- /dev/null +++ b/pytest_gui_status/status_gui/gui_frontend.py @@ -0,0 +1,44 @@ +import htmlPy +import os +import sys +from PyQt4.QtGui import QApplication +import PyQt4.QtCore as QtCore + +# Import back-end functionalities +from gui_backend import Controller + + +if len(sys.argv) > 1: + dir_name_raw = sys.argv[1] +else: + dir_name_raw = "." +dir_name = os.path.abspath(dir_name_raw) + +# GUI initializations +app = htmlPy.AppGUI(title=u"{dir_name} - Test Status".format(dir_name=dir_name), + developer_mode=True, width=150, height=80) +app.window.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint) +screen_geo = QApplication.desktop().availableGeometry() +screen_topright = screen_geo.topRight() +app.x_pos = (screen_topright.x() - 20) - app.width +app.y_pos = (screen_topright.y() + 20) +# import pdb;pdb.set_trace() + +# GUI configarg +BASE_DIR = os.path.abspath(os.path.dirname(__file__)) +app.static_path = os.path.join(BASE_DIR, "static/") +app.template_path = os.path.join(BASE_DIR, "tmpl/") +app.dir_name = dir_name + +# Register back-end functionalities +app_backend = Controller(app) +app.bind(app_backend) + +# GUI render config +# app.html = u"" +app_backend.redraw() + + +# Start application +if __name__ == "__main__": + app.start() diff --git a/pytest_gui_status/status_gui/tmpl/index.html b/pytest_gui_status/status_gui/tmpl/index.html new file mode 100644 index 0000000..26fc4c9 --- /dev/null +++ b/pytest_gui_status/status_gui/tmpl/index.html @@ -0,0 +1,109 @@ + + +
+ +