From 374aa7c1c800b789e97b7146890e06c3bad45d52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Jastrz=C4=99bski?= Date: Tue, 2 Jul 2019 08:32:28 +0200 Subject: [PATCH] Fixed issues with dev version detection (close #3) --- CB/CurseForge.py | 27 ++++++++++----------------- CB/__init__.py | 2 +- 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/CB/CurseForge.py b/CB/CurseForge.py index 6c4ae0c..1af16a4 100644 --- a/CB/CurseForge.py +++ b/CB/CurseForge.py @@ -4,6 +4,7 @@ import zipfile import requests from bs4 import BeautifulSoup +from operator import itemgetter from . import retry @@ -25,25 +26,17 @@ def __init__(self, url, cache, allowdev): self.directories = [] self.get_current_version() - def _parse_files(self, releasetype): - for f in self.payload['latestFiles']: - if f['releaseType'] == releasetype and '-nolib' not in f['displayName']: - self.downloadUrl = f['downloadUrl'] - self.currentVersion = f['displayName'] - break - def get_current_version(self): - if self.allowDev: - self._parse_files(3) - if not self.downloadUrl and not self.currentVersion: - self._parse_files(2) - if not self.downloadUrl and not self.currentVersion: - self._parse_files(1) + files = sorted(self.payload['latestFiles'], key=itemgetter('id'), reverse=True) + for status in [[3, 2], [1]] if self.allowDev else [[1], [2], [3]]: + for f in files: + if f['releaseType'] in status and '-nolib' not in f['displayName'] and not f['isAlternate']: + self.downloadUrl = f['downloadUrl'] + self.currentVersion = f['displayName'] + break + if self.downloadUrl and self.currentVersion: + break else: - self._parse_files(1) - if not self.downloadUrl and not self.currentVersion: - self._parse_files(2) - if not self.downloadUrl or not self.currentVersion: raise RuntimeError @retry() diff --git a/CB/__init__.py b/CB/__init__.py index 0343233..97fa5a7 100644 --- a/CB/__init__.py +++ b/CB/__init__.py @@ -1,4 +1,4 @@ -__version__ = '1.5.2' +__version__ = '1.5.3' __license__ = 'GPLv3' __copyright__ = '2019, Paweł Jastrzębski ' __docformat__ = 'restructuredtext en'