예제 #1
0
def test_errored_states(state):
    assert TorrentStates(state).is_errored
예제 #2
0
def test_paused_states(state):
    assert TorrentStates(state).is_paused
예제 #3
0
def test_completing_states(state):
    assert TorrentStates(state).is_complete
예제 #4
0
def test_checking_states(state):
    assert TorrentStates(state).is_checking
예제 #5
0
def test_uploading_states(state):
    assert TorrentStates(state).is_uploading
예제 #6
0
def test_downloading_states(state):
    assert TorrentStates(state).is_downloading
예제 #7
0
def test_all_states(state):
    assert TorrentStates(state) in TorrentStates
예제 #8
0
def test_torrent_states_exists():
    assert isinstance(TorrentStates("unknown"), Enum)
    def get_qbittorrent_torrent_tags_metrics(self):
        try:
            categories = self.client.torrent_categories.categories
        except Exception as e:
            logger.error(f"Couldn't fetch categories: {e}")
            return []

        if not self.torrents:
            return []

        metrics = []
        categories.Uncategorized = AttrDict({'name': 'Uncategorized', 'savePath': ''})
        for category in categories:
            category_torrents = [t for t in self.torrents if t['category'] == category or (category == "Uncategorized" and t['category'] == "")]

            for status in self.TORRENT_STATUSES:
                status_prop = f"is_{status}"
                status_torrents = [
                    t for t in category_torrents if getattr(TorrentStates, status_prop).fget(TorrentStates(t['state']))
                ]
                metrics.append({
                    "name": f"{self.config['metrics_prefix']}_torrents_count",
                    "value": len(status_torrents),
                    "labels": {
                        "status": status,
                        "category": category,
                    },
                    "help": f"Number of torrents in status {status} under category {category}"
                })

        return metrics