Repository: kellyjonbrazil/jc

Issue:
Incorrect handling of "k" "K" and similar suffixes for df, should be binary
Running `df -Bk` or `df -BK` is equivalent to `df -BKiB` but jc handles this as equivalent to `df -BKB`.

Coreutils handling of k/K as identical to KiB is documented here: https://www.gnu.org/software/coreutils/manual/html_node/Block-size.html, not sure how other systems handle this.

As a workaround it is possible to run `df -BKB` or `df -BKiB` explicitly

Discussion:
cdleonard: failures seem unrelated
kellyjonbrazil: Thanks for the contribution! That documentation is clear as mud - I'll take a closer look. No worries about the test failures. That's due to some backports going into previous Python versions that I need to deal with.
kellyjonbrazil: I made some test fixes in `dev` and moved this PR to that base branch. The tests are no longer failing. I'll take a closer look before merging. Thanks!
kellyjonbrazil: I'll go ahead an merge your PR and make a couple changes after. I updated `convert_size_to_int()` to add `posix_mode` and `decimal_bias` parameters. I have to add a check in the `df` parser to see whether the output is linux vs. macOS/bsd to control the `posix_mode` parameter since both systems handle the units differently.

Patch:
diff --git a/jc/parsers/df.py b/jc/parsers/df.py
index fbe1ca80..d8a25d39 100644
--- a/jc/parsers/df.py
+++ b/jc/parsers/df.py
@@ -159,7 +159,7 @@ def _process(proc_data):
         # parse the size, used, and available fields to bytes
         for key in entry:
             if key in size_list:
-                entry[key] = jc.utils.convert_size_to_int(entry[key])
+                entry[key] = jc.utils.convert_size_to_int(entry[key], True)
 
         # convert integers
         for key in entry:


Test patch:
diff --git a/tests/fixtures/centos-7.7/df-h.json b/tests/fixtures/centos-7.7/df-h.json
index 54d0d054..9f38e03c 100644
--- a/tests/fixtures/centos-7.7/df-h.json
+++ b/tests/fixtures/centos-7.7/df-h.json
@@ -1,1 +1,1 @@
-[{"filesystem":"devtmpfs","size":1900000000,"used":0,"mounted_on":"/dev","available":1900000000,"use_percent":0},{"filesystem":"tmpfs","size":1900000000,"used":0,"mounted_on":"/dev/shm","available":1900000000,"use_percent":0},{"filesystem":"tmpfs","size":1900000000,"used":12000000,"mounted_on":"/run","available":1900000000,"use_percent":1},{"filesystem":"tmpfs","size":1900000000,"used":0,"mounted_on":"/sys/fs/cgroup","available":1900000000,"use_percent":0},{"filesystem":"/dev/mapper/centos-root","size":17000000000,"used":1800000000,"mounted_on":"/","available":16000000000,"use_percent":11},{"filesystem":"/dev/sda1","size":1014000000,"used":233000000,"mounted_on":"/boot","available":782000000,"use_percent":23},{"filesystem":"tmpfs","size":378000000,"used":0,"mounted_on":"/run/user/1000","available":378000000,"use_percent":0}]
+[{"filesystem":"devtmpfs","size":2040109465,"used":0,"mounted_on":"/dev","available":2040109465,"use_percent":0},{"filesystem":"tmpfs","size":2040109465,"used":0,"mounted_on":"/dev/shm","available":2040109465,"use_percent":0},{"filesystem":"tmpfs","size":2040109465,"used":12582912,"mounted_on":"/run","available":2040109465,"use_percent":1},{"filesystem":"tmpfs","size":2040109465,"used":0,"mounted_on":"/sys/fs/cgroup","available":2040109465,"use_percent":0},{"filesystem":"/dev/mapper/centos-root","size":18253611008,"used":1932735283,"mounted_on":"/","available":17179869184,"use_percent":11},{"filesystem":"/dev/sda1","size":1063256064,"used":244318208,"mounted_on":"/boot","available":819986432,"use_percent":23},{"filesystem":"tmpfs","size":396361728,"used":0,"mounted_on":"/run/user/1000","available":396361728,"use_percent":0}]
diff --git a/tests/fixtures/osx-10.11.6/df-h.json b/tests/fixtures/osx-10.11.6/df-h.json
index bcb76e37..4b3e1fc3 100644
--- a/tests/fixtures/osx-10.11.6/df-h.json
+++ b/tests/fixtures/osx-10.11.6/df-h.json
@@ -1,1 +1,1 @@
-[{"filesystem":"/dev/disk1s1","size":466000000000,"used":137000000000,"iused":674413,"ifree":9223372036854101394,"mounted_on":"/","available":326000000000,"capacity_percent":30,"iused_percent":0},{"filesystem":"devfs","size":188000,"used":188000,"iused":650,"ifree":0,"mounted_on":"/dev","available":0,"capacity_percent":100,"iused_percent":100},{"filesystem":"/dev/disk1s4","size":466000000000,"used":2000000000,"iused":2,"ifree":9223372036854775805,"mounted_on":"/private/var/vm","available":326000000000,"capacity_percent":1,"iused_percent":0},{"filesystem":"map -hosts","size":0,"used":0,"iused":0,"ifree":0,"mounted_on":"/net","available":0,"capacity_percent":100,"iused_percent":100},{"filesystem":"map auto_home","size":0,"used":0,"iused":0,"ifree":0,"mounted_on":"/home","available":0,"capacity_percent":100,"iused_percent":100},{"filesystem":"//brazil@MyCloudEX2Ultra._afpovertcp._tcp.local/brazil","size":3500000000000,"used":1100000000000,"iused":301134832,"ifree":649465741,"mounted_on":"/Volumes/brazil","available":2400000000000,"capacity_percent":32,"iused_percent":32}]
+[{"filesystem":"/dev/disk1s1","size":500363689984,"used":147102629888,"iused":674413,"ifree":9223372036854101394,"mounted_on":"/","available":350039834624,"capacity_percent":30,"iused_percent":0},{"filesystem":"devfs","size":192512,"used":192512,"iused":650,"ifree":0,"mounted_on":"/dev","available":0,"capacity_percent":100,"iused_percent":100},{"filesystem":"/dev/disk1s4","size":500363689984,"used":2147483648,"iused":2,"ifree":9223372036854775805,"mounted_on":"/private/var/vm","available":350039834624,"capacity_percent":1,"iused_percent":0},{"filesystem":"map -hosts","size":0,"used":0,"iused":0,"ifree":0,"mounted_on":"/net","available":0,"capacity_percent":100,"iused_percent":100},{"filesystem":"map auto_home","size":0,"used":0,"iused":0,"ifree":0,"mounted_on":"/home","available":0,"capacity_percent":100,"iused_percent":100},{"filesystem":"//brazil@MyCloudEX2Ultra._afpovertcp._tcp.local/brazil","size":3848290697216,"used":1209462790553,"iused":301134832,"ifree":649465741,"mounted_on":"/Volumes/brazil","available":2638827906662,"capacity_percent":32,"iused_percent":32}]
diff --git a/tests/fixtures/osx-10.14.6/df-h.json b/tests/fixtures/osx-10.14.6/df-h.json
index 790a3604..da9ce27c 100644
--- a/tests/fixtures/osx-10.14.6/df-h.json
+++ b/tests/fixtures/osx-10.14.6/df-h.json
@@ -1,1 +1,1 @@
-[{"filesystem":"/dev/disk1s1","size":466000000000,"used":144000000000,"iused":1507697,"ifree":9223372036853268110,"mounted_on":"/","available":315000000000,"capacity_percent":32,"iused_percent":0},{"filesystem":"devfs","size":334000,"used":334000,"iused":1154,"ifree":0,"mounted_on":"/dev","available":0,"capacity_percent":100,"iused_percent":100},{"filesystem":"/dev/disk1s4","size":466000000000,"used":6000000000,"iused":6,"ifree":9223372036854775801,"mounted_on":"/private/var/vm","available":315000000000,"capacity_percent":2,"iused_percent":0},{"filesystem":"map -hosts","size":0,"used":0,"iused":0,"ifree":0,"mounted_on":"/net","available":0,"capacity_percent":100,"iused_percent":100},{"filesystem":"map auto_home","size":0,"used":0,"iused":0,"ifree":0,"mounted_on":"/home","available":0,"capacity_percent":100,"iused_percent":100},{"filesystem":"/dev/disk2s2","size":6900000000,"used":5200000000,"iused":8,"ifree":4294967271,"mounted_on":"/Volumes/InstallESD","available":1700000000,"capacity_percent":76,"iused_percent":0},{"filesystem":"com.apple.TimeMachine.2019-11-29-075900@/dev/disk1s1","size":466000000000,"used":132000000000,"iused":1459164,"ifree":9223372036853316643,"mounted_on":"/Volumes/com.apple.TimeMachine.localsnapshots/Backups.backupdb/kbrazil-mac/2019-11-29-075900/Macintosh HD","available":315000000000,"capacity_percent":30,"iused_percent":0},{"filesystem":"//brazil@MyCloudEX2Ultra._afpovertcp._tcp.local/brazil","size":3500000000000,"used":1100000000000,"iused":301134832,"ifree":649465741,"mounted_on":"/Volumes/brazil","available":2400000000000,"capacity_percent":32,"iused_percent":32}]
+[{"filesystem":"/dev/disk1s1","size":500363689984,"used":154618822656,"iused":1507697,"ifree":9223372036853268110,"mounted_on":"/","available":338228674560,"capacity_percent":32,"iused_percent":0},{"filesystem":"devfs","size":342016,"used":342016,"iused":1154,"ifree":0,"mounted_on":"/dev","available":0,"capacity_percent":100,"iused_percent":100},{"filesystem":"/dev/disk1s4","size":500363689984,"used":6442450944,"iused":6,"ifree":9223372036854775801,"mounted_on":"/private/var/vm","available":338228674560,"capacity_percent":2,"iused_percent":0},{"filesystem":"map -hosts","size":0,"used":0,"iused":0,"ifree":0,"mounted_on":"/net","available":0,"capacity_percent":100,"iused_percent":100},{"filesystem":"map auto_home","size":0,"used":0,"iused":0,"ifree":0,"mounted_on":"/home","available":0,"capacity_percent":100,"iused_percent":100},{"filesystem":"/dev/disk2s2","size":7408818585,"used":5583457484,"iused":8,"ifree":4294967271,"mounted_on":"/Volumes/InstallESD","available":1825361100,"capacity_percent":76,"iused_percent":0},{"filesystem":"com.apple.TimeMachine.2019-11-29-075900@/dev/disk1s1","size":500363689984,"used":141733920768,"iused":1459164,"ifree":9223372036853316643,"mounted_on":"/Volumes/com.apple.TimeMachine.localsnapshots/Backups.backupdb/kbrazil-mac/2019-11-29-075900/Macintosh HD","available":338228674560,"capacity_percent":30,"iused_percent":0},{"filesystem":"//brazil@MyCloudEX2Ultra._afpovertcp._tcp.local/brazil","size":3848290697216,"used":1209462790553,"iused":301134832,"ifree":649465741,"mounted_on":"/Volumes/brazil","available":2638827906662,"capacity_percent":32,"iused_percent":32}]
diff --git a/tests/fixtures/ubuntu-18.04/df-h.json b/tests/fixtures/ubuntu-18.04/df-h.json
index a297c854..073c72b6 100644
--- a/tests/fixtures/ubuntu-18.04/df-h.json
+++ b/tests/fixtures/ubuntu-18.04/df-h.json
@@ -1,1 +1,1 @@
-[{"filesystem":"udev","size":955000000,"used":0,"mounted_on":"/dev","available":955000000,"use_percent":0},{"filesystem":"tmpfs","size":198000000,"used":1200000,"mounted_on":"/run","available":196000000,"use_percent":1},{"filesystem":"/dev/sda2","size":20000000000,"used":5500000000,"mounted_on":"/","available":14000000000,"use_percent":30},{"filesystem":"tmpfs","size":986000000,"used":0,"mounted_on":"/dev/shm","available":986000000,"use_percent":0},{"filesystem":"tmpfs","size":5000000,"used":0,"mounted_on":"/run/lock","available":5000000,"use_percent":0},{"filesystem":"tmpfs","size":986000000,"used":0,"mounted_on":"/sys/fs/cgroup","available":986000000,"use_percent":0},{"filesystem":"/dev/loop0","size":55000000,"used":55000000,"mounted_on":"/snap/core18/1223","available":0,"use_percent":100},{"filesystem":"/dev/loop1","size":11000000,"used":11000000,"mounted_on":"/snap/slcli/383","available":0,"use_percent":100},{"filesystem":"/dev/loop2","size":89000000,"used":89000000,"mounted_on":"/snap/core/7396","available":0,"use_percent":100},{"filesystem":"/dev/loop3","size":67000000,"used":67000000,"mounted_on":"/snap/google-cloud-sdk/103","available":0,"use_percent":100},{"filesystem":"/dev/loop5","size":55000000,"used":55000000,"mounted_on":"/snap/core18/1074","available":0,"use_percent":100},{"filesystem":"/dev/loop7","size":8700000,"used":8700000,"mounted_on":"/snap/doctl/187","available":0,"use_percent":100},{"filesystem":"/dev/loop8","size":3200000,"used":3200000,"mounted_on":"/snap/stress-ng/847","available":0,"use_percent":100},{"filesystem":"/dev/loop10","size":90000000,"used":90000000,"mounted_on":"/snap/core/7917","available":0,"use_percent":100},{"filesystem":"/dev/loop11","size":3300000,"used":3300000,"mounted_on":"/snap/stress-ng/924","available":0,"use_percent":100},{"filesystem":"tmpfs","size":197000000,"used":0,"mounted_on":"/run/user/1000","available":197000000,"use_percent":0},{"filesystem":"/dev/loop9","size":8700000,"used":8700000,"mounted_on":"/snap/doctl/215","available":0,"use_percent":100},{"filesystem":"/dev/loop4","size":67000000,"used":67000000,"mounted_on":"/snap/google-cloud-sdk/104","available":0,"use_percent":100}]
+[{"filesystem":"udev","size":1001390080,"used":0,"mounted_on":"/dev","available":1001390080,"use_percent":0},{"filesystem":"tmpfs","size":207618048,"used":1258291,"mounted_on":"/run","available":205520896,"use_percent":1},{"filesystem":"/dev/sda2","size":21474836480,"used":5905580032,"mounted_on":"/","available":15032385536,"use_percent":30},{"filesystem":"tmpfs","size":1033895936,"used":0,"mounted_on":"/dev/shm","available":1033895936,"use_percent":0},{"filesystem":"tmpfs","size":5242880,"used":0,"mounted_on":"/run/lock","available":5242880,"use_percent":0},{"filesystem":"tmpfs","size":1033895936,"used":0,"mounted_on":"/sys/fs/cgroup","available":1033895936,"use_percent":0},{"filesystem":"/dev/loop0","size":57671680,"used":57671680,"mounted_on":"/snap/core18/1223","available":0,"use_percent":100},{"filesystem":"/dev/loop1","size":11534336,"used":11534336,"mounted_on":"/snap/slcli/383","available":0,"use_percent":100},{"filesystem":"/dev/loop2","size":93323264,"used":93323264,"mounted_on":"/snap/core/7396","available":0,"use_percent":100},{"filesystem":"/dev/loop3","size":70254592,"used":70254592,"mounted_on":"/snap/google-cloud-sdk/103","available":0,"use_percent":100},{"filesystem":"/dev/loop5","size":57671680,"used":57671680,"mounted_on":"/snap/core18/1074","available":0,"use_percent":100},{"filesystem":"/dev/loop7","size":9122611,"used":9122611,"mounted_on":"/snap/doctl/187","available":0,"use_percent":100},{"filesystem":"/dev/loop8","size":3355443,"used":3355443,"mounted_on":"/snap/stress-ng/847","available":0,"use_percent":100},{"filesystem":"/dev/loop10","size":94371840,"used":94371840,"mounted_on":"/snap/core/7917","available":0,"use_percent":100},{"filesystem":"/dev/loop11","size":3460300,"used":3460300,"mounted_on":"/snap/stress-ng/924","available":0,"use_percent":100},{"filesystem":"tmpfs","size":206569472,"used":0,"mounted_on":"/run/user/1000","available":206569472,"use_percent":0},{"filesystem":"/dev/loop9","size":9122611,"used":9122611,"mounted_on":"/snap/doctl/215","available":0,"use_percent":100},{"filesystem":"/dev/loop4","size":70254592,"used":70254592,"mounted_on":"/snap/google-cloud-sdk/104","available":0,"use_percent":100}]