summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2014-10-12 22:47:30 +0200
committerChristian Pointner <equinox@spreadspace.org>2014-10-12 22:47:30 +0200
commit9b494a9791d69fbeeef7852f7a3bdcec86d89514 (patch)
tree3412f0987419d146c98f62066cab04259a764be3
parentalso allow stdin as logfile (diff)
added switch for live mode
-rwxr-xr-xsrc/daq/accesslog/sfive-accesslog.py22
1 files changed, 15 insertions, 7 deletions
diff --git a/src/daq/accesslog/sfive-accesslog.py b/src/daq/accesslog/sfive-accesslog.py
index e88d7e4..133ff46 100755
--- a/src/daq/accesslog/sfive-accesslog.py
+++ b/src/daq/accesslog/sfive-accesslog.py
@@ -119,7 +119,12 @@ class AccessLog():
def _initLog(self):
try:
- self._fd = open(self._logfile, 'r') if self._logfile != '-' else sys.stdin
+ if self._logfile:
+ print 'SFive: will batch import form %s' % (self._logfile if self._logfile != '-' else 'standard input')
+ self._fd = open(self._logfile, 'r') if self._logfile != '-' else sys.stdin
+ else:
+ print 'SFive: live mode enabled'
+
regex = self._nameformat % { 'hostname': self._hostname,
'content-id': self._content_id,
'format': self._format,
@@ -149,10 +154,13 @@ class AccessLog():
def _socketReady(self):
print 'SFive: connection to sfive hub established'
self._sendInit()
- cnt = self._sendLogData()
- print 'SFive: sent %d datasets' % (cnt)
+ if hasattr(self, '_fd'):
+ cnt = self._sendLogData(self._fd)
+ print 'SFive: sent %d datasets' % (cnt)
+ self._fd.close()
+ else:
+ print 'SFive: live mode is not implemented yet!'
- self._fd.close()
reactor.stop()
def _sendInit(self):
@@ -202,11 +210,11 @@ class AccessLog():
linedata['ts'] = self._parseDatetime(linedata['ts'])
return linedata
- def _sendLogData(self):
+ def _sendLogData(self, data):
cnt = 0
try:
regex = self._prepareLineRegex()
- for line in self._fd:
+ for line in data:
linedata = self._parseLine(regex, line)
cnt += 1
print linedata
@@ -248,7 +256,7 @@ if __name__ == '__main__':
help='the quality (i.e. high)')
parser.add_argument('--tag', '-t', dest='tags', action='append',
help='tag to be added to the statistic data, can be invoked several times')
- parser.add_argument('--logfile', '-l', dest='logfile', required=True,
+ parser.add_argument('--logfile', '-l', dest='logfile', required=False,
help='path to the logfile or \'-\' for standard input')
parser.add_argument('--nameformat', '-F', dest='nameformat', required=True,
help='the format for filenames which are part of this stream, this may include python string expressions')