From 2e366f71f1ed021f2539c2947d049ac6a977acff Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Sun, 10 Oct 2021 21:30:40 +0200 Subject: [PATCH] catalog --- catalog.py | 10 +++++++--- local.py | 4 ++++ msys.py | 1 - remote.py | 27 ++------------------------- subsystem.py | 4 ++++ synchronization.py | 16 ++++++++-------- 6 files changed, 25 insertions(+), 37 deletions(-) diff --git a/catalog.py b/catalog.py index 12ce4c1..a096d34 100644 --- a/catalog.py +++ b/catalog.py @@ -4,17 +4,21 @@ import tarfile import package +CATALOG = '.files' FILES = 'files' PACKAGE = 'desc' class Catalog: - def __init__(self, binary): - self.binary = binary + def __init__(self, subsystem): + self.subsystem = subsystem + self.path = os.path.join(self.subsystem.path, + f'{self.subsystem.name}{CATALOG}') self.load() def load(self): - f = io.BytesIO(self.binary) + binary = self.subsystem.architecture.repository.get_file(self.path) + f = io.BytesIO(binary) archive = tarfile.open(fileobj=f) m = {} packages = {} diff --git a/local.py b/local.py index 2a53b80..d1af64f 100644 --- a/local.py +++ b/local.py @@ -10,6 +10,10 @@ class Local(repository.Repository): super().__init__(arguments.directory) self.temporary = arguments.temporary + def get_file(self, path): + with open(os.path.join(self.location, path), 'br') as f: + return f.read() + def get_files(self, path): *_, files = next(os.walk(os.path.join(self.location, path))) return files diff --git a/msys.py b/msys.py index 87eb923..b93f9a4 100644 --- a/msys.py +++ b/msys.py @@ -1,3 +1,2 @@ -CATALOG = '.files' CHARSET = 'u8' REPOSITORY = 'https://repo.msys2.org' diff --git a/remote.py b/remote.py index 71ae923..2939717 100644 --- a/remote.py +++ b/remote.py @@ -2,33 +2,16 @@ import os import requests import arguments -import catalog import hypertext -import msys import repository class Remote(repository.Repository): def __init__(self): super().__init__(arguments.remote) - self.load() - def load(self): - archives = {} - c = {} - for architecture in self.architectures: - subsystems = architecture.subsystems.keys() - # - c[architecture] = {} - for subsystem in subsystems: - location = os.path.join(self.location, - architecture.subsystems[subsystem] - .path, - f'{subsystem}{msys.CATALOG}') - binary = requests.get(location).content - c[architecture][subsystem] = catalog.Catalog(binary) - self.archives = archives - self.catalogs = c + def get_file(self, path): + return requests.get(os.path.join(self.location, path)).content def get_files(self, path): return hypertext.HyperText(os.path.join(self.location, path)).links @@ -36,11 +19,5 @@ class Remote(repository.Repository): def __str__(self): lines = [ super().__str__(), - 'Archives:', ] - for architecture, archive in reversed(sorted(self.archives.items())): - lines.append(f'{architecture} → {archive}') - lines.append('Subsystems:') - for arch, ss in reversed(sorted(self.catalogs.items())): - lines.append(f'{arch} → {list(ss.keys())}') return os.linesep.join(lines) diff --git a/subsystem.py b/subsystem.py index cae4ed0..765c344 100644 --- a/subsystem.py +++ b/subsystem.py @@ -1,5 +1,7 @@ import os +import catalog + CRT = 'mingw' MAIN = 'msys' @@ -18,6 +20,8 @@ class SubSystem: if self.name == MAIN: list.append(self.architecture.name) self.path = os.sep.join(list) + # catalog + self.catalog = catalog.Catalog(self) def __str__(self): lines = [ diff --git a/synchronization.py b/synchronization.py index c4fa2b8..9e28832 100644 --- a/synchronization.py +++ b/synchronization.py @@ -16,15 +16,13 @@ class Synchronization: def run(self): for architecture in self.remote.architectures: - for subsystem in architecture.subsystems.keys(): - catalog = self.remote.catalogs[architecture][subsystem] - path = architecture.subsystems[subsystem].path - for _, package in sorted(catalog.packages.items()): + for subsystem in architecture.subsystems.values(): + for _, package in sorted(subsystem.catalog.packages.items()): f = file.File( - os.path.join(self.remote.location, path), + os.path.join(self.remote.location, subsystem.path), package.name, package.csize, - os.path.join(self.repository.location, path), + os.path.join(self.repository.location, subsystem.path), package.sha256sum, ) print() @@ -37,8 +35,10 @@ class Synchronization: def __str__(self): lines = [ - str(self.remote), str(), - str(self.repository), str(), + str(self.remote), + str(), + str(self.repository), + str(), f'Temporary: {self.temporary}', ] return os.linesep.join(lines)