Esempio n. 1
0
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
Esempio n. 2
0
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;
Esempio n. 3
0
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;
Esempio n. 4
0
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;
Esempio n. 5
0
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 ) );
Esempio n. 6
0
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))