srlp/local.py

45 lines
1.3 KiB
Python
Raw Normal View History

2021-10-09 12:26:53 +02:00
import datetime
import os
2021-10-10 20:04:45 +02:00
import architecture
import arguments
2021-10-10 16:50:15 +02:00
import distribution
2021-10-10 03:00:43 +02:00
import msys
2021-10-10 14:48:12 +02:00
import repository
2021-10-09 15:58:44 +02:00
2021-10-09 12:26:53 +02:00
2021-10-10 14:48:12 +02:00
class Local(repository.Repository):
2021-10-10 19:02:34 +02:00
def __init__(self):
super().__init__(arguments.directory)
self.temporary = arguments.temporary
2021-10-09 15:58:44 +02:00
self.load()
def load(self):
2021-10-10 16:50:15 +02:00
distro = os.path.join(
self.location, distribution.DISTRIBUTION)
2021-10-09 15:58:44 +02:00
d = {}
2021-10-10 16:50:15 +02:00
_, architectures, _ = next(os.walk(distro))
2021-10-10 20:04:45 +02:00
for arch in [a for a in architectures
if a in architecture.ARCHITECTURES.keys()]:
directory = os.path.join(distro, arch)
2021-10-09 15:58:44 +02:00
_, _, files = next(os.walk(directory))
archives = sorted([file for file in files
2021-10-10 03:00:43 +02:00
if file.endswith(msys.ARCHIVE)])
2021-10-09 15:58:44 +02:00
archive = archives[-1]
2021-10-10 20:04:45 +02:00
d[arch] = archive
2021-10-09 15:58:44 +02:00
self.archives = d
2021-10-09 12:26:53 +02:00
2021-10-09 19:46:11 +02:00
def get_temporary(self):
2021-10-09 18:19:58 +02:00
return os.path.join(self.temporary,
datetime.datetime.now()
.strftime('%Y%m%d%H%M%S'))
2021-10-09 12:26:53 +02:00
def __str__(self):
2021-10-09 14:54:50 +02:00
lines = [
2021-10-10 15:01:24 +02:00
super().__str__(),
2021-10-09 19:46:11 +02:00
'Archives:',
2021-10-09 14:54:50 +02:00
]
2021-10-10 20:04:45 +02:00
for arch, archive in reversed(sorted(self.archives.items())):
lines.append(f'{arch}{archive}')
2021-10-09 14:54:50 +02:00
return os.linesep.join(lines)