mrmp/local.py

44 lines
1.3 KiB
Python
Raw Normal View History

2021-10-09 10:26:53 +00:00
import arguments
import datetime
import os
2021-10-10 14:50:15 +00:00
import distribution
2021-10-10 01:00:43 +00:00
import msys
2021-10-10 12:48:12 +00:00
import repository
2021-10-09 13:58:44 +00:00
2021-10-09 10:26:53 +00:00
2021-10-10 12:48:12 +00:00
class Local(repository.Repository):
2021-10-09 10:26:53 +00:00
def __init__(self, args):
2021-10-10 13:01:24 +00:00
super().__init__(args[arguments.DIRECTORY])
2021-10-09 10:26:53 +00:00
self.temporary = args[arguments.TEMPORARY]
2021-10-09 13:58:44 +00:00
self.load()
def load(self):
2021-10-10 14:50:15 +00:00
distro = os.path.join(
self.location, distribution.DISTRIBUTION)
2021-10-09 13:58:44 +00:00
d = {}
2021-10-10 14:50:15 +00:00
_, architectures, _ = next(os.walk(distro))
2021-10-09 13:58:44 +00:00
for architecture in [a for a in architectures
2021-10-10 01:55:22 +00:00
if a in msys.ARCHITECTURES]:
2021-10-10 14:50:15 +00:00
directory = os.path.join(distro, architecture)
2021-10-09 13:58:44 +00:00
_, _, files = next(os.walk(directory))
archives = sorted([file for file in files
2021-10-10 01:00:43 +00:00
if file.endswith(msys.ARCHIVE)])
2021-10-09 13:58:44 +00:00
archive = archives[-1]
d[architecture] = archive
self.archives = d
2021-10-09 10:26:53 +00:00
2021-10-09 17:46:11 +00:00
def get_temporary(self):
2021-10-09 16:19:58 +00:00
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 = [
2021-10-10 13:01:24 +00:00
super().__str__(),
2021-10-09 17:46:11 +00:00
'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)