This commit is contained in:
Marc Beninca 2021-10-10 21:30:40 +02:00 committed by Marc Beninca
parent 3763dce133
commit 2e366f71f1
6 changed files with 25 additions and 37 deletions

View file

@ -4,17 +4,21 @@ import tarfile
import package import package
CATALOG = '.files'
FILES = 'files' FILES = 'files'
PACKAGE = 'desc' PACKAGE = 'desc'
class Catalog: class Catalog:
def __init__(self, binary): def __init__(self, subsystem):
self.binary = binary self.subsystem = subsystem
self.path = os.path.join(self.subsystem.path,
f'{self.subsystem.name}{CATALOG}')
self.load() self.load()
def load(self): 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) archive = tarfile.open(fileobj=f)
m = {} m = {}
packages = {} packages = {}

View file

@ -10,6 +10,10 @@ class Local(repository.Repository):
super().__init__(arguments.directory) super().__init__(arguments.directory)
self.temporary = arguments.temporary 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): def get_files(self, path):
*_, files = next(os.walk(os.path.join(self.location, path))) *_, files = next(os.walk(os.path.join(self.location, path)))
return files return files

View file

@ -1,3 +1,2 @@
CATALOG = '.files'
CHARSET = 'u8' CHARSET = 'u8'
REPOSITORY = 'https://repo.msys2.org' REPOSITORY = 'https://repo.msys2.org'

View file

@ -2,33 +2,16 @@ import os
import requests import requests
import arguments import arguments
import catalog
import hypertext import hypertext
import msys
import repository import repository
class Remote(repository.Repository): class Remote(repository.Repository):
def __init__(self): def __init__(self):
super().__init__(arguments.remote) super().__init__(arguments.remote)
self.load()
def load(self): def get_file(self, path):
archives = {} return requests.get(os.path.join(self.location, path)).content
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_files(self, path): def get_files(self, path):
return hypertext.HyperText(os.path.join(self.location, path)).links return hypertext.HyperText(os.path.join(self.location, path)).links
@ -36,11 +19,5 @@ class Remote(repository.Repository):
def __str__(self): def __str__(self):
lines = [ lines = [
super().__str__(), 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) return os.linesep.join(lines)

View file

@ -1,5 +1,7 @@
import os import os
import catalog
CRT = 'mingw' CRT = 'mingw'
MAIN = 'msys' MAIN = 'msys'
@ -18,6 +20,8 @@ class SubSystem:
if self.name == MAIN: if self.name == MAIN:
list.append(self.architecture.name) list.append(self.architecture.name)
self.path = os.sep.join(list) self.path = os.sep.join(list)
# catalog
self.catalog = catalog.Catalog(self)
def __str__(self): def __str__(self):
lines = [ lines = [

View file

@ -16,15 +16,13 @@ class Synchronization:
def run(self): def run(self):
for architecture in self.remote.architectures: for architecture in self.remote.architectures:
for subsystem in architecture.subsystems.keys(): for subsystem in architecture.subsystems.values():
catalog = self.remote.catalogs[architecture][subsystem] for _, package in sorted(subsystem.catalog.packages.items()):
path = architecture.subsystems[subsystem].path
for _, package in sorted(catalog.packages.items()):
f = file.File( f = file.File(
os.path.join(self.remote.location, path), os.path.join(self.remote.location, subsystem.path),
package.name, package.name,
package.csize, package.csize,
os.path.join(self.repository.location, path), os.path.join(self.repository.location, subsystem.path),
package.sha256sum, package.sha256sum,
) )
print() print()
@ -37,8 +35,10 @@ class Synchronization:
def __str__(self): def __str__(self):
lines = [ lines = [
str(self.remote), str(), str(self.remote),
str(self.repository), str(), str(),
str(self.repository),
str(),
f'Temporary: {self.temporary}', f'Temporary: {self.temporary}',
] ]
return os.linesep.join(lines) return os.linesep.join(lines)