use get_binary_names.py to maybe fix pinning & and add our python apt experiments
This commit is contained in:
parent
9b6a058c21
commit
4e75a69c46
File diff suppressed because one or more lines are too long
37
utils/get_binary_names.py
Executable file
37
utils/get_binary_names.py
Executable file
@ -0,0 +1,37 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
import sys
|
||||||
|
|
||||||
|
import apt_pkg
|
||||||
|
|
||||||
|
import apt
|
||||||
|
|
||||||
|
# load the apt cache
|
||||||
|
cache = apt.Cache()
|
||||||
|
|
||||||
|
# base package that we use for binary calculation and output file path
|
||||||
|
if len(sys.argv) < 3:
|
||||||
|
print("Usage: get_binary_names.py [Source package name] [PATH TO OUTPUT FILE]")
|
||||||
|
sys.exit(1)
|
||||||
|
pkg = base = sys.argv[1]
|
||||||
|
output_file = sys.argv[2]
|
||||||
|
|
||||||
|
# reload source records
|
||||||
|
srcrecords = apt_pkg.SourceRecords()
|
||||||
|
# load source record for argument package
|
||||||
|
srcrec = srcrecords.lookup(base)
|
||||||
|
# if source load was successful
|
||||||
|
if srcrec:
|
||||||
|
# then
|
||||||
|
# read source binary record
|
||||||
|
bins = srcrecords.binaries
|
||||||
|
# open output file from argument
|
||||||
|
f = open(output_file, "a")
|
||||||
|
# write every binary package name with a space at the end
|
||||||
|
for bin in bins:
|
||||||
|
f.write(f"{bin} ")
|
||||||
|
else:
|
||||||
|
# else
|
||||||
|
# print an error and exit with status 5
|
||||||
|
print("%s Couldn't be find in apt source package records" % base)
|
||||||
|
sys.exit(5)
|
161
utils/get_full_builddep_tree.py
Executable file
161
utils/get_full_builddep_tree.py
Executable file
@ -0,0 +1,161 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
# this is a example how to access the build dependencies of a package
|
||||||
|
|
||||||
|
import sys
|
||||||
|
|
||||||
|
import apt_pkg
|
||||||
|
|
||||||
|
import apt
|
||||||
|
|
||||||
|
# load the apt cache
|
||||||
|
cache = apt.Cache()
|
||||||
|
|
||||||
|
# base package that we use for build-depends calculation and output file path
|
||||||
|
if len(sys.argv) < 3:
|
||||||
|
print("Usage: get_full_builddep_tree.py [Package name] [PATH TO OUTPUT FILE]")
|
||||||
|
sys.exit(1)
|
||||||
|
try:
|
||||||
|
pkg = base = cache[sys.argv[1]]
|
||||||
|
except KeyError:
|
||||||
|
print("No package %s found" % sys.argv[1])
|
||||||
|
sys.exit(1)
|
||||||
|
output_file = sys.argv[2]
|
||||||
|
|
||||||
|
# build-dep source_names blacklist
|
||||||
|
build_depends_blacklist = []
|
||||||
|
# build-dep names blacklist
|
||||||
|
build_depends_pkg_names_blacklist = []
|
||||||
|
# empty array to store build dependencies
|
||||||
|
all_build_depends = []
|
||||||
|
# empty array to make sure not to duplicate
|
||||||
|
already_proccessed = []
|
||||||
|
# empty array to make sure not to waste resources converting already scanned pkg_names
|
||||||
|
already_proccessed_pkg_names = []
|
||||||
|
|
||||||
|
# get the build depends for the package itself
|
||||||
|
# get source name of argument package from cache
|
||||||
|
srcpkg_name = base.candidate.source_name
|
||||||
|
if not srcpkg_name:
|
||||||
|
print("Can't find source package for '%s'" % pkg.name)
|
||||||
|
# reload source records
|
||||||
|
srcrecords = apt_pkg.SourceRecords()
|
||||||
|
# load source record for argument package
|
||||||
|
srcrec = srcrecords.lookup(srcpkg_name)
|
||||||
|
if srcrec:
|
||||||
|
# get build_depends as a dict
|
||||||
|
bd_dict = srcrecords.build_depends
|
||||||
|
try:
|
||||||
|
# load key "Build-Depends" from bd_dict
|
||||||
|
bd = bd_dict["Build-Depends"]
|
||||||
|
for b in bd:
|
||||||
|
for package in b:
|
||||||
|
# parse every key into the needed 3 values
|
||||||
|
name, version, comparator = package
|
||||||
|
try:
|
||||||
|
# if build-dep name isn't already processed or blacklisted
|
||||||
|
if not name in already_proccessed_pkg_names and not name in build_depends_pkg_names_blacklist:
|
||||||
|
# load build-dep from cache
|
||||||
|
apt_package = cache[name]
|
||||||
|
# get build-dep source name
|
||||||
|
pkg_source_name = apt_package.candidate.source_name
|
||||||
|
# if source package isn't blacklisted or already processed
|
||||||
|
if not pkg_source_name in already_proccessed and not pkg_source_name in build_depends_blacklist:
|
||||||
|
# then
|
||||||
|
# add the source package to the build_depends array
|
||||||
|
all_build_depends.append(pkg_source_name)
|
||||||
|
# and declare it already proccessed
|
||||||
|
already_proccessed.append(pkg_source_name)
|
||||||
|
except:
|
||||||
|
continue
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
try:
|
||||||
|
# load key "Build-Depends-Indep" from bd_dict
|
||||||
|
bd_indep = bd_dict["Build-Depends-Indep"]
|
||||||
|
for b in bd_indep:
|
||||||
|
# parse every key into the needed 3 values
|
||||||
|
name, version, comparator = package
|
||||||
|
try:
|
||||||
|
# if build-dep name isn't already processed or blacklisted
|
||||||
|
if not name in already_proccessed_pkg_names and not name in build_depends_pkg_names_blacklist:
|
||||||
|
# load build-dep from cache
|
||||||
|
apt_package = cache[name]
|
||||||
|
# get build-dep source name
|
||||||
|
pkg_source_name = apt_package.candidate.source_name
|
||||||
|
# if source package isn't blacklisted or already processed
|
||||||
|
if not pkg_source_name in already_proccessed and not pkg_source_name in build_depends_blacklist:
|
||||||
|
# then
|
||||||
|
# add the source package to the build_depends array
|
||||||
|
all_build_depends.append(pkg_source_name)
|
||||||
|
# and declare it already proccessed
|
||||||
|
already_proccessed.append(pkg_source_name)
|
||||||
|
except:
|
||||||
|
continue
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
for bd in all_build_depends:
|
||||||
|
# parent build-dep position in array
|
||||||
|
bd_position = all_build_depends.index(bd)
|
||||||
|
# reload source records
|
||||||
|
srcrecords = apt_pkg.SourceRecords()
|
||||||
|
# load source record for argument package
|
||||||
|
srcrec = srcrecords.lookup(bd)
|
||||||
|
if srcrec:
|
||||||
|
# get build_depends as a dict
|
||||||
|
bd_dict = srcrecords.build_depends
|
||||||
|
try:
|
||||||
|
# load key "Build-Depends" from bd_dict
|
||||||
|
bd = bd_dict["Build-Depends"]
|
||||||
|
for b in bd:
|
||||||
|
for package in b:
|
||||||
|
# parse every key into the needed 3 values
|
||||||
|
name, version, comparator = package
|
||||||
|
try:
|
||||||
|
# if build-dep name isn't already processed or blacklisted
|
||||||
|
if not name in already_proccessed_pkg_names and not name in build_depends_pkg_names_blacklist:
|
||||||
|
# load build-dep from cache
|
||||||
|
apt_package = cache[name]
|
||||||
|
# get build-dep source name
|
||||||
|
pkg_source_name = apt_package.candidate.source_name
|
||||||
|
# if source package isn't blacklisted or already processed
|
||||||
|
if not pkg_source_name in already_proccessed and not pkg_source_name in build_depends_blacklist:
|
||||||
|
# then
|
||||||
|
# add the source package to the build_depends array after it's parent position
|
||||||
|
all_build_depends.insert(bd_position, pkg_source_name)
|
||||||
|
# and declare it already proccessed
|
||||||
|
already_proccessed.append(pkg_source_name)
|
||||||
|
except:
|
||||||
|
continue
|
||||||
|
except:
|
||||||
|
continue
|
||||||
|
try:
|
||||||
|
# load key "Build-Depends-Indep" from bd_dict
|
||||||
|
bd_indep = bd_dict["Build-Depends-Indep"]
|
||||||
|
for b in bd_indep:
|
||||||
|
for package in b:
|
||||||
|
# parse every key into the needed 3 values
|
||||||
|
name, version, comparator = package
|
||||||
|
try:
|
||||||
|
# if build-dep name isn't already processed or blacklisted
|
||||||
|
if not name in already_proccessed_pkg_names and not name in build_depends_pkg_names_blacklist:
|
||||||
|
# load build-dep from cache
|
||||||
|
apt_package = cache[name]
|
||||||
|
# get build-dep source name
|
||||||
|
pkg_source_name = apt_package.candidate.source_name
|
||||||
|
# if source package isn't blacklisted or already processed
|
||||||
|
if not pkg_source_name in already_proccessed and not pkg_source_name in build_depends_blacklist:
|
||||||
|
# then
|
||||||
|
# add the source package to the build_depends array after it's parent position
|
||||||
|
all_build_depends.insert(bd_position, pkg_source_name)
|
||||||
|
# and declare it already proccessed
|
||||||
|
already_proccessed.append(pkg_source_name)
|
||||||
|
except:
|
||||||
|
continue
|
||||||
|
except:
|
||||||
|
continue
|
||||||
|
|
||||||
|
# write result to output file
|
||||||
|
f = open(output_file, "a")
|
||||||
|
for line in all_build_depends:
|
||||||
|
f.write(f"{line}\n")
|
Loading…
Reference in New Issue
Block a user