From 4397a20bfdb33c9312c3219d2fa6897e1cb2e242 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Sat, 9 Oct 2021 19:46:11 +0200 Subject: [PATCH] synchronization --- __init__.py | 24 ++++++++++-------------- remote.py | 3 ++- repository.py | 4 ++-- synchronization.py | 19 +++++++++++++++++++ 4 files changed, 33 insertions(+), 17 deletions(-) create mode 100644 synchronization.py diff --git a/__init__.py b/__init__.py index f91fa2f..48a2aa5 100755 --- a/__init__.py +++ b/__init__.py @@ -3,12 +3,11 @@ import sys import arguments -import remote import repository +import synchronization -def build(repository, arguments): - print('Build:') +def build(args): # TODO identify print('TODO identify') # TODO extract @@ -19,8 +18,7 @@ def build(repository, arguments): print('TODO archive') -def check(repository, arguments): - print('Check:') +def check(args): # TODO prepare threads print('TODO prepare threads') # TODO run threads @@ -29,14 +27,13 @@ def check(repository, arguments): print('TODO watch threads') -def info(repository, arguments): - print(repository) +def info(args): + print(repository.Repository(args)) -def sync(repository, args): - print('Sync:') - r = remote.Remote(args) - print(r) +def sync(args): + sync = synchronization.Synchronization(args) + print(sync) # TODO prepare temporary directory print('prepare…') # TODO fetch @@ -49,9 +46,8 @@ def sync(repository, args): def main(): args = arguments.parse() - repo = repository.Repository(args) - func = getattr(sys.modules[__name__], args[arguments.ACTION]) - func(repo, args) + function = getattr(sys.modules[__name__], args[arguments.ACTION]) + function(args) if __name__ == '__main__': diff --git a/remote.py b/remote.py index 4fd2e5f..a8d8972 100644 --- a/remote.py +++ b/remote.py @@ -16,11 +16,12 @@ SUBSYSTEMS = ['msys', 'mingw'] class Remote: def __init__(self, args): self.location = args[arguments.REMOTE] + self.architectures = args[arguments.ARCHITECTURES] self.load() def load(self): d = {} - for architecture in ARCHITECTURES: + for architecture in self.architectures: url = os.path.join(self.location, DISTRIBUTION, architecture) html = requests.get(url).content.decode(CHARSET) links = sorted(hypertext.get_links(html)) diff --git a/repository.py b/repository.py index 315dd3d..7bf0a56 100644 --- a/repository.py +++ b/repository.py @@ -26,7 +26,7 @@ class Repository: d[architecture] = archive self.archives = d - def get_temporary(): + def get_temporary(self): return os.path.join(self.temporary, datetime.datetime.now() .strftime('%Y%m%d%H%M%S')) @@ -35,7 +35,7 @@ class Repository: lines = [ f'Directory: {self.directory}', f' → {os.path.realpath(self.directory)}', - f'Archives:', + 'Archives:', ] for architecture, archive in reversed(sorted(self.archives.items())): lines.append(f'{architecture} → {archive}') diff --git a/synchronization.py b/synchronization.py new file mode 100644 index 0000000..0a268ac --- /dev/null +++ b/synchronization.py @@ -0,0 +1,19 @@ +import os + +import remote +import repository + + +class Synchronization: + def __init__(self, args): + self.remote = remote.Remote(args) + self.repository = repository.Repository(args) + self.temporary = self.repository.get_temporary() + + def __str__(self): + lines = [ + str(self.remote), str(), + str(self.repository), str(), + f'Temporary: {self.temporary}', + ] + return os.linesep.join(lines)