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)