Python psutil 模块,version_info() 实例源码

我们从Python开源项目中,提取了以下7个代码示例,用于说明如何使用psutil.version_info()

项目:flasksse_rpi    作者:petervflocke    | 项目源码 | 文件源码
def process(service, action):                             # control start, stop and status of a external service running on RPI
    if action == 'off':
        Services[service]['state'] = 99                   # wait for feedback from the service, do not change immediately
        Services[service]['newstate'] = 0
        sse_parm['LED_%s' % Services[service]['id']] = Services[service]['lpro']  
        sse_parm['BUT_%s' % Services[service]['id']] = Services[service]['bpro']          
        Popen(Services[service]['pfun4'], shell=True)      # and start the service        
    elif action == 'on':
        Services[service]['state'] = 99                    # wait for feedback from the service, do not change immediately
        Services[service]['newstate'] = 1        
        sse_parm['LED_%s' % Services[service]['id']] = Services[service]['lpro'] 
        sse_parm['BUT_%s' % Services[service]['id']] = Services[service]['bpro']          
        Popen(Services[service]['pfun3'], shell=True)      # and start the TVHeadOn service
    elif action == 'status':
        if version_info[0] < 4:
            return Services[service]['pfun1'] in [p.name for p in process_iter()]
        else:
            return Services[service]['pfun1'] in [p.name() for p in process_iter()]        
    else: raise ValueError('Unknown action "%s"' % action)
项目:flasksse_rpi    作者:petervflocke    | 项目源码 | 文件源码
def process(service, action):
    global Services
    global sse_parm    
    #with sync:
    if action == 'off':
        Services[service]['state'] = 99                   # wait for feedback from the service, do not change immediately
        Services[service]['newstate'] = 0

        sse_parm['LED_%s' % Services[service]['id']] = Services[service]['lpro']  
        sse_parm['BUT_%s' % Services[service]['id']] = Services[service]['bpro']          

        if service == 10:                               # TVHeadEnd 
            if param.RPI_Version is not None:
                RelayDev.RelayChange(0)                 # immediately change of the pin
                Services[23]['state'] = 99              # change the status monitor for GPIO
                Services[23]['newstate'] = 0
        Popen(Services[service]['pfun4'], shell=True)      # and start the TVHeadOn service        
    elif action == 'on':
        Services[service]['state'] = 99                    # wait for feedback from the service, do not change immediately
        Services[service]['newstate'] = 1        

        sse_parm['LED_%s' % Services[service]['id']] = Services[service]['lpro'] 
        sse_parm['BUT_%s' % Services[service]['id']] = Services[service]['bpro']          

        if service == 10:                               # TVHeadEnd 
            if param.RPI_Version is not None:
                RelayDev.RelayChange(1)                 # turn on power for usb
                Services[23]['state'] = 99              # change the status monitor for GPIO
                Services[23]['newstate'] = 1
        Popen(Services[service]['pfun3'], shell=True)      # and start the TVHeadOn service
    elif action == 'status':
        if version_info[0] < 4:
            return Services[service]['pfun1'] in [p.name for p in process_iter()]
        else:
            return Services[service]['pfun1'] in [p.name() for p in process_iter()]        
    else: raise ValueError('Unknown action "%s"' % action)
项目:respeaker_virtualenv    作者:respeaker    | 项目源码 | 文件源码
def test_version(self):
        self.assertEqual('.'.join([str(x) for x in psutil.version_info]),
                         psutil.__version__)
项目:nixstatsagent    作者:NIXStats    | 项目源码 | 文件源码
def run(self, *unused):
        systeminfo = {}
        cpu = {}
        if(os.path.isfile("/proc/cpuinfo")):
            f = open('/proc/cpuinfo')
            if f:
                for line in f:
                    # Ignore the blank line separating the information between
                    # details about two processing units
                    if line.strip():
                        if "model name" == line.rstrip('\n').split(':')[0].strip():
                            cpu['brand'] = line.rstrip('\n').split(':')[1].strip()
                        if "Processor" == line.rstrip('\n').split(':')[0].strip():
                            cpu['brand'] = line.rstrip('\n').split(':')[1].strip()
                        if "processor" == line.rstrip('\n').split(':')[0].strip():
                            cpu['count'] = line.rstrip('\n').split(':')[1].strip()
        else:
            cpu['brand'] = "Unknown CPU"
            cpu['count'] = 0
        mem = psutil.virtual_memory()
        if sys.platform == "linux" or sys.platform == "linux2":
            systeminfo['os'] = str(' '.join(platform.linux_distribution()))
        elif sys.platform == "darwin":
            systeminfo['os'] = "Mac OS %s" % platform.mac_ver()[0]
            cpu['brand'] = str(systemCommand('sysctl machdep.cpu.brand_string', False)[0]).split(': ')[1]
            cpu['count'] = systemCommand('sysctl hw.ncpu')
        elif sys.platform == "freebsd10" or sys.platform == "freebsd11":
            systeminfo['os'] = "FreeBSD %s" % platform.release()
            cpu['brand'] = str(systemCommand('sysctl hw.model', False)[0]).split(': ')[1]
            cpu['count'] = systemCommand('sysctl hw.ncpu')
        elif sys.platform == "win32":
            systeminfo['os'] = "{} {}".format(platform.uname()[0], platform.uname()[2])
        systeminfo['cpu'] = cpu['brand']
        systeminfo['cores'] = cpu['count']
        systeminfo['memory'] = mem.total
        systeminfo['psutil'] = '.'.join(map(str, psutil.version_info))
        systeminfo['platform'] = platform.platform()
        systeminfo['uptime'] = int(time.time()-psutil.boot_time())
        systeminfo['ip_addresses'] = ip_addresses()
        return systeminfo
项目:ntpmon    作者:paulgear    | 项目源码 | 文件源码
def __init__(self, names=None):
        """
        Save which process names we're looking for, and the version of psutil.
        """
        if names is None:
            self.names = ["ntpd", "xntpd"]
        else:
            self.names = names
        # Check for old psutil per http://grodola.blogspot.com.au/2014/01/psutil-20-porting.html
        self.PSUTIL2 = psutil.version_info >= (2, 0)
项目:zenchmarks    作者:squeaky-pl    | 项目源码 | 文件源码
def test_version(self):
        self.assertEqual('.'.join([str(x) for x in psutil.version_info]),
                         psutil.__version__)
项目:FancyWord    作者:EastonLee    | 项目源码 | 文件源码
def test_version(self):
        self.assertEqual('.'.join([str(x) for x in psutil.version_info]),
                         psutil.__version__)