def isOnNao(): """Are we on THE real Nao ?""" szCpuInfo = "/proc/cpuinfo" # if not isFileExists( szCpuInfo ): # already done by the getFileContents # return False; szAllFile = filetools.getFileContents(szCpuInfo) if (szAllFile.find("Geode") == -1): return False return True
def isOnNao(): """Are we on THE real Nao ?""" szCpuInfo = "/proc/cpuinfo"; # if not isFileExists( szCpuInfo ): # already done by the getFileContents # return False; szAllFile = filetools.getFileContents( szCpuInfo ); if( szAllFile.find( "Geode" ) == -1 ): return False; return True;
def executeAndGrabOutput( strCommand, bLimitToFirstLine = False ): "execute a command in system shell and return grabbed output" "WARNING: it's a 'not efficient' function!" strTimeStamp = filetools.getFilenameFromTime(); strOutputFilename = pathtools.getVolatilePath() + "grab_output_" + strTimeStamp+ ".tmp"; # generate a different file each call for multithreading capabilities mySystemCall( strCommand + " > " + strOutputFilename ); if( bLimitToFirstLine ): strBufferRead = filetools.getFileFirstLine( strOutputFilename ); else: strBufferRead = filetools.getFileContents( strOutputFilename ); try: os.unlink( strOutputFilename ); except: pass debug.debug( "executeAndGrabOutput: '%s'" % strBufferRead ); return strBufferRead;
def getCpuLoad(): "get the current cpu load/usage (as a integer percent) (the second value from uptime)" "in fact the first value it's better: it represents 1min, so it's more interesting" # strRet = executeAndGrabOutput( "uptime | cut -dg -f2 | cut -d: -f2" ); #~ try: #~ strText = executeAndGrabOutput( "uptime" ); #~ aAnalysed = strText.split( 'load average:' ); #~ aAnalysed = aAnalysed[1].split( ',' ); #~ return int(float( aAnalysed[1] ) * 100); #~ except: #~ return 0; try: szCpuLoad = "/proc/loadavg"; strAllFile = filetools.getFileContents( szCpuLoad ); listVar = strAllFile.split( ' ' ); if( len( listVar ) > 1 ): return int( float( listVar[0] ) * 100 ); # change listVar[1] to [0] to have the time on 1 min except BaseException, err: debug.debug( "ERR: altools.getCpuLoad: %s" % str( err ) );
def getCpuLoad(): "get the current cpu load/usage (as a integer percent) (the second value from uptime)" "in fact the first value it's better: it represents 1min, so it's more interesting" # strRet = executeAndGrabOutput( "uptime | cut -dg -f2 | cut -d: -f2" ); #~ try: #~ strText = executeAndGrabOutput( "uptime" ); #~ aAnalysed = strText.split( 'load average:' ); #~ aAnalysed = aAnalysed[1].split( ',' ); #~ return int(float( aAnalysed[1] ) * 100); #~ except: #~ return 0; try: szCpuLoad = "/proc/loadavg" strAllFile = filetools.getFileContents(szCpuLoad) listVar = strAllFile.split(' ') if (len(listVar) > 1): return int(float(listVar[0]) * 100) # change listVar[1] to [0] to have the time on 1 min except BaseException, err: debug.debug("ERR: altools.getCpuLoad: %s" % str(err))