print('Serial device is not specified (neither in config nor in command line)')
logger.error('Serial device is not specified (neither in config nor in command line)')
exit()
ifbaudrateisNone:
print('Baudrate is not specified (neither in config nor in command line)')
logger.error('Baudrate is not specified (neither in config nor in command line)')
exit()
ifnotargs.manual:
drivesLen=len(config['drives'])
ifdrivesLen==0:
print('No drives are specified in config. At least one drive must be specified')
logger.error('No drives are specified in config. At least one drive must be specified')
exit()
ifdrivesLen>3:
print(f'{drivesLen} drives are specified in config. Note that only 3 drives are supported, so only the first 3 will be used.')
logger.warn(f'{drivesLen} drives are specified in config. Note that only 3 drives are supported, so only the first 3 will be used.')
iflen(config['controlGroups'])!=3:
print('Incorrect number of control groups in config. There should be 3 control groups.')
logger.error('Incorrect number of control groups in config. There should be 3 control groups.')
exit()
serial_port=open_serial(port,baudrate)
ifserial_portisNone:
print(f'Failed to open {config["device"]} serial port. Trying again...')
logger.error(f'Failed to open {config["device"]} serial port. Trying again...')
try:
whileTrue:
...
...
@@ -208,7 +211,7 @@ if __name__ == "__main__":
output=str(subprocess.Popen(['netcat','-d','localhost','7634'],stdout=subprocess.PIPE,stderr=subprocess.STDOUT).communicate()[0])#получаем output от hddtemp
#b'|/dev/sda2|ST340014A|41|C|'
ifoutput=="b''":
print('Hddtemp output is empty, make sure it is running. If not, launch it: #systemctl start hddtemp.service')
logger.error('Hddtemp output is empty, make sure it is running. If not, launch it: #systemctl start hddtemp.service')
#exit()
else:
driveCount=len(config['drives'])
...
...
@@ -219,7 +222,7 @@ if __name__ == "__main__":
drive=config['drives'][i]
drive_pos=output.find(drive)
ifdrive_pos==-1:
print(f'Drive {drive} not found in hddtemp output')
logger.error(f'Drive {drive} not found in hddtemp output')
continue
try:
...
...
@@ -231,7 +234,7 @@ if __name__ == "__main__":
temp=output[temp_pos_start:temp_pos_end]
temperatures[i]=int(temp)
exceptValueError:
print(f'Failed to parse a temperature value from hddtemp output for drive {drive}')
logger.error(f'Failed to parse a temperature value from hddtemp output for drive {drive}')
continue
if(poll(serial_port)):
...
...
@@ -242,10 +245,10 @@ if __name__ == "__main__":
except(OSError,termios.error):
ifserial_portisnotNone:
print('Serial port error. Trying to open serial port again...')
logger.error('Serial port error. Trying to open serial port again...')
serial_port=open_serial(port,baudrate)
ifserial_portisnotNone:
print('Success')
logger.info('Success')
#обычнаый интервал используется при обычном обмене когда всё ок