mrmp/remote.py

55 lines
1.7 KiB
Python
Raw Normal View History

2021-10-09 12:02:10 +00:00
import os
import requests
import arguments
import hypertext
2021-10-09 12:36:53 +00:00
ARCHIVE = '.tar.xz'
ARCHITECTURES = ['x86_64', 'i686']
2021-10-09 12:02:10 +00:00
CHARSET = 'u8'
DISTRIBUTION = 'distrib'
2021-10-09 18:45:16 +00:00
FILES = '.files'
MINGW = 'mingw'
2021-10-09 12:36:53 +00:00
SIGNATURE = '.sig'
2021-10-09 18:45:16 +00:00
SUBSYSTEMS = ['msys', 'mingw64']
2021-10-09 12:02:10 +00:00
class Remote:
def __init__(self, args):
self.location = args[arguments.REMOTE]
2021-10-09 17:46:11 +00:00
self.architectures = args[arguments.ARCHITECTURES]
2021-10-09 18:01:02 +00:00
self.subsystems = args[arguments.SUBSYSTEMS]
2021-10-09 12:36:53 +00:00
self.load()
2021-10-09 12:02:10 +00:00
2021-10-09 12:36:53 +00:00
def load(self):
2021-10-09 18:45:16 +00:00
a = {}
c = {}
2021-10-09 17:46:11 +00:00
for architecture in self.architectures:
2021-10-09 12:36:53 +00:00
url = os.path.join(self.location, DISTRIBUTION, architecture)
html = requests.get(url).content.decode(CHARSET)
links = sorted(hypertext.get_links(html))
archives = [link for link in links
if link.endswith(ARCHIVE)]
archive = archives[-1]
2021-10-09 18:45:16 +00:00
a[architecture] = archive
#
for subsystem in self.subsystems:
location = [self.location]
if subsystem != SUBSYSTEMS[0]:
location.append(MINGW)
location = os.path.join(*location, subsystem, architecture,
f'{subsystem}{FILES}')
binary = requests.get(url).content
c[architecture] = binary
self.archives = a
self.catalogs = c
2021-10-09 12:02:10 +00:00
def __str__(self):
2021-10-09 12:55:05 +00:00
lines = [f'Location: {self.location}',
'Archives:']
2021-10-09 12:59:07 +00:00
for architecture, archive in reversed(sorted(self.archives.items())):
2021-10-09 12:55:05 +00:00
lines.append(f'{architecture}{archive}')
2021-10-09 18:07:29 +00:00
lines.append(f'Subsystems: {self.subsystems}')
2021-10-09 12:55:05 +00:00
return os.linesep.join(lines)