<s> from __future__ import with_statement <EOL> import subprocess as sp <EOL> import psutil <EOL> def get_cpu_usage ( ) : <EOL> cpu_usage = psutil . cpu_percent ( ) <EOL> return '<STR_LIT>' % cpu_usage <EOL> def get_mem_usage ( ) : <EOL> with open ( '<STR_LIT>' ) as mem_info : <EOL> mem_total = mem_info . readline ( ) <EOL> mem_free = mem_info . readline ( ) <EOL> mem_buff = mem_info . readline ( ) <EOL> if not mem_buff . startswith ( '<STR_LIT>' ) : <EOL> mem_buff = mem_info . readline ( ) <EOL> mem_cached = mem_info . readline ( ) <EOL> mem_total = int ( mem_total . split ( '<STR_LIT::>' , <NUM_LIT:1> ) [ <NUM_LIT:1> ] . split ( ) [ <NUM_LIT:0> ] ) <EOL> mem_free = int ( mem_free . split ( '<STR_LIT::>' , <NUM_LIT:1> ) [ <NUM_LIT:1> ] . split ( ) [ <NUM_LIT:0> ] ) <EOL> mem_buff = int ( mem_buff . split ( '<STR_LIT::>' , <NUM_LIT:1> ) [ <NUM_LIT:1> ] . split ( ) [ <NUM_LIT:0> ] ) <EOL> mem_cached = int ( mem_cached . split ( '<STR_LIT::>' , <NUM_LIT:1> ) [ <NUM_LIT:1> ] . split ( ) [ <NUM_LIT:0> ] ) <EOL> mem_usage = mem_total - ( mem_free + mem_buff + mem_cached ) <EOL> mem_usage = <NUM_LIT:1.0> * <NUM_LIT:100> * mem_usage / mem_total <EOL> return ( '<STR_LIT>' % mem_usage , '<STR_LIT>' % ( mem_total / <NUM_LIT> ) ) <EOL> _CPU_STYLE = None <EOL> def get_cpu_style ( ) : <EOL> global _CPU_STYLE <EOL> if _CPU_STYLE is None : <EOL> popen = sp . Popen ( '<STR_LIT>' , stdout = sp . PIPE , shell = True ) <EOL> popen . wait ( ) <EOL> result = popen . stdout . read ( ) <EOL> _CPU_STYLE = result . split ( '<STR_LIT::>' , <NUM_LIT:1> ) [ <NUM_LIT:1> ] . strip ( ) <EOL> return _CPU_STYLE <EOL> _IP_ADDRESS = None <EOL> def get_ip ( ) : <EOL> def get_ip_address ( ifname ) : <EOL> s = socket . socket ( socket . AF_INET , socket . SOCK_DGRAM ) <EOL> return socket . inet_ntoa ( fcntl . ioctl ( <EOL> s . fileno ( ) , <EOL> <NUM_LIT> , <EOL> struct . pack ( '<STR_LIT>' , ifname [ : <NUM_LIT:15> ] ) <EOL> ) [ <NUM_LIT:20> : <NUM_LIT> ] ) <EOL> global _IP_ADDRESS <EOL> if _IP_ADDRESS is None : <EOL> import socket , fcntl , struct <EOL> popen = sp . Popen ( "<STR_LIT>" , stdout = sp . PIPE , shell = True ) <EOL> popen . wait ( ) <EOL> result = popen . stdout . read ( ) <EOL> for iface_name in result . split ( ) : <EOL> if iface_name in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> continue <EOL> try : <EOL> _IP_ADDRESS = get_ip_address ( iface_name ) <EOL> except : <EOL> pass <EOL> else : <EOL> break <EOL> if _IP_ADDRESS is None : <EOL> _IP_ADDRESS = '<STR_LIT:127.0.0.1>' <EOL> return _IP_ADDRESS <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> print '<STR_LIT>' % get_cpu_style ( ) <EOL> print '<STR_LIT>' % get_cpu_usage ( ) <EOL> print '<STR_LIT>' % get_mem_usage ( ) <EOL> print '<STR_LIT>' % get_ip ( ) </s>
