mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-06-17 00:07:37 +02:00
du tests and docs
This commit is contained in:
@ -1,7 +1,7 @@
|
|||||||
jc changelog
|
jc changelog
|
||||||
|
|
||||||
2019xxxx v1.6.1
|
2019xxxx v1.6.1
|
||||||
- Add du parser (linux and OSX support)
|
- Add du parser (tested on linux and OSX)
|
||||||
- Add OSX support for the ifconfig, arp, df, mount, and uname parsers
|
- Add OSX support for the ifconfig, arp, df, mount, and uname parsers
|
||||||
- Add tests for ls, dig, ps, w, uptime on OSX
|
- Add tests for ls, dig, ps, w, uptime on OSX
|
||||||
- Add about option
|
- Add about option
|
||||||
|
@ -7,6 +7,7 @@ pydocmd simple utils+ > ../docs/utils.md
|
|||||||
pydocmd simple jc.parsers.arp+ > ../docs/parsers/arp.md
|
pydocmd simple jc.parsers.arp+ > ../docs/parsers/arp.md
|
||||||
pydocmd simple jc.parsers.df+ > ../docs/parsers/df.md
|
pydocmd simple jc.parsers.df+ > ../docs/parsers/df.md
|
||||||
pydocmd simple jc.parsers.dig+ > ../docs/parsers/dig.md
|
pydocmd simple jc.parsers.dig+ > ../docs/parsers/dig.md
|
||||||
|
pydocmd simple jc.parsers.du+ > ../docs/parsers/du.md
|
||||||
pydocmd simple jc.parsers.env+ > ../docs/parsers/env.md
|
pydocmd simple jc.parsers.env+ > ../docs/parsers/env.md
|
||||||
pydocmd simple jc.parsers.free+ > ../docs/parsers/free.md
|
pydocmd simple jc.parsers.free+ > ../docs/parsers/free.md
|
||||||
pydocmd simple jc.parsers.fstab+ > ../docs/parsers/fstab.md
|
pydocmd simple jc.parsers.fstab+ > ../docs/parsers/fstab.md
|
||||||
|
115
docs/parsers/du.md
Normal file
115
docs/parsers/du.md
Normal file
@ -0,0 +1,115 @@
|
|||||||
|
# jc.parsers.du
|
||||||
|
jc - JSON CLI output utility du Parser
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
|
||||||
|
specify --du as the first argument if the piped input is coming from du
|
||||||
|
|
||||||
|
Compatibility:
|
||||||
|
|
||||||
|
'linux', 'darwin', 'cygwin', 'win32', 'aix', 'freebsd'
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
|
||||||
|
$ du /usr | jc --du -p
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"size": 104608,
|
||||||
|
"name": "/usr/bin"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"size": 56,
|
||||||
|
"name": "/usr/standalone/firmware/iBridge1_1Customer.bundle/Contents/_CodeSignature"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"size": 0,
|
||||||
|
"name": "/usr/standalone/firmware/iBridge1_1Customer.bundle/Contents/Resources/Firmware/usr/local/standalone"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"size": 0,
|
||||||
|
"name": "/usr/standalone/firmware/iBridge1_1Customer.bundle/Contents/Resources/Firmware/usr/local"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"size": 0,
|
||||||
|
"name": "/usr/standalone/firmware/iBridge1_1Customer.bundle/Contents/Resources/Firmware/usr"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"size": 1008,
|
||||||
|
"name": "/usr/standalone/firmware/iBridge1_1Customer.bundle/Contents/Resources/Firmware/dfu"
|
||||||
|
},
|
||||||
|
...
|
||||||
|
]
|
||||||
|
|
||||||
|
$ du /usr | jc --du -p -r
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"size": "104608",
|
||||||
|
"name": "/usr/bin"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"size": "56",
|
||||||
|
"name": "/usr/standalone/firmware/iBridge1_1Customer.bundle/Contents/_CodeSignature"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"size": "0",
|
||||||
|
"name": "/usr/standalone/firmware/iBridge1_1Customer.bundle/Contents/Resources/Firmware/usr/local/standalone"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"size": "0",
|
||||||
|
"name": "/usr/standalone/firmware/iBridge1_1Customer.bundle/Contents/Resources/Firmware/usr/local"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"size": "0",
|
||||||
|
"name": "/usr/standalone/firmware/iBridge1_1Customer.bundle/Contents/Resources/Firmware/usr"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"size": "1008",
|
||||||
|
"name": "/usr/standalone/firmware/iBridge1_1Customer.bundle/Contents/Resources/Firmware/dfu"
|
||||||
|
},
|
||||||
|
...
|
||||||
|
]
|
||||||
|
|
||||||
|
## info
|
||||||
|
```python
|
||||||
|
info(self, /, *args, **kwargs)
|
||||||
|
```
|
||||||
|
|
||||||
|
## process
|
||||||
|
```python
|
||||||
|
process(proc_data)
|
||||||
|
```
|
||||||
|
|
||||||
|
Final processing to conform to the schema.
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
|
||||||
|
proc_data: (dictionary) raw structured data to process
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
dictionary structured data with the following schema:
|
||||||
|
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"size": integer,
|
||||||
|
"name": string
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
## parse
|
||||||
|
```python
|
||||||
|
parse(data, raw=False, quiet=False)
|
||||||
|
```
|
||||||
|
|
||||||
|
Main text parsing function
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
|
||||||
|
data: (string) text data to parse
|
||||||
|
raw: (boolean) output preprocessed JSON if True
|
||||||
|
quiet: (boolean) suppress warning messages if True
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
dictionary raw or processed structured data
|
||||||
|
|
@ -11,7 +11,7 @@ Limitations:
|
|||||||
|
|
||||||
Compatibility:
|
Compatibility:
|
||||||
|
|
||||||
'linux'
|
'linux', 'darwin'
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
|
1
tests/fixtures/osx-10.14.6/du.json
vendored
Normal file
1
tests/fixtures/osx-10.14.6/du.json
vendored
Normal file
File diff suppressed because one or more lines are too long
@ -16,6 +16,9 @@ class MyTests(unittest.TestCase):
|
|||||||
# with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/du.out'), 'r') as f:
|
# with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/du.out'), 'r') as f:
|
||||||
# self.ubuntu_18_4_du = f.read()
|
# self.ubuntu_18_4_du = f.read()
|
||||||
|
|
||||||
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/du.out'), 'r') as f:
|
||||||
|
self.osx_10_14_6_du = f.read()
|
||||||
|
|
||||||
# output
|
# output
|
||||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/du.json'), 'r') as f:
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/du.json'), 'r') as f:
|
||||||
self.centos_7_7_du_json = json.loads(f.read())
|
self.centos_7_7_du_json = json.loads(f.read())
|
||||||
@ -23,6 +26,9 @@ class MyTests(unittest.TestCase):
|
|||||||
# with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/du.json'), 'r') as f:
|
# with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/du.json'), 'r') as f:
|
||||||
# self.ubuntu_18_4_du_json = json.loads(f.read())
|
# self.ubuntu_18_4_du_json = json.loads(f.read())
|
||||||
|
|
||||||
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/du.json'), 'r') as f:
|
||||||
|
self.osx_10_14_6_du_json = json.loads(f.read())
|
||||||
|
|
||||||
def test_du_centos_7_7(self):
|
def test_du_centos_7_7(self):
|
||||||
"""
|
"""
|
||||||
Test 'du' on Centos 7.7
|
Test 'du' on Centos 7.7
|
||||||
@ -35,6 +41,12 @@ class MyTests(unittest.TestCase):
|
|||||||
# """
|
# """
|
||||||
# self.assertEqual(jc.parsers.du.parse(self.ubuntu_18_4_du, quiet=True), self.ubuntu_18_4_du_json)
|
# self.assertEqual(jc.parsers.du.parse(self.ubuntu_18_4_du, quiet=True), self.ubuntu_18_4_du_json)
|
||||||
|
|
||||||
|
def test_du_osx_10_14_6(self):
|
||||||
|
"""
|
||||||
|
Test 'du' on OSX 10.14.6
|
||||||
|
"""
|
||||||
|
self.assertEqual(jc.parsers.du.parse(self.osx_10_14_6_du, quiet=True), self.osx_10_14_6_du_json)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
Reference in New Issue
Block a user