17
17
18
18
try :
19
19
import os
20
- import commands
21
- import sys , getopt
22
- import logging
23
20
import re
24
21
import time
25
22
import syslog
26
23
from sonic_sfp .bcmshell import bcmshell
24
+ from sonic_py_common .general import getstatusoutput_noshell
27
25
28
26
except ImportError as e :
29
27
raise ImportError ("%s - required module not found" % str (e ))
@@ -53,10 +51,10 @@ def initialLoop():
53
51
bcm_obj = BCMUtil ()
54
52
bcm_obj .execute_command ("echo" )
55
53
initialNotOK = False
56
- print bcm_obj
54
+ print ( bcm_obj )
57
55
log_message ( syslog .LOG_INFO , "BCMUtil Object initialed successfully" )
58
- except Exception , e :
59
- print "Exception. The warning is {0}" .format (str (e ))
56
+ except Exception as e :
57
+ print ( "Exception. The warning is {0}" .format (str (e )))
60
58
time .sleep (10 )
61
59
62
60
class BCMUtil (bcmshell ):
@@ -66,7 +64,7 @@ class BCMUtil(bcmshell):
66
64
67
65
def get_platform (self ):
68
66
if self .platform is None :
69
- self .platform = os . popen ( "uname -n" ). read ( ).strip ()
67
+ _ , self .platform = getstatusoutput_noshell ([ "uname" , " -n"] ).strip ()
70
68
return self .platform
71
69
72
70
def get_asic_temperature ( self ):
@@ -102,14 +100,18 @@ def main():
102
100
content = readPtr .read ().strip ()
103
101
if bcm_obj .get_platform () == INV_SEQUOIA_PLATFORM :
104
102
if content == "inv_bmc" and SWITCH_TEMP_FILE_NAME in file_list :
105
- os .system ("echo {0} > {1}/{2}/device/{3}" .format ( ( bcm_obj .get_asic_temperature () * 1000 ), HWMON_PATH , index , SWITCH_TEMP_FILE_NAME ))
103
+ file = "{0}/{1}/device/{2}" .format (HWMON_PATH , index , SWITCH_TEMP_FILE_NAME )
104
+ with open (file , 'w' ) as f :
105
+ f .write (str (bcm_obj .get_asic_temperature () * 1000 ) + '\n ' )
106
106
break
107
107
else :
108
108
if content == "inv_psoc" and SWITCH_TEMP_FILE_NAME in file_list :
109
- print "echo {0} > {1}/{2}/device/{3}" .format ( ( bcm_obj .get_asic_temperature () * 1000 ), HWMON_PATH , index , SWITCH_TEMP_FILE_NAME )
110
- os .system ("echo {0} > {1}/{2}/device/{3}" .format ( ( bcm_obj .get_asic_temperature () * 1000 ), HWMON_PATH , index , SWITCH_TEMP_FILE_NAME ))
109
+ print ("echo {0} > {1}/{2}/device/{3}" .format ( ( bcm_obj .get_asic_temperature () * 1000 ), HWMON_PATH , index , SWITCH_TEMP_FILE_NAME ))
110
+ file = "{0}/{1}/device/{2}" .format (HWMON_PATH , index , SWITCH_TEMP_FILE_NAME )
111
+ with open (file , 'w' ) as f :
112
+ f .write (str (bcm_obj .get_asic_temperature () * 1000 ) + '\n ' )
111
113
break
112
- except Exception , e :
114
+ except Exception as e :
113
115
log_message ( syslog .LOG_WARNING , "Exception. The warning is {0}" .format (str (e )) )
114
116
initialLoop ()
115
117
time .sleep (5 )
0 commit comments