62 lines
1.7 KiB
Python
62 lines
1.7 KiB
Python
|
|
import argparse
|
|
from typing import List, Tuple
|
|
import pathlib
|
|
|
|
import os
|
|
|
|
|
|
def rtl_manifest_main():
|
|
parser = argparse.ArgumentParser(
|
|
prog='rtl-manifest',
|
|
description='Read in sources.list files and return a string of all source files',
|
|
epilog='Made by Byron Lathi')
|
|
|
|
parser.add_argument("source")
|
|
|
|
args = parser.parse_args()
|
|
files = read_sources(args.source)
|
|
|
|
for file in files:
|
|
print(file, end = " ")
|
|
|
|
pass
|
|
|
|
def read_sources(source_file: str) -> List[str]:
|
|
sources, incdirs = parse(source_file)
|
|
|
|
return sources
|
|
|
|
def read_incdirs(source_file: str) -> List[str]:
|
|
sources, incdirs = parse(source_file)
|
|
|
|
return incdirs
|
|
|
|
def parse(source_file: str) -> Tuple[List[str], List[str]]:
|
|
files = []
|
|
incdirs = []
|
|
|
|
def _recursive_parse(source_file: str):
|
|
base_dir = pathlib.Path(source_file).parent
|
|
with open(source_file, "r") as file:
|
|
for line in file:
|
|
path = os.path.expandvars(line.strip())
|
|
if path.startswith("#"):
|
|
continue
|
|
if path == "":
|
|
continue
|
|
if path.startswith("`include "):
|
|
abs_path = pathlib.Path(base_dir / path.split()[1]).absolute()
|
|
incdirs.append(str(abs_path))
|
|
continue
|
|
if (path.endswith("sources.list")):
|
|
new_path = pathlib.Path(base_dir) / path
|
|
_recursive_parse(new_path)
|
|
else:
|
|
abs_path = pathlib.Path(base_dir / path).absolute()
|
|
files.append(str(abs_path))
|
|
|
|
_recursive_parse(source_file)
|
|
|
|
return files, incdirs
|