Exemplo n.º 1
0
    def __init__(self):
        super(ExploreDownloadAction, self).__init__()

        self.add_action(PageAction('downloads'))
        self.add_action(WaitAction(1000))
        self.add_action(
            CustomAction(
                """if len(window.downloads_page.downloads['downloads']) == 0:
    exit_script()
        """))
        self.add_action(
            ClickAction(
                'window.downloads_list.topLevelItem(randint(0, len(window.downloads_page.download_widgets.keys()) - 1)).progress_slider'
            ))
        self.add_action(
            CustomAction(
                'window.download_details_widget.setCurrentIndex(randint(0, 3))'
            ))
        self.add_action(WaitAction(2000))
        self.add_action(
            CustomAction(
                'window.download_details_widget.setCurrentIndex(randint(0, 3))'
            ))
        self.add_action(WaitAction(2000))
        self.add_action(
            CustomAction(
                'window.download_details_widget.setCurrentIndex(randint(0, 3))'
            ))
    def __init__(self):
        super(ExploreChannelAction, self).__init__()

        self.add_action(PageAction('discovered'))
        self.add_action(WaitAction(1000))
        self.add_action(
            CustomAction("""if window.discovered_channels_list.count() == 0:
    exit_script()
        """))
        self.add_action(
            ClickAction(
                'window.discovered_channels_list.itemWidget(window.discovered_channels_list.item(randint(0, window.discovered_channels_list.count() - 1)))'
            ))
        self.add_action(WaitAction(2500))

        # We now click a random torrent to initiate the torrent checker
        self.add_action(
            CustomAction(
                """if window.channel_page_container.items_list.count() == 0:
    exit_script()
        """))
        self.add_action(
            ClickAction(
                'window.channel_page_container.items_list.itemWidget(window.channel_page_container.items_list.item(randint(0, window.channel_page_container.items_list.count() - 1)))'
            ))
        self.add_action(WaitAction(2000))
        self.add_action(ClickAction('window.channel_back_button'))
    def __init__(self):
        super(StartVODAction, self).__init__()

        self.add_action(PageAction('downloads'))
        self.add_action(WaitAction(1000))
        self.add_action(CustomAction("""if not window.downloads_page.downloads or len(window.downloads_page.downloads['downloads']) == 0:
    exit_script()
        """))
        self.add_action(ClickAction('window.downloads_list.topLevelItem(randint(0, len(window.downloads_page.download_widgets.keys()) - 1)).progress_slider'))
        self.add_action(WaitAction(2000))
        self.add_action(ClickAction('window.play_download_button'))
    def __init__(self, download_uri):
        super(StartDownloadAction, self).__init__()

        self.add_action(CustomAction("window.on_add_torrent_from_url()"))
        self.add_action(WaitAction(1000))
        self.add_action(
            CustomAction(
                "window.dialog.dialog_widget.dialog_input.setText('%s')" %
                download_uri))
        self.add_action(WaitAction(1000))
        self.add_action(ClickAction("window.dialog.buttons[0]"))
        self.add_action(WaitAction(7000))
        self.add_action(
            ClickAction("window.dialog.dialog_widget.download_button"))
        self.add_action(WaitAction(2000))
    def __init__(self):
        super(BrowseDiscoveredAction, self).__init__()

        self.add_action(PageAction('discovered'))
        for _ in xrange(0, 10):
            self.add_action(
                RandomScrollAction("window.discovered_channels_list"))
            self.add_action(WaitAction(300))
Exemplo n.º 6
0
    def __init__(self, args):
        self.tribler_path = args.tribler_executable
        self._logger = logging.getLogger(self.__class__.__name__)
        self.allow_plain_downloads = args.plain
        self.magnets_file_path = args.magnetsfile
        self.pending_tasks = {}  # Dictionary of pending tasks
        self.probabilities = []

        if not args.silent:
            self.random_action_lc = LoopingCall(self.perform_random_action)
            self.random_action_lc.start(15)
        else:
            # Trigger Tribler startup through a simple action
            self.execute_action(WaitAction(1000))

        self.check_task_completion_lc = LoopingCall(self.check_task_completion)
        self.check_task_completion_lc.start(2, now=False)

        self.check_crash_lc = LoopingCall(self.check_crash)
        self.check_crash_lc.start(11, now=False)

        self.start_time = time.time()
        self.request_manager = HTTPRequestManager()
        self.irc_manager = None
        self.tribler_crashed = False
        self.download_monitor = None

        if args.ircid:
            self.irc_manager = IRCManager(self, args.ircid)
            self.irc_manager.start()

        if args.duration:
            reactor.callLater(args.duration, self.stop, 0)

        if args.monitordownloads:
            self.download_monitor = DownloadMonitor(args.monitordownloads)
            reactor.callLater(20, self.download_monitor.start)

        if args.monitorresources:
            self.resource_monitor = ResourceMonitor(args.monitorresources)
            reactor.callLater(20, self.resource_monitor.start)

        # Determine probabilities
        with open(os.path.join(os.getcwd(), "data", "action_weights.txt"),
                  "r") as action_weights_file:
            content = action_weights_file.read()
            for line in content.split('\n'):
                if len(line) == 0:
                    continue

                if line.startswith('#'):
                    continue

                parts = line.split('=')
                if len(parts) < 2:
                    continue

                self.probabilities.append((parts[0], int(parts[1])))
Exemplo n.º 7
0
    def __init__(self):
        super(SubscribeUnsubscribeAction, self).__init__()

        self.add_action(PageAction('discovered'))
        self.add_action(WaitAction(1000))
        self.add_action(CustomAction("""if window.discovered_channels_list.count() == 0:
    exit_script()
    """))
        self.add_action(ClickAction('window.discovered_channels_list.itemWidget(window.discovered_channels_list.item(randint(0, window.discovered_channels_list.count() - 1))).subscribe_button'))
Exemplo n.º 8
0
    def __init__(self):
        super(RemoveRandomDownloadAction, self).__init__()

        self.add_action(PageAction('downloads'))
        self.add_action(WaitAction(1000))
        self.add_action(
            CustomAction(
                """if len(window.downloads_page.downloads['downloads']) == 0:
    exit_script()
        """))
        self.add_action(
            ClickAction(
                'window.downloads_list.topLevelItem(randint(0, len(window.downloads_page.download_widgets.keys()) - 1)).progress_slider'
            ))
        self.add_action(WaitAction(1000))
        self.add_action(ClickAction('window.remove_download_button'))
        self.add_action(WaitAction(1000))
        self.add_action(ClickAction('window.downloads_page.dialog.buttons[1]'))
        self.add_action(WaitAction(1000))
Exemplo n.º 9
0
    def __init__(self, allow_plain=False):
        super(ChangeAnonymityAction, self).__init__()

        self.add_action(PageAction('downloads'))
        self.add_action(WaitAction(1000))
        self.add_action(CustomAction("""if len(window.downloads_page.downloads['downloads']) == 0:
    exit_script()
        """))
        self.add_action(ClickAction('window.downloads_list.topLevelItem(randint(0, len(window.downloads_page.download_widgets.keys()) - 1)).progress_slider'))
        min_hops = 0 if allow_plain else 1
        self.add_action(CustomAction("window.downloads_page.change_anonymity(randint(%d, 3))" % min_hops))
Exemplo n.º 10
0
Arquivo: ai.py Projeto: elunna/labhack
    def yield_action(self):
        """Determines if the monster should move closer, attack, or wait."""
        target = self.engine.player
        dx = target.x - self.parent.x
        dy = target.y - self.parent.y
        if self.can_attack(target, dx, dy):
            return BumpAction(self.parent, dx, dy)

        self.path = self.get_path_to(target.x, target.y, self.diagonal)

        # Only chase the player if we're under a chase distance threshold.
        if self.path and len(self.path) < self.chase_distance:
            # Move towards the player.
            dest_x, dest_y = self.path.pop(0)
            return MovementAction(
                self.parent, dest_x - self.parent.x, dest_y - self.parent.y,
            )

        # If the entity is not in the player’s vision, simply wait.
        return WaitAction(self.parent)
Exemplo n.º 11
0
    def __init__(self, args):
        self.tribler_path = args.tribler_executable
        self._logger = logging.getLogger(self.__class__.__name__)
        self.allow_plain_downloads = args.plain
        self.pending_tasks = {}  # Dictionary of pending tasks

        if not args.silent:
            self.random_action_lc = LoopingCall(self.perform_random_action)
            self.random_action_lc.start(15)
        else:
            # Trigger Tribler startup through a simple action
            self.execute_action(WaitAction(1000))

        self.check_task_completion_lc = LoopingCall(self.check_task_completion)
        self.check_task_completion_lc.start(2, now=False)

        self.check_crash_lc = LoopingCall(self.check_crash)
        self.check_crash_lc.start(11, now=False)

        self.start_time = time.time()
        self.request_manager = HTTPRequestManager()
        self.irc_manager = None
        self.tribler_crashed = False
        self.download_monitor = None

        if args.ircid:
            self.irc_manager = IRCManager(self, args.ircid)
            self.irc_manager.start()

        if args.duration:
            reactor.callLater(args.duration, self.stop, 0)

        if args.monitordownloads:
            self.download_monitor = DownloadMonitor(args.monitordownloads)
            reactor.callLater(20, self.download_monitor.start)

        if args.monitorresources:
            self.resource_monitor = ResourceMonitor(args.monitorresources)
            reactor.callLater(20, self.resource_monitor.start)
Exemplo n.º 12
0
    def perform_random_action(self):
        """
        This method performs a random action in Tribler.
        There are various actions possible that can occur with different probabilities.
        """
        action = self.weighted_choice(self.probabilities)
        if not action:
            self._logger.warning("No action available!")
            self.execute_action(WaitAction(1000))
            return
        self._logger.info("Performing action: %s", action)
        if action == 'random_page':
            action = RandomPageAction()
        elif action == 'search':
            action = RandomSearchAction()
        elif action == 'start_download':
            action = StartRandomDownloadAction(self.magnets_file_path)
        elif action == 'remove_download':
            action = RemoveRandomDownloadAction()
        elif action == 'explore_download':
            action = ExploreDownloadAction()
        elif action == 'browse_discovered':
            action = BrowseDiscoveredAction()
        elif action == 'explore_channel':
            action = ExploreChannelAction()
        elif action == 'screenshot':
            action = ScreenshotAction()
        elif action == 'start_vod':
            action = StartVODAction()
        elif action == 'change_anonymity':
            action = ChangeAnonymityAction(
                allow_plain=self.allow_plain_downloads)
        elif action == 'subscribe_unsubscribe':
            action = SubscribeUnsubscribeAction()

        self.execute_action(action)
Exemplo n.º 13
0
def test_init__is_Action(test_player):
    a = WaitAction(entity=test_player)
    assert isinstance(a, actions.Action)
Exemplo n.º 14
0
Arquivo: ai.py Projeto: elunna/labhack
 def yield_action(self):
     """Returns a WaitAction. """
     self.first_turn = False
     return WaitAction(self.parent)
Exemplo n.º 15
0
def test_perform(test_player):
    a = WaitAction(entity=test_player)
    assert a.perform() is None
    assert a.msg == ''
Exemplo n.º 16
0
 def handle_auto_states(self, actor):
     """ This handles things that "take over" an actors turn, like paralysis or sleep.
     """
     # For now just use WaitAction
     return WaitAction(actor)
Exemplo n.º 17
0
def test_init(test_player):
    a = WaitAction(entity=test_player)
    assert a.entity == test_player