Skip to content
Snippets Groups Projects
Unverified Commit c46fbdda authored by David Hoese's avatar David Hoese
Browse files

Fix python 3 compatiblity in ingest

parent 890ad462
No related branches found
No related tags found
No related merge requests found
...@@ -11,7 +11,7 @@ for a specified day. ...@@ -11,7 +11,7 @@ for a specified day.
import os import os
import re import re
from datetime import datetime, timedelta from datetime import datetime, timedelta
#from metobs.util import RODict, CONFIG as c from metobscommon.util import RODict, CONFIG as c
CEILO_INCOMING_DIR = os.environ.get( 'CEILO_INCOMING_DIR', '/beach/incoming/Instrument_Data/METOBS/RIG/Ceilo/raw') CEILO_INCOMING_DIR = os.environ.get( 'CEILO_INCOMING_DIR', '/beach/incoming/Instrument_Data/METOBS/RIG/Ceilo/raw')
CEILO_PRAW_DIR = os.environ.get( 'CEILO_PRAW_DIR', '/beach/raw/aoss/ceilo') CEILO_PRAW_DIR = os.environ.get( 'CEILO_PRAW_DIR', '/beach/raw/aoss/ceilo')
... ...
......
...@@ -39,6 +39,8 @@ import serial ...@@ -39,6 +39,8 @@ import serial
# https://stackoverflow.com/a/13638084/433202 # https://stackoverflow.com/a/13638084/433202
TRACE_LEVEL_NUM = 9 TRACE_LEVEL_NUM = 9
logging.addLevelName(TRACE_LEVEL_NUM, "TRACE") logging.addLevelName(TRACE_LEVEL_NUM, "TRACE")
def debugv(self, message, *args, **kws): def debugv(self, message, *args, **kws):
# Yes, logger takes its '*args' as 'args'. # Yes, logger takes its '*args' as 'args'.
if self.isEnabledFor(TRACE_LEVEL_NUM): if self.isEnabledFor(TRACE_LEVEL_NUM):
...@@ -47,16 +49,19 @@ logging.Logger.debugv = debugv ...@@ -47,16 +49,19 @@ logging.Logger.debugv = debugv
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
def epoch_secs(dt): def epoch_secs(dt):
"""Datetime to seconds from epoch. """Datetime to seconds from epoch.
""" """
return time.mktime(dt.utctimetuple()) return time.mktime(dt.utctimetuple())
def is_header(line): def is_header(line):
"""Is the line a valid message 2 header. """Is the line a valid message 2 header.
""" """
return re.match(r'^\x01CT[A-Z0-9][0-9]{2}[2].\x02\r\n$', line) return re.match(r'^\x01CT[A-Z0-9][0-9]{2}[2].\x02\r\n$', line)
def process_lines(in_lines, ref_dt): def process_lines(in_lines, ref_dt):
"""Process lines from the serial port. Epoch timestamps are injected """Process lines from the serial port. Epoch timestamps are injected
before the message header. All lines are stripped of white space before before the message header. All lines are stripped of white space before
...@@ -72,6 +77,7 @@ def process_lines(in_lines, ref_dt): ...@@ -72,6 +77,7 @@ def process_lines(in_lines, ref_dt):
out_lines.append(line) out_lines.append(line)
return num_hdrs, out_lines return num_hdrs, out_lines
def init_ceilo(portdev): def init_ceilo(portdev):
"""Initialize ceilometer by sending default configuration values to """Initialize ceilometer by sending default configuration values to
instrument. When this completes the instrument should be in autosend mode instrument. When this completes the instrument should be in autosend mode
...@@ -107,16 +113,17 @@ def init_ceilo(portdev): ...@@ -107,16 +113,17 @@ def init_ceilo(portdev):
stopbits=1, stopbits=1,
timeout=7.5) timeout=7.5)
def read_cfg(cfgfile): def read_cfg(cfgfile):
from ConfigParser import SafeConfigParser from configparser import ConfigParser
parser = SafeConfigParser() parser = ConfigParser()
parser.read(cfgfile) parser.read(cfgfile)
return dict(parser.items('ct25k')) return dict(parser.items('ct25k'))
def main():
def main():
from argparse import ArgumentParser from argparse import ArgumentParser
parser = ArgumentParser() parser = ArgumentParser()
...@@ -167,7 +174,7 @@ def main(): ...@@ -167,7 +174,7 @@ def main():
datalog.fptr = None datalog.fptr = None
def handle_signal(*args, **kwargs): def handle_signal(*args, **kwargs):
LOG.warn("received TERM or INT") LOG.warning("received TERM or INT")
signal.signal(signal.SIGTERM, handle_signal) signal.signal(signal.SIGTERM, handle_signal)
signal.signal(signal.SIGINT, handle_signal) signal.signal(signal.SIGINT, handle_signal)
...@@ -177,7 +184,6 @@ def main(): ...@@ -177,7 +184,6 @@ def main():
LOG.info("starting ingest") LOG.info("starting ingest")
while True: while True:
fptr = datalog() fptr = datalog()
LOG.log(9, "got log %s", fptr.name) LOG.log(9, "got log %s", fptr.name)
...@@ -200,7 +206,7 @@ def main(): ...@@ -200,7 +206,7 @@ def main():
try: try:
port.close() port.close()
except: except (serial.SerialException, IOError, OSError):
pass pass
if __name__ == '__main__': if __name__ == '__main__':
... ...
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment