Commit 6f05f9be authored by marc's avatar marc
Browse files

Draft backend class

parents
from __future__ import print_function
import logging
import subprocess
from configparser import ConfigParser
import os.path
import time
config = ConfigParser()
config.readfp(open(os.path.join(os.path.dirname(__file__), 'backend.ini')))
logging.basicConfig(level=logging.DEBUG)
class Backend():
def __init__(self,currentMode='Pulsar', setmode=None):
'''
Initializes a backend instance. The mode for writing can be
Pulsar', 'Line','Raw' or 'SDR'.
'''
self.runimpactTool = config.get('Tools','runimpact')
self.LSRTool = config.get('Tools', 'vlsr')
self.LSREnabled = False
if setmode not in ('Pulsar', 'Hydrogen', 'Raw', 'SDR', None):
raise ValueError("Mode must be 'Pulsar', 'Hydrogen', 'Raw', 'SDR':" + setmode)
self.setmode = setmode
self.currentMode = currentMode
self.runImpact = False
logging.info('Backend Intiatialised in mode: {}'.format(self.setmode))
logging.info('VLSR initialized in mode: {}'.format(self.LSREnabled))
def setMode(self, setmode):
'''
Compile CLI and execute command
'''
self.setmode = setmode
self.runImpact = False
logging.debug('Current Mode: {} \t SetMode: {}'.format(self.currentMode,self.setmode))
if self.currentMode is not self.setmode:
self.currentMode = setmode
self.runImpact = True
if self.runImpact==True:
if self.setmode == 'Pulsar':
argument = config.get('Modes','Pulsar')
if self.setmode == 'Hydrogen':
argument = config.get('Modes','Hydrogen')
if self.setmode == 'Raw':
argument = config.get('Modes','Raw')
if self.setmode == 'SDR':
argument = config.get('Modes','SDR')
logging.info('Excute CLI: {} {}'.format(self.runimpactTool, argument))
'''
Note: in the stub runimpact I added /bin/bash, otherwise you get an Exec format error.
'''
self.cli = subprocess.Popen(self.runimpactTool, 10, stdout=subprocess.PIPE)
self.cli.wait()
logging.info('runimpact completed')
else:
logging.info('Backend already in {} mode'.format(self.currentMode))
def enableLSR(self):
'''
Compile CLI and execute command
Note: in the stub runimpact I added /bin/bash, otherwise you get an Exec format error.
'''
if self.LSREnabled == False:
self.cli = subprocess.Popen(self.LSRTool, stdout=subprocess.PIPE)
self.cli.wait()
self.LSREnabled = True
logging.info('LSR compensation is enabled')
else:
logging.info('LSR is already enabled')
if __name__ == '__main__':
myBackend = Backend()
myBackend.enableLSR()
myBackend.enableLSR()
myBackend.setMode('Pulsar')
myBackend.setMode('Hydrogen')
myBackend.setMode('Hydrogen')
myBackend.setMode('Raw')
myBackend.setMode('Raw')
myBackend.setMode('SDR')
myBackend.setMode('SDR')
myBackend.setMode('Pulsar')
\ No newline at end of file
[Tools]
runimpact: /home/marc/bin/runimpact
vlsr: /home/marc/bin/trackHI.py
[Modes]
pulsar: pulsar.batch
hydrogen: line
raw: raw
SDR: sdr
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment