mrmp/remote.py

40 lines
960 B
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 12:36:53 +00:00
SIGNATURE = '.sig'
2021-10-09 12:02:10 +00:00
class Remote:
def __init__(self, args):
self.location = args[arguments.REMOTE]
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):
d = {}
for architecture in ARCHITECTURES:
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)]
signatures = [link for link in links
if link.endswith(SIGNATURE)]
archive = archives[-1]
d[architecture] = archive
self.archives = d
2021-10-09 12:02:10 +00:00
def __str__(self):
return f'''\
Location: {self.location}
2021-10-09 12:36:53 +00:00
Archives:
{self.archives}
2021-10-09 12:02:10 +00:00
'''