Page MenuHomeDevCentral
Paste P364

roles/freebsd-repo/ports/files/parse-portshaker-merged-ports.py
ActivePublic

Authored by dereckson on Oct 16 2024, 18:58.
#!/usr/bin/env python3
# -------------------------------------------------------------
# portshaker merged ports -> pkglist
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Project: Nasqueron
# Description: Read portshaker merged ports file
# Output a pkglist for Poudriere
# License: BSD-2-Clause
# -------------------------------------------------------------
import os
import sys
# -------------------------------------------------------------
# Poudriere helper methods
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
POUDRIERE_CONFIG_ROOT="/usr/local/etc/poudriere.d"
def get_ports_tree_config_dir(name):
return POUDRIERE_CONFIG_ROOT + "/ports/" + name
def is_ports_tree_exists(name):
return os.path.exists(get_ports_tree_config_dir(name))
def get_ports_tree_path(name):
mnt_path = get_ports_tree_config_dir(name) + "/mnt"
with open(mnt_path) as fd:
return fd.readline().strip()
# -------------------------------------------------------------
# Portshaker helper methods
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def parse_port(line):
return line.strip().split(":")[1]
def get_portshaker_merged_ports(name):
try:
ports_path = get_ports_tree_path(name) + "/.portshaker-merged-ports"
except FileNotFoundError:
return []
return [parse_port(line) for line in open(ports_path)]
# -------------------------------------------------------------
# Application entry point
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def run(tree_name):
ports = get_portshaker_merged_ports(tree_name)
for port in ports:
print(port)
if __name__ == "__main__":
argc = len(sys.argv)
if argc < 2:
print(f"Usage: {sys.argv[0]} <ports tree name>", file=sys.stderr)
sys.exit(1)
run(sys.argv[1])

Event Timeline

Initially devised for D3520, but as long as we don't move ports tree all the time, this awk command is equivalent to .split(":")[1] transformation in Python:

WindRiver
$ awk -F : '{print $2}' /usr/local/poudriere/ports/nasqueron/.portshaker-merged-ports
devel/notifications-cli-client
games/roll
net-mgmt/phpfpm_exporter_lusitaniae
security/vault-medusa
sysutils/alkane
sysutils/py-salt-tower