Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-ports-gnome
Path: blob/main/Tools/scripts/gnomedepends.py
16123 views
1
#!/usr/bin/env python
2
#
3
# gnomedepends
4
# Analyse pkg/PLIST and give an advice as to which GNOME
5
# ports should be listes in {RUN,LIB}_DEPENDS for this port
6
#
7
# ----------------------------------------------------------------------------
8
# "THE BEER-WARE LICENSE" (Revision 42, (c) Poul-Henning Kamp):
9
# Maxim Sobolev <[email protected]> wrote this file. As long as you retain
10
# this notice you can do whatever you want with this stuff. If we meet some
11
# day, and you think this stuff is worth it, you can buy me a beer in return.
12
#
13
# Maxim Sobolev
14
# ----------------------------------------------------------------------------
15
#
16
# MAINTAINER= [email protected]
17
#
18
# TODO:
19
# - analyse actual {RUN,LIB}_DEPENDS and give an advice about what should be
20
# added;
21
# - analyse results and remove redundant dependencies (for example if gnomecore
22
# has gnomecontrolcenter listed as dependency, and it is found that the port
23
# requires both gnomecontrolcenter and gnomecore do not list
24
# gnomecontrolcenter then);
25
# - parse ports/INDEX directly.
26
#
27
28
import os, os.path, sys, string, re
29
30
def getcmdout(cmdline):
31
results = []
32
pipe = os.popen(cmdline)
33
buffer = pipe.readlines()
34
for result in buffer:
35
result = string.strip(result)
36
if len(result) > 0:
37
results.append(result)
38
pipe.close()
39
return results
40
41
def readfile(filename):
42
file = open(filename)
43
result = file.readlines()
44
file.close()
45
return result
46
47
def filter(lines, regobj):
48
results = []
49
for line in lines:
50
match = regobj.match(line)
51
if match != None:
52
result = string.strip(match.group(1))
53
try:
54
tmp = results.index(result)
55
except ValueError:
56
results.append(result)
57
return results
58
59
gnomeports = getcmdout('cd /usr/ports && make search key=gnome | grep ^Path:')
60
newgnomeports = []
61
for i in gnomeports:
62
newgnomeports.append(string.split(i)[1])
63
gnomeports = newgnomeports
64
newgnomeports = []
65
66
regobj = re.compile('^@dirrm (?P<dirname>\S+).*$')
67
for portdir in gnomeports:
68
try:
69
lines = readfile(os.path.join(portdir, 'pkg-plist'))
70
lines = list(filter(lines, regobj))
71
if len(lines) > 0:
72
newgnomeports.append([portdir, lines])
73
except IOError:
74
pass
75
gnomeports = newgnomeports
76
newgnomeports = []
77
78
try:
79
currplist = readfile('pkg-plist')
80
except IOError as errmsg:
81
print(errmsg)
82
sys.exit(1)
83
84
regobj = re.compile('^(?!@)(?P<dirname>\S+)/.*')
85
currdirs = list(filter(currplist, regobj))
86
regobj = re.compile('^@dirrm (?P<dirname>\S+).*$')
87
currdirs.extend(list(filter(currplist, regobj)))
88
currportdir = os.getcwd()
89
90
newcurrdirs = []
91
for dir in currdirs:
92
incremental = ''
93
for component in string.split(dir, '/'):
94
if incremental != '':
95
incremental = incremental + '/'
96
incremental = incremental + component
97
try:
98
tmp = newcurrdirs.index(incremental)
99
except ValueError:
100
newcurrdirs.append(incremental)
101
currdirs = newcurrdirs
102
103
depends = []
104
for gnomeport in gnomeports:
105
if (currportdir == gnomeport[0]):
106
continue
107
matches = []
108
for gnomedir in gnomeport[1]:
109
for dir in currdirs:
110
if (gnomedir == dir):
111
matches.append(dir)
112
if len(matches) > 0:
113
depends.append([gnomeport[0], matches])
114
115
if len(depends) == 0:
116
sys.stdout.writelines(['No dependencies found (maybe it is not a GNOME port).\n'])
117
sys.exit(0)
118
119
sys.stdout.writelines(['According to the contents of pkg-plist the port depends on the following GNOME\n', 'port(s):\n\n'])
120
for depend in depends:
121
sys.stdout.writelines([depend[0], ', for directories:\n'])
122
for dir in depend[1]:
123
sys.stdout.writelines(['\t', dir, '\n'])
124
sys.stdout.writelines(['\n'])
125
126
127
128