Merge pull request #225 from doraskayo/source-manifest

Add a source manifest
This commit is contained in:
Andrius Štikonas 2023-01-13 21:39:51 +00:00 committed by GitHub
commit 13f8dabd89
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 89 additions and 31 deletions

View File

@ -3,7 +3,7 @@
This file contains a few functions to be shared by all Sys* classes
"""
# SPDX-FileCopyrightText: 2022 Dor Askayo <dor.askayo@gmail.com>
# SPDX-FileCopyrightText: 2022-2023 Dor Askayo <dor.askayo@gmail.com>
# SPDX-FileCopyrightText: 2021-22 fosslinux <fosslinux@aussies.space>
# SPDX-FileCopyrightText: 2021 Andrius Štikonas <andrius@stikonas.eu>
# SPDX-License-Identifier: GPL-3.0-or-later
@ -71,18 +71,15 @@ actual: {readable_hash}\n\
When in doubt, try deleting the file in question -- it will be downloaded again when running \
this script the next time")
def download_file(self, url, file_name=None):
def download_file(self, url, directory, file_name):
"""
Download a single source archive.
"""
# Automatically determine file name based on URL.
if file_name is None:
file_name = os.path.basename(url)
abs_file_name = os.path.join(self.cache_dir, file_name)
abs_file_name = os.path.join(directory, file_name)
# Create a cache directory for downloaded sources
if not os.path.isdir(self.cache_dir):
os.mkdir(self.cache_dir)
# Create a directory for downloaded file
if not os.path.isdir(directory):
os.mkdir(directory)
# Actually download the file
headers = {
@ -99,22 +96,41 @@ this script the next time")
raise Exception("Download failed.")
return abs_file_name
def get_packages(self):
def get_packages(self, source_manifest):
"""Prepare remaining sources"""
for line in source_manifest.split("\n"):
line = line.strip().split(" ")
path = self.download_file(line[2], line[1], line[3])
self.check_file(path, line[0])
@classmethod
def get_source_manifest(cls):
"""
Generage a source manifest for the system.
"""
manifest_lines = []
directory = os.path.relpath(cls.cache_dir, cls.git_dir)
# Find all source files
for file in os.listdir(self.sys_dir):
if os.path.isdir(os.path.join(self.sys_dir, file)):
sourcef = os.path.join(self.sys_dir, file, "sources")
for file in os.listdir(cls.sys_dir):
if os.path.isdir(os.path.join(cls.sys_dir, file)):
sourcef = os.path.join(cls.sys_dir, file, "sources")
if os.path.exists(sourcef):
# Download sources in the source file
# Read sources from the source file
with open(sourcef, "r", encoding="utf_8") as sources:
for line in sources.readlines():
line = line.strip().split(" ")
if len(line) > 2:
path = self.download_file(line[0], line[2])
file_name = line[2]
else:
path = self.download_file(line[0])
self.check_file(path, line[1])
# Automatically determine file name based on URL.
file_name = os.path.basename(line[0])
manifest_lines.append(f"{line[1]} {directory} {line[0]} {file_name}")
return "\n".join(manifest_lines)
def make_initramfs(self):
"""Package binary bootstrap seeds and sources into initramfs."""

34
source-manifest.py Executable file
View File

@ -0,0 +1,34 @@
#!/usr/bin/env python3
"""
A helper application used to get a list of source files required
for the bootstrapping process.
"""
# SPDX-License-Identifier: GPL-3.0-or-later
# SPDX-FileCopyrightText: 2023 Dor Askayo <dor.askayo@gmail.com>
import argparse
from sysa import SysA
from sysc import SysC
def main():
parser = argparse.ArgumentParser()
parser.add_argument("-s", "--system",
help="Generate source manifest for the specified systems",
choices=["sysa", "sysc"],
nargs="+",
action="extend",
required=True)
args = parser.parse_args()
if "sysa" in args.system:
print(SysA.get_source_manifest())
if "sysc" in args.system:
print(SysC.get_source_manifest())
if __name__ == "__main__":
main()

17
sysa.py
View File

@ -1,7 +1,7 @@
#!/usr/bin/env python3
"""System A"""
# SPDX-License-Identifier: GPL-3.0-or-later
# SPDX-FileCopyrightText: 2022 Dor Askayo <dor.askayo@gmail.com>
# SPDX-FileCopyrightText: 2022-2023 Dor Askayo <dor.askayo@gmail.com>
# SPDX-FileCopyrightText: 2021 Andrius Štikonas <andrius@stikonas.eu>
# SPDX-FileCopyrightText: 2021 Melg Eight <public.melg8@gmail.com>
# SPDX-FileCopyrightText: 2021-22 fosslinux <fosslinux@aussies.space>
@ -14,26 +14,30 @@ import tarfile
from lib.sysgeneral import SysGeneral, stage0_arch_map
# pylint: disable=consider-using-with
# pylint: disable=too-many-instance-attributes
class SysA(SysGeneral):
"""
Class responsible for preparing sources for System A.
"""
# pylint: disable=too-many-instance-attributes,too-many-arguments
git_dir = os.path.dirname(os.path.join(__file__))
sys_dir = os.path.join(git_dir, 'sysa')
cache_dir = os.path.join(sys_dir, 'distfiles')
# pylint: disable=too-many-arguments
def __init__(self, arch, preserve_tmp, external_sources,
early_preseed, tmpdir, sysb_dir, sysc_dir):
self.git_dir = os.path.dirname(os.path.join(__file__))
self.arch = arch
self.preserve_tmp = preserve_tmp
self.early_preseed = early_preseed
self.sys_dir = os.path.join(self.git_dir, 'sysa')
if tmpdir is None:
self.tmp_dir = os.path.join(self.git_dir, 'tmp')
else:
self.tmp_dir = os.path.join(tmpdir, 'sysa')
self.sysa_dir = os.path.join(self.tmp_dir, 'sysa')
self.base_dir = self.sysa_dir
self.cache_dir = os.path.join(self.sys_dir, 'distfiles')
self.sysb_dir = sysb_dir
self.sysc_dir = sysc_dir
self.external_sources = external_sources
@ -74,7 +78,8 @@ class SysA(SysGeneral):
def sysa(self):
"""Copy in sysa files for sysa."""
self.get_packages()
source_manifest = self.get_source_manifest()
self.get_packages(source_manifest)
shutil.copytree(self.sys_dir, os.path.join(self.tmp_dir, 'sysa'),
ignore=shutil.ignore_patterns('tmp'))

View File

@ -12,9 +12,10 @@ class SysB(SysGeneral):
"""
Class responsible for preparing sources for System B.
"""
git_dir = os.path.dirname(os.path.join(__file__))
sys_dir = os.path.join(git_dir, 'sysb')
def __init__(self, arch, preserve_tmp):
self.git_dir = os.path.dirname(os.path.join(__file__))
self.arch = arch
self.preserve_tmp = preserve_tmp
self.sys_dir = os.path.join(self.git_dir, 'sysb')

12
sysc.py
View File

@ -1,7 +1,7 @@
#!/usr/bin/env python3
"""System C"""
# SPDX-License-Identifier: GPL-3.0-or-later
# SPDX-FileCopyrightText: 2022 Dor Askayo <dor.askayo@gmail.com>
# SPDX-FileCopyrightText: 2022-2023 Dor Askayo <dor.askayo@gmail.com>
# SPDX-FileCopyrightText: 2021-22 fosslinux <fosslinux@aussies.space>
# SPDX-FileCopyrightText: 2021 Andrius Štikonas <andrius@stikonas.eu>
@ -18,16 +18,16 @@ class SysC(SysGeneral):
Class responsible for preparing sources for System C.
"""
git_dir = os.path.dirname(os.path.join(__file__))
sys_dir = os.path.join(git_dir, 'sysc')
cache_dir = os.path.join(sys_dir, 'distfiles')
dev_name = None
def __init__(self, arch, preserve_tmp, tmpdir, external_sources):
self.git_dir = os.path.dirname(os.path.join(__file__))
self.arch = arch
self.preserve_tmp = preserve_tmp
self.external_sources = external_sources
self.sys_dir = os.path.join(self.git_dir, 'sysc')
self.cache_dir = os.path.join(self.sys_dir, 'distfiles')
if tmpdir is None:
self.tmp_dir = os.path.join(self.sys_dir, 'tmp')
else:
@ -70,7 +70,9 @@ class SysC(SysGeneral):
rootfs_dir = self.tmp_dir
if self.external_sources:
self.get_packages()
source_manifest = self.get_source_manifest()
self.get_packages(source_manifest)
copytree(self.cache_dir, os.path.join(rootfs_dir, "distfiles"))
# Unmount tmp/mnt if it was mounted