mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-06-19 00:17:51 +02:00
process jobs data
This commit is contained in:
@ -8,6 +8,36 @@ Usage:
|
|||||||
Example:
|
Example:
|
||||||
|
|
||||||
$ jobs -l | jc --jobs -p
|
$ jobs -l | jc --jobs -p
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"job_number": 1,
|
||||||
|
"pid": 5283,
|
||||||
|
"status": "Running",
|
||||||
|
"command": "sleep 10000 &"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"job_number": 2,
|
||||||
|
"pid": 5284,
|
||||||
|
"status": "Running",
|
||||||
|
"command": "sleep 10100 &"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"job_number": 3,
|
||||||
|
"pid": 5285,
|
||||||
|
"history": "previous",
|
||||||
|
"status": "Running",
|
||||||
|
"command": "sleep 10001 &"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"job_number": 4,
|
||||||
|
"pid": 5286,
|
||||||
|
"history": "current",
|
||||||
|
"status": "Running",
|
||||||
|
"command": "sleep 10112 &"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
$ jobs -l | jc --jobs -p -r
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"job_number": "1",
|
"job_number": "1",
|
||||||
@ -40,8 +70,33 @@ $ jobs -l | jc --jobs -p
|
|||||||
import string
|
import string
|
||||||
|
|
||||||
|
|
||||||
def parse(data):
|
def process(proc_data):
|
||||||
output = []
|
'''schema:
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"job_number": integer,
|
||||||
|
"pid": integer,
|
||||||
|
"history": string,
|
||||||
|
"status": string,
|
||||||
|
"command": string
|
||||||
|
}
|
||||||
|
]
|
||||||
|
'''
|
||||||
|
for entry in proc_data:
|
||||||
|
int_list = ['job_number', 'pid']
|
||||||
|
for key in int_list:
|
||||||
|
if key in entry:
|
||||||
|
try:
|
||||||
|
key_int = int(entry[key])
|
||||||
|
entry[key] = key_int
|
||||||
|
except (ValueError, TypeError):
|
||||||
|
entry[key] = None
|
||||||
|
|
||||||
|
return proc_data
|
||||||
|
|
||||||
|
|
||||||
|
def parse(data, raw=False):
|
||||||
|
raw_output = []
|
||||||
|
|
||||||
linedata = data.splitlines()
|
linedata = data.splitlines()
|
||||||
|
|
||||||
@ -95,6 +150,9 @@ def parse(data):
|
|||||||
output_line['status'] = parsed_line[1]
|
output_line['status'] = parsed_line[1]
|
||||||
output_line['command'] = parsed_line[2]
|
output_line['command'] = parsed_line[2]
|
||||||
|
|
||||||
output.append(output_line)
|
raw_output.append(output_line)
|
||||||
|
|
||||||
return output
|
if raw:
|
||||||
|
return raw_output
|
||||||
|
else:
|
||||||
|
return process(raw_output)
|
||||||
|
Reference in New Issue
Block a user