mrmp/remote.py

47 lines
1.5 KiB
Python
Raw Normal View History

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-10 12:48:12 +00:00
import repository
2021-10-09 12:02:10 +00:00
2021-10-10 12:48:12 +00:00
class Remote(repository.Repository):
2021-10-09 12:02:10 +00:00
def __init__(self, args):
2021-10-10 13:01:24 +00:00
super().__init__(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):
2021-10-10 03:04:35 +00:00
archives = {}
2021-10-09 18:45:16 +00:00
c = {}
2021-10-09 17:46:11 +00:00
for architecture in self.architectures:
2021-10-10 14:27:52 +00:00
subsystems = architecture.subsystems.keys()
2021-10-10 02:01:32 +00:00
location = os.path.join(self.location,
2021-10-10 14:50:15 +00:00
architecture.distribution.path)
2021-10-10 03:04:35 +00:00
archives[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-10 02:43:33 +00:00
for subsystem in subsystems:
2021-10-10 03:01:21 +00:00
location = os.path.join(self.location,
2021-10-10 14:42:35 +00:00
architecture.subsystems[subsystem]
.path,
2021-10-10 02:43:33 +00:00
f'{subsystem}{msys.CATALOG}')
binary = requests.get(location).content
c[architecture][subsystem] = catalog.Catalog(binary)
2021-10-10 03:04:35 +00:00
self.archives = archives
2021-10-09 18:45:16 +00:00
self.catalogs = c
2021-10-09 12:02:10 +00:00
def __str__(self):
2021-10-10 13:01:24 +00:00
lines = [
super().__str__(),
'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)