change @staticmethod to @classmethod
This commit is contained in:
parent
e20df99b01
commit
1691bc8b26
24
srchproc.py
24
srchproc.py
|
@ -10,8 +10,8 @@ class Proc:
|
||||||
"""
|
"""
|
||||||
Find a running process from Python
|
Find a running process from Python
|
||||||
"""
|
"""
|
||||||
@staticmethod
|
@classmethod
|
||||||
def list_windows():
|
def _list_windows(cls):
|
||||||
"""
|
"""
|
||||||
Find all running process with wmi
|
Find all running process with wmi
|
||||||
:return: list of dictionaries with descriptions of found processes
|
:return: list of dictionaries with descriptions of found processes
|
||||||
|
@ -35,8 +35,8 @@ class Proc:
|
||||||
execlist.append({'execpid': execpid, 'exename': exename, 'exepath': exepath, 'cmdline': cmdline})
|
execlist.append({'execpid': execpid, 'exename': exename, 'exepath': exepath, 'cmdline': cmdline})
|
||||||
return execlist
|
return execlist
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def list_linux():
|
def _list_linux(cls):
|
||||||
"""
|
"""
|
||||||
Find all running process with ps
|
Find all running process with ps
|
||||||
:return: list of dictionaries with descriptions of found processes
|
:return: list of dictionaries with descriptions of found processes
|
||||||
|
@ -52,23 +52,23 @@ class Proc:
|
||||||
execlist.append({'execpid': execpid, 'exename': exename, 'exepath': exepath, 'cmdline': cmdline})
|
execlist.append({'execpid': execpid, 'exename': exename, 'exepath': exepath, 'cmdline': cmdline})
|
||||||
return execlist
|
return execlist
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def list():
|
def list(cls):
|
||||||
"""
|
"""
|
||||||
Find all running process
|
Find all running process
|
||||||
:return: list of dictionaries with descriptions of found processes
|
:return: list of dictionaries with descriptions of found processes
|
||||||
"""
|
"""
|
||||||
if platform.startswith('linux'):
|
if platform.startswith('linux'):
|
||||||
return Proc.list_linux()
|
return cls._list_linux()
|
||||||
elif platform.startswith('win32'):
|
elif platform.startswith('win32'):
|
||||||
return Proc.list_windows()
|
return cls._list_windows()
|
||||||
elif platform.startswith('darwin'):
|
elif platform.startswith('darwin'):
|
||||||
return Proc.list_linux()
|
return cls._list_linux()
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def search(find: str, exclude: str = None):
|
def search(cls, find: str, exclude: str = None):
|
||||||
"""
|
"""
|
||||||
Find specified processes
|
Find specified processes
|
||||||
:param find: find process pid, name or arguments
|
:param find: find process pid, name or arguments
|
||||||
|
@ -76,7 +76,7 @@ class Proc:
|
||||||
:return: list of dictionaries with descriptions of found processes
|
:return: list of dictionaries with descriptions of found processes
|
||||||
"""
|
"""
|
||||||
proc_found = []
|
proc_found = []
|
||||||
for proc in Proc.list():
|
for proc in cls.list():
|
||||||
if exclude and (exclude in proc['execpid'] or exclude in proc['exename'] or
|
if exclude and (exclude in proc['execpid'] or exclude in proc['exename'] or
|
||||||
exclude in proc['exepath'] or exclude in proc['cmdline']):
|
exclude in proc['exepath'] or exclude in proc['cmdline']):
|
||||||
pass
|
pass
|
||||||
|
|
Loading…
Reference in New Issue
Block a user