2021-10-09 10:26:53 +00:00
|
|
|
import arguments
|
|
|
|
import datetime
|
|
|
|
import os
|
|
|
|
|
2021-10-09 13:58:44 +00:00
|
|
|
import remote
|
|
|
|
|
2021-10-09 10:26:53 +00:00
|
|
|
|
|
|
|
class Repository:
|
|
|
|
def __init__(self, args):
|
|
|
|
self.directory = args[arguments.DIRECTORY]
|
|
|
|
self.temporary = args[arguments.TEMPORARY]
|
2021-10-09 13:58:44 +00:00
|
|
|
self.load()
|
|
|
|
|
|
|
|
def load(self):
|
|
|
|
distribution = os.path.join(
|
|
|
|
self.directory, remote.DISTRIBUTION)
|
|
|
|
d = {}
|
|
|
|
_, architectures, _ = next(os.walk(distribution))
|
|
|
|
for architecture in [a for a in architectures
|
|
|
|
if a in remote.ARCHITECTURES]:
|
|
|
|
directory = os.path.join(distribution, architecture)
|
|
|
|
_, _, files = next(os.walk(directory))
|
|
|
|
archives = sorted([file for file in files
|
|
|
|
if file.endswith(remote.ARCHIVE)])
|
|
|
|
archive = archives[-1]
|
|
|
|
d[architecture] = archive
|
|
|
|
self.archives = d
|
2021-10-09 10:26:53 +00:00
|
|
|
|
2021-10-09 16:19:58 +00:00
|
|
|
def get_temporary():
|
|
|
|
return os.path.join(self.temporary,
|
|
|
|
datetime.datetime.now()
|
|
|
|
.strftime('%Y%m%d%H%M%S'))
|
|
|
|
|
2021-10-09 10:26:53 +00:00
|
|
|
def __str__(self):
|
2021-10-09 12:54:50 +00:00
|
|
|
lines = [
|
|
|
|
f'Directory: {self.directory}',
|
|
|
|
f' → {os.path.realpath(self.directory)}',
|
2021-10-09 13:58:44 +00:00
|
|
|
f'Archives:',
|
2021-10-09 12:54:50 +00:00
|
|
|
]
|
2021-10-09 13:58:44 +00:00
|
|
|
for architecture, archive in reversed(sorted(self.archives.items())):
|
|
|
|
lines.append(f'{architecture} → {archive}')
|
2021-10-09 12:54:50 +00:00
|
|
|
return os.linesep.join(lines)
|