Path: blob/main/Tools/scripts/gnomedepends.py
16123 views
#!/usr/bin/env python1#2# gnomedepends3# Analyse pkg/PLIST and give an advice as to which GNOME4# ports should be listes in {RUN,LIB}_DEPENDS for this port5#6# ----------------------------------------------------------------------------7# "THE BEER-WARE LICENSE" (Revision 42, (c) Poul-Henning Kamp):8# Maxim Sobolev <[email protected]> wrote this file. As long as you retain9# this notice you can do whatever you want with this stuff. If we meet some10# day, and you think this stuff is worth it, you can buy me a beer in return.11#12# Maxim Sobolev13# ----------------------------------------------------------------------------14#15# MAINTAINER= [email protected]16#17# TODO:18# - analyse actual {RUN,LIB}_DEPENDS and give an advice about what should be19# added;20# - analyse results and remove redundant dependencies (for example if gnomecore21# has gnomecontrolcenter listed as dependency, and it is found that the port22# requires both gnomecontrolcenter and gnomecore do not list23# gnomecontrolcenter then);24# - parse ports/INDEX directly.25#2627import os, os.path, sys, string, re2829def getcmdout(cmdline):30results = []31pipe = os.popen(cmdline)32buffer = pipe.readlines()33for result in buffer:34result = string.strip(result)35if len(result) > 0:36results.append(result)37pipe.close()38return results3940def readfile(filename):41file = open(filename)42result = file.readlines()43file.close()44return result4546def filter(lines, regobj):47results = []48for line in lines:49match = regobj.match(line)50if match != None:51result = string.strip(match.group(1))52try:53tmp = results.index(result)54except ValueError:55results.append(result)56return results5758gnomeports = getcmdout('cd /usr/ports && make search key=gnome | grep ^Path:')59newgnomeports = []60for i in gnomeports:61newgnomeports.append(string.split(i)[1])62gnomeports = newgnomeports63newgnomeports = []6465regobj = re.compile('^@dirrm (?P<dirname>\S+).*$')66for portdir in gnomeports:67try:68lines = readfile(os.path.join(portdir, 'pkg-plist'))69lines = list(filter(lines, regobj))70if len(lines) > 0:71newgnomeports.append([portdir, lines])72except IOError:73pass74gnomeports = newgnomeports75newgnomeports = []7677try:78currplist = readfile('pkg-plist')79except IOError as errmsg:80print(errmsg)81sys.exit(1)8283regobj = re.compile('^(?!@)(?P<dirname>\S+)/.*')84currdirs = list(filter(currplist, regobj))85regobj = re.compile('^@dirrm (?P<dirname>\S+).*$')86currdirs.extend(list(filter(currplist, regobj)))87currportdir = os.getcwd()8889newcurrdirs = []90for dir in currdirs:91incremental = ''92for component in string.split(dir, '/'):93if incremental != '':94incremental = incremental + '/'95incremental = incremental + component96try:97tmp = newcurrdirs.index(incremental)98except ValueError:99newcurrdirs.append(incremental)100currdirs = newcurrdirs101102depends = []103for gnomeport in gnomeports:104if (currportdir == gnomeport[0]):105continue106matches = []107for gnomedir in gnomeport[1]:108for dir in currdirs:109if (gnomedir == dir):110matches.append(dir)111if len(matches) > 0:112depends.append([gnomeport[0], matches])113114if len(depends) == 0:115sys.stdout.writelines(['No dependencies found (maybe it is not a GNOME port).\n'])116sys.exit(0)117118sys.stdout.writelines(['According to the contents of pkg-plist the port depends on the following GNOME\n', 'port(s):\n\n'])119for depend in depends:120sys.stdout.writelines([depend[0], ', for directories:\n'])121for dir in depend[1]:122sys.stdout.writelines(['\t', dir, '\n'])123sys.stdout.writelines(['\n'])124125126127128