Best Python code snippet using SeleniumBase
update.py
Source:update.py
1# -*- coding: utf-8 -*- 2#3# Description:4#5# Definiton6#7#8#9# Changes:10#11# 2012-01-1012# Initial Commit13#14#15# Copyright 2010-2012, WyDev Team.16# Author: Polo35 (polo35580@hotmail.fr)17#18# Licenced under Academic Free License version 3.019# Review WyGui README & LICENSE files for further details.20nname: 52021n 520(None)[return None22]:23 i: 505(), 519()24 o: 25nname: 51926n 519(None)[]:27 i: 0(f)28 o: 520()29nname: 50530n 505(None)[self._post_update_check()31]:32 i: 0(t)33 o: 520()34nname: 035n 0(self.is_post_update())[self.is_checking = None36bus = pygui_globs['wydbus']37self.wyupdate = bus.reference(self.name, self.path)38self.sig_inst = bus.instance(self.path)39self.launch = self.wyupdate.method('launch', 'ss', '')40self.register = self.wyupdate.method('decision_agent_register', 's', 'i')41self.unregister = self.wyupdate.method('decision_agent_unregister', 's', 'i')42self.is_post_update = self.wyupdate.method('is_post_update', '', 'b')43self.post_update_valid_by_user = self.wyupdate.method('post_update_valid_by_user', '', '')44self.sig_inst.signal('update_available', 'ssss', self._update_available, 0)45self.sig_inst.signal('update_removed', 'ss', self._update_removed, 0)46self.sig_inst.signal('update_progress', 'ssi', self._update_progress, 0)47self.sig_inst.signal('update_end', 'ss', self._update_end, 0)48self.sig_inst.signal('update_failed', 'ssi', self._update_failed, 0)49self.sig_inst.signal('update_reboot', 'ss', self._update_reboot, 0)50self.sig_inst.signal('update_check_start', 'ss', self._update_check_start, 0)51self.sig_inst.signal('update_check_end', 'ss', self._update_check_end, 0)52self.sig_inst.signal('update_check_failed', 'ssi', self._update_check_failed, 0)53self.check_window, self.confirm_window, self.screen_blocker = None, None, None54self.register(self.name)55]:56 i: 57 o: 505(t), 519(f)58nname: 059n 0(None)[self.is_checking = None60bus = pygui_globs['wydbus']61self.wyupdate = bus.reference(self.name, self.path)62self.sig_inst = bus.instance(self.path)63self.launch = self.wyupdate.method('launch', 'ss', '')64self.register = self.wyupdate.method('decision_agent_register', 's', 'i')65self.unregister = self.wyupdate.method('decision_agent_unregister', 's', 'i')66self.is_post_update = self.wyupdate.method('is_post_update', '', 'b')67self.post_update_valid_by_user = self.wyupdate.method('post_update_valid_by_user', '', '')68self.sig_inst.signal('update_available', 'ssss', self._update_available, 0)69self.sig_inst.signal('update_removed', 'ss', self._update_removed, 0)70self.sig_inst.signal('update_progress', 'ssi', self._update_progress, 0)71self.sig_inst.signal('update_end', 'ss', self._update_end, 0)72self.sig_inst.signal('update_failed', 'ssi', self._update_failed, 0)73self.sig_inst.signal('update_reboot', 'ss', self._update_reboot, 0)74self.sig_inst.signal('update_check_start', 'ss', self._update_check_start, 0)75self.sig_inst.signal('update_check_end', 'ss', self._update_check_end, 0)76self.sig_inst.signal('update_check_failed', 'ssi', self._update_check_failed, 0)77self.check_window, self.confirm_window, self.screen_blocker = None, None, None78self.register(self.name)79if self.is_post_update():80 self._post_update_check()81return None82]:83 i: 84 o: 85self.nodes: {0: <unpyclib.structure.node instance at 0xb76b020c>}86nname: 087n 0(None)[self.check_window = UpdateWarningTextWindow(_('An update has been detected. Checking files. Please wait...'))88self.check_window.show()89self.is_checking = True90]:91 i: 92 o: 93self.nodes: {0: <unpyclib.structure.node instance at 0xb76a5c2c>}94nname: 2795n 27(None)[self.check_window = None96self.is_checking = False97return None98]:99 i: 9(), 26()100 o: 101nname: 26102n 26(None)[]:103 i: 0(f)104 o: 27()105nname: 9106n 9(None)[self.check_window.hide()107]:108 i: 0(t)109 o: 27()110nname: 0111n 0(self.check_window)[]:112 i: 113 o: 9(t), 26(f)114nname: 0115n 0(None)[if self.check_window:116 self.check_window.hide()117self.check_window = None118self.is_checking = False119return None120]:121 i: 122 o: 123self.nodes: {0: <unpyclib.structure.node instance at 0xb76a5b6c>}124nname: 68125n 68(None)[w = UpdateWarningTextWindow(text)126t = Task(w.hide)127w.show()128t.start(delay=10)129]:130 i: 39(), 55()131 o: 132nname: 55133n 55(None)[text = _('An error has occurred when checking update integrity !')134]:135 i: 27(f)136 o: 68()137nname: 39138n 39(None)[text = _('You are already using a more recent firmware')139]:140 i: 27(t)141 o: 68()142nname: 27143n 27(error_code == OLD_VERSION_ERROR)[]:144 i: 9(), 26()145 o: 39(t), 55(f)146nname: 26147n 26(None)[]:148 i: 0(f)149 o: 27()150nname: 9151n 9(None)[self.check_window.hide()152]:153 i: 0(t)154 o: 27()155nname: 0156n 0(self.check_window)[]:157 i: 158 o: 9(t), 26(f)159nname: 68160n 68(None)[w = UpdateWarningTextWindow(text)161t = Task(w.hide)162w.show()163t.start(delay=10)164]:165 i: 0()166 o: 167nname: 0168n 0(None)[if self.check_window:169 self.check_window.hide()170if error_code == OLD_VERSION_ERROR:171 text = _('You are already using a more recent firmware')172else:173 text = _('An error has occurred when checking update integrity !')174]:175 i: 176 o: 68()177nname: 0178n 0(None)[if self.check_window:179 self.check_window.hide()180if error_code == OLD_VERSION_ERROR:181 text = _('You are already using a more recent firmware')182else:183 text = _('An error has occurred when checking update integrity !')184w = UpdateWarningTextWindow(text)185t = Task(w.hide)186w.show()187t.start(delay=10)188]:189 i: 190 o: 191self.nodes: {0: <unpyclib.structure.node instance at 0xb76a5eec>}192nname: 0193n 0(None)[pygui_globs['menustack'].close_player()194self.caution_window = UpdateWarningTextWindow(_('DO NOT SWITCH OFF BOX DURING UPDATE'))195self.caution_window.show()196template = _('Update in progress (version %(version)s)')197text = template % {'version': format_version(version), 'type': type_}198self.screen_blocker = NoHomeProgressWindow(text)199self.screen_blocker.type = 'progress_update'200self.screen_blocker.show()201self.launch(type_, version)202]:203 i: 204 o: 205self.nodes: {0: <unpyclib.structure.node instance at 0xb76ab44c>}206nname: 0207n 0(None)[template = _('Do you want to install the update for %(display_name)s, (version %(version)s) ?')208text = template % {'display_name': display_name, 'version': format_version(version), 'type': type_, 'description': description}209self.confirm_window = UpdateConfirmWindow(text, confirm_action=self._do_launch, confirm_args=(type_, version))210self.confirm_window.show()211]:212 i: 213 o: 214self.nodes: {0: <unpyclib.structure.node instance at 0xb76a5dec>}215nname: 63216n 63(None)[self.check_window = None217return None218]:219 i: 45(), 62()220 o: 221nname: 62222n 62(None)[]:223 i: 27(f)224 o: 63()225nname: 45226n 45(None)[self.check_window.hide()227]:228 i: 27(t)229 o: 63()230nname: 27231n 27(self.check_window)[self.confirm_window = None232]:233 i: 9(), 26()234 o: 45(t), 62(f)235nname: 26236n 26(None)[]:237 i: 0(f)238 o: 27()239nname: 9240n 9(None)[self.confirm_window.hide()241]:242 i: 0(t)243 o: 27()244nname: 0245n 0(self.confirm_window)[]:246 i: 247 o: 9(t), 26(f)248nname: 63249n 63(None)[self.check_window = None250return None251]:252 i: 0()253 o: 254nname: 0255n 0(None)[if self.confirm_window:256 self.confirm_window.hide()257self.confirm_window = None258if self.check_window:259 self.check_window.hide()260]:261 i: 262 o: 63()263nname: 0264n 0(None)[if self.confirm_window:265 self.confirm_window.hide()266self.confirm_window = None267if self.check_window:268 self.check_window.hide()269self.check_window = None270return None271]:272 i: 273 o: 274self.nodes: {0: <unpyclib.structure.node instance at 0xb76a5f8c>}275nname: 62276n 62(None)[return None277]:278 i: 29(), 61()279 o: 280nname: 61281n 61(None)[]:282 i: 0&21(f)283 o: 62()284nname: 29285n 29(None)[self.screen_blocker.progress = i286self.screen_blocker.total = '%s%%' % i287]:288 i: 0&21(t)289 o: 62()290nname: 0&21291n 0&21(check is not None and not check)[check = self.is_checking292]:293 i: 294 o: 29(t), 61(f)295nname: 0&21296n 0&21(None)[check = self.is_checking297if check is not None and not check:298 self.screen_blocker.progress = i299 self.screen_blocker.total = '%s%%' % i300return None301]:302 i: 303 o: 304self.nodes: {'0&21': <unpyclib.structure.node instance at 0xb76a5eac>}305nname: 0306n 0(None)[self.screen_blocker.hide()307self.caution_window.hide()308w = TextWindow(_('Update was successfully installed. The box will reboot automatically'))309w.show()310]:311 i: 312 o: 313self.nodes: {0: <unpyclib.structure.node instance at 0xb76a5f6c>}314nname: 27315n 27(None)[self.caution_window.hide()316template = _('Update (version %(version)s) failed. Please reboot.')317text = template % {'version': format_version(version)}318w = TextWindow(text)319w.show()320]:321 i: 9(), 26()322 o: 323nname: 26324n 26(None)[]:325 i: 0(f)326 o: 27()327nname: 9328n 9(None)[self.screen_blocker.hide()329]:330 i: 0(t)331 o: 27()332nname: 0333n 0(self.screen_blocker)[]:334 i: 335 o: 9(t), 26(f)336nname: 0337n 0(None)[if self.screen_blocker:338 self.screen_blocker.hide()339self.caution_window.hide()340template = _('Update (version %(version)s) failed. Please reboot.')341text = template % {'version': format_version(version)}342w = TextWindow(text)343w.show()344]:345 i: 346 o: 347self.nodes: {0: <unpyclib.structure.node instance at 0xb76a5f0c>}348nname: 0349n 0(None)[from pygui.config import version350w = PostUpdateWindow(format_version(version), self.post_update_valid_by_user)351w.show()352]:353 i: 354 o: 355self.nodes: {0: <unpyclib.structure.node instance at 0xb76a5c4c>}356nname: 0357n 0(None)[Task(reboot).start(delay=1)358]:359 i: 360 o: 361self.nodes: {0: <unpyclib.structure.node instance at 0xb76a59cc>}362nname: 36363n 36(None)[return None364]:365 i: 9(), 35()366 o: 367nname: 35368n 35(None)[]:369 i: 0(f)370 o: 36()371nname: 9372n 9(None)[self.confirm_window.hide()373self.confirm_window = None374]:375 i: 0(t)376 o: 36()377nname: 0378n 0(self.confirm_window)[]:379 i: 380 o: 9(t), 35(f)381nname: 0382n 0(None)[if self.confirm_window:383 self.confirm_window.hide()384 self.confirm_window = None385return None386]:387 i: 388 o: 389self.nodes: {0: <unpyclib.structure.node instance at 0xb76a58ec>}390nname: 6391n 6(None)[__doc__ = 'Update manager. Handles the UI for notifying the user of updates\n and helping him install them.'392__metaclass__ = MetaSingleton393name = 'com.wyplay.update'394path = '/com/wyplay/Update'395def __init__(self):396 self.is_checking = None397 bus = pygui_globs['wydbus']398 self.wyupdate = bus.reference(self.name, self.path)399 self.sig_inst = bus.instance(self.path)400 self.launch = self.wyupdate.method('launch', 'ss', '')401 self.register = self.wyupdate.method('decision_agent_register', 's', 'i')402 self.unregister = self.wyupdate.method('decision_agent_unregister', 's', 'i')403 self.is_post_update = self.wyupdate.method('is_post_update', '', 'b')404 self.post_update_valid_by_user = self.wyupdate.method('post_update_valid_by_user', '', '')405 self.sig_inst.signal('update_available', 'ssss', self._update_available, 0)406 self.sig_inst.signal('update_removed', 'ss', self._update_removed, 0)407 self.sig_inst.signal('update_progress', 'ssi', self._update_progress, 0)408 self.sig_inst.signal('update_end', 'ss', self._update_end, 0)409 self.sig_inst.signal('update_failed', 'ssi', self._update_failed, 0)410 self.sig_inst.signal('update_reboot', 'ss', self._update_reboot, 0)411 self.sig_inst.signal('update_check_start', 'ss', self._update_check_start, 0)412 self.sig_inst.signal('update_check_end', 'ss', self._update_check_end, 0)413 self.sig_inst.signal('update_check_failed', 'ssi', self._update_check_failed, 0)414 self.check_window, self.confirm_window, self.screen_blocker = None, None, None415 self.register(self.name)416 if self.is_post_update():417 self._post_update_check()418 return None419def _update_check_start(self, type_, version):420 self.check_window = UpdateWarningTextWindow(_('An update has been detected. Checking files. Please wait...'))421 self.check_window.show()422 self.is_checking = True423def _update_check_end(self, type_, version):424 if self.check_window:425 self.check_window.hide()426 self.check_window = None427 self.is_checking = False428 return None429def _update_check_failed(self, type_, version, error_code):430 if self.check_window:431 self.check_window.hide()432 if error_code == OLD_VERSION_ERROR:433 text = _('You are already using a more recent firmware')434 else:435 text = _('An error has occurred when checking update integrity !')436 w = UpdateWarningTextWindow(text)437 t = Task(w.hide)438 w.show()439 t.start(delay=10)440def _do_launch(self, type_, version):441 pygui_globs['menustack'].close_player()442 self.caution_window = UpdateWarningTextWindow(_('DO NOT SWITCH OFF BOX DURING UPDATE'))443 self.caution_window.show()444 template = _('Update in progress (version %(version)s)')445 text = template % {'version': format_version(version), 'type': type_}446 self.screen_blocker = NoHomeProgressWindow(text)447 self.screen_blocker.type = 'progress_update'448 self.screen_blocker.show()449 self.launch(type_, version)450def _update_available(self, type_, display_name, description, version):451 template = _('Do you want to install the update for %(display_name)s, (version %(version)s) ?')452 text = template % {'display_name': display_name, 'version': format_version(version), 'type': type_, 'description': description}453 self.confirm_window = UpdateConfirmWindow(text, confirm_action=self._do_launch, confirm_args=(type_, version))454 self.confirm_window.show()455def _update_removed(self, a, b):456 if self.confirm_window:457 self.confirm_window.hide()458 self.confirm_window = None459 if self.check_window:460 self.check_window.hide()461 self.check_window = None462 return None463def _update_progress(self, a, b, i):464 check = self.is_checking465 if check is not None and not check:466 self.screen_blocker.progress = i467 self.screen_blocker.total = '%s%%' % i468 return None469def _update_end(self, a, b):470 self.screen_blocker.hide()471 self.caution_window.hide()472 w = TextWindow(_('Update was successfully installed. The box will reboot automatically'))473 w.show()474def _update_failed(self, type_, version, error_code):475 if self.screen_blocker:476 self.screen_blocker.hide()477 self.caution_window.hide()478 template = _('Update (version %(version)s) failed. Please reboot.')479 text = template % {'version': format_version(version)}480 w = TextWindow(text)481 w.show()482def _post_update_check(self):483 from pygui.config import version484 w = PostUpdateWindow(format_version(version), self.post_update_valid_by_user)485 w.show()486def _update_reboot(self, a, b):487 Task(reboot).start(delay=1)488def unplug_update(self):489 if self.confirm_window:490 self.confirm_window.hide()491 self.confirm_window = None492 return None493]:494 i: 495 o: 496self.nodes: {6: <unpyclib.structure.node instance at 0xb76a520c>}497nname: 0498n 0(None)[from __future__ import absolute_import499__all__ = ['UpdateManager']500from pygui.window import Button, ConfirmWindow, MessageWindow, NoHomeProgressWindow, TextWindow501from pygui.window.updatewindow import UpdateConfirmWindow, UpdateWarningTextWindow, PostUpdateWindow502from pygui.shared import pygui_globs503from peewee.misc_utils import MetaSingleton504from peewee.notifier import Task505from peewee.version import format_version506from .power import reboot507OLD_VERSION_ERROR = -1000508class UpdateManager(object):509 __doc__ = 'Update manager. Handles the UI for notifying the user of updates\n and helping him install them.'510 __metaclass__ = MetaSingleton511 name = 'com.wyplay.update'512 path = '/com/wyplay/Update'513 def __init__(self):514 self.is_checking = None515 bus = pygui_globs['wydbus']516 self.wyupdate = bus.reference(self.name, self.path)517 self.sig_inst = bus.instance(self.path)518 self.launch = self.wyupdate.method('launch', 'ss', '')519 self.register = self.wyupdate.method('decision_agent_register', 's', 'i')520 self.unregister = self.wyupdate.method('decision_agent_unregister', 's', 'i')521 self.is_post_update = self.wyupdate.method('is_post_update', '', 'b')522 self.post_update_valid_by_user = self.wyupdate.method('post_update_valid_by_user', '', '')523 self.sig_inst.signal('update_available', 'ssss', self._update_available, 0)524 self.sig_inst.signal('update_removed', 'ss', self._update_removed, 0)525 self.sig_inst.signal('update_progress', 'ssi', self._update_progress, 0)526 self.sig_inst.signal('update_end', 'ss', self._update_end, 0)527 self.sig_inst.signal('update_failed', 'ssi', self._update_failed, 0)528 self.sig_inst.signal('update_reboot', 'ss', self._update_reboot, 0)529 self.sig_inst.signal('update_check_start', 'ss', self._update_check_start, 0)530 self.sig_inst.signal('update_check_end', 'ss', self._update_check_end, 0)531 self.sig_inst.signal('update_check_failed', 'ssi', self._update_check_failed, 0)532 self.check_window, self.confirm_window, self.screen_blocker = None, None, None533 self.register(self.name)534 if self.is_post_update():535 self._post_update_check()536 return None537 def _update_check_start(self, type_, version):538 self.check_window = UpdateWarningTextWindow(_('An update has been detected. Checking files. Please wait...'))539 self.check_window.show()540 self.is_checking = True541 def _update_check_end(self, type_, version):542 if self.check_window:543 self.check_window.hide()544 self.check_window = None545 self.is_checking = False546 return None547 def _update_check_failed(self, type_, version, error_code):548 if self.check_window:549 self.check_window.hide()550 if error_code == OLD_VERSION_ERROR:551 text = _('You are already using a more recent firmware')552 else:553 text = _('An error has occurred when checking update integrity !')554 w = UpdateWarningTextWindow(text)555 t = Task(w.hide)556 w.show()557 t.start(delay=10)558 def _do_launch(self, type_, version):559 pygui_globs['menustack'].close_player()560 self.caution_window = UpdateWarningTextWindow(_('DO NOT SWITCH OFF BOX DURING UPDATE'))561 self.caution_window.show()562 template = _('Update in progress (version %(version)s)')563 text = template % {'version': format_version(version), 'type': type_}564 self.screen_blocker = NoHomeProgressWindow(text)565 self.screen_blocker.type = 'progress_update'566 self.screen_blocker.show()567 self.launch(type_, version)568 def _update_available(self, type_, display_name, description, version):569 template = _('Do you want to install the update for %(display_name)s, (version %(version)s) ?')570 text = template % {'display_name': display_name, 'version': format_version(version), 'type': type_, 'description': description}571 self.confirm_window = UpdateConfirmWindow(text, confirm_action=self._do_launch, confirm_args=(type_, version))572 self.confirm_window.show()573 def _update_removed(self, a, b):574 if self.confirm_window:575 self.confirm_window.hide()576 self.confirm_window = None577 if self.check_window:578 self.check_window.hide()579 self.check_window = None580 return None581 def _update_progress(self, a, b, i):582 check = self.is_checking583 if check is not None and not check:584 self.screen_blocker.progress = i585 self.screen_blocker.total = '%s%%' % i586 return None587 def _update_end(self, a, b):588 self.screen_blocker.hide()589 self.caution_window.hide()590 w = TextWindow(_('Update was successfully installed. The box will reboot automatically'))591 w.show()592 def _update_failed(self, type_, version, error_code):593 if self.screen_blocker:594 self.screen_blocker.hide()595 self.caution_window.hide()596 template = _('Update (version %(version)s) failed. Please reboot.')597 text = template % {'version': format_version(version)}598 w = TextWindow(text)599 w.show()600 def _post_update_check(self):601 from pygui.config import version602 w = PostUpdateWindow(format_version(version), self.post_update_valid_by_user)603 w.show()604 def _update_reboot(self, a, b):605 Task(reboot).start(delay=1)606 def unplug_update(self):607 if self.confirm_window:608 self.confirm_window.hide()609 self.confirm_window = None610 return None611]:612 i: 613 o: 614self.nodes: {0: <unpyclib.structure.node instance at 0xb7699c4c>}615from __future__ import absolute_import616__all__ = ['UpdateManager']617from pygui.window import Button, ConfirmWindow, MessageWindow, NoHomeProgressWindow, TextWindow618from pygui.window.updatewindow import UpdateConfirmWindow, UpdateWarningTextWindow, PostUpdateWindow619from pygui.shared import pygui_globs620from peewee.misc_utils import MetaSingleton621from peewee.notifier import Task622from peewee.version import format_version623from .power import reboot624OLD_VERSION_ERROR = -1000625class UpdateManager(object):626 __doc__ = 'Update manager. Handles the UI for notifying the user of updates\n and helping him install them.'627 __metaclass__ = MetaSingleton628 name = 'com.wyplay.update'629 path = '/com/wyplay/Update'630 def __init__(self):631 self.is_checking = None632 bus = pygui_globs['wydbus']633 self.wyupdate = bus.reference(self.name, self.path)634 self.sig_inst = bus.instance(self.path)635 self.launch = self.wyupdate.method('launch', 'ss', '')636 self.register = self.wyupdate.method('decision_agent_register', 's', 'i')637 self.unregister = self.wyupdate.method('decision_agent_unregister', 's', 'i')638 self.is_post_update = self.wyupdate.method('is_post_update', '', 'b')639 self.post_update_valid_by_user = self.wyupdate.method('post_update_valid_by_user', '', '')640 self.sig_inst.signal('update_available', 'ssss', self._update_available, 0)641 self.sig_inst.signal('update_removed', 'ss', self._update_removed, 0)642 self.sig_inst.signal('update_progress', 'ssi', self._update_progress, 0)643 self.sig_inst.signal('update_end', 'ss', self._update_end, 0)644 self.sig_inst.signal('update_failed', 'ssi', self._update_failed, 0)645 self.sig_inst.signal('update_reboot', 'ss', self._update_reboot, 0)646 self.sig_inst.signal('update_check_start', 'ss', self._update_check_start, 0)647 self.sig_inst.signal('update_check_end', 'ss', self._update_check_end, 0)648 self.sig_inst.signal('update_check_failed', 'ssi', self._update_check_failed, 0)649 self.check_window, self.confirm_window, self.screen_blocker = None, None, None650 self.register(self.name)651 if self.is_post_update():652 self._post_update_check()653 return None654 def _update_check_start(self, type_, version):655 self.check_window = UpdateWarningTextWindow(_('An update has been detected. Checking files. Please wait...'))656 self.check_window.show()657 self.is_checking = True658 def _update_check_end(self, type_, version):659 if self.check_window:660 self.check_window.hide()661 self.check_window = None662 self.is_checking = False663 return None664 def _update_check_failed(self, type_, version, error_code):665 if self.check_window:666 self.check_window.hide()667 if error_code == OLD_VERSION_ERROR:668 text = _('You are already using a more recent firmware')669 else:670 text = _('An error has occurred when checking update integrity !')671 w = UpdateWarningTextWindow(text)672 t = Task(w.hide)673 w.show()674 t.start(delay=10)675 def _do_launch(self, type_, version):676 pygui_globs['menustack'].close_player()677 self.caution_window = UpdateWarningTextWindow(_('DO NOT SWITCH OFF BOX DURING UPDATE'))678 self.caution_window.show()679 template = _('Update in progress (version %(version)s)')680 text = template % {'version': format_version(version), 'type': type_}681 self.screen_blocker = NoHomeProgressWindow(text)682 self.screen_blocker.type = 'progress_update'683 self.screen_blocker.show()684 self.launch(type_, version)685 def _update_available(self, type_, display_name, description, version):686 template = _('Do you want to install the update for %(display_name)s, (version %(version)s) ?')687 text = template % {'display_name': display_name, 'version': format_version(version), 'type': type_, 'description': description}688 self.confirm_window = UpdateConfirmWindow(text, confirm_action=self._do_launch, confirm_args=(type_, version))689 self.confirm_window.show()690 def _update_removed(self, a, b):691 if self.confirm_window:692 self.confirm_window.hide()693 self.confirm_window = None694 if self.check_window:695 self.check_window.hide()696 self.check_window = None697 return None698 def _update_progress(self, a, b, i):699 check = self.is_checking700 if check is not None and not check:701 self.screen_blocker.progress = i702 self.screen_blocker.total = '%s%%' % i703 return None704 def _update_end(self, a, b):705 self.screen_blocker.hide()706 self.caution_window.hide()707 w = TextWindow(_('Update was successfully installed. The box will reboot automatically'))708 w.show()709 def _update_failed(self, type_, version, error_code):710 if self.screen_blocker:711 self.screen_blocker.hide()712 self.caution_window.hide()713 template = _('Update (version %(version)s) failed. Please reboot.')714 text = template % {'version': format_version(version)}715 w = TextWindow(text)716 w.show()717 def _post_update_check(self):718 from pygui.config import version719 w = PostUpdateWindow(format_version(version), self.post_update_valid_by_user)720 w.show()721 def _update_reboot(self, a, b):722 Task(reboot).start(delay=1)723 def unplug_update(self):724 if self.confirm_window:725 self.confirm_window.hide()726 self.confirm_window = None...
candle_strategy.py
Source:candle_strategy.py
1from operator import index2from typing import final3from numpy.core.fromnumeric import shape4import pandas as pd5#from binance_functions import *6from cheap_algos import *7from candle_patterns import *8opens = pd.read_csv('Binance/opens_4h.csv', usecols=range(0,50))9closes = pd.read_csv('Binance/closes_4h.csv', usecols=range(0,50))10#opens, closes = opens[3000:], closes[3000:]11def make_MAs():12 df = pd.DataFrame()13 for col in closes.columns:14 values = closes[f'{col}'].values15 mov = [0]*316 for i,j in enumerate(values):17 # do not start calc until short and long ma's can be evaluated... 18 if i > 2:19 ma = np.average(values[i-2:i+1])20 mov.append(ma)21 df[f"{col}"] = mov22 df = df.round(8)23 return df24"""25...26Step 2) Adapt fxn to also work with Forex backtesting info27Step 3) Avg those MF's together to get avg profit.28"""29def candle_strategy_realism(max_threads, max_holding_time):30 """31 Pass in dfs of opens, closes, avgs32 """33 col_count = 5034 opens = pd.read_csv('Binance/opens_4h.csv', usecols=range(0,col_count))35 closes = pd.read_csv('Binance/closes_4h.csv', usecols=range(0,col_count)) 36 moving_averages = pd.read_csv('Binance/moving_averages_4h.csv', usecols=range(0,col_count))37 df = pd.concat([opens, closes, moving_averages], axis=1)38 current_positions = 039 bought, trade_pcs, c, holding_time, trade_info = [[] for _ in range(0,5)]40 # iterate by row through the df41 for ind, row in df.iterrows():42 if ind > 10:43 c.append(current_positions)44 for col in range(0,col_count):45 window = df.iloc[ind-6:ind+1,col::col_count]46 cl = window.iloc[:, 1]47 my_col = window.columns[0]48 t = trend_finder(cl.values)49 b = [i for i,j,k in bought]50 # SELL CONDITIONS51 if my_col in b:52 my_buy = [(i,j,k) for i,j,k in bought if i == my_col]53 uptrend_candle_patterns = [three_black_crows, three_inside_down, three_outside_down, evening_star]54 little_window = window.iloc[-3:,:]55 little_window.columns = ['Open', 'Close', 'MA']56 57 if ind - my_buy[0][2] > max_holding_time:58 holding_time.append(max_holding_time)59 pc = percent_change(float(my_buy[0][1]), float(little_window.iloc[-1,1]))60 trade_pcs.append(pc)61 bought.remove(my_buy[0])62 current_positions -= 163 trade_info.append((pc / max_threads, ind))64 break65 if t == 'uptrend':66 for pattern in uptrend_candle_patterns:67 x = pattern(little_window)68 if x:69 # print(check_window)70 # print(f"'{pattern.__name__}' detected")71 pc = percent_change(float(my_buy[0][1]), float(little_window.iloc[-1,1]))72 trade_pcs.append(pc)73 holding_time.append(ind - my_buy[0][2])74 trade_info.append((pc / max_threads, ind))75 bought.remove(my_buy[0])76 current_positions -= 177 break78 # BUY CONDITION79 if my_col not in b and current_positions < max_threads:80 if t == 'downtrend':81 downtrend_candle_patterns = [three_white_soldiers, three_inside_up, three_outside_up, morning_star]82 little_window = window.iloc[-3:,:]83 little_window.columns = ['Open', 'Close', 'MA']84 for pattern in downtrend_candle_patterns:85 x = pattern(little_window)86 if x:87 # print(check_window)88 # print(f"'{pattern.__name__}' detected")89 buy_info = (window.columns[0], window.iloc[-1,1], ind)90 bought.append(buy_info)91 current_positions += 192 break93 94 avg = np.average(trade_pcs) / max_threads95 std = np.std(trade_pcs) / max_threads96 avg_pos_count = np.average(c)97 avg_ht = np.average(holding_time)98 avg_ht = avg_ht / 699 avg_per_wk = (avg / avg_ht)*7100 ls = [avg, std, len(trade_pcs), avg_pos_count, avg_per_wk]101 ls = [round(i, 3) for i in ls] 102 # trade_info has all the (pc, ind) for graphs103 the_goods = []104 for ind in range(0, len(df[10:])):105 if ind in [j for i,j in trade_info]:106 the_goods.append([i for i,j in trade_info if j == ind][0])107 else:108 the_goods.append(0)109 return the_goods110#x = candle_strategy_realism(2, 100)111#print(x)112def candle_strategy_backtesting(df):113 pc_changes, trade_lengths, my_ls = [], [], []114 bought = False115 sold = False116 # first we must get a moving avg col for our df117 moving_averages = [0]*3118 pc_or_no = [0]*9119 closes = df["Close"].values120 121 for i,j in enumerate(closes):122 # do not start calc until short and long ma's can be evaluated... 123 if i > 2:124 ma = np.average(closes[i-2:i+1])125 moving_averages.append(ma)126 df["MA"] = moving_averages127 df = df.round(5)128 # now we can do our candlestick business129 for ind in range(9, len(df)):130 # first we check for the trend:131 # the value of the trend that will actually be used is moving avg at t-2. 132 uptrend, downtrend = False, False133 up, down = 0,0134 ma_values = moving_averages[ind - 7:ind-1]135 for i,j,k in zip(ma_values, sorted(ma_values), reversed(sorted(ma_values))):136 if up > 4:137 uptrend = True138 break139 if down > 4:140 downtrend = True141 break142 if i == j:143 up += 1144 if i == k:145 down += 1146 # check for each candlestick pattern147 if bought == False and downtrend:148 check_window = df.iloc[ind-2:ind+1, :]149 # check for the 4 downtrend reversal patterns.150 downtrend_candle_patterns = [three_white_soldiers, three_inside_up, three_outside_up, morning_star]151 pc_or_no.append(0)152 for pattern in downtrend_candle_patterns:153 x = pattern(check_window)154 if x:155 # print(check_window)156 # print(f"'{pattern.__name__}' detected")157 buy_ind, buy_val = ind, df.iloc[ind, 0]158 bought = True159 break160 continue161 162 if bought == True:163 if uptrend:164 # check for the 4 uptrend reversal patterns165 check_window = df.iloc[ind-2:ind+1,:]166 uptrend_candle_patterns = [three_black_crows, three_inside_down, three_outside_down, evening_star]167 for pattern in uptrend_candle_patterns:168 x = pattern(check_window)169 if x:170 # print(check_window)171 # print(f"'{pattern.__name__}' detected")172 173 # sell at open of next candle174 trade_pc = percent_change(buy_val, df.iloc[ind, 0])175 trade_len = ind - buy_ind176 #my_ls.append([buy_ind, buy_val, ind, df.iloc[ind, 0]])177 trade_lengths.append(trade_len)178 pc_changes.append(trade_pc)179 sold = True180 bought = False181 break182 183 if sold:184 pc_or_no.append(trade_pc)185 sold = False186 else:187 pc_or_no.append(0)188 if bought == True:189 final_trade = percent_change(buy_val, df.iloc[-1, 0])190 pc_changes.append(final_trade)191 192 # relegating all results and returning193 if len(pc_changes) > 1:194 ls = [pc_changes, trade_lengths]195 res = [np.average(i) for i in ls]196 win_pc = len([i for i in pc_changes if i > 0])*100 / len(pc_changes)197 std = np.std(pc_changes)198 res.extend([win_pc, std, len(pc_changes)])199 res = [round(i,2) for i in res[:-1]]200 res.append(pc_or_no)201 # returns [avg_pc, avg_trade_len, win_pc, std, total_trades, pc_or_no -> list] 202 return res203 else:204 return 'no trades'205def backtest():206 avie, trade_len, win_rate, stds = [[] for _ in range(0,4)]207 ls = [avie, trade_len, win_rate, stds]208 pc_df = pd.DataFrame()209 210 for col in opens.columns:211 df = pd.DataFrame()212 df['Open'] = opens[col].values213 df['Close'] = closes[col].values214 x = candle_strategy_backtesting(df)215 if x == 'no trades':216 continue217 else:218 pc_df[f'{col}'] = x[-1]219 do = [j.append(x[i]) for i,j in enumerate(ls)]220 total_trades = round(sum(ls[-1]))221 res = [round(np.average(i), 2) for i in ls[:-1]]222 res.append(total_trades)223 pc_df['sum'] = pc_df.sum(axis=1)224 225 return pc_df226#x = backtest() ; print(x)227def candle_strategy(df, bought):228 # firstly, this fxn only needs to check certain things, depending on whether we are holding the coin or not.229 # the following chunk gets an MA col for our df.230 moving_averages = [0]*2231 coin_closes = df.columns[0]232 closes = df[coin_closes].values233 234 for i,j in enumerate(closes):235 if i > 1:236 ma = np.average(closes[i-2:i+1])237 moving_averages.append(ma)238 239 dfw = df.copy()240 dfw["MA"] = moving_averages241 df = dfw.round(5)242 # first we check for the trend:243 # the value of the trend that will actually be used is moving avg at ind-2.244 uptrend, downtrend = False, False245 up, down = 0,0246 ma_values = moving_averages[-8:-2]247 for i,j,k in zip(ma_values, sorted(ma_values), reversed(sorted(ma_values))):248 if up > 4:249 uptrend = True250 break251 if down > 4:252 downtrend = True253 break254 if i == j:255 up += 1256 if i == k:257 down += 1258 259 260 # BUY CONDITIONS261 if not bought:262 if downtrend:263 check_window = df.iloc[-3:, :]264 check_window.columns = ['Open', 'Close', 'MA']265 # check for the 4 downtrend reversal patterns.266 downtrend_candle_patterns = [three_white_soldiers, three_inside_up, three_outside_up, morning_star]267 for pattern in downtrend_candle_patterns:268 # candle patterns return True or False269 x = pattern(check_window)270 if x:271 # print(f"'{pattern.__name__}' detected")272 return 'buy'273 return 'leave'274 275 # SELL CONDITIONS276 if bought:277 if uptrend:278 # check for the 4 uptrend reversal patterns279 check_window = df.iloc[-3:,:]280 check_window.columns = ['Open', 'Close', 'MA']281 uptrend_candle_patterns = [three_black_crows, three_inside_down, three_outside_down, evening_star]282 for pattern in uptrend_candle_patterns:283 x = pattern(check_window)284 if x:285 # print(check_window)286 # print(f"'{pattern.__name__}' detected")287 return 'sell'288 return 'hold'289 ...
layout_test.py
Source:layout_test.py
2class VisualLayoutTests(BaseCase):3 def test_applitools_layout_change(self):4 self.open("https://applitools.com/helloworld?diff1")5 print('\nCreating baseline in "visual_baseline" folder.')6 self.check_window(name="helloworld", baseline=True)7 # Click a button that changes the text of an element8 # (Text changes do not impact visual comparisons)9 self.click('a[href="?diff1"]')10 # Verify html tags match the baseline11 self.check_window(name="helloworld", level=1)12 # Verify html tags and attribute names match the baseline13 self.check_window(name="helloworld", level=2)14 # Verify html tags and attribute values match the baseline15 self.check_window(name="helloworld", level=3)16 # Click a button that makes a hidden element visible17 self.click("button")18 self.check_window(name="helloworld", level=1)19 self.check_window(name="helloworld", level=2)20 with self.assert_raises(Exception):21 self.check_window(name="helloworld", level=3)22 # Now that we know the Exception was raised as expected,23 # let's print out the comparison results by running a Level-0 check.24 # (NOTE: Running with level-0 will print but NOT raise an Exception.)...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!