pika-debian-bleedingedge/gen-i386-whitelist.py

79 lines
2.1 KiB
Python
Raw Permalink Normal View History

2024-08-04 16:41:46 +02:00
#! /bin/python3
import os, errno
import json
import subprocess
import apt
2024-08-04 19:15:06 +02:00
import numpy as np
import threading
2024-08-04 16:41:46 +02:00
def silentremove(filename):
try:
os.remove(filename)
except OSError as e: # this would be "except OSError, e:" before Python 2.6
if e.errno != errno.ENOENT: # errno.ENOENT = no such file or directory
raise # re-raise exception if a different error occurred
2024-08-04 19:15:06 +02:00
def pharse_build_tree(pkg_arr, current_path, pkgname_lines):
for pkgname in pkg_arr:
print("Parsing dep tree for: " + pkgname)
result = subprocess.run([current_path + '/get_depend_tree.sh', pkgname], stdout=subprocess.PIPE)
stdout = result.stdout.decode('utf-8')
for line in stdout.splitlines():
if line != "":
pkgname_lines.append(line)
2024-08-04 16:41:46 +02:00
current_path = os.path.dirname(os.path.realpath(__file__))
2024-08-05 15:47:33 +02:00
global whitelist_arr
2024-08-04 19:15:06 +02:00
whitelist_arr = np.array([])
thread_arr = []
2024-08-04 16:41:46 +02:00
pkgname_lines = []
srcname_lines = []
srcnames_clean = []
file = open(current_path + "/i386_whitelist_bins", "r")
2024-08-04 19:15:06 +02:00
2024-08-04 16:41:46 +02:00
for line in file.readlines():
pkgname = line.strip()
if pkgname != "" and not pkgname.endswith("-udeb"):
pkgname_lines.append(pkgname)
2024-08-05 15:47:33 +02:00
whitelist_arr = np.append(whitelist_arr, [pkgname])
2024-08-04 16:41:46 +02:00
file.close()
2024-08-05 15:47:33 +02:00
newarr = np.array_split(whitelist_arr, 20)
2024-08-04 19:15:06 +02:00
for array in newarr:
t0 = threading.Thread(target=pharse_build_tree, args=(array, current_path, pkgname_lines,))
thread_arr.append(t0)
for thread_proc in thread_arr:
thread_proc.start()
for thread_proc in thread_arr:
2024-08-05 15:47:33 +02:00
thread_proc.join()
2024-08-04 19:15:06 +02:00
2024-08-04 16:41:46 +02:00
c = apt.Cache()
for pkgname in pkgname_lines:
2024-08-04 18:45:31 +02:00
try:
src_name = c[pkgname].candidate.source_name
if src_name:
srcname_lines.append(src_name)
except:
pass
2024-08-04 16:41:46 +02:00
for i in srcname_lines:
2024-08-04 19:15:06 +02:00
if i not in srcnames_clean and i + "-dmo" not in srcnames_clean:
2024-08-04 16:41:46 +02:00
srcnames_clean.append(i)
src_data = {
'i386_whitelist': [source_name for source_name in srcnames_clean],
}
silentremove("i386_src_whitelist.json")
with open("i386_src_whitelist.json", "w") as twitterDataFile:
twitterDataFile.write(
json.dumps(src_data, indent=4)
)