Added get_process()
This commit is contained in:
parent
7d851d2222
commit
d1d3e1592e
1 changed files with 24 additions and 9 deletions
|
|
@ -197,6 +197,30 @@ def extract_item(item, filter='', silent=False):
|
|||
if not silent:
|
||||
print_warning('WARNING: Errors encountered while exctracting data')
|
||||
|
||||
def get_process(name=None):
|
||||
"""Get process by name, returns psutil.Process obj."""
|
||||
proc = None
|
||||
if not name:
|
||||
raise GenericError
|
||||
|
||||
for p in psutil.process_iter():
|
||||
try:
|
||||
if p.name() == name:
|
||||
proc = p
|
||||
except psutil._exceptions.NoSuchProcess:
|
||||
# Process finished during iteration? Going to ignore
|
||||
pass
|
||||
return proc
|
||||
|
||||
def get_simple_string(prompt='Enter string'):
|
||||
"""Get string from user (minimal allowed character set) and return as str."""
|
||||
simple_string = None
|
||||
while simple_string is None:
|
||||
_input = input('{}: '.format(prompt))
|
||||
if re.match(r'^(\w|-|_| )+$', _input, re.ASCII):
|
||||
simple_string = _input.strip()
|
||||
return simple_string
|
||||
|
||||
def get_ticket_number():
|
||||
"""Get TicketNumber from user, save in LogDir, and return as str."""
|
||||
if not ENABLED_TICKET_NUMBERS:
|
||||
|
|
@ -213,15 +237,6 @@ def get_ticket_number():
|
|||
f.write(ticket_number)
|
||||
return ticket_number
|
||||
|
||||
def get_simple_string(prompt='Enter string'):
|
||||
"""Get string from user (minimal allowed character set) and return as str."""
|
||||
simple_string = None
|
||||
while simple_string is None:
|
||||
_input = input('{}: '.format(prompt))
|
||||
if re.match(r'^(\w|-|_| )+$', _input, re.ASCII):
|
||||
simple_string = _input.strip()
|
||||
return simple_string
|
||||
|
||||
def human_readable_size(size, decimals=0):
|
||||
"""Convert size in bytes to a human-readable format and return a str."""
|
||||
# Prep string formatting
|
||||
|
|
|
|||
Loading…
Reference in a new issue