1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
import web
import helpers
from config import render, db
class Package(object):
def GET(self, *args):
try:
top = int(web.input(top="5").top)
except ValueError:
top = 5
l = len(args)
if l == 0:
return self.__GET(top)
elif l == 1:
return self.__GET_C(top, args[0])
elif l == 2:
cpv = helpers.pkgsplit(args[0] + '/' + args[1])
if cpv['ver'] == '':
return self.__GET_CP(top, cpv['cat'], cpv['pkg'])
else:
return self.__GET_CPV(cpv['cat'], cpv['pkg'], cpv['ver'])
else:
return config.internalerror()
def __GET(self, top):
p_query = db.query('SELECT COUNT(DISTINCT UUID) AS HOST_COUNT, \
COUNT(DISTINCT CAT) AS C_COUNT, \
COUNT(DISTINCT CAT, PKG) AS CP_COUNT, \
COUNT(DISTINCT CAT, PKG, VER) AS CPV_COUNT\
FROM INSTALLED_PACKAGES RIGHT OUTER JOIN PACKAGES\
ON INSTALLED_PACKAGES.PKEY = PACKAGES.PKEY')
p_tuple = p_query[0]
p_data = {
'HOST_COUNT':p_tuple['HOST_COUNT'],
'C_COUNT':p_tuple['C_COUNT'],
'CP_COUNT':p_tuple['CP_COUNT'],
'CPV_COUNT':p_tuple['CPV_COUNT'],
'TOP_C':self.__top(top)
}
return render.package(p_data)
def __GET_C(self, top, cat):
p_query = db.query('SELECT COUNT(DISTINCT UUID) AS HOST_COUNT, \
COUNT(DISTINCT CAT, PKG) AS CP_COUNT, \
COUNT(DISTINCT CAT, PKG, VER) AS CPV_COUNT\
FROM INSTALLED_PACKAGES RIGHT OUTER JOIN PACKAGES\
ON INSTALLED_PACKAGES.PKEY = PACKAGES.PKEY\
WHERE CAT=$cat', vars={'cat':cat})
p_tuple = p_query[0]
p_data = {
'HOST_COUNT':p_tuple['HOST_COUNT'],
'CP_COUNT':p_tuple['CP_COUNT'],
'CPV_COUNT':p_tuple['CPV_COUNT'],
'TOP_CP':self.__top(top, cat)
}
return render.package_c(cat, p_data)
def __GET_CP(self, top, cat, pkg):
p_query = db.query('SELECT COUNT(DISTINCT UUID) AS HOST_COUNT, \
COUNT(DISTINCT CAT, PKG, VER) AS CPV_COUNT\
FROM INSTALLED_PACKAGES RIGHT OUTER JOIN PACKAGES\
ON INSTALLED_PACKAGES.PKEY = PACKAGES.PKEY\
WHERE CAT=$cat AND PKG=$pkg', vars={'cat':cat, 'pkg':pkg})
p_tuple = p_query[0]
p_data = {
'HOST_COUNT':p_tuple['HOST_COUNT'],
'CPV_COUNT':p_tuple['CPV_COUNT'],
'TOP_CPV':self.__top(top, cat, pkg)
}
return render.package_cp(cat, pkg, p_data)
def __GET_CPV(self, cat, pkg, ver):
p_query = db.query('SELECT COUNT(DISTINCT UUID) AS HOST_COUNT\
FROM INSTALLED_PACKAGES RIGHT OUTER JOIN PACKAGES\
ON INSTALLED_PACKAGES.PKEY = PACKAGES.PKEY\
WHERE CAT=$cat AND PKG=$pkg AND VER=$ver', vars={'cat':cat, 'pkg':pkg, 'ver':ver})
p_tuple = p_query[0]
p_data = {
'HOST_COUNT':p_tuple['HOST_COUNT'],
}
return render.package_cpv(cat, pkg, ver, p_data)
def __top(self, count, *args):
t_list = list()
if len(args) == 0:
tc_query = db.query('SELECT CAT, COUNT(DISTINCT UUID) AS HOST_COUNT\
FROM INSTALLED_PACKAGES RIGHT OUTER JOIN PACKAGES\
ON INSTALLED_PACKAGES.PKEY = PACKAGES.PKEY\
GROUP BY CAT\
ORDER BY HOST_COUNT DESC, CAT')
for idx in range(0, count):
try:
tc_tuple = tc_query[idx]
t_list.append({
'CAT':tc_tuple['CAT'],
'HOST_COUNT':tc_tuple['HOST_COUNT']
})
except IndexError:
break
elif len(args) == 1:
tcp_query = db.query('SELECT CAT, PKG, COUNT(DISTINCT UUID) AS HOST_COUNT\
FROM INSTALLED_PACKAGES RIGHT OUTER JOIN PACKAGES\
ON INSTALLED_PACKAGES.PKEY = PACKAGES.PKEY\
WHERE CAT=$cat\
GROUP BY CAT, PKG\
ORDER BY HOST_COUNT DESC, CAT, PKG',
vars={'cat':args[0]})
for idx in range(0, count):
try:
tcp_tuple = tcp_query[idx]
t_list.append({
'CAT':tcp_tuple['CAT'],
'PKG':tcp_tuple['PKG'],
'HOST_COUNT':tcp_tuple['HOST_COUNT']
})
except IndexError:
break
elif len(args) == 2:
tcpv_query = db.query('SELECT CAT, PKG, VER, COUNT(DISTINCT UUID) AS HOST_COUNT\
FROM INSTALLED_PACKAGES RIGHT OUTER JOIN PACKAGES\
ON INSTALLED_PACKAGES.PKEY = PACKAGES.PKEY\
WHERE CAT=$cat AND PKG=$pkg\
GROUP BY CAT, PKG, VER\
ORDER BY HOST_COUNT DESC, CAT, PKG, VER',
vars={'cat':args[0], 'pkg':args[1]})
for idx in range(0, count):
try:
tcpv_tuple = tcpv_query[idx]
t_list.append({
'CAT':tcpv_tuple['CAT'],
'PKG':tcpv_tuple['PKG'],
'VER':tcpv_tuple['VER'],
'HOST_COUNT':tcpv_tuple['HOST_COUNT']
})
except IndexError:
break
return t_list
|