-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkomserverstats
executable file
·114 lines (95 loc) · 3.64 KB
/
komserverstats
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
#!/usr/bin/env python
# -*- coding: iso-8859-1 -*-
# Get server statistics using get-stats (protocol version 11 and up)
# $Id: komserverstats,v 1.2 2003/09/02 19:34:08 kent Exp $
# (C) 2003 Kent Engström. Released under GPL.
import sys
import optparse # Python 2.3 needed
import kom
import komconnect # Python 2.3 needed
errwrite = sys.stderr.write
# Option handling
optp = optparse.OptionParser()
komconnect.add_server_name_password(optp) # Standard options for login
ogrp = optparse.OptionGroup(optp, "Statistics Gathering")
ogrp.add_option("--property",
help = "get the value of PROP", metavar="PROP")
ogrp.add_option("--period", type="int", default=0,
help = "get the value for SECS seconds", metavar="SECS")
ogrp.add_option("--rates", action="store_true",
help = "include +/- rates")
ogrp.add_option("--describe", action="store_true",
help = "show properties and periods")
optp.add_option_group(ogrp)
ogrp = optparse.OptionGroup(optp, "Highest Text Numbers")
ogrp.add_option("--highest-global", action="store_true",
help = "get the highest global text number")
ogrp.add_option("--highest-local",
help = "get the highest local text number in CONF",
metavar="CONF")
ogrp.add_option("--no-of-created",
help = "get the number of texts created by PERS",
metavar="PERS")
optp.add_option_group(ogrp)
(options, args) = optp.parse_args()
# Connect and log in
try:
conn = komconnect.connect_and_login(options, kom.CachedConnection)
except komconnect.Error, error:
errwrite("%s: %s\n" % (sys.argv[0], error))
sys.exit(1)
# Do the work
if options.describe:
sd = kom.ReqGetStatsDescription(conn).response()
print "Periods:"
for per in sd.when: print " " + str(per)
print
print "Properties:"
for prop in sd.what: print " " + prop
elif options.property is not None and options.period is not None:
sd = kom.ReqGetStatsDescription(conn).response()
if options.property not in sd.what:
errwrite("unknown property %s\n" % options.property)
sys.exit(1)
try:
ix = sd.when.index(options.period)
except ValueError:
errwrite("unknown period %d\n" % options.period)
sys.exit(1)
stats = kom.ReqGetStats(conn, options.property).response()
if options.rates:
print "%f %f %f" % (stats[ix].average,
stats[ix].ascent_rate,
stats[ix].descent_rate)
else:
print "%f" % stats[ix].average
elif options.highest_global:
print kom.ReqFindPreviousTextNo(conn, sys.maxint).response()
elif options.highest_local:
confs = conn.lookup_name(options.highest_local,
want_pers = 1, want_confs = 1)
if len(confs) == 1:
conference = confs[0][0]
elif len(confs) > 1:
errwrite("%s is not a unique name\n"% options.highest_local)
sys.exit(1)
else:
errwrite("%s not found\n" % options.highest_local)
sys.exit(1)
print conn.uconferences[conference].highest_local_no
elif options.no_of_created:
persons = conn.lookup_name(options.no_of_created,
want_pers = 1, want_confs = 0)
if len(persons) == 1:
person = persons[0][0]
elif len(persons) > 1:
errwrite("%s is not a unique name\n"% options.no_of_created)
sys.exit(1)
else:
errwrite("%s not found\n" % options.no_of_created)
sys.exit(1)
print conn.persons[person].no_of_created_texts + \
conn.persons[person].first_created_local_no - 1
else:
optp.print_help()
sys.exit(1)