synchronization

This commit is contained in:
Marc Beninca 2021-10-09 19:46:11 +02:00 committed by Marc Beninca
parent 47120adeb5
commit 4397a20bfd
4 changed files with 33 additions and 17 deletions

View file

@ -3,12 +3,11 @@
import sys import sys
import arguments import arguments
import remote
import repository import repository
import synchronization
def build(repository, arguments): def build(args):
print('Build:')
# TODO identify # TODO identify
print('TODO identify') print('TODO identify')
# TODO extract # TODO extract
@ -19,8 +18,7 @@ def build(repository, arguments):
print('TODO archive') print('TODO archive')
def check(repository, arguments): def check(args):
print('Check:')
# TODO prepare threads # TODO prepare threads
print('TODO prepare threads') print('TODO prepare threads')
# TODO run threads # TODO run threads
@ -29,14 +27,13 @@ def check(repository, arguments):
print('TODO watch threads') print('TODO watch threads')
def info(repository, arguments): def info(args):
print(repository) print(repository.Repository(args))
def sync(repository, args): def sync(args):
print('Sync:') sync = synchronization.Synchronization(args)
r = remote.Remote(args) print(sync)
print(r)
# TODO prepare temporary directory # TODO prepare temporary directory
print('prepare…') print('prepare…')
# TODO fetch # TODO fetch
@ -49,9 +46,8 @@ def sync(repository, args):
def main(): def main():
args = arguments.parse() args = arguments.parse()
repo = repository.Repository(args) function = getattr(sys.modules[__name__], args[arguments.ACTION])
func = getattr(sys.modules[__name__], args[arguments.ACTION]) function(args)
func(repo, args)
if __name__ == '__main__': if __name__ == '__main__':

View file

@ -16,11 +16,12 @@ SUBSYSTEMS = ['msys', 'mingw']
class Remote: class Remote:
def __init__(self, args): def __init__(self, args):
self.location = args[arguments.REMOTE] self.location = args[arguments.REMOTE]
self.architectures = args[arguments.ARCHITECTURES]
self.load() self.load()
def load(self): def load(self):
d = {} d = {}
for architecture in ARCHITECTURES: for architecture in self.architectures:
url = os.path.join(self.location, DISTRIBUTION, architecture) url = os.path.join(self.location, DISTRIBUTION, architecture)
html = requests.get(url).content.decode(CHARSET) html = requests.get(url).content.decode(CHARSET)
links = sorted(hypertext.get_links(html)) links = sorted(hypertext.get_links(html))

View file

@ -26,7 +26,7 @@ class Repository:
d[architecture] = archive d[architecture] = archive
self.archives = d self.archives = d
def get_temporary(): def get_temporary(self):
return os.path.join(self.temporary, return os.path.join(self.temporary,
datetime.datetime.now() datetime.datetime.now()
.strftime('%Y%m%d%H%M%S')) .strftime('%Y%m%d%H%M%S'))
@ -35,7 +35,7 @@ class Repository:
lines = [ lines = [
f'Directory: {self.directory}', f'Directory: {self.directory}',
f'{os.path.realpath(self.directory)}', f'{os.path.realpath(self.directory)}',
f'Archives:', 'Archives:',
] ]
for architecture, archive in reversed(sorted(self.archives.items())): for architecture, archive in reversed(sorted(self.archives.items())):
lines.append(f'{architecture}{archive}') lines.append(f'{architecture}{archive}')

19
synchronization.py Normal file
View file

@ -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)