Esempio n. 1
0
def test_errored_states(state):
    assert TorrentStates(state).is_errored
Esempio n. 2
0
def test_paused_states(state):
    assert TorrentStates(state).is_paused
Esempio n. 3
0
def test_completing_states(state):
    assert TorrentStates(state).is_complete
Esempio n. 4
0
def test_checking_states(state):
    assert TorrentStates(state).is_checking
Esempio n. 5
0
def test_uploading_states(state):
    assert TorrentStates(state).is_uploading
Esempio n. 6
0
def test_downloading_states(state):
    assert TorrentStates(state).is_downloading
Esempio n. 7
0
def test_all_states(state):
    assert TorrentStates(state) in TorrentStates
Esempio n. 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