From e90a4396fa8d8d5bd78af14a7196efa4939abd93 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Sun, 10 Oct 2021 13:45:02 +0200 Subject: [PATCH] packages --- __init__.py | 9 +-------- package.py | 13 +++++++++++-- synchronization.py | 18 ++++++++++++++++++ 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/__init__.py b/__init__.py index 48a2aa5..f0cd852 100755 --- a/__init__.py +++ b/__init__.py @@ -34,14 +34,7 @@ def info(args): def sync(args): sync = synchronization.Synchronization(args) print(sync) - # TODO prepare temporary directory - print('prepare…') - # TODO fetch - print('fetch…') - # TODO purge useless files - print('purge…') - # TODO clean temporary directory - print('clean…') + sync.run() def main(): diff --git a/package.py b/package.py index 2c43295..f8f0b9c 100644 --- a/package.py +++ b/package.py @@ -1,6 +1,7 @@ import os -CHARSET = 'u8' +import msys + KEY = '%' SEPARATOR = f'{os.linesep}{os.linesep}' @@ -8,7 +9,7 @@ SEPARATOR = f'{os.linesep}{os.linesep}' class Package: def __init__(self, package, files): for binary in [package, files]: - text = binary.decode(CHARSET).strip() + text = binary.decode(msys.CHARSET).strip() for item in text.split(SEPARATOR): line, *lines = item.split(os.linesep) key = line.split(KEY)[1].lower() @@ -17,3 +18,11 @@ class Package: else: value = lines setattr(self, key, value) + + def __str__(self): + lines = [ + f'Name: {self.name}', + f'Size: {self.csize}', + f'Hash: {self.sha256sum}', + ] + return os.linesep.join(lines) diff --git a/synchronization.py b/synchronization.py index 0a268ac..f824470 100644 --- a/synchronization.py +++ b/synchronization.py @@ -1,5 +1,8 @@ import os +import shutil +import arguments +import msys import remote import repository @@ -9,6 +12,21 @@ class Synchronization: self.remote = remote.Remote(args) self.repository = repository.Repository(args) self.temporary = self.repository.get_temporary() + self.threads = args[arguments.THREADS] + + def run(self): + for architecture in self.remote.architectures: + for subsystem in msys.get_subsystems(architecture, + self.remote.subsystems): + catalog = self.remote.catalogs[architecture][subsystem] + for _, package in sorted(catalog.packages.items()): + print() + print(package) + tmp = os.path.join(self.repository.directory, + self.repository.get_temporary()) + os.makedirs(tmp) + # clean temporary directory + shutil.rmtree(tmp) def __str__(self): lines = [