2021-10-09 12:02:10 +00:00
|
|
|
import os
|
|
|
|
import requests
|
|
|
|
|
|
|
|
import arguments
|
2021-10-09 21:39:16 +00:00
|
|
|
import catalog
|
2021-10-09 12:02:10 +00:00
|
|
|
import hypertext
|
2021-10-10 01:52:31 +00:00
|
|
|
import msys
|
2021-10-09 12:02:10 +00:00
|
|
|
|
|
|
|
|
2021-10-09 19:39:10 +00:00
|
|
|
ARCHITECTURES_BITS = {
|
2021-10-09 20:26:39 +00:00
|
|
|
'x86_64': 64,
|
|
|
|
'i686': 32,
|
2021-10-09 19:39:10 +00:00
|
|
|
}
|
|
|
|
ARCHITECTURES_SUBSYSTEMS = {
|
2021-10-09 20:26:39 +00:00
|
|
|
'x86_64': ['msys', 'clang64', 'mingw64', 'ucrt64'],
|
|
|
|
'i686': ['msys', 'clang32', 'mingw32'],
|
2021-10-09 19:39:10 +00:00
|
|
|
}
|
2021-10-09 18:45:16 +00:00
|
|
|
MINGW = 'mingw'
|
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-10 02:01:32 +00:00
|
|
|
location = os.path.join(self.location,
|
|
|
|
msys.DISTRIBUTION, architecture)
|
2021-10-10 01:46:44 +00:00
|
|
|
a[architecture] = hypertext.HyperText(location).archive
|
2021-10-09 18:45:16 +00:00
|
|
|
#
|
2021-10-09 19:59:07 +00:00
|
|
|
c[architecture] = {}
|
2021-10-09 19:39:10 +00:00
|
|
|
for ss in self.subsystems:
|
|
|
|
location = self.location
|
2021-10-10 01:52:31 +00:00
|
|
|
if ss == msys.SUBSYSTEMS[0]:
|
2021-10-09 19:39:10 +00:00
|
|
|
subsystem = ss
|
|
|
|
location = os.path.join(location, subsystem, architecture)
|
|
|
|
else:
|
|
|
|
subsystem = f'{ss}{ARCHITECTURES_BITS[architecture]}'
|
|
|
|
location = os.path.join(location, MINGW, subsystem)
|
|
|
|
if subsystem in ARCHITECTURES_SUBSYSTEMS[architecture]:
|
2021-10-10 01:57:52 +00:00
|
|
|
location = os.path.join(location,
|
|
|
|
f'{subsystem}{msys.CATALOG}')
|
2021-10-09 21:39:16 +00:00
|
|
|
binary = requests.get(location).content
|
|
|
|
c[architecture][subsystem] = catalog.Catalog(binary)
|
2021-10-09 18:45:16 +00:00
|
|
|
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 19:59:07 +00:00
|
|
|
lines.append('Subsystems:')
|
2021-10-09 20:26:39 +00:00
|
|
|
for arch, ss in reversed(sorted(self.catalogs.items())):
|
|
|
|
lines.append(f'{arch} → {list(ss.keys())}')
|
2021-10-09 12:55:05 +00:00
|
|
|
return os.linesep.join(lines)
|