From 4a106b9c7d00dbf86ac999a2ca03fbe01eaedd3b Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Sun, 10 Oct 2021 03:00:43 +0200 Subject: [PATCH] hypertext,msys --- hypertext.py | 20 ++++++++++++++------ msys.py | 2 ++ remote.py | 6 +----- repository.py | 3 ++- 4 files changed, 19 insertions(+), 12 deletions(-) create mode 100644 msys.py diff --git a/hypertext.py b/hypertext.py index 42c5e49..9252081 100644 --- a/hypertext.py +++ b/hypertext.py @@ -1,7 +1,7 @@ import html.parser import requests -CHARSET = 'u8' +import msys class Parser(html.parser.HTMLParser): @@ -15,8 +15,16 @@ class Parser(html.parser.HTMLParser): [v for k, v in attributes if k == 'href']) -def get_links(location): - hypertext = requests.get(location).content.decode(CHARSET) - parser = Parser() - parser.feed(hypertext) - return parser.links +class HyperText: + def __init__(self, location): + self.location = location + self.load() + + def load(self): + hypertext = requests.get(self.location).content.decode(msys.CHARSET) + parser = Parser() + parser.feed(hypertext) + self.links = parser.links + self.archives = [link for link in self.links + if link.endswith(msys.ARCHIVE)] + self.archive = sorted(self.archives)[-1] diff --git a/msys.py b/msys.py new file mode 100644 index 0000000..b70d268 --- /dev/null +++ b/msys.py @@ -0,0 +1,2 @@ +ARCHIVE = '.tar.xz' +CHARSET = 'u8' diff --git a/remote.py b/remote.py index 27b28c0..eacfe5c 100644 --- a/remote.py +++ b/remote.py @@ -6,7 +6,6 @@ import catalog import hypertext -ARCHIVE = '.tar.xz' ARCHITECTURES = ['x86_64', 'i686'] ARCHITECTURES_BITS = { 'x86_64': 64, @@ -36,10 +35,7 @@ class Remote: c = {} for architecture in self.architectures: location = os.path.join(self.location, DISTRIBUTION, architecture) - links = sorted(hypertext.get_links(location)) - archives = [link for link in links - if link.endswith(ARCHIVE)] - archive = archives[-1] + archive = hypertext.HyperText(location).archive a[architecture] = archive # c[architecture] = {} diff --git a/repository.py b/repository.py index 5d46fa5..3926ac1 100644 --- a/repository.py +++ b/repository.py @@ -2,6 +2,7 @@ import arguments import datetime import os +import msys import remote @@ -21,7 +22,7 @@ class Repository: directory = os.path.join(distribution, architecture) _, _, files = next(os.walk(directory)) archives = sorted([file for file in files - if file.endswith(remote.ARCHIVE)]) + if file.endswith(msys.ARCHIVE)]) archive = archives[-1] d[architecture] = archive self.archives = d