-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.py
49 lines (40 loc) · 1.46 KB
/
server.py
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
'''
Created on Jul 2, 2012
@author: Daniele Kruse, Alex Iribarren
'''
from Tsm import Tsm
from table import Table
import config
import logging
class Server(object):
_TABLES = []
def __init__(self, name, outputdir, freq, timedate_string, table_names):
self.name = name.upper()
self.outputdir = outputdir
self.timedate_string = timedate_string
self.log = logging.getLogger('Server')
if table_names:
for t in table_names:
self._TABLES.append(Table(t))
else:
for table in config.columns:
tfreq = config.columns[table]['frequency']
if tfreq != 'NEVER' and (freq == 'ALL' or freq == tfreq):
self._TABLES.append(Table(table))
def run(self, query):
_SERVER = Tsm(self.name, query, username=config.user, pwfile=config.pwfile)
if _SERVER.ret == 0:
return _SERVER.output
elif _SERVER.ret == 11:
return []
elif _SERVER.ret == 124:
self.log.error('[%s] Timeout while reading data' % self.name)
else:
self.log.error('[%s] Error %d reading data: %s' % (self.name, _SERVER.ret, ' '.join(_SERVER.output)))
return None
def readData(self):
for table in self._TABLES:
table.readFromServer(self, self.timedate_string)
def writeData(self):
for table in self._TABLES:
table.dumpToFile(self.outputdir, self.name)