/[gentoo-src]/portage/pym/vertest
Gentoo

Contents of /portage/pym/vertest

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (show annotations) (download)
Mon Jan 28 20:29:30 2002 UTC (12 years, 2 months ago) by gbevin
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +0 -0 lines
FILE REMOVED
moved version tests to seperate dir

1 #!/usr/bin/env spython
2
3 import portage
4 import sys
5 import sys
6 import commands
7 import popen2
8
9
10 # eliminate duplicates
11 def uniq(list):
12 list.sort()
13 old = ''
14 tmp = []
15 for x in list:
16 if x != old:
17 tmp += [x]
18 old = x
19 return tmp
20
21
22 cmd = "/bin/ls /usr/portage/*/*/*.ebuild | cut -d/ -f 6- | sed 's:.ebuild$::'"
23 cmd += r"|sed -e 's:-r[0-9]$::' -e 's:\(.*\)-\([^-]*\):\1 \2:' | sort"
24
25 # get list of all used version pairs
26 def get_versions():
27
28 # this will get a list of "pkg_name version"
29 res = commands.getoutput(cmd).split('\n')
30
31 # group by package name
32 d = {}
33 for p in res:
34 if not p.strip():
35 continue
36 n,v = p.strip().split()
37 d.setdefault(n, []).append(v)
38
39 # for every package with multiple versions available
40 # build all possible unordered pairs of versions
41 res = []
42 for n in d.keys():
43 if len(d[n]) > 1:
44 for i in range(len(d[n])-1):
45 for j in range(i, len(d[n])):
46 if d[n][i] != d[n][j]:
47 res += [[d[n][i], d[n][j]]]
48 #res += ["%s %s %s" % (n, d[n][i], d[n][j])]
49
50 return uniq(res)
51
52 def sign(x):
53 if x > 0:
54 return 1
55 elif x < 0:
56 return -1
57 return 0
58
59
60
61 def readlist(filename):
62 file = open(filename)
63 res = file.readlines()
64 file.close()
65 return [ x.split() for x in res if x]
66
67 def writelist(filename, list):
68 file = open(filename, "w")
69 list = [" ".join(x) for x in list]
70 file.write("\n".join(list) + '\n')
71 file.close()
72
73
74
75
76 # runs comparing func on every pair from the list
77 # returns list of [x,y,sign(foo(x,y))]
78 def compare(list, func):
79 res = []
80 for test in list:
81 r = func(test[0], test[1])
82 if r != - func(test[1], test[0]):
83 print 'ERROR not simmetric:', test
84 sys.exit(1)
85 res += [[test[0], test[1], str(sign(r))]]
86
87 return res
88
89
90
91
92
93 if len(sys.argv) != 2:
94 print """
95 Usage: vertest create|update|verify
96 create create vlist
97 update update vlist
98 verify compare portage results to vlist
99 compare get a list of pairs from stdin and produce
100 results in format of create
101 """
102 sys.exit(1)
103
104 p = sys.argv[1]
105
106 if p == "create":
107 tmp = compare(get_versions(), portage.vercmp)
108 writelist("vlist", tmp)
109
110 elif p == "update":
111 list = readlist("vlist")
112 list += compare(get_versions(), portage.vercmp)
113 writelist("vlist.new", uniq(list))
114
115 elif p == "verify":
116 list = readlist("vlist")
117 test = [[x,y] for (x,y,z) in list]
118 list2 = compare(test, portage.vercmp)
119 for i in range(len(list)):
120 if list[i][2] != list2[i][2]:
121 print list[i][0], list[i][1], list[i][2], list2[i][2]
122 elif p == "compare":
123 list = sys.stdin.readlines()
124 list = [x.strip().split() for x in list if x.strip()]
125 list = compare(list, portage.vercmp)
126 list = [" ".join(x) for x in list]
127 print "\n".join(list)
128
129
130
131
132

  ViewVC Help
Powered by ViewVC 1.1.20