So, i'm creating an automated test system(scope bloat - the original intent was a one-off bash automation of a particular test case that has turned into creating a system that will do many other things). i've done a few things similar to this, but somehow never got to using classes, everything was down at the functions level in modules i wrote for past projects.
so i'm looking for a simple check/confirmation that i'm approaching this right. it's a communications module intended to connect via telnet to a remote linux machine, then pull various i2c reads from a device the linux machine is connected to.
i want to make sure i'm creating it correctly, and declaring objects correctly so the functions/methods in the class object will perform their individual tasks rightly. i think i'm on the right track but having people a little more experienced take a look couldn't hurt. in particular i want to make sure i'm setting the class up for instantiation correctly, and declaring self/init in the right way.
thanks for your time.
class Communications: #logs in to the remote as root.
def __init__(self):
self.term = telnetlib.open('10.100.100.103')
print ('logging in now')
term.read_until(b"ogin: ")
term.write('root\n')
time.sleep(3)
term.read_very_eager()
#device power-up and power-down
def node_startup(node):
if node == 1:
node_command = 'node_on 1\n'
elif node == 2:
node_command = 'node_on 2\n'
term.write(node_command)
print (b'powering node', node, 'on\n')
def node_shutdown(node):
if node == 1:
node_command = 'node_off 1\n'
elif node == 2:
node_command = 'node_off 2\n'
term.write(node_command)
print (b'shutting node', node, ' down')
#device sample retrieval
def get_voltage_i2c(bus, device, datapoint, test, node):
i2c_sample = term.write('i2cget -y -f %d %d 0x 8b w >> /tmp/%s_%d.txt\n' %(bus, device, test, node))
def get_voltage_i2c(bus, device, datapoint, test, node):
i2c_sample = term.write('i2cget -y -f %d %d %d %s %d w >> /tmp/%s_%d.txt\n' %(bus, device, datapoint, test, node))
def get_voltage_i2c(bus, device, datapoint, test, node):
i2c_sample = term.write('i2cget -y -f %d %d %d %s %d w >> /tmp/%s_%d.txt\n' %(bus, device, datapoint, test, node))
#output-scraper to slurp results from the output files the i2cgets write to. (devnote: incomplete at time of posting)
def get_sample_results():
time.sleep(30)
term.read_very_eager()
term.write(b'cat ')