mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2026-04-03 17:44:07 +02:00
Compare commits
671 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9e3b88727c | ||
|
|
b12217466e | ||
|
|
8b9c932f9b | ||
|
|
5986ce03db | ||
|
|
a7b0e936e4 | ||
|
|
cb02211424 | ||
|
|
bd443bf392 | ||
|
|
1f547edd36 | ||
|
|
e4bac3a493 | ||
|
|
5e6bfa681a | ||
|
|
276160125e | ||
|
|
d4ae5543f2 | ||
|
|
55f360e267 | ||
|
|
fdedab2a0c | ||
|
|
a9be42e303 | ||
|
|
6da9510e46 | ||
|
|
0431798178 | ||
|
|
62432f3c48 | ||
|
|
9fbbc30906 | ||
|
|
d1567d1f62 | ||
|
|
6ca1f5970b | ||
|
|
1c880b9e24 | ||
|
|
3b7d54c720 | ||
|
|
44a7406057 | ||
|
|
8157dcfdb1 | ||
|
|
28762aea15 | ||
|
|
439871ea9f | ||
|
|
c9180b005c | ||
|
|
b14e0725f8 | ||
|
|
70fe3dcb4d | ||
|
|
8c554604a4 | ||
|
|
a0a35454bd | ||
|
|
e8467e2af5 | ||
|
|
7515deb566 | ||
|
|
ed9e52af24 | ||
|
|
592a380410 | ||
|
|
1a458d2d5b | ||
|
|
0e4cf53b92 | ||
|
|
e2f06ccb33 | ||
|
|
8abff004cd | ||
|
|
c4a0e2e3fe | ||
|
|
4f10f79c73 | ||
|
|
69e7a560fd | ||
|
|
59b1055808 | ||
|
|
6ed48c6289 | ||
|
|
f2fb4d3f41 | ||
|
|
6aeea59ea8 | ||
|
|
d016f3bbb3 | ||
|
|
7131c29718 | ||
|
|
7432442983 | ||
|
|
5344883394 | ||
|
|
3fcd2f6c2e | ||
|
|
f3d84bd5bf | ||
|
|
549780c232 | ||
|
|
2a6da69b82 | ||
|
|
5c538816cf | ||
|
|
7b8b378a7d | ||
|
|
e30a75e25c | ||
|
|
85ad5cfd0b | ||
|
|
88b9d5068c | ||
|
|
f8c4948a09 | ||
|
|
412322447f | ||
|
|
d4f289e40f | ||
|
|
e1f3feb8f5 | ||
|
|
37d3bc699c | ||
|
|
672fd18016 | ||
|
|
bc2c23a2a0 | ||
|
|
865f7e7812 | ||
|
|
720212b552 | ||
|
|
d3be61f608 | ||
|
|
13418b16b8 | ||
|
|
42d2017cd6 | ||
|
|
4345e76ead | ||
|
|
741431322b | ||
|
|
980beaaf41 | ||
|
|
2205034e09 | ||
|
|
82b9c87a66 | ||
|
|
dda517a937 | ||
|
|
4e6d283b9e | ||
|
|
55acab05aa | ||
|
|
ed38a18d23 | ||
|
|
95b3c11203 | ||
|
|
dce318f4fd | ||
|
|
85127f0fb8 | ||
|
|
fb45058244 | ||
|
|
45bb5ae389 | ||
|
|
339238ab36 | ||
|
|
032cda8b3d | ||
|
|
6badd3fb1e | ||
|
|
724d825745 | ||
|
|
ff1e32ad2e | ||
|
|
a5f97febd3 | ||
|
|
5baa6cc865 | ||
|
|
7a4f30b843 | ||
|
|
b2c385dc4f | ||
|
|
5d5da8d33f | ||
|
|
e604571578 | ||
|
|
f9dacc3f95 | ||
|
|
6086920332 | ||
|
|
f52f3163bc | ||
|
|
d18ff73e88 | ||
|
|
1e5d602cae | ||
|
|
12912521ec | ||
|
|
842ea3a94b | ||
|
|
a8560dbc15 | ||
|
|
a65e27540a | ||
|
|
c3c5ed11e6 | ||
|
|
ce24149335 | ||
|
|
0314ca8c48 | ||
|
|
ebd8ee49a9 | ||
|
|
38d10c9781 | ||
|
|
360106c24d | ||
|
|
ca470a5d02 | ||
|
|
57f66e6b1d | ||
|
|
e774f67924 | ||
|
|
ac10e576c1 | ||
|
|
bcae0a99cd | ||
|
|
c73c2ff879 | ||
|
|
c39b1a3356 | ||
|
|
125dc2d9e0 | ||
|
|
b7d4ddc7ce | ||
|
|
f5e546c6fa | ||
|
|
928e39cd10 | ||
|
|
d0b7ea68a0 | ||
|
|
8444690133 | ||
|
|
c03c42d767 | ||
|
|
ab67688a00 | ||
|
|
5dcb7166da | ||
|
|
14697b86d7 | ||
|
|
4f4b6276d4 | ||
|
|
7bc497e129 | ||
|
|
68a37a6a5a | ||
|
|
6f5cd1d7c5 | ||
|
|
126b1b121c | ||
|
|
2341e456a0 | ||
|
|
72d80e95bb | ||
|
|
f5ec82440c | ||
|
|
c8e526ead3 | ||
|
|
066adfb764 | ||
|
|
5b444d4717 | ||
|
|
69c95adc8d | ||
|
|
2b0e0d8f5c | ||
|
|
778d1bacbf | ||
|
|
7e1b041016 | ||
|
|
313b9b329c | ||
|
|
6830062256 | ||
|
|
323072c982 | ||
|
|
8719d96bdd | ||
|
|
dd5d318ab5 | ||
|
|
d6dc7f5e65 | ||
|
|
c203664eb5 | ||
|
|
19ecf1fa19 | ||
|
|
b8deb0426c | ||
|
|
3b8371f020 | ||
|
|
20bb1cdf39 | ||
|
|
301daa48d0 | ||
|
|
8421ec8803 | ||
|
|
74211eb012 | ||
|
|
60bd42f298 | ||
|
|
14bdd74526 | ||
|
|
fb0f3eda04 | ||
|
|
91ee6e6701 | ||
|
|
51f4e6927c | ||
|
|
94988d8667 | ||
|
|
fe36f5a98c | ||
|
|
f9eb18b927 | ||
|
|
cc60f36748 | ||
|
|
604ade791f | ||
|
|
690ac52a91 | ||
|
|
34ed772775 | ||
|
|
d5ab95571f | ||
|
|
ffb3a0ee5f | ||
|
|
94b12b57aa | ||
|
|
6d149e8457 | ||
|
|
1ad89c90d8 | ||
|
|
fb71c7b020 | ||
|
|
28ed17ad3b | ||
|
|
0c2a4e2bf7 | ||
|
|
62bec30de2 | ||
|
|
3fced77e4e | ||
|
|
a09d1d8b76 | ||
|
|
8f4243fbd8 | ||
|
|
47aaf20549 | ||
|
|
0c5289ea50 | ||
|
|
3e53323514 | ||
|
|
a5ee9861b9 | ||
|
|
feb8ca7654 | ||
|
|
a7abe4473b | ||
|
|
780b9b61de | ||
|
|
19ace36ffa | ||
|
|
5fff8afc9f | ||
|
|
4ad230c927 | ||
|
|
dd98eb1ec8 | ||
|
|
c6baf42e72 | ||
|
|
e2bac97d56 | ||
|
|
d112ee94d0 | ||
|
|
27b21b2faf | ||
|
|
8c96d5cd20 | ||
|
|
c29ed3fd69 | ||
|
|
cedf603f12 | ||
|
|
279161c36f | ||
|
|
ce0b43d919 | ||
|
|
ddafa5bf06 | ||
|
|
bc7116c31b | ||
|
|
53b7092721 | ||
|
|
beb9174b1b | ||
|
|
aea41ed341 | ||
|
|
d789494cb1 | ||
|
|
608e7b4cff | ||
|
|
4ee199c02a | ||
|
|
fbf47d4085 | ||
|
|
5a238e4b42 | ||
|
|
f852b8246a | ||
|
|
88140d929a | ||
|
|
45f7268240 | ||
|
|
3a3c8e4d4a | ||
|
|
c1ac183a04 | ||
|
|
18bb779ee5 | ||
|
|
8b6612fe79 | ||
|
|
fde0bc8534 | ||
|
|
e661a78939 | ||
|
|
847e346602 | ||
|
|
b969751688 | ||
|
|
ad6f2ba03a | ||
|
|
63c6a5edc0 | ||
|
|
9f4cf9dd5e | ||
|
|
51331b6dc0 | ||
|
|
efb6761033 | ||
|
|
6a4f737a0f | ||
|
|
be6864b778 | ||
|
|
de3b91a36c | ||
|
|
ef5482c3b5 | ||
|
|
d20b795137 | ||
|
|
8a134065df | ||
|
|
22aee1bfa4 | ||
|
|
b282820fd6 | ||
|
|
3ee098306d | ||
|
|
09e8f379a6 | ||
|
|
69018cdb3a | ||
|
|
d0d7254c6a | ||
|
|
cc0f0971d7 | ||
|
|
2af61730f0 | ||
|
|
83f41b83dc | ||
|
|
1fb84fce88 | ||
|
|
a8837e1244 | ||
|
|
04d2eec558 | ||
|
|
1b57ec92f0 | ||
|
|
4d88595404 | ||
|
|
52b1272a3a | ||
|
|
d2ccad6a83 | ||
|
|
cad6dde4ac | ||
|
|
06811c3539 | ||
|
|
0cb23c2b21 | ||
|
|
ac4688dca2 | ||
|
|
326c3b4670 | ||
|
|
9b29d0c268 | ||
|
|
e0013c3871 | ||
|
|
a75744075b | ||
|
|
525aec1a02 | ||
|
|
0bf9a7a072 | ||
|
|
d8f2f4c95b | ||
|
|
35d733b44f | ||
|
|
9179b4175c | ||
|
|
bb07d78c78 | ||
|
|
07b179cd7f | ||
|
|
054422d837 | ||
|
|
3e052d1810 | ||
|
|
c8e72805cf | ||
|
|
12a80e7db0 | ||
|
|
ee7ff9a09d | ||
|
|
f6478fb636 | ||
|
|
811a0b0495 | ||
|
|
aeb48edf72 | ||
|
|
b1e94f0df7 | ||
|
|
60050e3c0f | ||
|
|
39ef09aa5b | ||
|
|
8377d43116 | ||
|
|
54e4c447ab | ||
|
|
937a9fa9cf | ||
|
|
808ff6cf0e | ||
|
|
7f5c649a95 | ||
|
|
b72727dec9 | ||
|
|
3fc88bfb33 | ||
|
|
9f2279d586 | ||
|
|
346a14cb9b | ||
|
|
dac00d17ff | ||
|
|
9ca7cd4060 | ||
|
|
aa31628970 | ||
|
|
bed694fcf5 | ||
|
|
4b4af69fa1 | ||
|
|
9d96190a5b | ||
|
|
fa44d48c09 | ||
|
|
4ef961c278 | ||
|
|
292a837d5c | ||
|
|
aa7b915d84 | ||
|
|
c46fe73236 | ||
|
|
039b2c129c | ||
|
|
8f2e5e4808 | ||
|
|
c4da8e4f78 | ||
|
|
bcab9078a4 | ||
|
|
b3c6c1ea92 | ||
|
|
a3af8662bd | ||
|
|
35940d0bc8 | ||
|
|
26994cdcb7 | ||
|
|
017159a829 | ||
|
|
b4e9c85e08 | ||
|
|
189146cd84 | ||
|
|
af34153ffa | ||
|
|
bf2ff3ffbb | ||
|
|
6423c9efd6 | ||
|
|
58ab0d4ece | ||
|
|
83a738bf4d | ||
|
|
3640671fc6 | ||
|
|
1da623b30e | ||
|
|
b10ca64646 | ||
|
|
2128763ee6 | ||
|
|
a27e7ed39c | ||
|
|
f07b7eaa47 | ||
|
|
6ce18de84c | ||
|
|
8631b756e7 | ||
|
|
7414d98412 | ||
|
|
d7b19892e8 | ||
|
|
96df396eaf | ||
|
|
2f6f640317 | ||
|
|
c4a0a50f3a | ||
|
|
658f8a3842 | ||
|
|
bfb876a1e3 | ||
|
|
90c34b1f4e | ||
|
|
3f9164ea77 | ||
|
|
7fd6fecbf5 | ||
|
|
8029f72363 | ||
|
|
c7fdce5d3b | ||
|
|
84f48aa369 | ||
|
|
2e9a0a9c12 | ||
|
|
c1f6f2b950 | ||
|
|
ede21bca13 | ||
|
|
8dd9a9f9cb | ||
|
|
04f92cd133 | ||
|
|
8be8d2393b | ||
|
|
0a879681be | ||
|
|
2ca1587a49 | ||
|
|
ec2cd2d708 | ||
|
|
5d0dbece93 | ||
|
|
df1e4b414b | ||
|
|
40760991e7 | ||
|
|
464f5f86cf | ||
|
|
7b09e9fccd | ||
|
|
6cba7d4298 | ||
|
|
9730f62e49 | ||
|
|
e0c1c87f54 | ||
|
|
931b3d2b83 | ||
|
|
e5d561baee | ||
|
|
2867593e7a | ||
|
|
dd52fee563 | ||
|
|
8e1f885827 | ||
|
|
2d39a58f90 | ||
|
|
9c4fa2ae26 | ||
|
|
de52d84e82 | ||
|
|
ce9b55059a | ||
|
|
bcd370a6a0 | ||
|
|
c8216850ab | ||
|
|
f5feedb90b | ||
|
|
a4371cd187 | ||
|
|
9d5ba4c834 | ||
|
|
1639dee1bb | ||
|
|
9363f430f2 | ||
|
|
9192a09073 | ||
|
|
b915eb9755 | ||
|
|
1cfcc2b592 | ||
|
|
7138dd02b7 | ||
|
|
b4276643b7 | ||
|
|
2ef00763bf | ||
|
|
54364928fc | ||
|
|
09b3b4932b | ||
|
|
29d6670119 | ||
|
|
2f654b5f1a | ||
|
|
e53b9f5992 | ||
|
|
addb234e61 | ||
|
|
76eca3b659 | ||
|
|
f90dec4c0e | ||
|
|
8900a59d4c | ||
|
|
6685138200 | ||
|
|
4d3e65b980 | ||
|
|
e9282bb546 | ||
|
|
f5627a4594 | ||
|
|
81ffdb2510 | ||
|
|
4c00a99850 | ||
|
|
2bfcb45b28 | ||
|
|
ab0c10e791 | ||
|
|
2c1935115d | ||
|
|
d98e43dc78 | ||
|
|
9348988d64 | ||
|
|
1285c66467 | ||
|
|
b7191bbc13 | ||
|
|
98b97509f7 | ||
|
|
2b2b570490 | ||
|
|
cce2d1ff29 | ||
|
|
b79600c572 | ||
|
|
140f1a8543 | ||
|
|
e34657cfde | ||
|
|
99070fa607 | ||
|
|
2b46785b1f | ||
|
|
c72562524b | ||
|
|
b7dd6441c7 | ||
|
|
31fcc2f755 | ||
|
|
b391aa14bc | ||
|
|
d3c45debbb | ||
|
|
5b08469b87 | ||
|
|
4a77ec63a4 | ||
|
|
d13606b6dc | ||
|
|
05291c93bb | ||
|
|
8cf00a208e | ||
|
|
06d73c8876 | ||
|
|
649c646ea2 | ||
|
|
b7756d9250 | ||
|
|
1cd2cd954c | ||
|
|
72020b8da9 | ||
|
|
cf9720b749 | ||
|
|
967b9db7f9 | ||
|
|
bb3acb1182 | ||
|
|
560c7f7e6d | ||
|
|
79b2841764 | ||
|
|
a06a89cbd1 | ||
|
|
431bd969eb | ||
|
|
c87b722aec | ||
|
|
3688b8b014 | ||
|
|
07b8d9e0c0 | ||
|
|
7454b53e39 | ||
|
|
3d6a76024d | ||
|
|
421b980957 | ||
|
|
4a22e27d6a | ||
|
|
99f7842dee | ||
|
|
7f869b4b18 | ||
|
|
9665f4ee84 | ||
|
|
606904d48b | ||
|
|
3f5279b97c | ||
|
|
f5ec21e6ac | ||
|
|
578a284465 | ||
|
|
422e392d9d | ||
|
|
54dfffd34a | ||
|
|
cffba64d2b | ||
|
|
56a0c12a59 | ||
|
|
c174d3de18 | ||
|
|
a9c59ef9fc | ||
|
|
abdb9b2673 | ||
|
|
548aaab626 | ||
|
|
20571c87ae | ||
|
|
19e49200de | ||
|
|
d32f5c67a9 | ||
|
|
b83b626435 | ||
|
|
ab2c1b25ec | ||
|
|
f2d46313a4 | ||
|
|
87e4796a6c | ||
|
|
0014a5c2f4 | ||
|
|
7af56e0dad | ||
|
|
a5ae6e3c01 | ||
|
|
fe1a0d1faf | ||
|
|
302f05cdda | ||
|
|
c0044be7b0 | ||
|
|
0110078807 | ||
|
|
42eacb45f8 | ||
|
|
a43e2e1991 | ||
|
|
c8b721d4f6 | ||
|
|
d0bfddc3d9 | ||
|
|
6b925a16c8 | ||
|
|
89ebd9fc22 | ||
|
|
6b4ba66231 | ||
|
|
5b697dc381 | ||
|
|
9ba73c95d1 | ||
|
|
93aa390447 | ||
|
|
3cfb8945dd | ||
|
|
cd8d38f2a1 | ||
|
|
8ec8cd6294 | ||
|
|
c028113561 | ||
|
|
5f22e1c803 | ||
|
|
d3351787e5 | ||
|
|
e5bea9ae3b | ||
|
|
93c710abe9 | ||
|
|
c29e7cfe5c | ||
|
|
cb5c1ba00d | ||
|
|
9a012b94e1 | ||
|
|
400f5a44ec | ||
|
|
a2ab5bab91 | ||
|
|
fc8ab27361 | ||
|
|
59f19d33a5 | ||
|
|
dfc9618115 | ||
|
|
8e02e5c75a | ||
|
|
970493ab93 | ||
|
|
64d78956eb | ||
|
|
40c05346f4 | ||
|
|
e9b0bc1409 | ||
|
|
798e6bb7d9 | ||
|
|
12a370deed | ||
|
|
553bfbe1a0 | ||
|
|
52494321fc | ||
|
|
c6c9e06496 | ||
|
|
e3a6c05a58 | ||
|
|
391d06f68d | ||
|
|
99804ea06e | ||
|
|
51935deb2a | ||
|
|
b24d0c3a47 | ||
|
|
762a886d6f | ||
|
|
2c3e9ddfe4 | ||
|
|
c7cd2b63c8 | ||
|
|
f0528ea831 | ||
|
|
5bc5596f60 | ||
|
|
2c27ac46be | ||
|
|
caad840153 | ||
|
|
65bd7e2904 | ||
|
|
c3d7d7db12 | ||
|
|
5605310362 | ||
|
|
17b6efe82e | ||
|
|
a032ae56ae | ||
|
|
eab2f4b056 | ||
|
|
aff86ae6c7 | ||
|
|
7ece9ddc1a | ||
|
|
7cd048e839 | ||
|
|
1e22f610a3 | ||
|
|
5249c972ae | ||
|
|
fd45f856a0 | ||
|
|
c8ab40cd33 | ||
|
|
b2c872925b | ||
|
|
f48e229202 | ||
|
|
799fec92c3 | ||
|
|
87a41c2fca | ||
|
|
7f85de0c46 | ||
|
|
13661b1993 | ||
|
|
51d5c3892d | ||
|
|
e4eab4641a | ||
|
|
9b148e0ba3 | ||
|
|
de28932650 | ||
|
|
5f798d603e | ||
|
|
a0757b2dd3 | ||
|
|
498d51b4e8 | ||
|
|
b06b6bae3f | ||
|
|
b5eaff2137 | ||
|
|
c01bcd3734 | ||
|
|
d75c4068ca | ||
|
|
6aa2d5a3d2 | ||
|
|
065276805f | ||
|
|
a63408c8cf | ||
|
|
69576f6bfa | ||
|
|
19845624e2 | ||
|
|
22ff2964e9 | ||
|
|
d96b3a65a9 | ||
|
|
4989445ef4 | ||
|
|
6770892acd | ||
|
|
d4eba8740f | ||
|
|
9f60760560 | ||
|
|
0a8f8ac934 | ||
|
|
6ae24c8244 | ||
|
|
d3679082a8 | ||
|
|
fb08b42dca | ||
|
|
4aeaa9f42a | ||
|
|
5f5693da04 | ||
|
|
5eb0f61727 | ||
|
|
958e998991 | ||
|
|
b78c1509f6 | ||
|
|
ce184d4d57 | ||
|
|
b4c3714ced | ||
|
|
5b7dfa0438 | ||
|
|
391a388476 | ||
|
|
d9c4e2ed4c | ||
|
|
0c42db38b1 | ||
|
|
2f9be8bf33 | ||
|
|
e8c00155e8 | ||
|
|
cc88fdd9ee | ||
|
|
d9de11ef1d | ||
|
|
0ceda97d09 | ||
|
|
d0dec92ba8 | ||
|
|
d420c008d8 | ||
|
|
f0b32db433 | ||
|
|
bc838eda59 | ||
|
|
afe55b6af0 | ||
|
|
dd3a3ac302 | ||
|
|
f9982a7947 | ||
|
|
07c1be9e9a | ||
|
|
f832b88755 | ||
|
|
0fac757efc | ||
|
|
fc15742065 | ||
|
|
6f2466a131 | ||
|
|
4b90e22f0a | ||
|
|
c493568785 | ||
|
|
1cdf004b77 | ||
|
|
a4ea504261 | ||
|
|
4c2c234c3b | ||
|
|
3d4c0f3e89 | ||
|
|
52fad02903 | ||
|
|
9dcabc057c | ||
|
|
db8c1079dd | ||
|
|
8f954673ab | ||
|
|
79522d1c7d | ||
|
|
a18bf03079 | ||
|
|
c02b6b5d82 | ||
|
|
f99b423284 | ||
|
|
d7d9d45d4f | ||
|
|
90065ec0cd | ||
|
|
51157ebb86 | ||
|
|
96d95c79ca | ||
|
|
e5da34c233 | ||
|
|
f09d657f77 | ||
|
|
0f4b0189f5 | ||
|
|
4666042abb | ||
|
|
027d544c2b | ||
|
|
f1967d0138 | ||
|
|
c1d896027d | ||
|
|
5c2d2a6618 | ||
|
|
997b269b0b | ||
|
|
61257e7525 | ||
|
|
53ee2c3631 | ||
|
|
8bfa0bddec | ||
|
|
ad61e6bc81 | ||
|
|
873b5ba8ac | ||
|
|
6ae50054e2 | ||
|
|
22a35f41bf | ||
|
|
961696c963 | ||
|
|
c7b7f1a5dc | ||
|
|
b5a0d650b1 | ||
|
|
573b279464 | ||
|
|
116e07f161 | ||
|
|
964868c8af | ||
|
|
c8dac32df8 | ||
|
|
72a0016bd8 | ||
|
|
2ad3167434 | ||
|
|
ddabfaa05c | ||
|
|
f857523ca7 | ||
|
|
00d53858e8 | ||
|
|
c008167e66 | ||
|
|
102344a041 | ||
|
|
c865298ef3 | ||
|
|
6ac03faf93 | ||
|
|
49c2701743 | ||
|
|
d1a271b08e | ||
|
|
7388ad19b9 | ||
|
|
2e63cb5fad | ||
|
|
e7f14d02b1 | ||
|
|
873771d05a | ||
|
|
d7de122e36 | ||
|
|
4ef0434f53 | ||
|
|
1aa2c99259 | ||
|
|
c2450b27b0 | ||
|
|
14d6d8b84f | ||
|
|
f0e3846c03 | ||
|
|
6ba64f1128 | ||
|
|
13bcdbc6c9 | ||
|
|
cfba62db20 | ||
|
|
18fb69e36e | ||
|
|
474eb0f3fd | ||
|
|
7f47b53370 | ||
|
|
dc2907d3ce | ||
|
|
1af85811e0 | ||
|
|
1c1b19a478 | ||
|
|
66942d64ba | ||
|
|
2fb6ae08d7 | ||
|
|
bf8811e03e | ||
|
|
c8b502c571 | ||
|
|
81c11a975c | ||
|
|
0d370eb403 | ||
|
|
7492c3f1e3 | ||
|
|
515a8a84b7 | ||
|
|
dd6680efb2 | ||
|
|
a7158373cd | ||
|
|
6d50ec7199 | ||
|
|
95dbf98e8e | ||
|
|
d49323e4eb | ||
|
|
08c1e2aec9 | ||
|
|
a2c137df2e | ||
|
|
fe27dcdb8f | ||
|
|
028e136161 | ||
|
|
9a85a0a4d5 | ||
|
|
3a1cbc4d50 |
31
.github/workflows/pythonapp.yml
vendored
Normal file
31
.github/workflows/pythonapp.yml
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
name: Tests
|
||||
|
||||
on:
|
||||
push:
|
||||
paths:
|
||||
- "**/*.py"
|
||||
pull_request:
|
||||
paths:
|
||||
- "**/*.py"
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
matrix:
|
||||
os: [macos-latest, ubuntu-latest, windows-latest]
|
||||
python-version: [3.6, 3.7, 3.8, 3.9]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Set up Python ${{ matrix.python-version }}
|
||||
uses: actions/setup-python@v1
|
||||
with:
|
||||
python-version: ${{ matrix.python-version }}
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
pip install -r requirements.txt
|
||||
- name: Test with unittest
|
||||
run: |
|
||||
python -m unittest discover tests
|
||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -3,4 +3,4 @@ __pycache__
|
||||
dist/
|
||||
build/
|
||||
*.egg-info/
|
||||
jc/parsers.old/
|
||||
.github/
|
||||
|
||||
289
CHANGELOG
Normal file
289
CHANGELOG
Normal file
@@ -0,0 +1,289 @@
|
||||
jc changelog
|
||||
|
||||
20201231 v1.14.0
|
||||
- Add hashsum parser tested on linux, macos
|
||||
- Add hash parser tested on linux, macos
|
||||
- Add cksum parser tested on linux, macos
|
||||
- Add wc parser tested on linux, macos
|
||||
- Add printenv support under env parser
|
||||
- Add vdir support under ls parser
|
||||
- Add python 3.9 to github automation tests
|
||||
|
||||
20200805 v1.13.4
|
||||
- Update crontab and crontab-u parsers to tighten up variable detection
|
||||
- Update ping parser to tighten linux/bsd detection
|
||||
|
||||
20200804 v1.13.3
|
||||
- Update ping parser for Raspberry Pi compatibility
|
||||
|
||||
20200803 v1.13.2
|
||||
- Add key/value file parser (wrapper for ini parser)
|
||||
- Add date command parser
|
||||
- Update traceroute parser to more gracefully handle missing header row
|
||||
- Update traceroute parser to handle annotations
|
||||
- Update traceroute parser to only return successful probes
|
||||
|
||||
20200727 v1.13.1
|
||||
- Add route -6 tests
|
||||
|
||||
20200727 v1.13.0
|
||||
- Add ping and ping6 command parser tested on linux, macos, and freebsd
|
||||
- Add traceroute and traceroute6 command parser tested on linux, macos, and freebsd
|
||||
- Add tracepath command parser tested on linux
|
||||
- Update ini parser to support files only containing key/value pairs
|
||||
- Update uname parser exception with a hint to use "uname -a"
|
||||
- Update route parser to support IPv6 tables
|
||||
|
||||
20200711 v1.12.1
|
||||
- Fix tests when using older version of pygments library
|
||||
|
||||
20200710 v1.12.0
|
||||
- Add sysctl command parser tested on linux, macOS, and freebsd
|
||||
- Update the cli code to allow older versions of the pygments library (2.3.0) for debian packaging
|
||||
- Code cleanup on the cli
|
||||
- Add tests for the cli
|
||||
- Vendorize cgitb as tracebackplus for verbose debug messages
|
||||
|
||||
20200625 v1.11.8
|
||||
- Add verbose debug option using -dd argument
|
||||
|
||||
20200622 v1.11.7
|
||||
- Fix iptables parser issue which would not output the last chain
|
||||
|
||||
20200614 v1.11.6
|
||||
- Improve and standardize empty data check for all parsers
|
||||
|
||||
20200612 v1.11.5
|
||||
- Update airport_s parser to fix error on parsing empty data
|
||||
- Update arp parser to fix error on parsing empty data
|
||||
- Update blkid parser to fix error on parsing empty data
|
||||
- Update crontab parser to fix error on parsing empty data
|
||||
- Update crontab_u parser to fix error on parsing empty data
|
||||
- Update df parser to fix error on parsing empty data
|
||||
- Update free parser to fix error on parsing empty data
|
||||
- Update lsblk parser to fix error on parsing empty data
|
||||
- Update lsmod parser to fix error on parsing empty data
|
||||
- Update mount parser to fix error on parsing empty data
|
||||
- Update netstat parser to fix error on parsing empty data
|
||||
- Update ntpq parser to fix error on parsing empty data
|
||||
- Update ps parser to fix error on parsing empty data
|
||||
- Update route parser to fix error on parsing empty data
|
||||
- Update systemctl parser to fix error on parsing empty data
|
||||
- Update systemctl_lj parser to fix error on parsing empty data
|
||||
- Update systemctl_ls parser to fix error on parsing empty data
|
||||
- Update systemctl_luf parser to fix error on parsing empty data
|
||||
- Update uptime parser to fix error on parsing empty data
|
||||
- Update w parser to fix error on parsing empty data
|
||||
- Update xml parser to fix error on parsing empty data
|
||||
- Add tests to all parsers for no data condition
|
||||
- Update ss parser to fix integer fields
|
||||
|
||||
20200610 v1.11.4
|
||||
- Update ls parser to fix error on parsing an empty directory
|
||||
|
||||
20200609 v1.11.3
|
||||
- Add local parser plugin feature (contributed by Dean Serenevy)
|
||||
|
||||
20200530 v1.11.2
|
||||
- Update netstat parser to add freebsd support
|
||||
- Update netstat parser to add route_flags_pretty field
|
||||
- Update netstat parser to change osx_inode field name to unix_inode
|
||||
- Update netstat parser to change osx_flags field name to unix_flags
|
||||
- Update netstat parser to strip whitespace from state field
|
||||
- Update route parser to add flags_pretty field
|
||||
- Update arp parser to add permanent field (freebsd and osx)
|
||||
- Update arp parser to add expires field (freebsd)
|
||||
- Update w parser to strip whitespace from what field
|
||||
- Update last parser to fix FreeBSD issues
|
||||
- Update stat parser to change osx_flags field name to unix_flags
|
||||
- Update stat parser to add unix_device field for freebsd and osx
|
||||
- Fix freebsd compatibility message for df, fstab, mount, ntpq, stat, and uname parsers
|
||||
- Fix compatibility message for platforms that include the version number at the end (e.g. freebsd12)
|
||||
|
||||
20200523 v1.11.1
|
||||
- Update stat command parser to change osx_flags field to string
|
||||
|
||||
20200522 v1.11.0
|
||||
- Add dmidecode command parser
|
||||
- Update stat command parser to add OSX support
|
||||
- Update netstat command parser to add OSX support
|
||||
- Update netstat command parser to add -r (route) functionality for linux and OSX
|
||||
- Update netstat command parser to add -i (interface) functionality for linux and OSX
|
||||
|
||||
20200511 v1.10.12
|
||||
- Remove shebang from jc/cli.py for Fedora packaging
|
||||
|
||||
20200511 v1.10.11
|
||||
- Change file permissions for Fedora packaging
|
||||
|
||||
20200509 v1.10.10
|
||||
- Fix ls parser issue where the first file was skipped for ls -R on some platforms
|
||||
- Update last parser to handle 'gone - no logout' condition
|
||||
- Update netstat parser to handle bluetooth section (ignore gracefully for now)
|
||||
|
||||
20200508 v1.10.9
|
||||
- Add license info to vendorized ifconfig-parser class
|
||||
|
||||
20200508 v1.10.8
|
||||
- Add license file to dist for Fedora RPM packaging requirements
|
||||
- Remove tests from package to keep from polluting the global site-packages
|
||||
|
||||
20200501 v1.10.7
|
||||
- Requirements modifications for Fedora RPM packaging requirements
|
||||
|
||||
20200420 v1.10.6
|
||||
- Remove homebrew shim references from du osx tests
|
||||
|
||||
20200414 v1.10.5
|
||||
- Minor change of using sys.exit(0) instead of exit()
|
||||
|
||||
20200412 v1.10.4
|
||||
- Add color customization via JC_COLORS env variable
|
||||
|
||||
20200409 v1.10.3
|
||||
- Fix break on pipe error
|
||||
|
||||
20200409 v1.10.2
|
||||
- Change colors to ansi and match jello colors
|
||||
|
||||
20200402 v1.10.1
|
||||
- Code cleanup
|
||||
|
||||
20200402 v1.10.0
|
||||
- Add color output by default when not piping data to another program
|
||||
- Add -m option for monochrome output
|
||||
|
||||
20200326 v1.9.3
|
||||
- Add axfr support for dig command parser
|
||||
|
||||
20200312 v1.9.2
|
||||
- Updated arp parser to fix OSX detection for some edge cases
|
||||
|
||||
20200312 v1.9.1
|
||||
- Updated file command parser to make filename splitting more robust
|
||||
|
||||
20200311 v1.9.0
|
||||
- Added ntpq command parser
|
||||
- Added timedatectl status command parser
|
||||
- Added airport -I and airport -s command parser
|
||||
- Added file command parser
|
||||
- Optimized history command parser by https://github.com/philippeitis
|
||||
- Magic syntax fix for certain edge cases
|
||||
|
||||
20200308 v1.8.1
|
||||
- CLI optimizations by https://github.com/philippeitis
|
||||
- Refactored magic syntax function and added tests (https://github.com/philippeitis)
|
||||
- Github actions for CI testing on multiple platforms by https://github.com/philippeitis
|
||||
- Updated ls parser to fix parsing error in OSX with -lR when there are empty folders
|
||||
|
||||
20200303 v1.8.0
|
||||
- Added blkid command parser
|
||||
- Added last and lastb command parser
|
||||
- Added who command parser
|
||||
- Added CSV file parser
|
||||
- Added /etc/passwd file parser
|
||||
- Added /etc/shadow file parser
|
||||
- Added /etc/group file parser
|
||||
- Added /etc/gshadow file parser
|
||||
|
||||
20200227 v1.7.5
|
||||
- Updated ls parser to support filenames with newline characters
|
||||
|
||||
20200219 v1.7.4
|
||||
- Updated ls parser to support multiple directories, globbing, and -R (recursive)
|
||||
|
||||
20200211 v1.7.3
|
||||
- Add alternative 'magic' syntax: e.g. `jc ls -al`
|
||||
- Options can now be condensed (e.g. -prq is equivalant to -p -r -q)
|
||||
|
||||
20200208 v1.7.2
|
||||
- Include test fixtures in wheel and sdist
|
||||
|
||||
20200205 v1.7.1
|
||||
- Add YAML file parser
|
||||
- Add INI file parser
|
||||
- Add XML file parser
|
||||
- Add id parser (tested on linux and OSX)
|
||||
- Add crontab file parser with user support (tested on linux)
|
||||
- Add __version__ variable to parser modules
|
||||
- Add exit code on error
|
||||
- Updated history parser to output "line" as an integer
|
||||
- Updated compatibility list for some parsers
|
||||
- Bugfix in crontab file parser: header insertion was clobbering first row
|
||||
- Just-in-time loading of parser modules instead of loading all at start
|
||||
|
||||
20191217 v1.6.1
|
||||
- Add du parser (tested on linux and OSX)
|
||||
- Add crontab parser (tested on linux and OSX)
|
||||
- Add pip list parser (tested on linux and OSX)
|
||||
- Add pip show parser (tested on linux and OSX)
|
||||
- Add OSX support for the ifconfig, arp, df, mount, and uname parsers
|
||||
- Add tests for ls, dig, ps, w, uptime on OSX
|
||||
- Add about option
|
||||
- Add universal parsers to refactor repetitive code
|
||||
- Updated ifconfig parser to output 'state' as an array
|
||||
|
||||
20191117 v1.5.1
|
||||
- Add ss parser
|
||||
- Add stat parser
|
||||
- Add /etc/hosts parser
|
||||
- Add /etc/fstab parser
|
||||
- Add systemctl parser (includes list-jobs, list-sockets, and list-unit-files)
|
||||
- Add -r and raw=True options. By default, jc will now convert numbers and boolean, if possible, and add other semantic information, while the raw output will keep all values as text and provide a more literal JSON output
|
||||
- Add -q and quiet=True options to suppress warnings to stderr
|
||||
- Add -d option to debug parsing issues
|
||||
- Add compatibility warnings to stderr
|
||||
- Add documentation
|
||||
- Updated iptables parser to allow --line-numbers option
|
||||
- Updated lsblk parser to allow parsing of added columns
|
||||
- Updated mount parser: changed 'access' field name to 'options'
|
||||
- Updated netstat parser to allow parsing of unix sockets and raw network connections
|
||||
- Updated w parser to fix unaligned data where blanks are possible
|
||||
- Clean up code and reorganize package
|
||||
|
||||
20191031 v1.1.1
|
||||
- Add arp parser
|
||||
- Add dig parser
|
||||
- Add unit tests
|
||||
- fix netstat parser (remove side effects due to global variable)
|
||||
|
||||
20191025 v1.0.1
|
||||
- Add w parser
|
||||
- Add uptime parser
|
||||
- Add history parser
|
||||
- Flatten env parser output
|
||||
- Remove problematic characters from key names in: df, free, history, lsblk, lsof, and w
|
||||
- Where possible, lowercase all keys (except cases like env where the key is the variable name)
|
||||
- Remove integer values
|
||||
- Handle CTRL-C gracefully
|
||||
|
||||
20191023 v0.9.1
|
||||
- Add jobs parser
|
||||
- Add lsof parser
|
||||
- Add lsmod parser
|
||||
- No blocking if no piped data
|
||||
- Better help text
|
||||
- Clean up iptables parser code
|
||||
|
||||
20191022 v0.8.1
|
||||
- Add env parser
|
||||
- Add df parser
|
||||
- Add free parser
|
||||
- Add lsblk parser
|
||||
- Add mount parser
|
||||
- Add uname parser
|
||||
- Add iptables parser
|
||||
|
||||
20191021 v0.6.4
|
||||
- Flatten netstat parser output
|
||||
- Clean up argument parsing
|
||||
- Fix command help
|
||||
|
||||
20191018 v0.5.5
|
||||
- Fix netstat -p parsing for Ubuntu
|
||||
- Add ps parser
|
||||
- Add route parser
|
||||
- ls parser fixes
|
||||
|
||||
20191017 v0.2.0
|
||||
- ifconfig, ls, and netstat support
|
||||
2748
EXAMPLES.md
Normal file
2748
EXAMPLES.md
Normal file
File diff suppressed because it is too large
Load Diff
2
LICENSE.md
Executable file → Normal file
2
LICENSE.md
Executable file → Normal file
@@ -1,6 +1,6 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2019 Kelly Brazil
|
||||
Copyright (c) 2020 Kelly Brazil
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
||||
@@ -1,90 +0,0 @@
|
||||
jc changelog
|
||||
|
||||
20200205 v1.7.1
|
||||
- Add YAML file parser
|
||||
- Add INI file parser
|
||||
- Add XML file parser
|
||||
- Add id parser (tested on linux and OSX)
|
||||
- Add crontab file parser with user support (tested on linux)
|
||||
- Add __version__ variable to parser modules
|
||||
- Add exit code on error
|
||||
- Updated history parser to output "line" as an integer
|
||||
- Updated compatibility list for some parsers
|
||||
- Bugfix in crontab file parser: header insertion was clobbering first row
|
||||
- Just-in-time loading of parser modules instead of loading all at start
|
||||
|
||||
20191217 v1.6.1
|
||||
- Add du parser (tested on linux and OSX)
|
||||
- Add crontab parser (tested on linux and OSX)
|
||||
- Add pip list parser (tested on linux and OSX)
|
||||
- Add pip show parser (tested on linux and OSX)
|
||||
- Add OSX support for the ifconfig, arp, df, mount, and uname parsers
|
||||
- Add tests for ls, dig, ps, w, uptime on OSX
|
||||
- Add about option
|
||||
- Add universal parsers to refactor repetitive code
|
||||
- Updated ifconfig parser to output 'state' as an array
|
||||
|
||||
20191117 v1.5.1
|
||||
- Add ss parser
|
||||
- Add stat parser
|
||||
- Add /etc/hosts parser
|
||||
- Add /etc/fstab parser
|
||||
- Add systemctl parser (includes list-jobs, list-sockets, and list-unit-files)
|
||||
- Add -r and raw=True options. By default, jc will now convert numbers and boolean, if possible, and add other semantic information, while the raw output will keep all values as text and provide a more literal JSON output
|
||||
- Add -q and quiet=True options to suppress warnings to stderr
|
||||
- Add -d option to debug parsing issues
|
||||
- Add compatibility warnings to stderr
|
||||
- Add documentation
|
||||
- Updated iptables parser to allow --line-numbers option
|
||||
- Updated lsblk parser to allow parsing of added columns
|
||||
- Updated mount parser: changed 'access' field name to 'options'
|
||||
- Updated netstat parser to allow parsing of unix sockets and raw network connections
|
||||
- Updated w parser to fix unaligned data where blanks are possible
|
||||
- Clean up code and reorganize package
|
||||
|
||||
20191031 v1.1.1
|
||||
- Add arp parser
|
||||
- Add dig parser
|
||||
- Add unit tests
|
||||
- fix netstat parser (remove side effects due to global variable)
|
||||
|
||||
20191025 v1.0.1
|
||||
- Add w parser
|
||||
- Add uptime parser
|
||||
- Add history parser
|
||||
- Flatten env parser output
|
||||
- Remove problematic characters from key names in: df, free, history, lsblk, lsof, and w
|
||||
- Where possible, lowercase all keys (except cases like env where the key is the variable name)
|
||||
- Remove integer values
|
||||
- Handle CTRL-C gracefully
|
||||
|
||||
20191023 v0.9.1
|
||||
- Add jobs parser
|
||||
- Add lsof parser
|
||||
- Add lsmod parser
|
||||
- No blocking if no piped data
|
||||
- Better help text
|
||||
- Clean up iptables parser code
|
||||
|
||||
20191022 v0.8.1
|
||||
- Add env parser
|
||||
- Add df parser
|
||||
- Add free parser
|
||||
- Add lsblk parser
|
||||
- Add mount parser
|
||||
- Add uname parser
|
||||
- Add iptables parser
|
||||
|
||||
20191021 v0.6.4
|
||||
- Flatten netstat parser output
|
||||
- Clean up argument parsing
|
||||
- Fix command help
|
||||
|
||||
20191018 v0.5.5
|
||||
- Fix netstat -p parsing for Ubuntu
|
||||
- Add ps parser
|
||||
- Add route parser
|
||||
- ls parser fixes
|
||||
|
||||
20191017 v0.2.0
|
||||
- ifconfig, ls, and netstat support
|
||||
24
docgen.sh
24
docgen.sh
@@ -1,18 +1,31 @@
|
||||
#!/bin/bash
|
||||
# Generate docs.md
|
||||
# requires pydoc-markdown 2.1.0.post1
|
||||
|
||||
cd jc
|
||||
pydocmd simple jc+ > ../docs/readme.md
|
||||
pydocmd simple utils+ > ../docs/utils.md
|
||||
pydocmd simple jc.parsers.airport+ > ../docs/parsers/airport.md
|
||||
pydocmd simple jc.parsers.airport_s+ > ../docs/parsers/airport_s.md
|
||||
pydocmd simple jc.parsers.arp+ > ../docs/parsers/arp.md
|
||||
pydocmd simple jc.parsers.blkid+ > ../docs/parsers/blkid.md
|
||||
pydocmd simple jc.parsers.cksum+ > ../docs/parsers/cksum.md
|
||||
pydocmd simple jc.parsers.crontab+ > ../docs/parsers/crontab.md
|
||||
pydocmd simple jc.parsers.crontab_u+ > ../docs/parsers/crontab_u.md
|
||||
pydocmd simple jc.parsers.csv+ > ../docs/parsers/csv.md
|
||||
pydocmd simple jc.parsers.date+ > ../docs/parsers/date.md
|
||||
pydocmd simple jc.parsers.df+ > ../docs/parsers/df.md
|
||||
pydocmd simple jc.parsers.dig+ > ../docs/parsers/dig.md
|
||||
pydocmd simple jc.parsers.dmidecode+ > ../docs/parsers/dmidecode.md
|
||||
pydocmd simple jc.parsers.du+ > ../docs/parsers/du.md
|
||||
pydocmd simple jc.parsers.env+ > ../docs/parsers/env.md
|
||||
pydocmd simple jc.parsers.file+ > ../docs/parsers/file.md
|
||||
pydocmd simple jc.parsers.free+ > ../docs/parsers/free.md
|
||||
pydocmd simple jc.parsers.fstab+ > ../docs/parsers/fstab.md
|
||||
pydocmd simple jc.parsers.group+ > ../docs/parsers/group.md
|
||||
pydocmd simple jc.parsers.gshadow+ > ../docs/parsers/gshadow.md
|
||||
pydocmd simple jc.parsers.hash+ > ../docs/parsers/hash.md
|
||||
pydocmd simple jc.parsers.hashsum+ > ../docs/parsers/hashsum.md
|
||||
pydocmd simple jc.parsers.history+ > ../docs/parsers/history.md
|
||||
pydocmd simple jc.parsers.hosts+ > ../docs/parsers/hosts.md
|
||||
pydocmd simple jc.parsers.id+ > ../docs/parsers/id.md
|
||||
@@ -20,24 +33,35 @@ pydocmd simple jc.parsers.ifconfig+ > ../docs/parsers/ifconfig.md
|
||||
pydocmd simple jc.parsers.ini+ > ../docs/parsers/ini.md
|
||||
pydocmd simple jc.parsers.iptables+ > ../docs/parsers/iptables.md
|
||||
pydocmd simple jc.parsers.jobs+ > ../docs/parsers/jobs.md
|
||||
pydocmd simple jc.parsers.kv+ > ../docs/parsers/kv.md
|
||||
pydocmd simple jc.parsers.last+ > ../docs/parsers/last.md
|
||||
pydocmd simple jc.parsers.ls+ > ../docs/parsers/ls.md
|
||||
pydocmd simple jc.parsers.lsblk+ > ../docs/parsers/lsblk.md
|
||||
pydocmd simple jc.parsers.lsmod+ > ../docs/parsers/lsmod.md
|
||||
pydocmd simple jc.parsers.lsof+ > ../docs/parsers/lsof.md
|
||||
pydocmd simple jc.parsers.mount+ > ../docs/parsers/mount.md
|
||||
pydocmd simple jc.parsers.netstat+ > ../docs/parsers/netstat.md
|
||||
pydocmd simple jc.parsers.ntpq+ > ../docs/parsers/ntpq.md
|
||||
pydocmd simple jc.parsers.passwd+ > ../docs/parsers/passwd.md
|
||||
pydocmd simple jc.parsers.ping+ > ../docs/parsers/ping.md
|
||||
pydocmd simple jc.parsers.pip_list+ > ../docs/parsers/pip_list.md
|
||||
pydocmd simple jc.parsers.pip_show+ > ../docs/parsers/pip_show.md
|
||||
pydocmd simple jc.parsers.ps+ > ../docs/parsers/ps.md
|
||||
pydocmd simple jc.parsers.route+ > ../docs/parsers/route.md
|
||||
pydocmd simple jc.parsers.shadow+ > ../docs/parsers/shadow.md
|
||||
pydocmd simple jc.parsers.ss+ > ../docs/parsers/ss.md
|
||||
pydocmd simple jc.parsers.stat+ > ../docs/parsers/stat.md
|
||||
pydocmd simple jc.parsers.sysctl+ > ../docs/parsers/sysctl.md
|
||||
pydocmd simple jc.parsers.systemctl+ > ../docs/parsers/systemctl.md
|
||||
pydocmd simple jc.parsers.systemctl_lj+ > ../docs/parsers/systemctl_lj.md
|
||||
pydocmd simple jc.parsers.systemctl_ls+ > ../docs/parsers/systemctl_ls.md
|
||||
pydocmd simple jc.parsers.systemctl_luf+ > ../docs/parsers/systemctl_luf.md
|
||||
pydocmd simple jc.parsers.timedatectl+ > ../docs/parsers/timedatectl.md
|
||||
pydocmd simple jc.parsers.tracepath+ > ../docs/parsers/tracepath.md
|
||||
pydocmd simple jc.parsers.traceroute+ > ../docs/parsers/traceroute.md
|
||||
pydocmd simple jc.parsers.uname+ > ../docs/parsers/uname.md
|
||||
pydocmd simple jc.parsers.uptime+ > ../docs/parsers/uptime.md
|
||||
pydocmd simple jc.parsers.w+ > ../docs/parsers/w.md
|
||||
pydocmd simple jc.parsers.who+ > ../docs/parsers/who.md
|
||||
pydocmd simple jc.parsers.xml+ > ../docs/parsers/xml.md
|
||||
pydocmd simple jc.parsers.yaml+ > ../docs/parsers/yaml.md
|
||||
|
||||
121
docs/parsers/airport.md
Normal file
121
docs/parsers/airport.md
Normal file
@@ -0,0 +1,121 @@
|
||||
|
||||
# jc.parsers.airport
|
||||
jc - JSON CLI output utility `airport -I` command output parser
|
||||
|
||||
The `airport` program can be found at `/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport`.
|
||||
|
||||
Usage (cli):
|
||||
|
||||
$ airport -I | jc --airport
|
||||
|
||||
or
|
||||
|
||||
$ jc airport -I
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.airport
|
||||
result = jc.parsers.airport.parse(airport_command_output)
|
||||
|
||||
Compatibility:
|
||||
|
||||
'darwin'
|
||||
|
||||
Examples:
|
||||
|
||||
$ airport -I | jc --airport -p
|
||||
{
|
||||
"agrctlrssi": -66,
|
||||
"agrextrssi": 0,
|
||||
"agrctlnoise": -90,
|
||||
"agrextnoise": 0,
|
||||
"state": "running",
|
||||
"op_mode": "station",
|
||||
"lasttxrate": 195,
|
||||
"maxrate": 867,
|
||||
"lastassocstatus": 0,
|
||||
"802_11_auth": "open",
|
||||
"link_auth": "wpa2-psk",
|
||||
"bssid": "3c:37:86:15:ad:f9",
|
||||
"ssid": "SnazzleDazzle",
|
||||
"mcs": 0,
|
||||
"channel": "48,80"
|
||||
}
|
||||
|
||||
$ airport -I | jc --airport -p -r
|
||||
{
|
||||
"agrctlrssi": "-66",
|
||||
"agrextrssi": "0",
|
||||
"agrctlnoise": "-90",
|
||||
"agrextnoise": "0",
|
||||
"state": "running",
|
||||
"op_mode": "station",
|
||||
"lasttxrate": "195",
|
||||
"maxrate": "867",
|
||||
"lastassocstatus": "0",
|
||||
"802_11_auth": "open",
|
||||
"link_auth": "wpa2-psk",
|
||||
"bssid": "3c:37:86:15:ad:f9",
|
||||
"ssid": "SnazzleDazzle",
|
||||
"mcs": "0",
|
||||
"channel": "48,80"
|
||||
}
|
||||
|
||||
|
||||
## info
|
||||
```python
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## 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:
|
||||
|
||||
{
|
||||
"agrctlrssi": integer,
|
||||
"agrextrssi": integer,
|
||||
"agrctlnoise": integer,
|
||||
"agrextnoise": integer,
|
||||
"state": string,
|
||||
"op_mode": string,
|
||||
"lasttxrate": integer,
|
||||
"maxrate": integer,
|
||||
"lastassocstatus": integer,
|
||||
"802_11_auth": string,
|
||||
"link_auth": string,
|
||||
"bssid": string,
|
||||
"ssid": string,
|
||||
"mcs": integer,
|
||||
"channel": 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.
|
||||
|
||||
148
docs/parsers/airport_s.md
Normal file
148
docs/parsers/airport_s.md
Normal file
@@ -0,0 +1,148 @@
|
||||
|
||||
# jc.parsers.airport_s
|
||||
jc - JSON CLI output utility `airport -s` command output parser
|
||||
|
||||
The `airport` program can be found at `/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport`.
|
||||
|
||||
Usage (cli):
|
||||
|
||||
$ airport -s | jc --airport-s
|
||||
|
||||
or
|
||||
|
||||
$ jc airport -s
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.airport_s
|
||||
result = jc.parsers.airport_s.parse(airport_s_command_output)
|
||||
|
||||
Compatibility:
|
||||
|
||||
'darwin'
|
||||
|
||||
Examples:
|
||||
|
||||
$ airport -s | jc --airport-s -p
|
||||
[
|
||||
{
|
||||
"ssid": "DIRECT-4A-HP OfficeJet 3830",
|
||||
"bssid": "00:67:eb:2a:a7:3b",
|
||||
"rssi": -90,
|
||||
"channel": "6",
|
||||
"ht": true,
|
||||
"cc": "--",
|
||||
"security": [
|
||||
"WPA2(PSK/AES/AES)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"ssid": "Latitude38",
|
||||
"bssid": "c0:ff:d5:d2:7a:f3",
|
||||
"rssi": -85,
|
||||
"channel": "11",
|
||||
"ht": true,
|
||||
"cc": "US",
|
||||
"security": [
|
||||
"WPA2(PSK/AES/AES)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"ssid": "xfinitywifi",
|
||||
"bssid": "6e:e3:0e:b8:45:99",
|
||||
"rssi": -83,
|
||||
"channel": "11",
|
||||
"ht": true,
|
||||
"cc": "US",
|
||||
"security": [
|
||||
"NONE"
|
||||
]
|
||||
},
|
||||
...
|
||||
]
|
||||
|
||||
$ airport -s | jc --airport -p -r
|
||||
[
|
||||
{
|
||||
"ssid": "DIRECT-F3-HP ENVY 5660 series",
|
||||
"bssid": "b0:5a:da:6f:0a:d4",
|
||||
"rssi": "-93",
|
||||
"channel": "1",
|
||||
"ht": "Y",
|
||||
"cc": "--",
|
||||
"security": "WPA2(PSK/AES/AES)"
|
||||
},
|
||||
{
|
||||
"ssid": "YouAreInfected-5",
|
||||
"bssid": "5c:e3:0e:c2:85:da",
|
||||
"rssi": "-85",
|
||||
"channel": "36",
|
||||
"ht": "Y",
|
||||
"cc": "US",
|
||||
"security": "WPA(PSK/AES,TKIP/TKIP) WPA2(PSK/AES,TKIP/TKIP)"
|
||||
},
|
||||
{
|
||||
"ssid": "YuanFamily",
|
||||
"bssid": "5c:e3:0e:b8:5f:9a",
|
||||
"rssi": "-84",
|
||||
"channel": "11",
|
||||
"ht": "Y",
|
||||
"cc": "US",
|
||||
"security": "WPA(PSK/AES,TKIP/TKIP) WPA2(PSK/AES,TKIP/TKIP)"
|
||||
},
|
||||
...
|
||||
]
|
||||
|
||||
|
||||
## info
|
||||
```python
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## process
|
||||
```python
|
||||
process(proc_data)
|
||||
```
|
||||
|
||||
Final processing to conform to the schema.
|
||||
|
||||
Parameters:
|
||||
|
||||
proc_data: (dictionary) raw structured data to process
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Structured data with the following schema:
|
||||
[
|
||||
{
|
||||
"ssid": string,
|
||||
"bssid": string,
|
||||
"rssi": integer,
|
||||
"channel": string,
|
||||
"ht": boolean,
|
||||
"cc": string,
|
||||
"security": [
|
||||
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:
|
||||
|
||||
List of dictionaries. Raw or processed structured data.
|
||||
|
||||
@@ -1,13 +1,21 @@
|
||||
|
||||
# jc.parsers.arp
|
||||
jc - JSON CLI output utility arp Parser
|
||||
jc - JSON CLI output utility `arp` command output parser
|
||||
|
||||
Usage:
|
||||
Supports `arp` and `arp -a` output.
|
||||
|
||||
specify --arp as the first argument if the piped input is coming from:
|
||||
Usage (cli):
|
||||
|
||||
arp
|
||||
or
|
||||
arp -a
|
||||
$ arp | jc --arp
|
||||
|
||||
or
|
||||
|
||||
$ jc arp
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.arp
|
||||
result = jc.parsers.arp.parse(arp_command_output)
|
||||
|
||||
Compatibility:
|
||||
|
||||
@@ -59,6 +67,8 @@ Examples:
|
||||
"hwtype": "ether",
|
||||
"hwaddress": "00:50:56:f0:98:26",
|
||||
"iface": "ens33"
|
||||
"permanent": false,
|
||||
"expires": 1182
|
||||
},
|
||||
{
|
||||
"name": "gateway",
|
||||
@@ -66,6 +76,8 @@ Examples:
|
||||
"hwtype": "ether",
|
||||
"hwaddress": "00:50:56:f7:4a:fc",
|
||||
"iface": "ens33"
|
||||
"permanent": false,
|
||||
"expires": 110
|
||||
}
|
||||
]
|
||||
|
||||
@@ -77,6 +89,8 @@ Examples:
|
||||
"hwtype": "ether",
|
||||
"hwaddress": "00:50:56:fe:7a:b4",
|
||||
"iface": "ens33"
|
||||
"permanent": false,
|
||||
"expires": "1182"
|
||||
},
|
||||
{
|
||||
"name": "_gateway",
|
||||
@@ -84,14 +98,18 @@ Examples:
|
||||
"hwtype": "ether",
|
||||
"hwaddress": "00:50:56:f7:4a:fc",
|
||||
"iface": "ens33"
|
||||
"permanent": false,
|
||||
"expires": "110"
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
## info
|
||||
```python
|
||||
info(self, /, *args, **kwargs)
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## process
|
||||
```python
|
||||
process(proc_data)
|
||||
@@ -114,10 +132,13 @@ Returns:
|
||||
"hwtype": string,
|
||||
"hwaddress": string,
|
||||
"flags_mask": string,
|
||||
"iface": string
|
||||
"iface": string,
|
||||
"permanent": boolean,
|
||||
"expires": integer
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
## parse
|
||||
```python
|
||||
parse(data, raw=False, quiet=False)
|
||||
|
||||
161
docs/parsers/blkid.md
Normal file
161
docs/parsers/blkid.md
Normal file
@@ -0,0 +1,161 @@
|
||||
|
||||
# jc.parsers.blkid
|
||||
jc - JSON CLI output utility `blkid` command output parser
|
||||
|
||||
Usage (cli):
|
||||
|
||||
$ blkid | jc --blkid
|
||||
|
||||
or
|
||||
|
||||
$ jc blkid
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.blkid
|
||||
result = jc.parsers.blkid.parse(blkid_command_output)
|
||||
|
||||
Compatibility:
|
||||
|
||||
'linux'
|
||||
|
||||
Examples:
|
||||
|
||||
$ blkid | jc --blkid -p
|
||||
[
|
||||
{
|
||||
"device": "/dev/sda1",
|
||||
"uuid": "05d927ab-5875-49e4-ada1-7f46cb32c932",
|
||||
"type": "xfs"
|
||||
},
|
||||
{
|
||||
"device": "/dev/sda2",
|
||||
"uuid": "3klkIj-w1kk-DkJi-0XBJ-y3i7-i2Ac-vHqWBM",
|
||||
"type": "LVM2_member"
|
||||
},
|
||||
{
|
||||
"device": "/dev/mapper/centos-root",
|
||||
"uuid": "07d718ff-950c-4e5b-98f0-42a1147c77d9",
|
||||
"type": "xfs"
|
||||
},
|
||||
{
|
||||
"device": "/dev/mapper/centos-swap",
|
||||
"uuid": "615eb89a-bcbf-46fd-80e3-c483ff5c931f",
|
||||
"type": "swap"
|
||||
}
|
||||
]
|
||||
|
||||
$ sudo blkid -o udev -ip /dev/sda2 | jc --blkid -p
|
||||
[
|
||||
{
|
||||
"id_fs_uuid": "3klkIj-w1kk-DkJi-0XBJ-y3i7-i2Ac-vHqWBM",
|
||||
"id_fs_uuid_enc": "3klkIj-w1kk-DkJi-0XBJ-y3i7-i2Ac-vHqWBM",
|
||||
"id_fs_version": "LVM2\x20001",
|
||||
"id_fs_type": "LVM2_member",
|
||||
"id_fs_usage": "raid",
|
||||
"id_iolimit_minimum_io_size": 512,
|
||||
"id_iolimit_physical_sector_size": 512,
|
||||
"id_iolimit_logical_sector_size": 512,
|
||||
"id_part_entry_scheme": "dos",
|
||||
"id_part_entry_type": "0x8e",
|
||||
"id_part_entry_number": 2,
|
||||
"id_part_entry_offset": 2099200,
|
||||
"id_part_entry_size": 39843840,
|
||||
"id_part_entry_disk": "8:0"
|
||||
}
|
||||
]
|
||||
|
||||
$ sudo blkid -ip /dev/sda1 | jc --blkid -p -r
|
||||
[
|
||||
{
|
||||
"devname": "/dev/sda1",
|
||||
"uuid": "05d927bb-5875-49e3-ada1-7f46cb31c932",
|
||||
"type": "xfs",
|
||||
"usage": "filesystem",
|
||||
"minimum_io_size": "512",
|
||||
"physical_sector_size": "512",
|
||||
"logical_sector_size": "512",
|
||||
"part_entry_scheme": "dos",
|
||||
"part_entry_type": "0x83",
|
||||
"part_entry_flags": "0x80",
|
||||
"part_entry_number": "1",
|
||||
"part_entry_offset": "2048",
|
||||
"part_entry_size": "2097152",
|
||||
"part_entry_disk": "8:0"
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
## info
|
||||
```python
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## process
|
||||
```python
|
||||
process(proc_data)
|
||||
```
|
||||
|
||||
Final processing to conform to the schema.
|
||||
|
||||
Parameters:
|
||||
|
||||
proc_data: (dictionary) raw structured data to process
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Structured data with the following schema:
|
||||
|
||||
[
|
||||
{
|
||||
"device": string,
|
||||
"uuid": string,
|
||||
"type": string,
|
||||
"usage": string,
|
||||
"part_entry_scheme": string,
|
||||
"part_entry_type": string,
|
||||
"part_entry_flags": string,
|
||||
"part_entry_number": integer,
|
||||
"part_entry_offset": integer,
|
||||
"part_entry_size": integer,
|
||||
"part_entry_disk": string,
|
||||
"id_fs_uuid": string,
|
||||
"id_fs_uuid_enc": string,
|
||||
"id_fs_version": string,
|
||||
"id_fs_type": string,
|
||||
"id_fs_usage": string,
|
||||
"id_part_entry_scheme": string,
|
||||
"id_part_entry_type": string,
|
||||
"id_part_entry_flags": string,
|
||||
"id_part_entry_number": integer,
|
||||
"id_part_entry_offset": integer,
|
||||
"id_part_entry_size": integer,
|
||||
"id_iolimit_minimum_io_size": integer,
|
||||
"id_iolimit_physical_sector_size": integer,
|
||||
"id_iolimit_logical_sector_size": integer,
|
||||
"id_part_entry_disk": string,
|
||||
"minimum_io_size": integer,
|
||||
"physical_sector_size": integer,
|
||||
"logical_sector_size": integer
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
## 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:
|
||||
|
||||
List of dictionaries. Raw or processed structured data.
|
||||
|
||||
95
docs/parsers/cksum.md
Normal file
95
docs/parsers/cksum.md
Normal file
@@ -0,0 +1,95 @@
|
||||
|
||||
# jc.parsers.cksum
|
||||
jc - JSON CLI output utility `cksum` command output parser
|
||||
|
||||
This parser works with the following checksum calculation utilities:
|
||||
- `sum`
|
||||
- `cksum`
|
||||
|
||||
Usage (cli):
|
||||
|
||||
$ cksum file.txt | jc --cksum
|
||||
|
||||
or
|
||||
|
||||
$ jc cksum file.txt
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.cksum
|
||||
result = jc.parsers.cksum.parse(cksum_command_output)
|
||||
|
||||
Compatibility:
|
||||
|
||||
'linux', 'darwin', 'cygwin', 'aix', 'freebsd'
|
||||
|
||||
Examples:
|
||||
|
||||
$ cksum * | jc --cksum -p
|
||||
[
|
||||
{
|
||||
"filename": "__init__.py",
|
||||
"checksum": 4294967295,
|
||||
"blocks": 0
|
||||
},
|
||||
{
|
||||
"filename": "airport.py",
|
||||
"checksum": 2208551092,
|
||||
"blocks": 3745
|
||||
},
|
||||
{
|
||||
"filename": "airport_s.py",
|
||||
"checksum": 1113817598,
|
||||
"blocks": 4572
|
||||
},
|
||||
...
|
||||
]
|
||||
|
||||
|
||||
## info
|
||||
```python
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## process
|
||||
```python
|
||||
process(proc_data)
|
||||
```
|
||||
|
||||
Final processing to conform to the schema.
|
||||
|
||||
Parameters:
|
||||
|
||||
proc_data: (dictionary) raw structured data to process
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Structured data with the following schema:
|
||||
|
||||
[
|
||||
{
|
||||
"filename": string,
|
||||
"checksum": integer,
|
||||
"blocks": integer
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
## 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:
|
||||
|
||||
List of dictionaries. Raw or processed structured data.
|
||||
|
||||
@@ -1,9 +1,21 @@
|
||||
|
||||
# jc.parsers.crontab
|
||||
jc - JSON CLI output utility crontab file Parser
|
||||
jc - JSON CLI output utility `crontab -l` command output and crontab file parser
|
||||
|
||||
Usage:
|
||||
Supports `crontab -l` command output and crontab files.
|
||||
|
||||
specify --crontab as the first argument if the piped input is coming from a crontab file
|
||||
Usage (cli):
|
||||
|
||||
$ crontab -l | jc --crontab
|
||||
|
||||
or
|
||||
|
||||
$ jc crontab -l
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.crontab
|
||||
result = jc.parsers.crontab.parse(crontab_output)
|
||||
|
||||
Compatibility:
|
||||
|
||||
@@ -11,7 +23,7 @@ Compatibility:
|
||||
|
||||
Examples:
|
||||
|
||||
$ cat /etc/crontab | jc --crontab -p
|
||||
$ crontab -l | jc --crontab -p
|
||||
{
|
||||
"variables": [
|
||||
{
|
||||
@@ -128,11 +140,13 @@ Examples:
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
## info
|
||||
```python
|
||||
info(self, /, *args, **kwargs)
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## process
|
||||
```python
|
||||
process(proc_data)
|
||||
@@ -178,6 +192,7 @@ Returns:
|
||||
}
|
||||
|
||||
|
||||
|
||||
## parse
|
||||
```python
|
||||
parse(data, raw=False, quiet=False)
|
||||
|
||||
@@ -1,9 +1,17 @@
|
||||
|
||||
# jc.parsers.crontab_u
|
||||
jc - JSON CLI output utility crontab file Parser
|
||||
jc - JSON CLI output utility `crontab -l` command output and crontab file parser
|
||||
|
||||
Usage:
|
||||
This version of the `crontab -l` parser supports output that contains user information for processes.
|
||||
|
||||
specify --crontab-u as the first argument if the piped input is coming from a crontab file with User specified
|
||||
Usage (cli):
|
||||
|
||||
$ crontab -l | jc --crontab-u
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.crontab_u
|
||||
result = jc.parsers.crontab_u.parse(crontab_u_output)
|
||||
|
||||
Compatibility:
|
||||
|
||||
@@ -11,7 +19,7 @@ Compatibility:
|
||||
|
||||
Examples:
|
||||
|
||||
$ cat /etc/crontab | jc --crontab -p
|
||||
$ cat /etc/crontab | jc --crontab-u -p
|
||||
{
|
||||
"variables": [
|
||||
{
|
||||
@@ -129,11 +137,13 @@ Examples:
|
||||
|
||||
|
||||
|
||||
|
||||
## info
|
||||
```python
|
||||
info(self, /, *args, **kwargs)
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## process
|
||||
```python
|
||||
process(proc_data)
|
||||
@@ -180,6 +190,7 @@ Returns:
|
||||
}
|
||||
|
||||
|
||||
|
||||
## parse
|
||||
```python
|
||||
parse(data, raw=False, quiet=False)
|
||||
|
||||
113
docs/parsers/csv.md
Normal file
113
docs/parsers/csv.md
Normal file
@@ -0,0 +1,113 @@
|
||||
|
||||
# jc.parsers.csv
|
||||
jc - JSON CLI output utility `csv` file parser
|
||||
|
||||
The `csv` parser will attempt to automatically detect the delimiter character. If the delimiter cannot be detected it will default to comma. The first row of the file must be a header row.
|
||||
|
||||
Usage (cli):
|
||||
|
||||
$ cat file.csv | jc --csv
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.csv
|
||||
result = jc.parsers.csv.parse(csv_output)
|
||||
|
||||
Compatibility:
|
||||
|
||||
'linux', 'darwin', 'cygwin', 'win32', 'aix', 'freebsd'
|
||||
|
||||
Examples:
|
||||
|
||||
$ cat homes.csv
|
||||
"Sell", "List", "Living", "Rooms", "Beds", "Baths", "Age", "Acres", "Taxes"
|
||||
142, 160, 28, 10, 5, 3, 60, 0.28, 3167
|
||||
175, 180, 18, 8, 4, 1, 12, 0.43, 4033
|
||||
129, 132, 13, 6, 3, 1, 41, 0.33, 1471
|
||||
...
|
||||
|
||||
$ cat homes.csv | jc --csv -p
|
||||
[
|
||||
{
|
||||
"Sell": "142",
|
||||
"List": "160",
|
||||
"Living": "28",
|
||||
"Rooms": "10",
|
||||
"Beds": "5",
|
||||
"Baths": "3",
|
||||
"Age": "60",
|
||||
"Acres": "0.28",
|
||||
"Taxes": "3167"
|
||||
},
|
||||
{
|
||||
"Sell": "175",
|
||||
"List": "180",
|
||||
"Living": "18",
|
||||
"Rooms": "8",
|
||||
"Beds": "4",
|
||||
"Baths": "1",
|
||||
"Age": "12",
|
||||
"Acres": "0.43",
|
||||
"Taxes": "4033"
|
||||
},
|
||||
{
|
||||
"Sell": "129",
|
||||
"List": "132",
|
||||
"Living": "13",
|
||||
"Rooms": "6",
|
||||
"Beds": "3",
|
||||
"Baths": "1",
|
||||
"Age": "41",
|
||||
"Acres": "0.33",
|
||||
"Taxes": "1471"
|
||||
},
|
||||
...
|
||||
]
|
||||
|
||||
|
||||
## info
|
||||
```python
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## process
|
||||
```python
|
||||
process(proc_data)
|
||||
```
|
||||
|
||||
Final processing to conform to the schema.
|
||||
|
||||
Parameters:
|
||||
|
||||
proc_data: (dictionary) raw structured data to process
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Each dictionary represents a row in the csv file:
|
||||
|
||||
[
|
||||
{
|
||||
csv file converted to a Dictionary
|
||||
https://docs.python.org/3/library/csv.html
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
## 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:
|
||||
|
||||
List of dictionaries. Raw or processed structured data.
|
||||
|
||||
102
docs/parsers/date.md
Normal file
102
docs/parsers/date.md
Normal file
@@ -0,0 +1,102 @@
|
||||
|
||||
# jc.parsers.date
|
||||
jc - JSON CLI output utility `date` command output parser
|
||||
|
||||
Usage (cli):
|
||||
|
||||
$ date | jc --date
|
||||
|
||||
or
|
||||
|
||||
$ jc date
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.date
|
||||
result = jc.parsers.date.parse(date_command_output)
|
||||
|
||||
Compatibility:
|
||||
|
||||
'linux', 'darwin', 'freebsd'
|
||||
|
||||
Examples:
|
||||
|
||||
$ date | jc --date -p
|
||||
{
|
||||
"year": 2020,
|
||||
"month_num": 7,
|
||||
"day": 31,
|
||||
"hour": 16,
|
||||
"minute": 48,
|
||||
"second": 11,
|
||||
"month": "Jul",
|
||||
"weekday": "Fri",
|
||||
"weekday_num": 6,
|
||||
"timezone": "PDT"
|
||||
}
|
||||
|
||||
$ date | jc --date -p -r
|
||||
{
|
||||
"year": "2020",
|
||||
"month": "Jul",
|
||||
"day": "31",
|
||||
"weekday": "Fri",
|
||||
"hour": "16",
|
||||
"minute": "50",
|
||||
"second": "01",
|
||||
"timezone": "PDT"
|
||||
}
|
||||
|
||||
|
||||
## info
|
||||
```python
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## 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:
|
||||
|
||||
{
|
||||
"year": integer,
|
||||
"month_num": integer,
|
||||
"day": integer,
|
||||
"hour": integer,
|
||||
"minute": integer,
|
||||
"second": integer,
|
||||
"month": string,
|
||||
"weekday": string,
|
||||
"weekday_num": integer,
|
||||
"timezone": 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.
|
||||
|
||||
@@ -1,13 +1,23 @@
|
||||
|
||||
# jc.parsers.df
|
||||
jc - JSON CLI output utility df Parser
|
||||
jc - JSON CLI output utility `df` command output parser
|
||||
|
||||
Usage:
|
||||
Usage (cli):
|
||||
|
||||
specify --df as the first argument if the piped input is coming from df
|
||||
$ df | jc --df
|
||||
|
||||
or
|
||||
|
||||
$ jc df
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.df
|
||||
result = jc.parsers.df.parse(df_command_output)
|
||||
|
||||
Compatibility:
|
||||
|
||||
'linux', 'darwin'
|
||||
'linux', 'darwin', 'freebsd'
|
||||
|
||||
Examples:
|
||||
|
||||
@@ -69,11 +79,13 @@ Examples:
|
||||
...
|
||||
]
|
||||
|
||||
|
||||
## info
|
||||
```python
|
||||
info(self, /, *args, **kwargs)
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## process
|
||||
```python
|
||||
process(proc_data)
|
||||
@@ -106,6 +118,7 @@ Returns:
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
## parse
|
||||
```python
|
||||
parse(data, raw=False, quiet=False)
|
||||
|
||||
@@ -1,9 +1,19 @@
|
||||
|
||||
# jc.parsers.dig
|
||||
jc - JSON CLI output utility dig Parser
|
||||
jc - JSON CLI output utility `dig` command output parser
|
||||
|
||||
Usage:
|
||||
Usage (cli):
|
||||
|
||||
Specify --dig as the first argument if the piped input is coming from dig
|
||||
$ dig example.com | jc --dig
|
||||
|
||||
or
|
||||
|
||||
$ jc dig example.com
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.dig
|
||||
result = jc.parsers.dig.parse(dig_command_output)
|
||||
|
||||
Compatibility:
|
||||
|
||||
@@ -321,11 +331,13 @@ Examples:
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
## info
|
||||
```python
|
||||
info(self, /, *args, **kwargs)
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## process
|
||||
```python
|
||||
process(proc_data)
|
||||
@@ -353,6 +365,15 @@ Returns:
|
||||
"answer_num": integer,
|
||||
"authority_num": integer,
|
||||
"additional_num": integer,
|
||||
"axfr": [
|
||||
{
|
||||
"name": string,
|
||||
"class": string,
|
||||
"type": string,
|
||||
"ttl": integer,
|
||||
"data": string
|
||||
}
|
||||
],
|
||||
"question": {
|
||||
"name": string,
|
||||
"class": string,
|
||||
@@ -380,9 +401,11 @@ Returns:
|
||||
"server": string,
|
||||
"when": string,
|
||||
"rcvd": integer
|
||||
"size": string
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
## parse
|
||||
```python
|
||||
parse(data, raw=False, quiet=False)
|
||||
|
||||
166
docs/parsers/dmidecode.md
Normal file
166
docs/parsers/dmidecode.md
Normal file
@@ -0,0 +1,166 @@
|
||||
|
||||
# jc.parsers.dmidecode
|
||||
jc - JSON CLI output utility `dmidecode` command output parser
|
||||
|
||||
Usage (cli):
|
||||
|
||||
$ dmidecode | jc --dmidecode
|
||||
|
||||
or
|
||||
|
||||
$ jc dmidecode
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.dmidecode
|
||||
result = jc.parsers.dmidecode.parse(dmidecode_command_output)
|
||||
|
||||
Compatibility:
|
||||
|
||||
'linux'
|
||||
|
||||
Examples:
|
||||
|
||||
# dmidecode | jc --dmidecode -p
|
||||
[
|
||||
{
|
||||
"handle": "0x0000",
|
||||
"type": 0,
|
||||
"bytes": 24,
|
||||
"description": "BIOS Information",
|
||||
"values": {
|
||||
"vendor": "Phoenix Technologies LTD",
|
||||
"version": "6.00",
|
||||
"release_date": "04/13/2018",
|
||||
"address": "0xEA490",
|
||||
"runtime_size": "88944 bytes",
|
||||
"rom_size": "64 kB",
|
||||
"characteristics": [
|
||||
"ISA is supported",
|
||||
"PCI is supported",
|
||||
"PC Card (PCMCIA) is supported",
|
||||
"PNP is supported",
|
||||
"APM is supported",
|
||||
"BIOS is upgradeable",
|
||||
"BIOS shadowing is allowed",
|
||||
"ESCD support is available",
|
||||
"Boot from CD is supported",
|
||||
"Selectable boot is supported",
|
||||
"EDD is supported",
|
||||
"Print screen service is supported (int 5h)",
|
||||
"8042 keyboard services are supported (int 9h)",
|
||||
"Serial services are supported (int 14h)",
|
||||
"Printer services are supported (int 17h)",
|
||||
"CGA/mono video services are supported (int 10h)",
|
||||
"ACPI is supported",
|
||||
"Smart battery is supported",
|
||||
"BIOS boot specification is supported",
|
||||
"Function key-initiated network boot is supported",
|
||||
"Targeted content distribution is supported"
|
||||
],
|
||||
"bios_revision": "4.6",
|
||||
"firmware_revision": "0.0"
|
||||
}
|
||||
},
|
||||
...
|
||||
]
|
||||
|
||||
# dmidecode | jc --dmidecode -p -r
|
||||
[
|
||||
{
|
||||
"handle": "0x0000",
|
||||
"type": "0",
|
||||
"bytes": "24",
|
||||
"description": "BIOS Information",
|
||||
"values": {
|
||||
"vendor": "Phoenix Technologies LTD",
|
||||
"version": "6.00",
|
||||
"release_date": "04/13/2018",
|
||||
"address": "0xEA490",
|
||||
"runtime_size": "88944 bytes",
|
||||
"rom_size": "64 kB",
|
||||
"characteristics": [
|
||||
"ISA is supported",
|
||||
"PCI is supported",
|
||||
"PC Card (PCMCIA) is supported",
|
||||
"PNP is supported",
|
||||
"APM is supported",
|
||||
"BIOS is upgradeable",
|
||||
"BIOS shadowing is allowed",
|
||||
"ESCD support is available",
|
||||
"Boot from CD is supported",
|
||||
"Selectable boot is supported",
|
||||
"EDD is supported",
|
||||
"Print screen service is supported (int 5h)",
|
||||
"8042 keyboard services are supported (int 9h)",
|
||||
"Serial services are supported (int 14h)",
|
||||
"Printer services are supported (int 17h)",
|
||||
"CGA/mono video services are supported (int 10h)",
|
||||
"ACPI is supported",
|
||||
"Smart battery is supported",
|
||||
"BIOS boot specification is supported",
|
||||
"Function key-initiated network boot is supported",
|
||||
"Targeted content distribution is supported"
|
||||
],
|
||||
"bios_revision": "4.6",
|
||||
"firmware_revision": "0.0"
|
||||
}
|
||||
},
|
||||
...
|
||||
]
|
||||
|
||||
|
||||
## info
|
||||
```python
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## process
|
||||
```python
|
||||
process(proc_data)
|
||||
```
|
||||
|
||||
Final processing to conform to the schema.
|
||||
|
||||
Parameters:
|
||||
|
||||
proc_data: (dictionary) raw structured data to process
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Structured data with the following schema:
|
||||
|
||||
[
|
||||
{
|
||||
"handle": string,
|
||||
"type": integer,
|
||||
"bytes": integer,
|
||||
"description": string,
|
||||
"values": { (null if empty)
|
||||
"lowercase_no_spaces_keys": string,
|
||||
"multiline_key_values": [
|
||||
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:
|
||||
|
||||
List of dictionaries. Raw or processed structured data.
|
||||
|
||||
@@ -1,9 +1,19 @@
|
||||
|
||||
# jc.parsers.du
|
||||
jc - JSON CLI output utility du Parser
|
||||
jc - JSON CLI output utility `du` command output parser
|
||||
|
||||
Usage:
|
||||
Usage (cli):
|
||||
|
||||
specify --du as the first argument if the piped input is coming from du
|
||||
$ du | jc --du
|
||||
|
||||
or
|
||||
|
||||
$ jc du
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.du
|
||||
result = jc.parsers.du.parse(du_command_output)
|
||||
|
||||
Compatibility:
|
||||
|
||||
@@ -69,11 +79,13 @@ Examples:
|
||||
...
|
||||
]
|
||||
|
||||
|
||||
## info
|
||||
```python
|
||||
info(self, /, *args, **kwargs)
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## process
|
||||
```python
|
||||
process(proc_data)
|
||||
@@ -96,6 +108,7 @@ Returns:
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
## parse
|
||||
```python
|
||||
parse(data, raw=False, quiet=False)
|
||||
|
||||
@@ -1,9 +1,21 @@
|
||||
|
||||
# jc.parsers.env
|
||||
jc - JSON CLI output utility env Parser
|
||||
jc - JSON CLI output utility `env` and `printenv` command output parser
|
||||
|
||||
Usage:
|
||||
This parser will output a list of dictionaries each containing `name` and `value` keys. If you would like a simple dictionary output, then use the `-r` command-line option or the `raw=True` argument in the `parse()` function.
|
||||
|
||||
specify --env as the first argument if the piped input is coming from env
|
||||
Usage (cli):
|
||||
|
||||
$ env | jc --env
|
||||
|
||||
or
|
||||
|
||||
$ jc env
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.env
|
||||
result = jc.parsers.env.parse(env_command_output)
|
||||
|
||||
Compatibility:
|
||||
|
||||
@@ -49,11 +61,13 @@ Examples:
|
||||
"_": "/usr/bin/env"
|
||||
}
|
||||
|
||||
|
||||
## info
|
||||
```python
|
||||
info(self, /, *args, **kwargs)
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## process
|
||||
```python
|
||||
process(proc_data)
|
||||
@@ -76,6 +90,7 @@ Returns:
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
## parse
|
||||
```python
|
||||
parse(data, raw=False, quiet=False)
|
||||
|
||||
103
docs/parsers/file.md
Normal file
103
docs/parsers/file.md
Normal file
@@ -0,0 +1,103 @@
|
||||
|
||||
# jc.parsers.file
|
||||
jc - JSON CLI output utility `file` command output parser
|
||||
|
||||
Usage (cli):
|
||||
|
||||
$ file * | jc --file
|
||||
|
||||
or
|
||||
|
||||
$ jc file *
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.file
|
||||
result = jc.parsers.file.parse(file_command_output)
|
||||
|
||||
Compatibility:
|
||||
|
||||
'linux', 'aix', 'freebsd', 'darwin'
|
||||
|
||||
Examples:
|
||||
|
||||
$ file * | jc --file -p
|
||||
[
|
||||
{
|
||||
"filename": "Applications",
|
||||
"type": "directory"
|
||||
},
|
||||
{
|
||||
"filename": "another file with spaces",
|
||||
"type": "empty"
|
||||
},
|
||||
{
|
||||
"filename": "argstest.py",
|
||||
"type": "Python script text executable, ASCII text"
|
||||
},
|
||||
{
|
||||
"filename": "blkid-p.out",
|
||||
"type": "ASCII text"
|
||||
},
|
||||
{
|
||||
"filename": "blkid-pi.out",
|
||||
"type": "ASCII text, with very long lines"
|
||||
},
|
||||
{
|
||||
"filename": "cd_catalog.xml",
|
||||
"type": "XML 1.0 document text, ASCII text, with CRLF line terminators"
|
||||
},
|
||||
{
|
||||
"filename": "centosserial.sh",
|
||||
"type": "Bourne-Again shell script text executable, UTF-8 Unicode text"
|
||||
},
|
||||
...
|
||||
]
|
||||
|
||||
|
||||
## info
|
||||
```python
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## process
|
||||
```python
|
||||
process(proc_data)
|
||||
```
|
||||
|
||||
Final processing to conform to the schema.
|
||||
|
||||
Parameters:
|
||||
|
||||
proc_data: (dictionary) raw structured data to process
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Structured data with the following schema:
|
||||
|
||||
[
|
||||
{
|
||||
"filename": string,
|
||||
"type ": 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:
|
||||
|
||||
List of dictionaries. Raw or processed structured data.
|
||||
|
||||
@@ -1,9 +1,19 @@
|
||||
|
||||
# jc.parsers.free
|
||||
jc - JSON CLI output utility free Parser
|
||||
jc - JSON CLI output utility `free` command output parser
|
||||
|
||||
Usage:
|
||||
Usage (cli):
|
||||
|
||||
specify --free as the first argument if the piped input is coming from free
|
||||
$ free | jc --free
|
||||
|
||||
or
|
||||
|
||||
$ jc free
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.free
|
||||
result = jc.parsers.free.parse(free_command_output)
|
||||
|
||||
Compatibility:
|
||||
|
||||
@@ -49,11 +59,13 @@ Examples:
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
## info
|
||||
```python
|
||||
info(self, /, *args, **kwargs)
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## process
|
||||
```python
|
||||
process(proc_data)
|
||||
@@ -81,6 +93,7 @@ Returns:
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
## parse
|
||||
```python
|
||||
parse(data, raw=False, quiet=False)
|
||||
|
||||
@@ -1,13 +1,19 @@
|
||||
|
||||
# jc.parsers.fstab
|
||||
jc - JSON CLI output utility fstab Parser
|
||||
jc - JSON CLI output utility `fstab` file parser
|
||||
|
||||
Usage:
|
||||
Usage (cli):
|
||||
|
||||
specify --fstab as the first argument if the piped input is coming from a fstab file
|
||||
$ cat /etc/fstab | jc --fstab
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.fstab
|
||||
result = jc.parsers.fstab.parse(fstab_command_output)
|
||||
|
||||
Compatibility:
|
||||
|
||||
'linux'
|
||||
'linux', 'freebsd'
|
||||
|
||||
Examples:
|
||||
|
||||
@@ -67,11 +73,13 @@ Examples:
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
## info
|
||||
```python
|
||||
info(self, /, *args, **kwargs)
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## process
|
||||
```python
|
||||
process(proc_data)
|
||||
@@ -98,6 +106,7 @@ Returns:
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
## parse
|
||||
```python
|
||||
parse(data, raw=False, quiet=False)
|
||||
|
||||
150
docs/parsers/group.md
Normal file
150
docs/parsers/group.md
Normal file
@@ -0,0 +1,150 @@
|
||||
|
||||
# jc.parsers.group
|
||||
jc - JSON CLI output utility `/etc/group` file parser
|
||||
|
||||
Usage (cli):
|
||||
|
||||
$ cat /etc/group | jc --group
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.group
|
||||
result = jc.parsers.group.parse(group_file_output)
|
||||
|
||||
Compatibility:
|
||||
|
||||
'linux', 'darwin', 'aix', 'freebsd'
|
||||
|
||||
Examples:
|
||||
|
||||
$ cat /etc/group | jc --group -p
|
||||
[
|
||||
{
|
||||
"group_name": "nobody",
|
||||
"password": "*",
|
||||
"gid": -2,
|
||||
"members": []
|
||||
},
|
||||
{
|
||||
"group_name": "nogroup",
|
||||
"password": "*",
|
||||
"gid": -1,
|
||||
"members": []
|
||||
},
|
||||
{
|
||||
"group_name": "wheel",
|
||||
"password": "*",
|
||||
"gid": 0,
|
||||
"members": [
|
||||
"root"
|
||||
]
|
||||
},
|
||||
{
|
||||
"group_name": "certusers",
|
||||
"password": "*",
|
||||
"gid": 29,
|
||||
"members": [
|
||||
"root",
|
||||
"_jabber",
|
||||
"_postfix",
|
||||
"_cyrus",
|
||||
"_calendar",
|
||||
"_dovecot"
|
||||
]
|
||||
},
|
||||
...
|
||||
]
|
||||
|
||||
$ cat /etc/group | jc --group -p -r
|
||||
[
|
||||
{
|
||||
"group_name": "nobody",
|
||||
"password": "*",
|
||||
"gid": "-2",
|
||||
"members": [
|
||||
""
|
||||
]
|
||||
},
|
||||
{
|
||||
"group_name": "nogroup",
|
||||
"password": "*",
|
||||
"gid": "-1",
|
||||
"members": [
|
||||
""
|
||||
]
|
||||
},
|
||||
{
|
||||
"group_name": "wheel",
|
||||
"password": "*",
|
||||
"gid": "0",
|
||||
"members": [
|
||||
"root"
|
||||
]
|
||||
},
|
||||
{
|
||||
"group_name": "certusers",
|
||||
"password": "*",
|
||||
"gid": "29",
|
||||
"members": [
|
||||
"root",
|
||||
"_jabber",
|
||||
"_postfix",
|
||||
"_cyrus",
|
||||
"_calendar",
|
||||
"_dovecot"
|
||||
]
|
||||
},
|
||||
...
|
||||
]
|
||||
|
||||
|
||||
## info
|
||||
```python
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## process
|
||||
```python
|
||||
process(proc_data)
|
||||
```
|
||||
|
||||
Final processing to conform to the schema.
|
||||
|
||||
Parameters:
|
||||
|
||||
proc_data: (dictionary) raw structured data to process
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Structured data with the following schema:
|
||||
|
||||
[
|
||||
{
|
||||
"group_name": string,
|
||||
"password": string,
|
||||
"gid": integer,
|
||||
"members": [
|
||||
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:
|
||||
|
||||
List of dictionaries. Raw or processed structured data.
|
||||
|
||||
118
docs/parsers/gshadow.md
Normal file
118
docs/parsers/gshadow.md
Normal file
@@ -0,0 +1,118 @@
|
||||
|
||||
# jc.parsers.gshadow
|
||||
jc - JSON CLI output utility `/etc/gshadow` file parser
|
||||
|
||||
Usage (cli):
|
||||
|
||||
$ cat /etc/gshadow | jc --gshadow
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.gshadow
|
||||
result = jc.parsers.gshadow.parse(gshadow_file_output)
|
||||
|
||||
Compatibility:
|
||||
|
||||
'linux', 'aix', 'freebsd'
|
||||
|
||||
Examples:
|
||||
|
||||
$ cat /etc/gshadow | jc --gshadow -p
|
||||
[
|
||||
{
|
||||
"group_name": "root",
|
||||
"password": "*",
|
||||
"administrators": [],
|
||||
"members": []
|
||||
},
|
||||
{
|
||||
"group_name": "adm",
|
||||
"password": "*",
|
||||
"administrators": [],
|
||||
"members": [
|
||||
"syslog",
|
||||
"joeuser"
|
||||
]
|
||||
},
|
||||
...
|
||||
]
|
||||
|
||||
$ cat /etc/gshadow | jc --gshadow -p -r
|
||||
[
|
||||
{
|
||||
"group_name": "root",
|
||||
"password": "*",
|
||||
"administrators": [
|
||||
""
|
||||
],
|
||||
"members": [
|
||||
""
|
||||
]
|
||||
},
|
||||
{
|
||||
"group_name": "adm",
|
||||
"password": "*",
|
||||
"administrators": [
|
||||
""
|
||||
],
|
||||
"members": [
|
||||
"syslog",
|
||||
"joeuser"
|
||||
]
|
||||
},
|
||||
...
|
||||
]
|
||||
|
||||
|
||||
## info
|
||||
```python
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## process
|
||||
```python
|
||||
process(proc_data)
|
||||
```
|
||||
|
||||
Final processing to conform to the schema.
|
||||
|
||||
Parameters:
|
||||
|
||||
proc_data: (dictionary) raw structured data to process
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Structured data with the following schema:
|
||||
|
||||
[
|
||||
{
|
||||
"group_name": string,
|
||||
"password": string,
|
||||
"administrators": [
|
||||
string
|
||||
],
|
||||
"members": [
|
||||
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:
|
||||
|
||||
List of dictionaries. Raw or processed structured data.
|
||||
|
||||
78
docs/parsers/hash.md
Normal file
78
docs/parsers/hash.md
Normal file
@@ -0,0 +1,78 @@
|
||||
|
||||
# jc.parsers.hash
|
||||
jc - JSON CLI output utility `hash` command output parser
|
||||
|
||||
Usage (cli):
|
||||
|
||||
$ hash | jc --hash
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.hash
|
||||
result = jc.parsers.hash.parse(hash_command_output)
|
||||
|
||||
Compatibility:
|
||||
|
||||
'linux', 'darwin', 'cygwin', 'aix', 'freebsd'
|
||||
|
||||
Examples:
|
||||
|
||||
$ hash | jc --hash -p
|
||||
[
|
||||
{
|
||||
"hits": 2,
|
||||
"command": "/bin/cat"
|
||||
},
|
||||
{
|
||||
"hits": 1,
|
||||
"command": "/bin/ls"
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
## info
|
||||
```python
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## process
|
||||
```python
|
||||
process(proc_data)
|
||||
```
|
||||
|
||||
Final processing to conform to the schema.
|
||||
|
||||
Parameters:
|
||||
|
||||
proc_data: (dictionary) raw structured data to process
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Structured data with the following schema:
|
||||
|
||||
[
|
||||
{
|
||||
"command": string,
|
||||
"hits": integer
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
## 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:
|
||||
|
||||
List of dictionaries. Raw or processed structured data.
|
||||
|
||||
109
docs/parsers/hashsum.md
Normal file
109
docs/parsers/hashsum.md
Normal file
@@ -0,0 +1,109 @@
|
||||
|
||||
# jc.parsers.hashsum
|
||||
jc - JSON CLI output utility `hash sum` command output parser
|
||||
|
||||
This parser works with the following hash calculation utilities:
|
||||
- `md5`
|
||||
- `md5sum`
|
||||
- `shasum`
|
||||
- `sha1sum`
|
||||
- `sha224sum`
|
||||
- `sha256sum`
|
||||
- `sha384sum`
|
||||
- `sha512sum`
|
||||
|
||||
Usage (cli):
|
||||
|
||||
$ md5sum file.txt | jc --hashsum
|
||||
|
||||
or
|
||||
|
||||
$ jc md5sum file.txt
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.hashsum
|
||||
result = jc.parsers.hashsum.parse(md5sum_command_output)
|
||||
|
||||
Compatibility:
|
||||
|
||||
'linux', 'darwin', 'cygwin', 'aix', 'freebsd'
|
||||
|
||||
Examples:
|
||||
|
||||
$ md5sum * | jc --hashsum -p
|
||||
[
|
||||
{
|
||||
"filename": "devtoolset-3-gcc-4.9.2-6.el7.x86_64.rpm",
|
||||
"hash": "65fc958c1add637ec23c4b137aecf3d3"
|
||||
},
|
||||
{
|
||||
"filename": "digout",
|
||||
"hash": "5b9312ee5aff080927753c63a347707d"
|
||||
},
|
||||
{
|
||||
"filename": "dmidecode.out",
|
||||
"hash": "716fd11c2ac00db109281f7110b8fb9d"
|
||||
},
|
||||
{
|
||||
"filename": "file with spaces in the name",
|
||||
"hash": "d41d8cd98f00b204e9800998ecf8427e"
|
||||
},
|
||||
{
|
||||
"filename": "id-centos.out",
|
||||
"hash": "4295be239a14ad77ef3253103de976d2"
|
||||
},
|
||||
{
|
||||
"filename": "ifcfg.json",
|
||||
"hash": "01fda0d9ba9a75618b072e64ff512b43"
|
||||
},
|
||||
...
|
||||
]
|
||||
|
||||
|
||||
## info
|
||||
```python
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## process
|
||||
```python
|
||||
process(proc_data)
|
||||
```
|
||||
|
||||
Final processing to conform to the schema.
|
||||
|
||||
Parameters:
|
||||
|
||||
proc_data: (dictionary) raw structured data to process
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Structured data with the following schema:
|
||||
|
||||
[
|
||||
{
|
||||
"filename": string,
|
||||
"hash": 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:
|
||||
|
||||
List of dictionaries. Raw or processed structured data.
|
||||
|
||||
@@ -1,9 +1,17 @@
|
||||
|
||||
# jc.parsers.history
|
||||
jc - JSON CLI output utility history Parser
|
||||
jc - JSON CLI output utility `history` command output parser
|
||||
|
||||
Usage:
|
||||
This parser will output a list of dictionaries each containing `line` and `command` keys. If you would like a simple dictionary output, then use the `-r` command-line option or the `raw=True` argument in the `parse()` function.
|
||||
|
||||
specify --history as the first argument if the piped input is coming from history
|
||||
Usage (cli):
|
||||
|
||||
$ history | jc --history
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.history
|
||||
result = jc.parsers.history.parse(history_command_output)
|
||||
|
||||
Compatibility:
|
||||
|
||||
@@ -41,11 +49,13 @@ Examples:
|
||||
...
|
||||
}
|
||||
|
||||
|
||||
## info
|
||||
```python
|
||||
info(self, /, *args, **kwargs)
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## process
|
||||
```python
|
||||
process(proc_data)
|
||||
@@ -68,6 +78,7 @@ Returns:
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
## parse
|
||||
```python
|
||||
parse(data, raw=False, quiet=False)
|
||||
|
||||
@@ -1,9 +1,15 @@
|
||||
|
||||
# jc.parsers.hosts
|
||||
jc - JSON CLI output utility hosts Parser
|
||||
jc - JSON CLI output utility `/etc/hosts` file parser
|
||||
|
||||
Usage:
|
||||
Usage (cli):
|
||||
|
||||
specify --hosts as the first argument if the piped input is coming from a hosts file
|
||||
$ cat /etc/hosts | jc --hosts
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.hosts
|
||||
result = jc.parsers.hosts.parse(hosts_file_output)
|
||||
|
||||
Compatibility:
|
||||
|
||||
@@ -58,11 +64,13 @@ Examples:
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
## info
|
||||
```python
|
||||
info(self, /, *args, **kwargs)
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## process
|
||||
```python
|
||||
process(proc_data)
|
||||
@@ -87,6 +95,7 @@ Returns:
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
## parse
|
||||
```python
|
||||
parse(data, raw=False, quiet=False)
|
||||
|
||||
@@ -1,9 +1,19 @@
|
||||
|
||||
# jc.parsers.id
|
||||
jc - JSON CLI output utility id Parser
|
||||
jc - JSON CLI output utility `id` command output parser
|
||||
|
||||
Usage:
|
||||
Usage (cli):
|
||||
|
||||
specify --id as the first argument if the piped input is coming from id
|
||||
$ id | jc --id
|
||||
|
||||
or
|
||||
|
||||
$ jc id
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.id
|
||||
result = jc.parsers.id.parse(id_command_output)
|
||||
|
||||
Compatibility:
|
||||
|
||||
@@ -67,11 +77,13 @@ Examples:
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
## info
|
||||
```python
|
||||
info(self, /, *args, **kwargs)
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## process
|
||||
```python
|
||||
process(proc_data)
|
||||
@@ -114,6 +126,7 @@ Returns:
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
## parse
|
||||
```python
|
||||
parse(data, raw=False, quiet=False)
|
||||
|
||||
@@ -1,11 +1,21 @@
|
||||
|
||||
# jc.parsers.ifconfig
|
||||
jc - JSON CLI output utility ifconfig Parser
|
||||
jc - JSON CLI output utility `ifconfig` command output parser
|
||||
|
||||
Usage:
|
||||
Note: No `ifconfig` options are supported.
|
||||
|
||||
specify --ifconfig as the first argument if the piped input is coming from ifconfig
|
||||
Usage (cli):
|
||||
|
||||
no ifconfig options are supported.
|
||||
$ ifconfig | jc --ifconfig
|
||||
|
||||
or
|
||||
|
||||
$ jc ifconfig
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.ifconfig
|
||||
result = jc.parsers.ifconfig.parse(ifconfig_command_output)
|
||||
|
||||
Compatibility:
|
||||
|
||||
@@ -142,11 +152,19 @@ Examples:
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
## info
|
||||
```python
|
||||
info(self, /, *args, **kwargs)
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## IfconfigParser
|
||||
```python
|
||||
IfconfigParser(console_output)
|
||||
```
|
||||
|
||||
|
||||
## process
|
||||
```python
|
||||
process(proc_data)
|
||||
@@ -195,6 +213,7 @@ Returns:
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
## parse
|
||||
```python
|
||||
parse(data, raw=False, quiet=False)
|
||||
|
||||
@@ -1,9 +1,19 @@
|
||||
|
||||
# jc.parsers.ini
|
||||
jc - JSON CLI output utility INI Parser
|
||||
jc - JSON CLI output utility `INI` file parser
|
||||
|
||||
Usage:
|
||||
Parses standard `INI` files and files containing simple key/value pairs. Delimiter can be `=` or `:`. Missing values are supported. Comment prefix can be `#` or `;`. Comments must be on their own line.
|
||||
|
||||
specify --ini as the first argument if the piped input is coming from an INI file
|
||||
Note: Values starting and ending with quotation marks will have the marks removed. If you would like to keep the quotation marks, use the `-r` command-line argument or the `raw=True` argument in `parse()`.
|
||||
|
||||
Usage (cli):
|
||||
|
||||
$ cat foo.ini | jc --ini
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.ini
|
||||
result = jc.parsers.ini.parse(ini_file_output)
|
||||
|
||||
Compatibility:
|
||||
|
||||
@@ -43,11 +53,13 @@ Examples:
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
## info
|
||||
```python
|
||||
info(self, /, *args, **kwargs)
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## process
|
||||
```python
|
||||
process(proc_data)
|
||||
@@ -61,13 +73,17 @@ Parameters:
|
||||
|
||||
Returns:
|
||||
|
||||
Dictionary representing an ini document:
|
||||
Dictionary representing an ini or simple key/value pair document:
|
||||
|
||||
{
|
||||
ini document converted to a dictionary
|
||||
see configparser standard library documentation for more details
|
||||
ini or key/value document converted to a dictionary - see configparser standard
|
||||
library documentation for more details.
|
||||
|
||||
Note: Values starting and ending with quotation marks will have the marks removed.
|
||||
If you would like to keep the quotation marks, use the -r or raw=True argument.
|
||||
}
|
||||
|
||||
|
||||
## parse
|
||||
```python
|
||||
parse(data, raw=False, quiet=False)
|
||||
|
||||
@@ -1,11 +1,21 @@
|
||||
|
||||
# jc.parsers.iptables
|
||||
jc - JSON CLI output utility ipables Parser
|
||||
jc - JSON CLI output utility `ipables` command output parser
|
||||
|
||||
Usage:
|
||||
Supports `-vLn` and `--line-numbers` for all tables.
|
||||
|
||||
Specify --iptables as the first argument if the piped input is coming from iptables
|
||||
Usage (cli):
|
||||
|
||||
Supports -vLn and --line-numbers for all tables
|
||||
$ sudo iptables -L -t nat | jc --iptables
|
||||
|
||||
or
|
||||
|
||||
$ jc iptables -L -t nat
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.iptables
|
||||
result = jc.parsers.iptables.parse(iptables_command_output)
|
||||
|
||||
Compatibility:
|
||||
|
||||
@@ -131,11 +141,13 @@ Examples:
|
||||
...
|
||||
]
|
||||
|
||||
|
||||
## info
|
||||
```python
|
||||
info(self, /, *args, **kwargs)
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## process
|
||||
```python
|
||||
process(proc_data)
|
||||
@@ -172,6 +184,7 @@ Returns:
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
## parse
|
||||
```python
|
||||
parse(data, raw=False, quiet=False)
|
||||
|
||||
@@ -1,11 +1,21 @@
|
||||
|
||||
# jc.parsers.jobs
|
||||
jc - JSON CLI output utility jobs Parser
|
||||
jc - JSON CLI output utility `jobs` command output parser
|
||||
|
||||
Usage:
|
||||
Also supports the `-l` option.
|
||||
|
||||
specify --jobs as the first argument if the piped input is coming from jobs
|
||||
Usage (cli):
|
||||
|
||||
Also supports the -l option
|
||||
$ jobs | jc --jobs
|
||||
|
||||
or
|
||||
|
||||
$ jc jobs
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.jobs
|
||||
result = jc.parsers.jobs.parse(jobs_command_output)
|
||||
|
||||
Compatibility:
|
||||
|
||||
@@ -73,11 +83,13 @@ Example:
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
## info
|
||||
```python
|
||||
info(self, /, *args, **kwargs)
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## process
|
||||
```python
|
||||
process(proc_data)
|
||||
@@ -103,6 +115,7 @@ Returns:
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
## parse
|
||||
```python
|
||||
parse(data, raw=False, quiet=False)
|
||||
|
||||
69
docs/parsers/kv.md
Normal file
69
docs/parsers/kv.md
Normal file
@@ -0,0 +1,69 @@
|
||||
|
||||
# jc.parsers.kv
|
||||
jc - JSON CLI output utility `Key/Value` file parser
|
||||
|
||||
Supports files containing simple key/value pairs. Delimiter can be `=` or `:`. Missing values are supported. Comment prefix can be `#` or `;`. Comments must be on their own line.
|
||||
|
||||
Note: Values starting and ending with quotation marks will have the marks removed. If you would like to keep the quotation marks, use the `-r` command-line argument or the `raw=True` argument in `parse()`.
|
||||
|
||||
|
||||
Usage (cli):
|
||||
|
||||
$ cat foo.txt | jc --kv
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.kv
|
||||
result = jc.parsers.kv.parse(kv_file_output)
|
||||
|
||||
Compatibility:
|
||||
|
||||
'linux', 'darwin', 'cygwin', 'win32', 'aix', 'freebsd'
|
||||
|
||||
Examples:
|
||||
|
||||
$ cat keyvalue.txt
|
||||
# this file contains key/value pairs
|
||||
name = John Doe
|
||||
address=555 California Drive
|
||||
age: 34
|
||||
; comments can include # or ;
|
||||
# delimiter can be = or :
|
||||
# quoted values have quotation marks stripped by default
|
||||
# but can be preserved with the -r argument
|
||||
occupation:"Engineer"
|
||||
|
||||
$ cat keyvalue.txt | jc --ini -p
|
||||
{
|
||||
"name": "John Doe",
|
||||
"address": "555 California Drive",
|
||||
"age": "34",
|
||||
"occupation": "Engineer"
|
||||
}
|
||||
|
||||
|
||||
## info
|
||||
```python
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## parse
|
||||
```python
|
||||
parse(data, raw=False, quiet=False)
|
||||
```
|
||||
|
||||
Main text parsing function
|
||||
|
||||
Note: this is just a wrapper for jc.parsers.ini
|
||||
|
||||
Parameters:
|
||||
|
||||
data: (string) text data to parse
|
||||
raw: (boolean) output preprocessed JSON if True
|
||||
quiet: (boolean) suppress warning messages if True
|
||||
|
||||
Returns:
|
||||
|
||||
Dictionary representing the key/value file
|
||||
|
||||
131
docs/parsers/last.md
Normal file
131
docs/parsers/last.md
Normal file
@@ -0,0 +1,131 @@
|
||||
|
||||
# jc.parsers.last
|
||||
jc - JSON CLI output utility `last` and `lastb` command output parser
|
||||
|
||||
Usage (cli):
|
||||
|
||||
$ last | jc --last
|
||||
|
||||
or
|
||||
|
||||
$ jc last
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.last
|
||||
result = jc.parsers.last.parse(last_command_output)
|
||||
|
||||
Compatibility:
|
||||
|
||||
'linux', 'darwin', 'aix', 'freebsd'
|
||||
|
||||
Examples:
|
||||
|
||||
$ last | jc --last -p
|
||||
[
|
||||
{
|
||||
"user": "kbrazil",
|
||||
"tty": "ttys002",
|
||||
"hostname": null,
|
||||
"login": "Thu Feb 27 14:31",
|
||||
"logout": "still logged in"
|
||||
},
|
||||
{
|
||||
"user": "kbrazil",
|
||||
"tty": "ttys003",
|
||||
"hostname": null,
|
||||
"login": "Thu Feb 27 10:38",
|
||||
"logout": "10:38",
|
||||
"duration": "00:00"
|
||||
},
|
||||
{
|
||||
"user": "kbrazil",
|
||||
"tty": "ttys003",
|
||||
"hostname": null,
|
||||
"login": "Thu Feb 27 10:18",
|
||||
"logout": "10:18",
|
||||
"duration": "00:00"
|
||||
},
|
||||
...
|
||||
]
|
||||
|
||||
$ last | jc --last -p -r
|
||||
[
|
||||
{
|
||||
"user": "kbrazil",
|
||||
"tty": "ttys002",
|
||||
"hostname": "-",
|
||||
"login": "Thu Feb 27 14:31",
|
||||
"logout": "still_logged_in"
|
||||
},
|
||||
{
|
||||
"user": "kbrazil",
|
||||
"tty": "ttys003",
|
||||
"hostname": "-",
|
||||
"login": "Thu Feb 27 10:38",
|
||||
"logout": "10:38",
|
||||
"duration": "00:00"
|
||||
},
|
||||
{
|
||||
"user": "kbrazil",
|
||||
"tty": "ttys003",
|
||||
"hostname": "-",
|
||||
"login": "Thu Feb 27 10:18",
|
||||
"logout": "10:18",
|
||||
"duration": "00:00"
|
||||
},
|
||||
...
|
||||
]
|
||||
|
||||
|
||||
|
||||
## info
|
||||
```python
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## process
|
||||
```python
|
||||
process(proc_data)
|
||||
```
|
||||
|
||||
Final processing to conform to the schema.
|
||||
|
||||
Parameters:
|
||||
|
||||
proc_data: (dictionary) raw structured data to process
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Structured data with the following schema:
|
||||
|
||||
[
|
||||
{
|
||||
"user": string,
|
||||
"tty": string,
|
||||
"hostname": string,
|
||||
"login": string,
|
||||
"logout": string,
|
||||
"duration": 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:
|
||||
|
||||
List of dictionaries. Raw or processed structured data.
|
||||
|
||||
@@ -1,16 +1,26 @@
|
||||
|
||||
# jc.parsers.ls
|
||||
jc - JSON CLI output utility ls Parser
|
||||
jc - JSON CLI output utility `ls` and `vdir` command output parser
|
||||
|
||||
Usage:
|
||||
Options supported:
|
||||
- `lbaR`
|
||||
- `--time-style=full-iso`
|
||||
- `-h`: File sizes will be available in text form with `-r` but larger file sizes with human readable suffixes will be converted to `Null` in the default view since the parser attempts to convert this field to an integer.
|
||||
|
||||
specify --ls as the first argument if the piped input is coming from ls
|
||||
Note: The `-l` or `-b` option of `ls` should be used to correctly parse filenames that include newline characters. Since `ls` does not encode newlines in filenames when outputting to a pipe it will cause `jc` to see multiple files instead of a single file if `-l` or `-b` is not used. Alternatively, `vdir` can be used, which is the same as running `ls -lb`.
|
||||
|
||||
ls options supported:
|
||||
- None
|
||||
- la
|
||||
- h file sizes will be available in text form with -r but larger file sizes
|
||||
with human readable suffixes will be converted to Null in default view
|
||||
since the parser attempts to convert this field to an integer.
|
||||
Usage (cli):
|
||||
|
||||
$ ls | jc --ls
|
||||
|
||||
or
|
||||
|
||||
$ jc ls
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.ls
|
||||
result = jc.parsers.ls.parse(ls_command_output)
|
||||
|
||||
Compatibility:
|
||||
|
||||
@@ -140,11 +150,13 @@ Examples:
|
||||
"date": "May 3 2019"
|
||||
}
|
||||
|
||||
|
||||
## info
|
||||
```python
|
||||
info(self, /, *args, **kwargs)
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## process
|
||||
```python
|
||||
process(proc_data)
|
||||
@@ -165,6 +177,7 @@ Returns:
|
||||
"filename": string,
|
||||
"flags": string,
|
||||
"links": integer,
|
||||
"parent": string,
|
||||
"owner": string,
|
||||
"group": string,
|
||||
"size": integer,
|
||||
@@ -172,6 +185,7 @@ Returns:
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
## parse
|
||||
```python
|
||||
parse(data, raw=False, quiet=False)
|
||||
|
||||
@@ -1,9 +1,19 @@
|
||||
|
||||
# jc.parsers.lsblk
|
||||
jc - JSON CLI output utility lsblk Parser
|
||||
jc - JSON CLI output utility `lsblk` command output parser
|
||||
|
||||
Usage:
|
||||
Usage (cli):
|
||||
|
||||
specify --lsblk as the first argument if the piped input is coming from lsblk
|
||||
$ lsblk | jc --lsblk
|
||||
|
||||
or
|
||||
|
||||
$ jc lsblk
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.lsblk
|
||||
result = jc.parsers.lsblk.parse(lsblk_command_output)
|
||||
|
||||
Compatibility:
|
||||
|
||||
@@ -212,11 +222,13 @@ Examples:
|
||||
...
|
||||
]
|
||||
|
||||
|
||||
## info
|
||||
```python
|
||||
info(self, /, *args, **kwargs)
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## process
|
||||
```python
|
||||
process(proc_data)
|
||||
@@ -277,6 +289,7 @@ Returns:
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
## parse
|
||||
```python
|
||||
parse(data, raw=False, quiet=False)
|
||||
|
||||
@@ -1,9 +1,19 @@
|
||||
|
||||
# jc.parsers.lsmod
|
||||
jc - JSON CLI output utility lsmod Parser
|
||||
jc - JSON CLI output utility `lsmod` command output parser
|
||||
|
||||
Usage:
|
||||
Usage (cli):
|
||||
|
||||
specify --lsmod as the first argument if the piped input is coming from lsmod
|
||||
$ lsmod | jc --lsmod
|
||||
|
||||
or
|
||||
|
||||
$ jc lsmod
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.lsmod
|
||||
result = jc.parsers.lsmod.parse(lsmod_command_output)
|
||||
|
||||
Compatibility:
|
||||
|
||||
@@ -103,11 +113,13 @@ Examples:
|
||||
...
|
||||
]
|
||||
|
||||
|
||||
## info
|
||||
```python
|
||||
info(self, /, *args, **kwargs)
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## process
|
||||
```python
|
||||
process(proc_data)
|
||||
@@ -134,6 +146,7 @@ Returns:
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
## parse
|
||||
```python
|
||||
parse(data, raw=False, quiet=False)
|
||||
|
||||
@@ -1,9 +1,19 @@
|
||||
|
||||
# jc.parsers.lsof
|
||||
jc - JSON CLI output utility lsof Parser
|
||||
jc - JSON CLI output utility `lsof` command output parser
|
||||
|
||||
Usage:
|
||||
Usage (cli):
|
||||
|
||||
specify --lsof as the first argument if the piped input is coming from lsof
|
||||
$ lsof | jc --lsof
|
||||
|
||||
or
|
||||
|
||||
$ jc lsof
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.lsof
|
||||
result = jc.parsers.lsof.parse(lsof_command_output)
|
||||
|
||||
Compatibility:
|
||||
|
||||
@@ -93,11 +103,13 @@ Examples:
|
||||
...
|
||||
]
|
||||
|
||||
|
||||
## info
|
||||
```python
|
||||
info(self, /, *args, **kwargs)
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## process
|
||||
```python
|
||||
process(proc_data)
|
||||
@@ -128,6 +140,7 @@ Returns:
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
## parse
|
||||
```python
|
||||
parse(data, raw=False, quiet=False)
|
||||
|
||||
@@ -1,13 +1,23 @@
|
||||
|
||||
# jc.parsers.mount
|
||||
jc - JSON CLI output utility mount Parser
|
||||
jc - JSON CLI output utility `mount` command output parser
|
||||
|
||||
Usage:
|
||||
Usage (cli):
|
||||
|
||||
specify --mount as the first argument if the piped input is coming from mount
|
||||
$ mount | jc --mount
|
||||
|
||||
or
|
||||
|
||||
$ jc mount
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.mount
|
||||
result = jc.parsers.mount.parse(mount_command_output)
|
||||
|
||||
Compatibility:
|
||||
|
||||
'linux', 'darwin'
|
||||
'linux', 'darwin', 'freebsd'
|
||||
|
||||
Example:
|
||||
|
||||
@@ -53,11 +63,13 @@ Example:
|
||||
...
|
||||
]
|
||||
|
||||
|
||||
## info
|
||||
```python
|
||||
info(self, /, *args, **kwargs)
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## process
|
||||
```python
|
||||
process(proc_data)
|
||||
@@ -84,6 +96,7 @@ Returns:
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
## parse
|
||||
```python
|
||||
parse(data, raw=False, quiet=False)
|
||||
|
||||
@@ -1,17 +1,31 @@
|
||||
|
||||
# jc.parsers.netstat
|
||||
jc - JSON CLI output utility netstat Parser
|
||||
jc - JSON CLI output utility `netstat` command output parser
|
||||
|
||||
Usage:
|
||||
Caveats:
|
||||
- Use of multiple `l` options is not supported on OSX (e.g. `netstat -rlll`)
|
||||
- Use of the `A` option is not supported on OSX when using the `r` option (e.g. `netstat -rA`)
|
||||
|
||||
Specify --netstat as the first argument if the piped input is coming from netstat
|
||||
Usage (cli):
|
||||
|
||||
$ netstat | jc --netstat
|
||||
|
||||
or
|
||||
|
||||
$ jc netstat
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.netstat
|
||||
result = jc.parsers.netstat.parse(netstat_command_output)
|
||||
|
||||
Compatibility:
|
||||
|
||||
'linux'
|
||||
'linux', 'darwin', 'freebsd'
|
||||
|
||||
Examples:
|
||||
|
||||
$ sudo netstat -apee | jc --netstat -p
|
||||
# netstat -apee | jc --netstat -p
|
||||
[
|
||||
{
|
||||
"proto": "tcp",
|
||||
@@ -161,159 +175,92 @@ Examples:
|
||||
...
|
||||
]
|
||||
|
||||
$ sudo netstat -apee | jc --netstat -p -r
|
||||
$ netstat -r | jc --netstat -p
|
||||
[
|
||||
{
|
||||
"proto": "tcp",
|
||||
"recv_q": "0",
|
||||
"send_q": "0",
|
||||
"local_address": "localhost",
|
||||
"foreign_address": "0.0.0.0",
|
||||
"state": "LISTEN",
|
||||
"user": "systemd-resolve",
|
||||
"inode": "26958",
|
||||
"program_name": "systemd-resolve",
|
||||
"kind": "network",
|
||||
"pid": "887",
|
||||
"local_port": "domain",
|
||||
"foreign_port": "*",
|
||||
"transport_protocol": "tcp",
|
||||
"network_protocol": "ipv4"
|
||||
"destination": "default",
|
||||
"gateway": "gateway",
|
||||
"genmask": "0.0.0.0",
|
||||
"route_flags": "UG",
|
||||
"mss": 0,
|
||||
"window": 0,
|
||||
"irtt": 0,
|
||||
"iface": "ens33",
|
||||
"kind": "route",
|
||||
"route_flags_pretty": [
|
||||
"UP",
|
||||
"GATEWAY"
|
||||
]
|
||||
},
|
||||
{
|
||||
"proto": "tcp",
|
||||
"recv_q": "0",
|
||||
"send_q": "0",
|
||||
"local_address": "0.0.0.0",
|
||||
"foreign_address": "0.0.0.0",
|
||||
"state": "LISTEN",
|
||||
"user": "root",
|
||||
"inode": "30499",
|
||||
"program_name": "sshd",
|
||||
"kind": "network",
|
||||
"pid": "1186",
|
||||
"local_port": "ssh",
|
||||
"foreign_port": "*",
|
||||
"transport_protocol": "tcp",
|
||||
"network_protocol": "ipv4"
|
||||
"destination": "172.17.0.0",
|
||||
"gateway": "0.0.0.0",
|
||||
"genmask": "255.255.0.0",
|
||||
"route_flags": "U",
|
||||
"mss": 0,
|
||||
"window": 0,
|
||||
"irtt": 0,
|
||||
"iface": "docker0",
|
||||
"kind": "route",
|
||||
"route_flags_pretty": [
|
||||
"UP"
|
||||
]
|
||||
},
|
||||
{
|
||||
"proto": "tcp",
|
||||
"recv_q": "0",
|
||||
"send_q": "0",
|
||||
"local_address": "localhost",
|
||||
"foreign_address": "localhost",
|
||||
"state": "ESTABLISHED",
|
||||
"user": "root",
|
||||
"inode": "46829",
|
||||
"program_name": "sshd: root",
|
||||
"kind": "network",
|
||||
"pid": "2242",
|
||||
"local_port": "ssh",
|
||||
"foreign_port": "52186",
|
||||
"transport_protocol": "tcp",
|
||||
"network_protocol": "ipv4"
|
||||
},
|
||||
{
|
||||
"proto": "tcp",
|
||||
"recv_q": "0",
|
||||
"send_q": "0",
|
||||
"local_address": "localhost",
|
||||
"foreign_address": "localhost",
|
||||
"state": "ESTABLISHED",
|
||||
"user": "root",
|
||||
"inode": "46828",
|
||||
"program_name": "ssh",
|
||||
"kind": "network",
|
||||
"pid": "2241",
|
||||
"local_port": "52186",
|
||||
"foreign_port": "ssh",
|
||||
"transport_protocol": "tcp",
|
||||
"network_protocol": "ipv4"
|
||||
},
|
||||
{
|
||||
"proto": "tcp6",
|
||||
"recv_q": "0",
|
||||
"send_q": "0",
|
||||
"local_address": "[::]",
|
||||
"foreign_address": "[::]",
|
||||
"state": "LISTEN",
|
||||
"user": "root",
|
||||
"inode": "30510",
|
||||
"program_name": "sshd",
|
||||
"kind": "network",
|
||||
"pid": "1186",
|
||||
"local_port": "ssh",
|
||||
"foreign_port": "*",
|
||||
"transport_protocol": "tcp",
|
||||
"network_protocol": "ipv6"
|
||||
},
|
||||
{
|
||||
"proto": "udp",
|
||||
"recv_q": "0",
|
||||
"send_q": "0",
|
||||
"local_address": "localhost",
|
||||
"foreign_address": "0.0.0.0",
|
||||
"state": null,
|
||||
"user": "systemd-resolve",
|
||||
"inode": "26957",
|
||||
"program_name": "systemd-resolve",
|
||||
"kind": "network",
|
||||
"pid": "887",
|
||||
"local_port": "domain",
|
||||
"foreign_port": "*",
|
||||
"transport_protocol": "udp",
|
||||
"network_protocol": "ipv4"
|
||||
},
|
||||
{
|
||||
"proto": "raw6",
|
||||
"recv_q": "0",
|
||||
"send_q": "0",
|
||||
"local_address": "[::]",
|
||||
"foreign_address": "[::]",
|
||||
"state": "7",
|
||||
"user": "systemd-network",
|
||||
"inode": "27001",
|
||||
"program_name": "systemd-network",
|
||||
"kind": "network",
|
||||
"pid": "867",
|
||||
"local_port": "ipv6-icmp",
|
||||
"foreign_port": "*",
|
||||
"transport_protocol": null,
|
||||
"network_protocol": "ipv6"
|
||||
},
|
||||
{
|
||||
"proto": "unix",
|
||||
"refcnt": "2",
|
||||
"flags": null,
|
||||
"type": "DGRAM",
|
||||
"state": null,
|
||||
"inode": "33322",
|
||||
"program_name": "systemd",
|
||||
"path": "/run/user/1000/systemd/notify",
|
||||
"kind": "socket",
|
||||
"pid": " 1607"
|
||||
},
|
||||
{
|
||||
"proto": "unix",
|
||||
"refcnt": "2",
|
||||
"flags": "ACC",
|
||||
"type": "SEQPACKET",
|
||||
"state": "LISTENING",
|
||||
"inode": "20835",
|
||||
"program_name": "init",
|
||||
"path": "/run/udev/control",
|
||||
"kind": "socket",
|
||||
"pid": " 1"
|
||||
},
|
||||
...
|
||||
"destination": "192.168.71.0",
|
||||
"gateway": "0.0.0.0",
|
||||
"genmask": "255.255.255.0",
|
||||
"route_flags": "U",
|
||||
"mss": 0,
|
||||
"window": 0,
|
||||
"irtt": 0,
|
||||
"iface": "ens33",
|
||||
"kind": "route",
|
||||
"route_flags_pretty": [
|
||||
"UP"
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
$ netstat -i | jc --netstat -p
|
||||
[
|
||||
{
|
||||
"iface": "ens33",
|
||||
"mtu": 1500,
|
||||
"rx_ok": 476,
|
||||
"rx_err": 0,
|
||||
"rx_drp": 0,
|
||||
"rx_ovr": 0,
|
||||
"tx_ok": 312,
|
||||
"tx_err": 0,
|
||||
"tx_drp": 0,
|
||||
"tx_ovr": 0,
|
||||
"flg": "BMRU",
|
||||
"kind": "interface"
|
||||
},
|
||||
{
|
||||
"iface": "lo",
|
||||
"mtu": 65536,
|
||||
"rx_ok": 0,
|
||||
"rx_err": 0,
|
||||
"rx_drp": 0,
|
||||
"rx_ovr": 0,
|
||||
"tx_ok": 0,
|
||||
"tx_err": 0,
|
||||
"tx_drp": 0,
|
||||
"tx_ovr": 0,
|
||||
"flg": "LRU",
|
||||
"kind": "interface"
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
## info
|
||||
```python
|
||||
info(self, /, *args, **kwargs)
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## process
|
||||
```python
|
||||
process(proc_data)
|
||||
@@ -331,31 +278,104 @@ Returns:
|
||||
|
||||
[
|
||||
{
|
||||
"proto": string,
|
||||
"recv_q": integer,
|
||||
"send_q": integer,
|
||||
"transport_protocol" string,
|
||||
"network_protocol": string,
|
||||
"local_address": string,
|
||||
"local_port": string,
|
||||
"local_port_num": integer,
|
||||
"foreign_address": string,
|
||||
"foreign_port": string,
|
||||
"foreign_port_num": integer,
|
||||
"state": string,
|
||||
"program_name": string,
|
||||
"pid": integer,
|
||||
"user": string,
|
||||
"security_context": string,
|
||||
"refcnt": integer,
|
||||
"flags": string,
|
||||
"type": string,
|
||||
"inode": integer,
|
||||
"path": string,
|
||||
"kind": string
|
||||
"proto": string,
|
||||
"recv_q": integer,
|
||||
"send_q": integer,
|
||||
"transport_protocol" string,
|
||||
"network_protocol": string,
|
||||
"local_address": string,
|
||||
"local_port": string,
|
||||
"local_port_num": integer,
|
||||
"foreign_address": string,
|
||||
"foreign_port": string,
|
||||
"foreign_port_num": integer,
|
||||
"state": string,
|
||||
"program_name": string,
|
||||
"pid": integer,
|
||||
"user": string,
|
||||
"security_context": string,
|
||||
"refcnt": integer,
|
||||
"flags": string,
|
||||
"type": string,
|
||||
"inode": integer,
|
||||
"path": string,
|
||||
"kind": string,
|
||||
"address": string,
|
||||
"unix_inode": string,
|
||||
"conn": string,
|
||||
"refs": string,
|
||||
"nextref": string,
|
||||
"name": string,
|
||||
"unit": integer,
|
||||
"vendor": integer,
|
||||
"class": integer,
|
||||
"subcla": integer,
|
||||
"unix_flags": integer,
|
||||
"pcbcount": integer,
|
||||
"rcvbuf": integer,
|
||||
"sndbuf": integer,
|
||||
"rxbytes": integer,
|
||||
"txbytes": integer,
|
||||
"destination": string,
|
||||
"gateway": string,
|
||||
"route_flags": string,
|
||||
"route_flags_pretty": [
|
||||
string,
|
||||
]
|
||||
"route_refs": integer,
|
||||
"use": integer,
|
||||
"mtu": integer,
|
||||
"expire": string,
|
||||
"genmask": string,
|
||||
"mss": integer,
|
||||
"window": integer,
|
||||
"irtt": integer,
|
||||
"iface": string,
|
||||
"metric": integer,
|
||||
"network": string,
|
||||
"address": string,
|
||||
"ipkts": integer, - = null
|
||||
"ierrs": integer, - = null
|
||||
"idrop": integer, - = null
|
||||
"opkts": integer, - = null
|
||||
"oerrs": integer, - = null
|
||||
"coll": integer, - = null
|
||||
"rx_ok": integer,
|
||||
"rx_err": integer,
|
||||
"rx_drp": integer,
|
||||
"rx_ovr": integer,
|
||||
"tx_ok": integer,
|
||||
"tx_err": integer,
|
||||
"tx_drp": integer,
|
||||
"tx_ovr": integer,
|
||||
"flg": string,
|
||||
"ibytes": integer,
|
||||
"obytes": integer,
|
||||
"r_mbuf": integer,
|
||||
"s_mbuf": integer,
|
||||
"r_clus": integer,
|
||||
"s_clus": integer,
|
||||
"r_hiwa": integer,
|
||||
"s_hiwa": integer,
|
||||
"r_lowa": integer,
|
||||
"s_lowa": integer,
|
||||
"r_bcnt": integer,
|
||||
"s_bcnt": integer,
|
||||
"r_bmax": integer,
|
||||
"s_bmax": integer,
|
||||
"rexmit": integer,
|
||||
"ooorcv": integer,
|
||||
"0_win": integer,
|
||||
"rexmt": float,
|
||||
"persist": float,
|
||||
"keep": float,
|
||||
"2msl": float,
|
||||
"delack": float,
|
||||
"rcvtime": float,
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
## parse
|
||||
```python
|
||||
parse(data, raw=False, quiet=False)
|
||||
|
||||
248
docs/parsers/ntpq.md
Normal file
248
docs/parsers/ntpq.md
Normal file
@@ -0,0 +1,248 @@
|
||||
|
||||
# jc.parsers.ntpq
|
||||
jc - JSON CLI output utility `ntpq -p` command output parser
|
||||
|
||||
Usage (cli):
|
||||
|
||||
$ ntpq -p | jc --ntpq
|
||||
|
||||
or
|
||||
|
||||
$ jc ntpq -p
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.ntpq
|
||||
result = jc.parsers.ntpq.parse(ntpq_command_output)
|
||||
|
||||
Compatibility:
|
||||
|
||||
'linux', 'freebsd'
|
||||
|
||||
Examples:
|
||||
|
||||
$ ntpq -p | jc --ntpq -p
|
||||
[
|
||||
{
|
||||
"remote": "44.190.6.254",
|
||||
"refid": "127.67.113.92",
|
||||
"st": 2,
|
||||
"t": "u",
|
||||
"when": 1,
|
||||
"poll": 64,
|
||||
"reach": 1,
|
||||
"delay": 23.399,
|
||||
"offset": -2.805,
|
||||
"jitter": 2.131,
|
||||
"state": null
|
||||
},
|
||||
{
|
||||
"remote": "ntp.wdc1.us.lea",
|
||||
"refid": "130.133.1.10",
|
||||
"st": 2,
|
||||
"t": "u",
|
||||
"when": null,
|
||||
"poll": 64,
|
||||
"reach": 1,
|
||||
"delay": 93.053,
|
||||
"offset": -0.807,
|
||||
"jitter": 2.839,
|
||||
"state": null
|
||||
},
|
||||
{
|
||||
"remote": "clock.team-cymr",
|
||||
"refid": "204.9.54.119",
|
||||
"st": 2,
|
||||
"t": "u",
|
||||
"when": null,
|
||||
"poll": 64,
|
||||
"reach": 1,
|
||||
"delay": 70.337,
|
||||
"offset": -2.909,
|
||||
"jitter": 2.6,
|
||||
"state": null
|
||||
},
|
||||
{
|
||||
"remote": "mirror1.sjc02.s",
|
||||
"refid": "216.218.254.202",
|
||||
"st": 2,
|
||||
"t": "u",
|
||||
"when": 2,
|
||||
"poll": 64,
|
||||
"reach": 1,
|
||||
"delay": 29.325,
|
||||
"offset": 1.044,
|
||||
"jitter": 4.069,
|
||||
"state": null,
|
||||
}
|
||||
]
|
||||
|
||||
$ ntpq -pn| jc --ntpq -p
|
||||
[
|
||||
{
|
||||
"remote": "44.190.6.254",
|
||||
"refid": "127.67.113.92",
|
||||
"st": 2,
|
||||
"t": "u",
|
||||
"when": 66,
|
||||
"poll": 64,
|
||||
"reach": 377,
|
||||
"delay": 22.69,
|
||||
"offset": -0.392,
|
||||
"jitter": 2.085,
|
||||
"state": "+"
|
||||
},
|
||||
{
|
||||
"remote": "108.59.2.24",
|
||||
"refid": "130.133.1.10",
|
||||
"st": 2,
|
||||
"t": "u",
|
||||
"when": 63,
|
||||
"poll": 64,
|
||||
"reach": 377,
|
||||
"delay": 90.805,
|
||||
"offset": 2.84,
|
||||
"jitter": 1.908,
|
||||
"state": "-"
|
||||
},
|
||||
{
|
||||
"remote": "38.229.71.1",
|
||||
"refid": "204.9.54.119",
|
||||
"st": 2,
|
||||
"t": "u",
|
||||
"when": 64,
|
||||
"poll": 64,
|
||||
"reach": 377,
|
||||
"delay": 68.699,
|
||||
"offset": -0.61,
|
||||
"jitter": 2.576,
|
||||
"state": "+"
|
||||
},
|
||||
{
|
||||
"remote": "72.5.72.15",
|
||||
"refid": "216.218.254.202",
|
||||
"st": 2,
|
||||
"t": "u",
|
||||
"when": 63,
|
||||
"poll": 64,
|
||||
"reach": 377,
|
||||
"delay": 22.654,
|
||||
"offset": 0.231,
|
||||
"jitter": 1.964,
|
||||
"state": "*"
|
||||
}
|
||||
]
|
||||
|
||||
$ ntpq -pn| jc --ntpq -p -r
|
||||
[
|
||||
{
|
||||
"s": "+",
|
||||
"remote": "44.190.6.254",
|
||||
"refid": "127.67.113.92",
|
||||
"st": "2",
|
||||
"t": "u",
|
||||
"when": "66",
|
||||
"poll": "64",
|
||||
"reach": "377",
|
||||
"delay": "22.690",
|
||||
"offset": "-0.392",
|
||||
"jitter": "2.085"
|
||||
},
|
||||
{
|
||||
"s": "-",
|
||||
"remote": "108.59.2.24",
|
||||
"refid": "130.133.1.10",
|
||||
"st": "2",
|
||||
"t": "u",
|
||||
"when": "63",
|
||||
"poll": "64",
|
||||
"reach": "377",
|
||||
"delay": "90.805",
|
||||
"offset": "2.840",
|
||||
"jitter": "1.908"
|
||||
},
|
||||
{
|
||||
"s": "+",
|
||||
"remote": "38.229.71.1",
|
||||
"refid": "204.9.54.119",
|
||||
"st": "2",
|
||||
"t": "u",
|
||||
"when": "64",
|
||||
"poll": "64",
|
||||
"reach": "377",
|
||||
"delay": "68.699",
|
||||
"offset": "-0.610",
|
||||
"jitter": "2.576"
|
||||
},
|
||||
{
|
||||
"s": "*",
|
||||
"remote": "72.5.72.15",
|
||||
"refid": "216.218.254.202",
|
||||
"st": "2",
|
||||
"t": "u",
|
||||
"when": "63",
|
||||
"poll": "64",
|
||||
"reach": "377",
|
||||
"delay": "22.654",
|
||||
"offset": "0.231",
|
||||
"jitter": "1.964"
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
## info
|
||||
```python
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## process
|
||||
```python
|
||||
process(proc_data)
|
||||
```
|
||||
|
||||
Final processing to conform to the schema.
|
||||
|
||||
Parameters:
|
||||
|
||||
proc_data: (dictionary) raw structured data to process
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Structured data with the following schema:
|
||||
|
||||
[
|
||||
{
|
||||
"state": string, # space/~ converted to null
|
||||
"remote": string,
|
||||
"refid": string,
|
||||
"st": integer,
|
||||
"t": string,
|
||||
"when": integer, # - converted to null
|
||||
"poll": integer,
|
||||
"reach": integer,
|
||||
"delay": float,
|
||||
"offset": float,
|
||||
"jitter": float
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
|
||||
## 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:
|
||||
|
||||
List of dictionaries. Raw or processed structured data.
|
||||
|
||||
135
docs/parsers/passwd.md
Normal file
135
docs/parsers/passwd.md
Normal file
@@ -0,0 +1,135 @@
|
||||
|
||||
# jc.parsers.passwd
|
||||
jc - JSON CLI output utility `/etc/passwd` file Parser
|
||||
|
||||
Usage (cli):
|
||||
|
||||
$ cat /etc/passwd | jc --passwd
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.passwd
|
||||
result = jc.parsers.passwd.parse(passwd_file_output)
|
||||
|
||||
Compatibility:
|
||||
|
||||
'linux', 'darwin', 'aix', 'freebsd'
|
||||
|
||||
Examples:
|
||||
|
||||
$ cat /etc/passwd | jc --passwd -p
|
||||
[
|
||||
{
|
||||
"username": "nobody",
|
||||
"password": "*",
|
||||
"uid": -2,
|
||||
"gid": -2,
|
||||
"comment": "Unprivileged User",
|
||||
"home": "/var/empty",
|
||||
"shell": "/usr/bin/false"
|
||||
},
|
||||
{
|
||||
"username": "root",
|
||||
"password": "*",
|
||||
"uid": 0,
|
||||
"gid": 0,
|
||||
"comment": "System Administrator",
|
||||
"home": "/var/root",
|
||||
"shell": "/bin/sh"
|
||||
},
|
||||
{
|
||||
"username": "daemon",
|
||||
"password": "*",
|
||||
"uid": 1,
|
||||
"gid": 1,
|
||||
"comment": "System Services",
|
||||
"home": "/var/root",
|
||||
"shell": "/usr/bin/false"
|
||||
},
|
||||
...
|
||||
]
|
||||
|
||||
$ cat /etc/passwd | jc --passwd -p -r
|
||||
[
|
||||
{
|
||||
"username": "nobody",
|
||||
"password": "*",
|
||||
"uid": "-2",
|
||||
"gid": "-2",
|
||||
"comment": "Unprivileged User",
|
||||
"home": "/var/empty",
|
||||
"shell": "/usr/bin/false"
|
||||
},
|
||||
{
|
||||
"username": "root",
|
||||
"password": "*",
|
||||
"uid": "0",
|
||||
"gid": "0",
|
||||
"comment": "System Administrator",
|
||||
"home": "/var/root",
|
||||
"shell": "/bin/sh"
|
||||
},
|
||||
{
|
||||
"username": "daemon",
|
||||
"password": "*",
|
||||
"uid": "1",
|
||||
"gid": "1",
|
||||
"comment": "System Services",
|
||||
"home": "/var/root",
|
||||
"shell": "/usr/bin/false"
|
||||
},
|
||||
...
|
||||
]
|
||||
|
||||
|
||||
## info
|
||||
```python
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## process
|
||||
```python
|
||||
process(proc_data)
|
||||
```
|
||||
|
||||
Final processing to conform to the schema.
|
||||
|
||||
Parameters:
|
||||
|
||||
proc_data: (dictionary) raw structured data to process
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Structured data with the following schema:
|
||||
|
||||
[
|
||||
{
|
||||
"username": string,
|
||||
"password": string,
|
||||
"uid": integer,
|
||||
"gid": integer,
|
||||
"comment": string,
|
||||
"home": string,
|
||||
"shell": 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:
|
||||
|
||||
List of dictionaries. Raw or processed structured data.
|
||||
|
||||
186
docs/parsers/ping.md
Normal file
186
docs/parsers/ping.md
Normal file
@@ -0,0 +1,186 @@
|
||||
|
||||
# jc.parsers.ping
|
||||
jc - JSON CLI output utility `ping` command output parser
|
||||
|
||||
Supports `ping` and `ping6` output.
|
||||
|
||||
Usage (cli):
|
||||
|
||||
Note: Use the ping `-c` (count) option, otherwise data will not be piped to `jc`.
|
||||
|
||||
$ ping -c 3 1.2.3.4 | jc --ping
|
||||
|
||||
or
|
||||
|
||||
$ jc ping -c 3 1.2.3.4
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.ping
|
||||
result = jc.parsers.ping.parse(ping_command_output)
|
||||
|
||||
Compatibility:
|
||||
|
||||
'linux', 'darwin', 'freebsd'
|
||||
|
||||
Examples:
|
||||
|
||||
$ ping -c 3 -p ff cnn.com | jc --ping -p
|
||||
{
|
||||
"destination_ip": "151.101.1.67",
|
||||
"data_bytes": 56,
|
||||
"pattern": "0xff",
|
||||
"destination": "cnn.com",
|
||||
"packets_transmitted": 3,
|
||||
"packets_received": 3,
|
||||
"packet_loss_percent": 0.0,
|
||||
"duplicates": 0,
|
||||
"round_trip_ms_min": 28.015,
|
||||
"round_trip_ms_avg": 32.848,
|
||||
"round_trip_ms_max": 39.376,
|
||||
"round_trip_ms_stddev": 4.79,
|
||||
"responses": [
|
||||
{
|
||||
"type": "reply",
|
||||
"bytes": 64,
|
||||
"response_ip": "151.101.1.67",
|
||||
"icmp_seq": 0,
|
||||
"ttl": 59,
|
||||
"time_ms": 28.015,
|
||||
"duplicate": false
|
||||
},
|
||||
{
|
||||
"type": "reply",
|
||||
"bytes": 64,
|
||||
"response_ip": "151.101.1.67",
|
||||
"icmp_seq": 1,
|
||||
"ttl": 59,
|
||||
"time_ms": 39.376,
|
||||
"duplicate": false
|
||||
},
|
||||
{
|
||||
"type": "reply",
|
||||
"bytes": 64,
|
||||
"response_ip": "151.101.1.67",
|
||||
"icmp_seq": 2,
|
||||
"ttl": 59,
|
||||
"time_ms": 31.153,
|
||||
"duplicate": false
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
$ ping -c 3 -p ff cnn.com | jc --ping -p -r
|
||||
{
|
||||
"destination_ip": "151.101.129.67",
|
||||
"data_bytes": "56",
|
||||
"pattern": "0xff",
|
||||
"destination": "cnn.com",
|
||||
"packets_transmitted": "3",
|
||||
"packets_received": "3",
|
||||
"packet_loss_percent": "0.0",
|
||||
"duplicates": "0",
|
||||
"round_trip_ms_min": "25.078",
|
||||
"round_trip_ms_avg": "29.543",
|
||||
"round_trip_ms_max": "32.553",
|
||||
"round_trip_ms_stddev": "3.221",
|
||||
"responses": [
|
||||
{
|
||||
"type": "reply",
|
||||
"bytes": "64",
|
||||
"response_ip": "151.101.129.67",
|
||||
"icmp_seq": "0",
|
||||
"ttl": "59",
|
||||
"time_ms": "25.078",
|
||||
"duplicate": false
|
||||
},
|
||||
{
|
||||
"type": "reply",
|
||||
"bytes": "64",
|
||||
"response_ip": "151.101.129.67",
|
||||
"icmp_seq": "1",
|
||||
"ttl": "59",
|
||||
"time_ms": "30.999",
|
||||
"duplicate": false
|
||||
},
|
||||
{
|
||||
"type": "reply",
|
||||
"bytes": "64",
|
||||
"response_ip": "151.101.129.67",
|
||||
"icmp_seq": "2",
|
||||
"ttl": "59",
|
||||
"time_ms": "32.553",
|
||||
"duplicate": false
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
## info
|
||||
```python
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## 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:
|
||||
|
||||
{
|
||||
"source_ip": string,
|
||||
"destination_ip": string,
|
||||
"data_bytes": integer,
|
||||
"pattern": string, (null if not set)
|
||||
"destination": string,
|
||||
"packets_transmitted": integer,
|
||||
"packets_received": integer,
|
||||
"packet_loss_percent": float,
|
||||
"duplicates": integer,
|
||||
"round_trip_ms_min": float,
|
||||
"round_trip_ms_avg": float,
|
||||
"round_trip_ms_max": float,
|
||||
"round_trip_ms_stddev": float,
|
||||
"responses": [
|
||||
{
|
||||
"type": string, ('reply' or 'timeout')
|
||||
"timestamp": float,
|
||||
"bytes": integer,
|
||||
"response_ip": string,
|
||||
"icmp_seq": integer,
|
||||
"ttl": integer,
|
||||
"time_ms": float,
|
||||
"duplicate": boolean
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
## 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.
|
||||
|
||||
@@ -1,9 +1,19 @@
|
||||
|
||||
# jc.parsers.pip_list
|
||||
jc - JSON CLI output utility pip-list Parser
|
||||
jc - JSON CLI output utility `pip-list` command output parser
|
||||
|
||||
Usage:
|
||||
Usage (cli):
|
||||
|
||||
specify --pip-list as the first argument if the piped input is coming from pip list
|
||||
$ pip list | jc --pip-list
|
||||
|
||||
or
|
||||
|
||||
$ jc pip list
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.pip_list
|
||||
result = jc.parsers.pip_list.parse(pip_list_command_output)
|
||||
|
||||
Compatibility:
|
||||
|
||||
@@ -28,11 +38,13 @@ Examples:
|
||||
...
|
||||
]
|
||||
|
||||
|
||||
## info
|
||||
```python
|
||||
info(self, /, *args, **kwargs)
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## process
|
||||
```python
|
||||
process(proc_data)
|
||||
@@ -56,6 +68,7 @@ Returns:
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
## parse
|
||||
```python
|
||||
parse(data, raw=False, quiet=False)
|
||||
|
||||
@@ -1,9 +1,19 @@
|
||||
|
||||
# jc.parsers.pip_show
|
||||
jc - JSON CLI output utility pip-show Parser
|
||||
jc - JSON CLI output utility `pip-show` command output parser
|
||||
|
||||
Usage:
|
||||
Usage (cli):
|
||||
|
||||
specify --pip-show as the first argument if the piped input is coming from pip show
|
||||
$ pip show | jc --pip-show
|
||||
|
||||
or
|
||||
|
||||
$ jc pip show
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.pip_show
|
||||
result = jc.parsers.pip_show.parse(pip_show_command_output)
|
||||
|
||||
Compatibility:
|
||||
|
||||
@@ -39,11 +49,13 @@ Examples:
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
## info
|
||||
```python
|
||||
info(self, /, *args, **kwargs)
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## process
|
||||
```python
|
||||
process(proc_data)
|
||||
@@ -75,6 +87,7 @@ Returns:
|
||||
]
|
||||
|
||||
|
||||
|
||||
## parse
|
||||
```python
|
||||
parse(data, raw=False, quiet=False)
|
||||
|
||||
@@ -1,13 +1,23 @@
|
||||
|
||||
# jc.parsers.ps
|
||||
jc - JSON CLI output utility ps Parser
|
||||
jc - JSON CLI output utility `ps` command output parser
|
||||
|
||||
Usage:
|
||||
`ps` options supported:
|
||||
- `ef`
|
||||
- `axu`
|
||||
|
||||
specify --ps as the first argument if the piped input is coming from ps
|
||||
Usage (cli):
|
||||
|
||||
ps options supported:
|
||||
- ef
|
||||
- axu
|
||||
$ ps | jc --ps
|
||||
|
||||
or
|
||||
|
||||
$ jc ps
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.ps
|
||||
result = jc.parsers.ps.parse(ps_command_output)
|
||||
|
||||
Compatibility:
|
||||
|
||||
@@ -173,11 +183,13 @@ Examples:
|
||||
...
|
||||
]
|
||||
|
||||
|
||||
## info
|
||||
```python
|
||||
info(self, /, *args, **kwargs)
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## process
|
||||
```python
|
||||
process(proc_data)
|
||||
@@ -215,6 +227,7 @@ Returns:
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
## parse
|
||||
```python
|
||||
parse(data, raw=False, quiet=False)
|
||||
|
||||
@@ -1,9 +1,19 @@
|
||||
|
||||
# jc.parsers.route
|
||||
jc - JSON CLI output utility route Parser
|
||||
jc - JSON CLI output utility `route` command output parser
|
||||
|
||||
Usage:
|
||||
Usage (cli):
|
||||
|
||||
specify --route as the first argument if the piped input is coming from route
|
||||
$ route | jc --route
|
||||
|
||||
or
|
||||
|
||||
$ jc route
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.route
|
||||
result = jc.parsers.route.parse(route_command_output)
|
||||
|
||||
Compatibility:
|
||||
|
||||
@@ -15,53 +25,48 @@ Examples:
|
||||
[
|
||||
{
|
||||
"destination": "default",
|
||||
"gateway": "gateway",
|
||||
"gateway": "_gateway",
|
||||
"genmask": "0.0.0.0",
|
||||
"flags": "UG",
|
||||
"metric": 100,
|
||||
"metric": 202,
|
||||
"ref": 0,
|
||||
"use": 0,
|
||||
"iface": "ens33",
|
||||
"mss": 0,
|
||||
"window": 0,
|
||||
"irtt": 0
|
||||
},
|
||||
{
|
||||
"destination": "172.17.0.0",
|
||||
"gateway": "0.0.0.0",
|
||||
"genmask": "255.255.0.0",
|
||||
"flags": "U",
|
||||
"metric": 0,
|
||||
"ref": 0,
|
||||
"use": 0,
|
||||
"iface": "docker",
|
||||
"mss": 0,
|
||||
"window": 0,
|
||||
"irtt": 0
|
||||
"irtt": 0,
|
||||
"flags_pretty": [
|
||||
"UP",
|
||||
"GATEWAY"
|
||||
]
|
||||
},
|
||||
{
|
||||
"destination": "192.168.71.0",
|
||||
"gateway": "0.0.0.0",
|
||||
"genmask": "255.255.255.0",
|
||||
"flags": "U",
|
||||
"metric": 100,
|
||||
"metric": 202,
|
||||
"ref": 0,
|
||||
"use": 0,
|
||||
"iface": "ens33",
|
||||
"mss": 0,
|
||||
"window": 0,
|
||||
"irtt": 0
|
||||
"irtt": 0,
|
||||
"flags_pretty": [
|
||||
"UP"
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
$ route -ee | jc --route -p -r
|
||||
[
|
||||
{
|
||||
"destination": "default",
|
||||
"gateway": "gateway",
|
||||
"gateway": "_gateway",
|
||||
"genmask": "0.0.0.0",
|
||||
"flags": "UG",
|
||||
"metric": "100",
|
||||
"metric": "202",
|
||||
"ref": "0",
|
||||
"use": "0",
|
||||
"iface": "ens33",
|
||||
@@ -69,25 +74,12 @@ Examples:
|
||||
"window": "0",
|
||||
"irtt": "0"
|
||||
},
|
||||
{
|
||||
"destination": "172.17.0.0",
|
||||
"gateway": "0.0.0.0",
|
||||
"genmask": "255.255.0.0",
|
||||
"flags": "U",
|
||||
"metric": "0",
|
||||
"ref": "0",
|
||||
"use": "0",
|
||||
"iface": "docker",
|
||||
"mss": "0",
|
||||
"window": "0",
|
||||
"irtt": "0"
|
||||
},
|
||||
{
|
||||
"destination": "192.168.71.0",
|
||||
"gateway": "0.0.0.0",
|
||||
"genmask": "255.255.255.0",
|
||||
"flags": "U",
|
||||
"metric": "100",
|
||||
"metric": "202",
|
||||
"ref": "0",
|
||||
"use": "0",
|
||||
"iface": "ens33",
|
||||
@@ -97,11 +89,14 @@ Examples:
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
|
||||
## info
|
||||
```python
|
||||
info(self, /, *args, **kwargs)
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## process
|
||||
```python
|
||||
process(proc_data)
|
||||
@@ -119,20 +114,24 @@ Returns:
|
||||
|
||||
[
|
||||
{
|
||||
"destination": string,
|
||||
"gateway": string,
|
||||
"genmask": string,
|
||||
"flags": string,
|
||||
"metric": integer,
|
||||
"ref": integer,
|
||||
"use": integer,
|
||||
"mss": integer,
|
||||
"window": integer,
|
||||
"irtt": integer,
|
||||
"iface": string
|
||||
"destination": string,
|
||||
"gateway": string,
|
||||
"genmask": string,
|
||||
"flags": string,
|
||||
"flags_pretty": [
|
||||
string,
|
||||
]
|
||||
"metric": integer,
|
||||
"ref": integer,
|
||||
"use": integer,
|
||||
"mss": integer,
|
||||
"window": integer,
|
||||
"irtt": integer,
|
||||
"iface": string
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
## parse
|
||||
```python
|
||||
parse(data, raw=False, quiet=False)
|
||||
|
||||
142
docs/parsers/shadow.md
Normal file
142
docs/parsers/shadow.md
Normal file
@@ -0,0 +1,142 @@
|
||||
|
||||
# jc.parsers.shadow
|
||||
jc - JSON CLI output utility `/etc/shadow` file parser
|
||||
|
||||
Usage (cli):
|
||||
|
||||
$ sudo cat /etc/shadow | jc --shadow
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.shadow
|
||||
result = jc.parsers.shadow.parse(shadow_file_output)
|
||||
|
||||
Compatibility:
|
||||
|
||||
'linux', 'darwin', 'aix', 'freebsd'
|
||||
|
||||
Examples:
|
||||
|
||||
$ sudo cat /etc/shadow | jc --shadow -p
|
||||
[
|
||||
{
|
||||
"username": "root",
|
||||
"password": "*",
|
||||
"last_changed": 18113,
|
||||
"minimum": 0,
|
||||
"maximum": 99999,
|
||||
"warn": 7,
|
||||
"inactive": null,
|
||||
"expire": null
|
||||
},
|
||||
{
|
||||
"username": "daemon",
|
||||
"password": "*",
|
||||
"last_changed": 18113,
|
||||
"minimum": 0,
|
||||
"maximum": 99999,
|
||||
"warn": 7,
|
||||
"inactive": null,
|
||||
"expire": null
|
||||
},
|
||||
{
|
||||
"username": "bin",
|
||||
"password": "*",
|
||||
"last_changed": 18113,
|
||||
"minimum": 0,
|
||||
"maximum": 99999,
|
||||
"warn": 7,
|
||||
"inactive": null,
|
||||
"expire": null
|
||||
},
|
||||
...
|
||||
]
|
||||
|
||||
$ sudo cat /etc/shadow | jc --shadow -p -r
|
||||
[
|
||||
{
|
||||
"username": "root",
|
||||
"password": "*",
|
||||
"last_changed": "18113",
|
||||
"minimum": "0",
|
||||
"maximum": "99999",
|
||||
"warn": "7",
|
||||
"inactive": "",
|
||||
"expire": ""
|
||||
},
|
||||
{
|
||||
"username": "daemon",
|
||||
"password": "*",
|
||||
"last_changed": "18113",
|
||||
"minimum": "0",
|
||||
"maximum": "99999",
|
||||
"warn": "7",
|
||||
"inactive": "",
|
||||
"expire": ""
|
||||
},
|
||||
{
|
||||
"username": "bin",
|
||||
"password": "*",
|
||||
"last_changed": "18113",
|
||||
"minimum": "0",
|
||||
"maximum": "99999",
|
||||
"warn": "7",
|
||||
"inactive": "",
|
||||
"expire": ""
|
||||
},
|
||||
...
|
||||
]
|
||||
|
||||
|
||||
## info
|
||||
```python
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## process
|
||||
```python
|
||||
process(proc_data)
|
||||
```
|
||||
|
||||
Final processing to conform to the schema.
|
||||
|
||||
Parameters:
|
||||
|
||||
proc_data: (dictionary) raw structured data to process
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Structured data with the following schema:
|
||||
|
||||
[
|
||||
{
|
||||
"username": string,
|
||||
"password": string,
|
||||
"last_changed": integer,
|
||||
"minimum": integer,
|
||||
"maximum": integer,
|
||||
"warn": integer,
|
||||
"inactive": integer,
|
||||
"expire": integer
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
## 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:
|
||||
|
||||
List of dictionaries. Raw or processed structured data.
|
||||
|
||||
@@ -1,9 +1,19 @@
|
||||
|
||||
# jc.parsers.ss
|
||||
jc - JSON CLI output utility ss Parser
|
||||
jc - JSON CLI output utility `ss` command output parser
|
||||
|
||||
Usage:
|
||||
Usage (cli):
|
||||
|
||||
specify --ss as the first argument if the piped input is coming from ss
|
||||
$ ss | jc --ss
|
||||
|
||||
or
|
||||
|
||||
$ jc ss
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.ss
|
||||
result = jc.parsers.ss.parse(ss_command_output)
|
||||
|
||||
Limitations:
|
||||
|
||||
@@ -247,11 +257,13 @@ Examples:
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
## info
|
||||
```python
|
||||
info(self, /, *args, **kwargs)
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## process
|
||||
```python
|
||||
process(proc_data)
|
||||
@@ -289,6 +301,7 @@ Returns:
|
||||
|
||||
Information from https://www.cyberciti.biz/files/ss.html used to define field names
|
||||
|
||||
|
||||
## parse
|
||||
```python
|
||||
parse(data, raw=False, quiet=False)
|
||||
|
||||
@@ -1,13 +1,23 @@
|
||||
|
||||
# jc.parsers.stat
|
||||
jc - JSON CLI output utility stat Parser
|
||||
jc - JSON CLI output utility `stat` command output parser
|
||||
|
||||
Usage:
|
||||
Usage (cli):
|
||||
|
||||
specify --stat as the first argument if the piped input is coming from stat
|
||||
$ stat * | jc --stat
|
||||
|
||||
or
|
||||
|
||||
$ jc stat *
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.stat
|
||||
result = jc.parsers.stat.parse(stat_command_output)
|
||||
|
||||
Compatibility:
|
||||
|
||||
'linux'
|
||||
'linux', 'darwin', 'freebsd'
|
||||
|
||||
Examples:
|
||||
|
||||
@@ -101,11 +111,13 @@ Examples:
|
||||
..
|
||||
]
|
||||
|
||||
|
||||
## info
|
||||
```python
|
||||
info(self, /, *args, **kwargs)
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## process
|
||||
```python
|
||||
process(proc_data)
|
||||
@@ -141,10 +153,15 @@ Returns:
|
||||
"access_time": string, # - = null
|
||||
"modify_time": string, # - = null
|
||||
"change_time": string, # - = null
|
||||
"birth_time": string # - = null
|
||||
"birth_time": string, # - = null
|
||||
"unix_device": integer,
|
||||
"rdev": integer,
|
||||
"block_size": integer,
|
||||
"unix_flags": string
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
## parse
|
||||
```python
|
||||
parse(data, raw=False, quiet=False)
|
||||
|
||||
95
docs/parsers/sysctl.md
Normal file
95
docs/parsers/sysctl.md
Normal file
@@ -0,0 +1,95 @@
|
||||
|
||||
# jc.parsers.sysctl
|
||||
jc - JSON CLI output utility `sysctl -a` command output parser
|
||||
|
||||
Note: Since `sysctl` output is not easily parsable only a very simple key/value object will be output. An attempt is made to convert obvious integers and floats. If no conversion is desired, use the `-r` command-line argument or the `raw=True` argument in `parse()`.
|
||||
|
||||
Usage (cli):
|
||||
|
||||
$ sysctl -a | jc --sysctl
|
||||
|
||||
or
|
||||
|
||||
$ jc sysctl -a
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.sysctl
|
||||
result = jc.parsers.sysctl.parse(sysctl_command_output)
|
||||
|
||||
Compatibility:
|
||||
|
||||
'linux', 'darwin', 'freebsd'
|
||||
|
||||
Examples:
|
||||
|
||||
$ sysctl -a | jc --sysctl -p
|
||||
{
|
||||
"user.cs_path": "/usr/bin:/bin:/usr/sbin:/sbin",
|
||||
"user.bc_base_max": 99,
|
||||
"user.bc_dim_max": 2048,
|
||||
"user.bc_scale_max": 99,
|
||||
"user.bc_string_max": 1000,
|
||||
"user.coll_weights_max": 2,
|
||||
"user.expr_nest_max": 32
|
||||
...
|
||||
}
|
||||
|
||||
$ sysctl -a | jc --sysctl -p -r
|
||||
{
|
||||
"user.cs_path": "/usr/bin:/bin:/usr/sbin:/sbin",
|
||||
"user.bc_base_max": "99",
|
||||
"user.bc_dim_max": "2048",
|
||||
"user.bc_scale_max": "99",
|
||||
"user.bc_string_max": "1000",
|
||||
"user.coll_weights_max": "2",
|
||||
"user.expr_nest_max": "32",
|
||||
...
|
||||
}
|
||||
|
||||
|
||||
## info
|
||||
```python
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## 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:
|
||||
|
||||
{
|
||||
"foo": string/integer/float, # best guess based on value
|
||||
"bar": string/integer/float,
|
||||
"baz": string/integer/float
|
||||
}
|
||||
|
||||
|
||||
## 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.
|
||||
|
||||
@@ -1,9 +1,19 @@
|
||||
|
||||
# jc.parsers.systemctl
|
||||
jc - JSON CLI output utility systemctl Parser
|
||||
jc - JSON CLI output utility `systemctl` command output parser
|
||||
|
||||
Usage:
|
||||
Usage (cli):
|
||||
|
||||
specify --systemctl as the first argument if the piped input is coming from systemctl
|
||||
$ systemctl | jc --systemctl
|
||||
|
||||
or
|
||||
|
||||
$ jc systemctl
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.systemctl
|
||||
result = jc.parsers.systemctl.parse(systemctl_command_output)
|
||||
|
||||
Compatibility:
|
||||
|
||||
@@ -37,11 +47,13 @@ Examples:
|
||||
...
|
||||
]
|
||||
|
||||
|
||||
## info
|
||||
```python
|
||||
info(self, /, *args, **kwargs)
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## process
|
||||
```python
|
||||
process(proc_data)
|
||||
@@ -67,6 +79,7 @@ Returns:
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
## parse
|
||||
```python
|
||||
parse(data, raw=False, quiet=False)
|
||||
|
||||
@@ -1,9 +1,19 @@
|
||||
|
||||
# jc.parsers.systemctl_lj
|
||||
jc - JSON CLI output utility systemctl-lj Parser
|
||||
jc - JSON CLI output utility `systemctl list-jobs` command output parser
|
||||
|
||||
Usage:
|
||||
Usage (cli):
|
||||
|
||||
specify --systemctl-lj as the first argument if the piped input is coming from systemctl list-jobs
|
||||
$ systemctl list-jobs | jc --systemctl-lj
|
||||
|
||||
or
|
||||
|
||||
$ jc systemctl list-jobs
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.systemctl_lj
|
||||
result = jc.parsers.systemctl_lj.parse(systemctl_lj_command_output)
|
||||
|
||||
Compatibility:
|
||||
|
||||
@@ -56,11 +66,13 @@ Examples:
|
||||
]
|
||||
|
||||
|
||||
|
||||
## info
|
||||
```python
|
||||
info(self, /, *args, **kwargs)
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## process
|
||||
```python
|
||||
process(proc_data)
|
||||
@@ -85,6 +97,7 @@ Returns:
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
## parse
|
||||
```python
|
||||
parse(data, raw=False, quiet=False)
|
||||
|
||||
@@ -1,9 +1,19 @@
|
||||
|
||||
# jc.parsers.systemctl_ls
|
||||
jc - JSON CLI output utility systemctl-ls Parser
|
||||
jc - JSON CLI output utility `systemctl list-sockets` command output parser
|
||||
|
||||
Usage:
|
||||
Usage (cli):
|
||||
|
||||
specify --systemctl-ls as the first argument if the piped input is coming from systemctl list-sockets
|
||||
$ systemctl list-sockets | jc --systemctl-ls
|
||||
|
||||
or
|
||||
|
||||
$ jc systemctl list-sockets
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.systemctl_ls
|
||||
result = jc.parsers.systemctl_ls.parse(systemctl_ls_command_output)
|
||||
|
||||
Compatibility:
|
||||
|
||||
@@ -31,11 +41,13 @@ Examples:
|
||||
...
|
||||
]
|
||||
|
||||
|
||||
## info
|
||||
```python
|
||||
info(self, /, *args, **kwargs)
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## process
|
||||
```python
|
||||
process(proc_data)
|
||||
@@ -59,6 +71,7 @@ Returns:
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
## parse
|
||||
```python
|
||||
parse(data, raw=False, quiet=False)
|
||||
|
||||
@@ -1,9 +1,19 @@
|
||||
|
||||
# jc.parsers.systemctl_luf
|
||||
jc - JSON CLI output utility systemctl-luf Parser
|
||||
jc - JSON CLI output utility `systemctl list-unit-files` command output parser
|
||||
|
||||
Usage:
|
||||
Usage (cli):
|
||||
|
||||
specify --systemctl-luf as the first argument if the piped input is coming from systemctl list-unit-files
|
||||
$ systemctl list-unit-files | jc --systemctl-luf
|
||||
|
||||
or
|
||||
|
||||
$ jc systemctl list-unit-files
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.systemctl_luf
|
||||
result = jc.parsers.systemctl_luf.parse(systemctl_luf_command_output)
|
||||
|
||||
Compatibility:
|
||||
|
||||
@@ -28,11 +38,13 @@ Examples:
|
||||
...
|
||||
]
|
||||
|
||||
|
||||
## info
|
||||
```python
|
||||
info(self, /, *args, **kwargs)
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## process
|
||||
```python
|
||||
process(proc_data)
|
||||
@@ -55,6 +67,7 @@ Returns:
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
## parse
|
||||
```python
|
||||
parse(data, raw=False, quiet=False)
|
||||
|
||||
100
docs/parsers/timedatectl.md
Normal file
100
docs/parsers/timedatectl.md
Normal file
@@ -0,0 +1,100 @@
|
||||
|
||||
# jc.parsers.timedatectl
|
||||
jc - JSON CLI output utility `timedatectl` command output parser
|
||||
|
||||
Usage (cli):
|
||||
|
||||
$ timedatectl | jc --timedatectl
|
||||
|
||||
or
|
||||
|
||||
$ jc timedatectl
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.timedatectl
|
||||
result = jc.parsers.timedatectl.parse(timedatectl_command_output)
|
||||
|
||||
Compatibility:
|
||||
|
||||
'linux'
|
||||
|
||||
Examples:
|
||||
|
||||
$ timedatectl | jc --timedatectl -p
|
||||
{
|
||||
"local_time": "Tue 2020-03-10 17:53:21 PDT",
|
||||
"universal_time": "Wed 2020-03-11 00:53:21 UTC",
|
||||
"rtc_time": "Wed 2020-03-11 00:53:21",
|
||||
"time_zone": "America/Los_Angeles (PDT, -0700)",
|
||||
"ntp_enabled": true,
|
||||
"ntp_synchronized": true,
|
||||
"rtc_in_local_tz": false,
|
||||
"dst_active": true
|
||||
}
|
||||
|
||||
$ timedatectl | jc --timedatectl -p -r
|
||||
{
|
||||
"local_time": "Tue 2020-03-10 17:53:21 PDT",
|
||||
"universal_time": "Wed 2020-03-11 00:53:21 UTC",
|
||||
"rtc_time": "Wed 2020-03-11 00:53:21",
|
||||
"time_zone": "America/Los_Angeles (PDT, -0700)",
|
||||
"ntp_enabled": "yes",
|
||||
"ntp_synchronized": "yes",
|
||||
"rtc_in_local_tz": "no",
|
||||
"dst_active": "yes"
|
||||
}
|
||||
|
||||
|
||||
## info
|
||||
```python
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## 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:
|
||||
|
||||
{
|
||||
"local_time": string,
|
||||
"universal_time": string,
|
||||
"rtc_time": string,
|
||||
"time_zone": string,
|
||||
"ntp_enabled": boolean,
|
||||
"ntp_synchronized": boolean,
|
||||
"system_clock_synchronized": boolean,
|
||||
"systemd-timesyncd.service_active": boolean,
|
||||
"rtc_in_local_tz": boolean,
|
||||
"dst_active": boolean
|
||||
}
|
||||
|
||||
|
||||
## 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.
|
||||
|
||||
173
docs/parsers/tracepath.md
Normal file
173
docs/parsers/tracepath.md
Normal file
@@ -0,0 +1,173 @@
|
||||
|
||||
# jc.parsers.tracepath
|
||||
jc - JSON CLI output utility `tracepath` command output parser
|
||||
|
||||
Supports `tracepath` and `tracepath6` output.
|
||||
|
||||
Usage (cli):
|
||||
|
||||
$ tracepath 1.2.3.4 | jc --tracepath
|
||||
|
||||
or
|
||||
|
||||
$ jc tracepath 1.2.3.4
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.tracepath
|
||||
result = jc.parsers.tracepath.parse(tracepath_command_output)
|
||||
|
||||
Compatibility:
|
||||
|
||||
'linux'
|
||||
|
||||
Examples:
|
||||
|
||||
$ tracepath6 3ffe:2400:0:109::2 | jc --tracepath -p
|
||||
{
|
||||
"pmtu": 1480,
|
||||
"forward_hops": 2,
|
||||
"return_hops": 2,
|
||||
"hops": [
|
||||
{
|
||||
"ttl": 1,
|
||||
"guess": true,
|
||||
"host": "[LOCALHOST]",
|
||||
"reply_ms": null,
|
||||
"pmtu": 1500,
|
||||
"asymmetric_difference": null,
|
||||
"reached": false
|
||||
},
|
||||
{
|
||||
"ttl": 1,
|
||||
"guess": false,
|
||||
"host": "dust.inr.ac.ru",
|
||||
"reply_ms": 0.411,
|
||||
"pmtu": null,
|
||||
"asymmetric_difference": null,
|
||||
"reached": false
|
||||
},
|
||||
{
|
||||
"ttl": 2,
|
||||
"guess": false,
|
||||
"host": "dust.inr.ac.ru",
|
||||
"reply_ms": 0.39,
|
||||
"pmtu": 1480,
|
||||
"asymmetric_difference": 1,
|
||||
"reached": false
|
||||
},
|
||||
{
|
||||
"ttl": 2,
|
||||
"guess": false,
|
||||
"host": "3ffe:2400:0:109::2",
|
||||
"reply_ms": 463.514,
|
||||
"pmtu": null,
|
||||
"asymmetric_difference": null,
|
||||
"reached": true
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
$ tracepath6 3ffe:2400:0:109::2 | jc --tracepath -p -r
|
||||
{
|
||||
"pmtu": "1480",
|
||||
"forward_hops": "2",
|
||||
"return_hops": "2",
|
||||
"hops": [
|
||||
{
|
||||
"ttl": "1",
|
||||
"guess": true,
|
||||
"host": "[LOCALHOST]",
|
||||
"reply_ms": null,
|
||||
"pmtu": "1500",
|
||||
"asymmetric_difference": null,
|
||||
"reached": false
|
||||
},
|
||||
{
|
||||
"ttl": "1",
|
||||
"guess": false,
|
||||
"host": "dust.inr.ac.ru",
|
||||
"reply_ms": "0.411",
|
||||
"pmtu": null,
|
||||
"asymmetric_difference": null,
|
||||
"reached": false
|
||||
},
|
||||
{
|
||||
"ttl": "2",
|
||||
"guess": false,
|
||||
"host": "dust.inr.ac.ru",
|
||||
"reply_ms": "0.390",
|
||||
"pmtu": "1480",
|
||||
"asymmetric_difference": "1",
|
||||
"reached": false
|
||||
},
|
||||
{
|
||||
"ttl": "2",
|
||||
"guess": false,
|
||||
"host": "3ffe:2400:0:109::2",
|
||||
"reply_ms": "463.514",
|
||||
"pmtu": null,
|
||||
"asymmetric_difference": null,
|
||||
"reached": true
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
|
||||
## info
|
||||
```python
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## 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:
|
||||
|
||||
{
|
||||
"pmtu": integer,
|
||||
"forward_hops": integer,
|
||||
"return_hops": integer,
|
||||
"hops": [
|
||||
{
|
||||
"ttl": integer,
|
||||
"guess": boolean,
|
||||
"host": string,
|
||||
"reply_ms": float,
|
||||
"pmtu": integer,
|
||||
"asymmetric_difference": integer,
|
||||
"reached": boolean
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
## 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.
|
||||
|
||||
164
docs/parsers/traceroute.md
Normal file
164
docs/parsers/traceroute.md
Normal file
@@ -0,0 +1,164 @@
|
||||
|
||||
# jc.parsers.traceroute
|
||||
jc - JSON CLI output utility `traceroute` command output parser
|
||||
|
||||
Supports `traceroute` and `traceroute6` output.
|
||||
|
||||
Note: On some operating systems you will need to redirect `STDERR` to `STDOUT` for destination info since the header line is sent to `STDERR`. A warning message will be printed to `STDERR` if the header row is not found.
|
||||
|
||||
e.g. `$ traceroute 8.8.8.8 2>&1 | jc --traceroute`
|
||||
|
||||
Usage (cli):
|
||||
|
||||
$ traceroute 1.2.3.4 | jc --traceroute
|
||||
|
||||
or
|
||||
|
||||
$ jc traceroute 1.2.3.4
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.traceroute
|
||||
result = jc.parsers.traceroute.parse(traceroute_command_output)
|
||||
|
||||
Compatibility:
|
||||
|
||||
'linux', 'darwin', 'freebsd'
|
||||
|
||||
Examples:
|
||||
|
||||
$ traceroute google.com | jc --traceroute -p
|
||||
{
|
||||
"destination_ip": "216.58.194.46",
|
||||
"destination_name": "google.com",
|
||||
"hops": [
|
||||
{
|
||||
"hop": 1,
|
||||
"probes": [
|
||||
{
|
||||
"annotation": null,
|
||||
"asn": null,
|
||||
"ip": "216.230.231.141",
|
||||
"name": "216-230-231-141.static.houston.tx.oplink.net",
|
||||
"rtt": 198.574
|
||||
},
|
||||
{
|
||||
"annotation": null,
|
||||
"asn": null,
|
||||
"ip": "216.230.231.141",
|
||||
"name": "216-230-231-141.static.houston.tx.oplink.net",
|
||||
"rtt": null
|
||||
},
|
||||
{
|
||||
"annotation": null,
|
||||
"asn": null,
|
||||
"ip": "216.230.231.141",
|
||||
"name": "216-230-231-141.static.houston.tx.oplink.net",
|
||||
"rtt": 198.65
|
||||
}
|
||||
]
|
||||
},
|
||||
...
|
||||
]
|
||||
}
|
||||
|
||||
$ traceroute google.com | jc --traceroute -p -r
|
||||
{
|
||||
"destination_ip": "216.58.194.46",
|
||||
"destination_name": "google.com",
|
||||
"hops": [
|
||||
{
|
||||
"hop": "1",
|
||||
"probes": [
|
||||
{
|
||||
"annotation": null,
|
||||
"asn": null,
|
||||
"ip": "216.230.231.141",
|
||||
"name": "216-230-231-141.static.houston.tx.oplink.net",
|
||||
"rtt": "198.574"
|
||||
},
|
||||
{
|
||||
"annotation": null,
|
||||
"asn": null,
|
||||
"ip": "216.230.231.141",
|
||||
"name": "216-230-231-141.static.houston.tx.oplink.net",
|
||||
"rtt": null
|
||||
},
|
||||
{
|
||||
"annotation": null,
|
||||
"asn": null,
|
||||
"ip": "216.230.231.141",
|
||||
"name": "216-230-231-141.static.houston.tx.oplink.net",
|
||||
"rtt": "198.650"
|
||||
}
|
||||
]
|
||||
},
|
||||
...
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
## info
|
||||
```python
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## Hop
|
||||
```python
|
||||
Hop(idx)
|
||||
```
|
||||
|
||||
|
||||
## 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:
|
||||
|
||||
{
|
||||
"destination_ip": string,
|
||||
"destination_name": string,
|
||||
"hops": [
|
||||
{
|
||||
"hop": integer,
|
||||
"probes": [
|
||||
{
|
||||
"annotation": string,
|
||||
"asn": integer,
|
||||
"ip": string,
|
||||
"name": string,
|
||||
"rtt": float
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
## 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.
|
||||
|
||||
@@ -1,17 +1,25 @@
|
||||
|
||||
# jc.parsers.uname
|
||||
jc - JSON CLI output utility uname Parser
|
||||
jc - JSON CLI output utility `uname -a` command output parser
|
||||
|
||||
Usage:
|
||||
Note: Must use `uname -a`
|
||||
|
||||
specify --uname as the first argument if the piped input is coming from uname
|
||||
Usage (cli):
|
||||
|
||||
Limitations:
|
||||
$ uname -a | jc --uname
|
||||
|
||||
must use 'uname -a'
|
||||
or
|
||||
|
||||
$ jc uname -a
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.uname
|
||||
result = jc.parsers.uname.parse(uname_command_output)
|
||||
|
||||
Compatibility:
|
||||
|
||||
'linux', 'darwin'
|
||||
'linux', 'darwin', 'freebsd'
|
||||
|
||||
Example:
|
||||
|
||||
@@ -27,11 +35,13 @@ Example:
|
||||
"kernel_version": "#74-Ubuntu SMP Tue Sep 17 17:06:04 UTC 2019"
|
||||
}
|
||||
|
||||
|
||||
## info
|
||||
```python
|
||||
info(self, /, *args, **kwargs)
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## process
|
||||
```python
|
||||
process(proc_data)
|
||||
@@ -58,6 +68,7 @@ Returns:
|
||||
"kernel_version": string
|
||||
}
|
||||
|
||||
|
||||
## parse
|
||||
```python
|
||||
parse(data, raw=False, quiet=False)
|
||||
|
||||
@@ -1,9 +1,19 @@
|
||||
|
||||
# jc.parsers.uptime
|
||||
jc - JSON CLI output utility uptime Parser
|
||||
jc - JSON CLI output utility `uptime` command output parser
|
||||
|
||||
Usage:
|
||||
Usage (cli):
|
||||
|
||||
specify --uptime as the first argument if the piped input is coming from uptime
|
||||
$ uptime | jc --uptime
|
||||
|
||||
or
|
||||
|
||||
$ jc uptime
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.uptime
|
||||
result = jc.parsers.uptime.parse(uptime_command_output)
|
||||
|
||||
Compatibility:
|
||||
|
||||
@@ -31,11 +41,13 @@ Example:
|
||||
"load_15m": "0.05"
|
||||
}
|
||||
|
||||
|
||||
## info
|
||||
```python
|
||||
info(self, /, *args, **kwargs)
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## process
|
||||
```python
|
||||
process(proc_data)
|
||||
@@ -60,6 +72,7 @@ Returns:
|
||||
"load_15m": float
|
||||
}
|
||||
|
||||
|
||||
## parse
|
||||
```python
|
||||
parse(data, raw=False, quiet=False)
|
||||
|
||||
@@ -1,9 +1,19 @@
|
||||
|
||||
# jc.parsers.w
|
||||
jc - JSON CLI output utility w Parser
|
||||
jc - JSON CLI output utility `w` command output parser
|
||||
|
||||
Usage:
|
||||
Usage (cli):
|
||||
|
||||
specify --w as the first argument if the piped input is coming from w
|
||||
$ w | jc --w
|
||||
|
||||
or
|
||||
|
||||
$ jc w
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.w
|
||||
result = jc.parsers.w.parse(w_command_output)
|
||||
|
||||
Compatibility:
|
||||
|
||||
@@ -79,11 +89,13 @@ Examples:
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
## info
|
||||
```python
|
||||
info(self, /, *args, **kwargs)
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## process
|
||||
```python
|
||||
process(proc_data)
|
||||
@@ -112,6 +124,7 @@ Returns:
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
## parse
|
||||
```python
|
||||
parse(data, raw=False, quiet=False)
|
||||
|
||||
165
docs/parsers/who.md
Normal file
165
docs/parsers/who.md
Normal file
@@ -0,0 +1,165 @@
|
||||
|
||||
# jc.parsers.who
|
||||
jc - JSON CLI output utility `who` command output parser
|
||||
|
||||
Accepts any of the following who options (or no options): `-aTH`
|
||||
|
||||
Usage (cli):
|
||||
|
||||
$ who | jc --who
|
||||
|
||||
or
|
||||
|
||||
$ jc who
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.who
|
||||
result = jc.parsers.who.parse(who_command_output)
|
||||
|
||||
Compatibility:
|
||||
|
||||
'linux', 'darwin', 'cygwin', 'aix', 'freebsd'
|
||||
|
||||
Examples:
|
||||
|
||||
$ who -a | jc --who -p
|
||||
[
|
||||
{
|
||||
"event": "reboot",
|
||||
"time": "Feb 7 23:31",
|
||||
"pid": 1
|
||||
},
|
||||
{
|
||||
"user": "joeuser",
|
||||
"writeable_tty": "-",
|
||||
"tty": "console",
|
||||
"time": "Feb 7 23:32",
|
||||
"idle": "old",
|
||||
"pid": 105
|
||||
},
|
||||
{
|
||||
"user": "joeuser",
|
||||
"writeable_tty": "+",
|
||||
"tty": "ttys000",
|
||||
"time": "Feb 13 16:44",
|
||||
"idle": ".",
|
||||
"pid": 51217,
|
||||
"comment": "term=0 exit=0"
|
||||
},
|
||||
{
|
||||
"user": "joeuser",
|
||||
"writeable_tty": "?",
|
||||
"tty": "ttys003",
|
||||
"time": "Feb 28 08:59",
|
||||
"idle": "01:36",
|
||||
"pid": 41402
|
||||
},
|
||||
{
|
||||
"user": "joeuser",
|
||||
"writeable_tty": "+",
|
||||
"tty": "ttys004",
|
||||
"time": "Mar 1 16:35",
|
||||
"idle": ".",
|
||||
"pid": 15679,
|
||||
"from": "192.168.1.5"
|
||||
}
|
||||
]
|
||||
|
||||
$ who -a | jc --who -p -r
|
||||
[
|
||||
{
|
||||
"event": "reboot",
|
||||
"time": "Feb 7 23:31",
|
||||
"pid": "1"
|
||||
},
|
||||
{
|
||||
"user": "joeuser",
|
||||
"writeable_tty": "-",
|
||||
"tty": "console",
|
||||
"time": "Feb 7 23:32",
|
||||
"idle": "old",
|
||||
"pid": "105"
|
||||
},
|
||||
{
|
||||
"user": "joeuser",
|
||||
"writeable_tty": "+",
|
||||
"tty": "ttys000",
|
||||
"time": "Feb 13 16:44",
|
||||
"idle": ".",
|
||||
"pid": "51217",
|
||||
"comment": "term=0 exit=0"
|
||||
},
|
||||
{
|
||||
"user": "joeuser",
|
||||
"writeable_tty": "?",
|
||||
"tty": "ttys003",
|
||||
"time": "Feb 28 08:59",
|
||||
"idle": "01:36",
|
||||
"pid": "41402"
|
||||
},
|
||||
{
|
||||
"user": "joeuser",
|
||||
"writeable_tty": "+",
|
||||
"tty": "ttys004",
|
||||
"time": "Mar 1 16:35",
|
||||
"idle": ".",
|
||||
"pid": "15679",
|
||||
"from": "192.168.1.5"
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
## info
|
||||
```python
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## process
|
||||
```python
|
||||
process(proc_data)
|
||||
```
|
||||
|
||||
Final processing to conform to the schema.
|
||||
|
||||
Parameters:
|
||||
|
||||
proc_data: (dictionary) raw structured data to process
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Structured data with the following schema:
|
||||
|
||||
[
|
||||
{
|
||||
"user": string,
|
||||
"event": string,
|
||||
"writeable_tty": string,
|
||||
"tty": string,
|
||||
"time": string,
|
||||
"idle": string,
|
||||
"pid": integer,
|
||||
"from": string,
|
||||
"comment": 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:
|
||||
|
||||
List of dictionaries. Raw or processed structured data.
|
||||
|
||||
@@ -1,9 +1,15 @@
|
||||
|
||||
# jc.parsers.xml
|
||||
jc - JSON CLI output utility XML Parser
|
||||
jc - JSON CLI output utility `XML` file parser
|
||||
|
||||
Usage:
|
||||
Usage (cli):
|
||||
|
||||
specify --xml as the first argument if the piped input is coming from an XML file
|
||||
$ cat foo.xml | jc --xml
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.xml
|
||||
result = jc.parsers.xml.parse(xml_file_output)
|
||||
|
||||
Compatibility:
|
||||
|
||||
@@ -55,11 +61,13 @@ Examples:
|
||||
...
|
||||
}
|
||||
|
||||
|
||||
## info
|
||||
```python
|
||||
info(self, /, *args, **kwargs)
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## process
|
||||
```python
|
||||
process(proc_data)
|
||||
@@ -80,6 +88,7 @@ Returns:
|
||||
See https://github.com/martinblech/xmltodict for details
|
||||
}
|
||||
|
||||
|
||||
## parse
|
||||
```python
|
||||
parse(data, raw=False, quiet=False)
|
||||
|
||||
@@ -1,9 +1,15 @@
|
||||
|
||||
# jc.parsers.yaml
|
||||
jc - JSON CLI output utility YAML Parser
|
||||
jc - JSON CLI output utility `YAML` file parser
|
||||
|
||||
Usage:
|
||||
Usage (cli):
|
||||
|
||||
specify --yaml as the first argument if the piped input is coming from a YAML file
|
||||
$ cat foo.yaml | jc --yaml
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.yaml
|
||||
result = jc.parsers.yaml.parse(yaml_file_output)
|
||||
|
||||
Compatibility:
|
||||
|
||||
@@ -67,11 +73,13 @@ Examples:
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
## info
|
||||
```python
|
||||
info(self, /, *args, **kwargs)
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## process
|
||||
```python
|
||||
process(proc_data)
|
||||
@@ -94,6 +102,7 @@ Returns:
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
## parse
|
||||
```python
|
||||
parse(data, raw=False, quiet=False)
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
|
||||
# jc
|
||||
JC - JSON CLI output utility
|
||||
|
||||
@@ -5,6 +6,8 @@ JC - JSON CLI output utility
|
||||
|
||||
This package serializes the output of many standard unix command line tools to JSON format.
|
||||
|
||||
For documentation on each parser, see [docs/parsers](https://github.com/kellyjonbrazil/jc/tree/master/docs/parsers).
|
||||
|
||||
CLI Example:
|
||||
|
||||
$ ls -l /usr/bin | jc --ls -p
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
|
||||
# utils
|
||||
jc - JSON CLI output utility utils
|
||||
|
||||
## warning_message
|
||||
```python
|
||||
warning_message(message)
|
||||
@@ -15,6 +17,7 @@ Returns:
|
||||
|
||||
no return, just prints output to STDERR
|
||||
|
||||
|
||||
## error_message
|
||||
```python
|
||||
error_message(message)
|
||||
@@ -30,6 +33,7 @@ Returns:
|
||||
|
||||
no return, just prints output to STDERR
|
||||
|
||||
|
||||
## compatibility
|
||||
```python
|
||||
compatibility(mod_name, compatible)
|
||||
@@ -48,3 +52,19 @@ Returns:
|
||||
|
||||
no return, just prints output to STDERR
|
||||
|
||||
|
||||
## has_data
|
||||
```python
|
||||
has_data(data)
|
||||
```
|
||||
|
||||
Checks if the input contains data. If there are any non-whitespace characters then return True, else return False
|
||||
|
||||
Parameters:
|
||||
|
||||
data: (string) input to check whether it contains data
|
||||
|
||||
Returns:
|
||||
|
||||
Boolean True if input string (data) contains non-whitespace characters, otherwise False
|
||||
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
|
||||
This package serializes the output of many standard unix command line tools to JSON format.
|
||||
|
||||
For documentation on each parser, see [docs/parsers](https://github.com/kellyjonbrazil/jc/tree/master/docs/parsers).
|
||||
|
||||
CLI Example:
|
||||
|
||||
$ ls -l /usr/bin | jc --ls -p
|
||||
|
||||
611
jc/appdirs.py
Normal file
611
jc/appdirs.py
Normal file
@@ -0,0 +1,611 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright (c) 2005-2010 ActiveState Software Inc.
|
||||
# Copyright (c) 2013 Eddy Petrișor
|
||||
|
||||
'''
|
||||
# This is the MIT license
|
||||
|
||||
Copyright (c) 2010 ActiveState Software Inc.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a
|
||||
copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included
|
||||
in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
'''
|
||||
|
||||
"""Utilities for determining application-specific dirs.
|
||||
|
||||
See <https://github.com/ActiveState/appdirs> for details and usage.
|
||||
"""
|
||||
# Dev Notes:
|
||||
# - MSDN on where to store app data files:
|
||||
# http://support.microsoft.com/default.aspx?scid=kb;en-us;310294#XSLTH3194121123120121120120
|
||||
# - Mac OS X: http://developer.apple.com/documentation/MacOSX/Conceptual/BPFileSystem/index.html
|
||||
# - XDG spec for Un*x: https://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
|
||||
|
||||
__version__ = "1.4.4"
|
||||
__version_info__ = tuple(int(segment) for segment in __version__.split("."))
|
||||
|
||||
|
||||
import sys
|
||||
import os
|
||||
|
||||
PY3 = sys.version_info[0] == 3
|
||||
|
||||
if PY3:
|
||||
unicode = str
|
||||
|
||||
if sys.platform.startswith('java'):
|
||||
import platform
|
||||
os_name = platform.java_ver()[3][0]
|
||||
if os_name.startswith('Windows'): # "Windows XP", "Windows 7", etc.
|
||||
system = 'win32'
|
||||
elif os_name.startswith('Mac'): # "Mac OS X", etc.
|
||||
system = 'darwin'
|
||||
else: # "Linux", "SunOS", "FreeBSD", etc.
|
||||
# Setting this to "linux2" is not ideal, but only Windows or Mac
|
||||
# are actually checked for and the rest of the module expects
|
||||
# *sys.platform* style strings.
|
||||
system = 'linux2'
|
||||
else:
|
||||
system = sys.platform
|
||||
|
||||
|
||||
|
||||
def user_data_dir(appname=None, appauthor=None, version=None, roaming=False):
|
||||
r"""Return full path to the user-specific data dir for this application.
|
||||
|
||||
"appname" is the name of application.
|
||||
If None, just the system directory is returned.
|
||||
"appauthor" (only used on Windows) is the name of the
|
||||
appauthor or distributing body for this application. Typically
|
||||
it is the owning company name. This falls back to appname. You may
|
||||
pass False to disable it.
|
||||
"version" is an optional version path element to append to the
|
||||
path. You might want to use this if you want multiple versions
|
||||
of your app to be able to run independently. If used, this
|
||||
would typically be "<major>.<minor>".
|
||||
Only applied when appname is present.
|
||||
"roaming" (boolean, default False) can be set True to use the Windows
|
||||
roaming appdata directory. That means that for users on a Windows
|
||||
network setup for roaming profiles, this user data will be
|
||||
sync'd on login. See
|
||||
<http://technet.microsoft.com/en-us/library/cc766489(WS.10).aspx>
|
||||
for a discussion of issues.
|
||||
|
||||
Typical user data directories are:
|
||||
Mac OS X: ~/Library/Application Support/<AppName>
|
||||
Unix: ~/.local/share/<AppName> # or in $XDG_DATA_HOME, if defined
|
||||
Win XP (not roaming): C:\Documents and Settings\<username>\Application Data\<AppAuthor>\<AppName>
|
||||
Win XP (roaming): C:\Documents and Settings\<username>\Local Settings\Application Data\<AppAuthor>\<AppName>
|
||||
Win 7 (not roaming): C:\Users\<username>\AppData\Local\<AppAuthor>\<AppName>
|
||||
Win 7 (roaming): C:\Users\<username>\AppData\Roaming\<AppAuthor>\<AppName>
|
||||
|
||||
For Unix, we follow the XDG spec and support $XDG_DATA_HOME.
|
||||
That means, by default "~/.local/share/<AppName>".
|
||||
"""
|
||||
if system == "win32":
|
||||
if appauthor is None:
|
||||
appauthor = appname
|
||||
const = roaming and "CSIDL_APPDATA" or "CSIDL_LOCAL_APPDATA"
|
||||
path = os.path.normpath(_get_win_folder(const))
|
||||
if appname:
|
||||
if appauthor is not False:
|
||||
path = os.path.join(path, appauthor, appname)
|
||||
else:
|
||||
path = os.path.join(path, appname)
|
||||
elif system == 'darwin':
|
||||
path = os.path.expanduser('~/Library/Application Support/')
|
||||
if appname:
|
||||
path = os.path.join(path, appname)
|
||||
else:
|
||||
path = os.getenv('XDG_DATA_HOME', os.path.expanduser("~/.local/share"))
|
||||
if appname:
|
||||
path = os.path.join(path, appname)
|
||||
if appname and version:
|
||||
path = os.path.join(path, version)
|
||||
return path
|
||||
|
||||
|
||||
def site_data_dir(appname=None, appauthor=None, version=None, multipath=False):
|
||||
r"""Return full path to the user-shared data dir for this application.
|
||||
|
||||
"appname" is the name of application.
|
||||
If None, just the system directory is returned.
|
||||
"appauthor" (only used on Windows) is the name of the
|
||||
appauthor or distributing body for this application. Typically
|
||||
it is the owning company name. This falls back to appname. You may
|
||||
pass False to disable it.
|
||||
"version" is an optional version path element to append to the
|
||||
path. You might want to use this if you want multiple versions
|
||||
of your app to be able to run independently. If used, this
|
||||
would typically be "<major>.<minor>".
|
||||
Only applied when appname is present.
|
||||
"multipath" is an optional parameter only applicable to *nix
|
||||
which indicates that the entire list of data dirs should be
|
||||
returned. By default, the first item from XDG_DATA_DIRS is
|
||||
returned, or '/usr/local/share/<AppName>',
|
||||
if XDG_DATA_DIRS is not set
|
||||
|
||||
Typical site data directories are:
|
||||
Mac OS X: /Library/Application Support/<AppName>
|
||||
Unix: /usr/local/share/<AppName> or /usr/share/<AppName>
|
||||
Win XP: C:\Documents and Settings\All Users\Application Data\<AppAuthor>\<AppName>
|
||||
Vista: (Fail! "C:\ProgramData" is a hidden *system* directory on Vista.)
|
||||
Win 7: C:\ProgramData\<AppAuthor>\<AppName> # Hidden, but writeable on Win 7.
|
||||
|
||||
For Unix, this is using the $XDG_DATA_DIRS[0] default.
|
||||
|
||||
WARNING: Do not use this on Windows. See the Vista-Fail note above for why.
|
||||
"""
|
||||
if system == "win32":
|
||||
if appauthor is None:
|
||||
appauthor = appname
|
||||
path = os.path.normpath(_get_win_folder("CSIDL_COMMON_APPDATA"))
|
||||
if appname:
|
||||
if appauthor is not False:
|
||||
path = os.path.join(path, appauthor, appname)
|
||||
else:
|
||||
path = os.path.join(path, appname)
|
||||
elif system == 'darwin':
|
||||
path = os.path.expanduser('/Library/Application Support')
|
||||
if appname:
|
||||
path = os.path.join(path, appname)
|
||||
else:
|
||||
# XDG default for $XDG_DATA_DIRS
|
||||
# only first, if multipath is False
|
||||
path = os.getenv('XDG_DATA_DIRS',
|
||||
os.pathsep.join(['/usr/local/share', '/usr/share']))
|
||||
pathlist = [os.path.expanduser(x.rstrip(os.sep)) for x in path.split(os.pathsep)]
|
||||
if appname:
|
||||
if version:
|
||||
appname = os.path.join(appname, version)
|
||||
pathlist = [os.sep.join([x, appname]) for x in pathlist]
|
||||
|
||||
if multipath:
|
||||
path = os.pathsep.join(pathlist)
|
||||
else:
|
||||
path = pathlist[0]
|
||||
return path
|
||||
|
||||
if appname and version:
|
||||
path = os.path.join(path, version)
|
||||
return path
|
||||
|
||||
|
||||
def user_config_dir(appname=None, appauthor=None, version=None, roaming=False):
|
||||
r"""Return full path to the user-specific config dir for this application.
|
||||
|
||||
"appname" is the name of application.
|
||||
If None, just the system directory is returned.
|
||||
"appauthor" (only used on Windows) is the name of the
|
||||
appauthor or distributing body for this application. Typically
|
||||
it is the owning company name. This falls back to appname. You may
|
||||
pass False to disable it.
|
||||
"version" is an optional version path element to append to the
|
||||
path. You might want to use this if you want multiple versions
|
||||
of your app to be able to run independently. If used, this
|
||||
would typically be "<major>.<minor>".
|
||||
Only applied when appname is present.
|
||||
"roaming" (boolean, default False) can be set True to use the Windows
|
||||
roaming appdata directory. That means that for users on a Windows
|
||||
network setup for roaming profiles, this user data will be
|
||||
sync'd on login. See
|
||||
<http://technet.microsoft.com/en-us/library/cc766489(WS.10).aspx>
|
||||
for a discussion of issues.
|
||||
|
||||
Typical user config directories are:
|
||||
Mac OS X: ~/Library/Preferences/<AppName>
|
||||
Unix: ~/.config/<AppName> # or in $XDG_CONFIG_HOME, if defined
|
||||
Win *: same as user_data_dir
|
||||
|
||||
For Unix, we follow the XDG spec and support $XDG_CONFIG_HOME.
|
||||
That means, by default "~/.config/<AppName>".
|
||||
"""
|
||||
if system == "win32":
|
||||
path = user_data_dir(appname, appauthor, None, roaming)
|
||||
elif system == 'darwin':
|
||||
path = os.path.expanduser('~/Library/Preferences/')
|
||||
if appname:
|
||||
path = os.path.join(path, appname)
|
||||
else:
|
||||
path = os.getenv('XDG_CONFIG_HOME', os.path.expanduser("~/.config"))
|
||||
if appname:
|
||||
path = os.path.join(path, appname)
|
||||
if appname and version:
|
||||
path = os.path.join(path, version)
|
||||
return path
|
||||
|
||||
|
||||
def site_config_dir(appname=None, appauthor=None, version=None, multipath=False):
|
||||
r"""Return full path to the user-shared data dir for this application.
|
||||
|
||||
"appname" is the name of application.
|
||||
If None, just the system directory is returned.
|
||||
"appauthor" (only used on Windows) is the name of the
|
||||
appauthor or distributing body for this application. Typically
|
||||
it is the owning company name. This falls back to appname. You may
|
||||
pass False to disable it.
|
||||
"version" is an optional version path element to append to the
|
||||
path. You might want to use this if you want multiple versions
|
||||
of your app to be able to run independently. If used, this
|
||||
would typically be "<major>.<minor>".
|
||||
Only applied when appname is present.
|
||||
"multipath" is an optional parameter only applicable to *nix
|
||||
which indicates that the entire list of config dirs should be
|
||||
returned. By default, the first item from XDG_CONFIG_DIRS is
|
||||
returned, or '/etc/xdg/<AppName>', if XDG_CONFIG_DIRS is not set
|
||||
|
||||
Typical site config directories are:
|
||||
Mac OS X: same as site_data_dir
|
||||
Unix: /etc/xdg/<AppName> or $XDG_CONFIG_DIRS[i]/<AppName> for each value in
|
||||
$XDG_CONFIG_DIRS
|
||||
Win *: same as site_data_dir
|
||||
Vista: (Fail! "C:\ProgramData" is a hidden *system* directory on Vista.)
|
||||
|
||||
For Unix, this is using the $XDG_CONFIG_DIRS[0] default, if multipath=False
|
||||
|
||||
WARNING: Do not use this on Windows. See the Vista-Fail note above for why.
|
||||
"""
|
||||
if system == 'win32':
|
||||
path = site_data_dir(appname, appauthor)
|
||||
if appname and version:
|
||||
path = os.path.join(path, version)
|
||||
elif system == 'darwin':
|
||||
path = os.path.expanduser('/Library/Preferences')
|
||||
if appname:
|
||||
path = os.path.join(path, appname)
|
||||
else:
|
||||
# XDG default for $XDG_CONFIG_DIRS
|
||||
# only first, if multipath is False
|
||||
path = os.getenv('XDG_CONFIG_DIRS', '/etc/xdg')
|
||||
pathlist = [os.path.expanduser(x.rstrip(os.sep)) for x in path.split(os.pathsep)]
|
||||
if appname:
|
||||
if version:
|
||||
appname = os.path.join(appname, version)
|
||||
pathlist = [os.sep.join([x, appname]) for x in pathlist]
|
||||
|
||||
if multipath:
|
||||
path = os.pathsep.join(pathlist)
|
||||
else:
|
||||
path = pathlist[0]
|
||||
return path
|
||||
|
||||
|
||||
def user_cache_dir(appname=None, appauthor=None, version=None, opinion=True):
|
||||
r"""Return full path to the user-specific cache dir for this application.
|
||||
|
||||
"appname" is the name of application.
|
||||
If None, just the system directory is returned.
|
||||
"appauthor" (only used on Windows) is the name of the
|
||||
appauthor or distributing body for this application. Typically
|
||||
it is the owning company name. This falls back to appname. You may
|
||||
pass False to disable it.
|
||||
"version" is an optional version path element to append to the
|
||||
path. You might want to use this if you want multiple versions
|
||||
of your app to be able to run independently. If used, this
|
||||
would typically be "<major>.<minor>".
|
||||
Only applied when appname is present.
|
||||
"opinion" (boolean) can be False to disable the appending of
|
||||
"Cache" to the base app data dir for Windows. See
|
||||
discussion below.
|
||||
|
||||
Typical user cache directories are:
|
||||
Mac OS X: ~/Library/Caches/<AppName>
|
||||
Unix: ~/.cache/<AppName> (XDG default)
|
||||
Win XP: C:\Documents and Settings\<username>\Local Settings\Application Data\<AppAuthor>\<AppName>\Cache
|
||||
Vista: C:\Users\<username>\AppData\Local\<AppAuthor>\<AppName>\Cache
|
||||
|
||||
On Windows the only suggestion in the MSDN docs is that local settings go in
|
||||
the `CSIDL_LOCAL_APPDATA` directory. This is identical to the non-roaming
|
||||
app data dir (the default returned by `user_data_dir` above). Apps typically
|
||||
put cache data somewhere *under* the given dir here. Some examples:
|
||||
...\Mozilla\Firefox\Profiles\<ProfileName>\Cache
|
||||
...\Acme\SuperApp\Cache\1.0
|
||||
OPINION: This function appends "Cache" to the `CSIDL_LOCAL_APPDATA` value.
|
||||
This can be disabled with the `opinion=False` option.
|
||||
"""
|
||||
if system == "win32":
|
||||
if appauthor is None:
|
||||
appauthor = appname
|
||||
path = os.path.normpath(_get_win_folder("CSIDL_LOCAL_APPDATA"))
|
||||
if appname:
|
||||
if appauthor is not False:
|
||||
path = os.path.join(path, appauthor, appname)
|
||||
else:
|
||||
path = os.path.join(path, appname)
|
||||
if opinion:
|
||||
path = os.path.join(path, "Cache")
|
||||
elif system == 'darwin':
|
||||
path = os.path.expanduser('~/Library/Caches')
|
||||
if appname:
|
||||
path = os.path.join(path, appname)
|
||||
else:
|
||||
path = os.getenv('XDG_CACHE_HOME', os.path.expanduser('~/.cache'))
|
||||
if appname:
|
||||
path = os.path.join(path, appname)
|
||||
if appname and version:
|
||||
path = os.path.join(path, version)
|
||||
return path
|
||||
|
||||
|
||||
def user_state_dir(appname=None, appauthor=None, version=None, roaming=False):
|
||||
r"""Return full path to the user-specific state dir for this application.
|
||||
|
||||
"appname" is the name of application.
|
||||
If None, just the system directory is returned.
|
||||
"appauthor" (only used on Windows) is the name of the
|
||||
appauthor or distributing body for this application. Typically
|
||||
it is the owning company name. This falls back to appname. You may
|
||||
pass False to disable it.
|
||||
"version" is an optional version path element to append to the
|
||||
path. You might want to use this if you want multiple versions
|
||||
of your app to be able to run independently. If used, this
|
||||
would typically be "<major>.<minor>".
|
||||
Only applied when appname is present.
|
||||
"roaming" (boolean, default False) can be set True to use the Windows
|
||||
roaming appdata directory. That means that for users on a Windows
|
||||
network setup for roaming profiles, this user data will be
|
||||
sync'd on login. See
|
||||
<http://technet.microsoft.com/en-us/library/cc766489(WS.10).aspx>
|
||||
for a discussion of issues.
|
||||
|
||||
Typical user state directories are:
|
||||
Mac OS X: same as user_data_dir
|
||||
Unix: ~/.local/state/<AppName> # or in $XDG_STATE_HOME, if defined
|
||||
Win *: same as user_data_dir
|
||||
|
||||
For Unix, we follow this Debian proposal <https://wiki.debian.org/XDGBaseDirectorySpecification#state>
|
||||
to extend the XDG spec and support $XDG_STATE_HOME.
|
||||
|
||||
That means, by default "~/.local/state/<AppName>".
|
||||
"""
|
||||
if system in ["win32", "darwin"]:
|
||||
path = user_data_dir(appname, appauthor, None, roaming)
|
||||
else:
|
||||
path = os.getenv('XDG_STATE_HOME', os.path.expanduser("~/.local/state"))
|
||||
if appname:
|
||||
path = os.path.join(path, appname)
|
||||
if appname and version:
|
||||
path = os.path.join(path, version)
|
||||
return path
|
||||
|
||||
|
||||
def user_log_dir(appname=None, appauthor=None, version=None, opinion=True):
|
||||
r"""Return full path to the user-specific log dir for this application.
|
||||
|
||||
"appname" is the name of application.
|
||||
If None, just the system directory is returned.
|
||||
"appauthor" (only used on Windows) is the name of the
|
||||
appauthor or distributing body for this application. Typically
|
||||
it is the owning company name. This falls back to appname. You may
|
||||
pass False to disable it.
|
||||
"version" is an optional version path element to append to the
|
||||
path. You might want to use this if you want multiple versions
|
||||
of your app to be able to run independently. If used, this
|
||||
would typically be "<major>.<minor>".
|
||||
Only applied when appname is present.
|
||||
"opinion" (boolean) can be False to disable the appending of
|
||||
"Logs" to the base app data dir for Windows, and "log" to the
|
||||
base cache dir for Unix. See discussion below.
|
||||
|
||||
Typical user log directories are:
|
||||
Mac OS X: ~/Library/Logs/<AppName>
|
||||
Unix: ~/.cache/<AppName>/log # or under $XDG_CACHE_HOME if defined
|
||||
Win XP: C:\Documents and Settings\<username>\Local Settings\Application Data\<AppAuthor>\<AppName>\Logs
|
||||
Vista: C:\Users\<username>\AppData\Local\<AppAuthor>\<AppName>\Logs
|
||||
|
||||
On Windows the only suggestion in the MSDN docs is that local settings
|
||||
go in the `CSIDL_LOCAL_APPDATA` directory. (Note: I'm interested in
|
||||
examples of what some windows apps use for a logs dir.)
|
||||
|
||||
OPINION: This function appends "Logs" to the `CSIDL_LOCAL_APPDATA`
|
||||
value for Windows and appends "log" to the user cache dir for Unix.
|
||||
This can be disabled with the `opinion=False` option.
|
||||
"""
|
||||
if system == "darwin":
|
||||
path = os.path.join(
|
||||
os.path.expanduser('~/Library/Logs'),
|
||||
appname)
|
||||
elif system == "win32":
|
||||
path = user_data_dir(appname, appauthor, version)
|
||||
version = False
|
||||
if opinion:
|
||||
path = os.path.join(path, "Logs")
|
||||
else:
|
||||
path = user_cache_dir(appname, appauthor, version)
|
||||
version = False
|
||||
if opinion:
|
||||
path = os.path.join(path, "log")
|
||||
if appname and version:
|
||||
path = os.path.join(path, version)
|
||||
return path
|
||||
|
||||
|
||||
class AppDirs(object):
|
||||
"""Convenience wrapper for getting application dirs."""
|
||||
def __init__(self, appname=None, appauthor=None, version=None,
|
||||
roaming=False, multipath=False):
|
||||
self.appname = appname
|
||||
self.appauthor = appauthor
|
||||
self.version = version
|
||||
self.roaming = roaming
|
||||
self.multipath = multipath
|
||||
|
||||
@property
|
||||
def user_data_dir(self):
|
||||
return user_data_dir(self.appname, self.appauthor,
|
||||
version=self.version, roaming=self.roaming)
|
||||
|
||||
@property
|
||||
def site_data_dir(self):
|
||||
return site_data_dir(self.appname, self.appauthor,
|
||||
version=self.version, multipath=self.multipath)
|
||||
|
||||
@property
|
||||
def user_config_dir(self):
|
||||
return user_config_dir(self.appname, self.appauthor,
|
||||
version=self.version, roaming=self.roaming)
|
||||
|
||||
@property
|
||||
def site_config_dir(self):
|
||||
return site_config_dir(self.appname, self.appauthor,
|
||||
version=self.version, multipath=self.multipath)
|
||||
|
||||
@property
|
||||
def user_cache_dir(self):
|
||||
return user_cache_dir(self.appname, self.appauthor,
|
||||
version=self.version)
|
||||
|
||||
@property
|
||||
def user_state_dir(self):
|
||||
return user_state_dir(self.appname, self.appauthor,
|
||||
version=self.version)
|
||||
|
||||
@property
|
||||
def user_log_dir(self):
|
||||
return user_log_dir(self.appname, self.appauthor,
|
||||
version=self.version)
|
||||
|
||||
|
||||
#---- internal support stuff
|
||||
|
||||
def _get_win_folder_from_registry(csidl_name):
|
||||
"""This is a fallback technique at best. I'm not sure if using the
|
||||
registry for this guarantees us the correct answer for all CSIDL_*
|
||||
names.
|
||||
"""
|
||||
if PY3:
|
||||
import winreg as _winreg
|
||||
else:
|
||||
import _winreg
|
||||
|
||||
shell_folder_name = {
|
||||
"CSIDL_APPDATA": "AppData",
|
||||
"CSIDL_COMMON_APPDATA": "Common AppData",
|
||||
"CSIDL_LOCAL_APPDATA": "Local AppData",
|
||||
}[csidl_name]
|
||||
|
||||
key = _winreg.OpenKey(
|
||||
_winreg.HKEY_CURRENT_USER,
|
||||
r"Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders"
|
||||
)
|
||||
dir, type = _winreg.QueryValueEx(key, shell_folder_name)
|
||||
return dir
|
||||
|
||||
|
||||
def _get_win_folder_with_ctypes(csidl_name):
|
||||
import ctypes
|
||||
|
||||
csidl_const = {
|
||||
"CSIDL_APPDATA": 26,
|
||||
"CSIDL_COMMON_APPDATA": 35,
|
||||
"CSIDL_LOCAL_APPDATA": 28,
|
||||
}[csidl_name]
|
||||
|
||||
buf = ctypes.create_unicode_buffer(1024)
|
||||
ctypes.windll.shell32.SHGetFolderPathW(None, csidl_const, None, 0, buf)
|
||||
|
||||
# Downgrade to short path name if have highbit chars. See
|
||||
# <http://bugs.activestate.com/show_bug.cgi?id=85099>.
|
||||
has_high_char = False
|
||||
for c in buf:
|
||||
if ord(c) > 255:
|
||||
has_high_char = True
|
||||
break
|
||||
if has_high_char:
|
||||
buf2 = ctypes.create_unicode_buffer(1024)
|
||||
if ctypes.windll.kernel32.GetShortPathNameW(buf.value, buf2, 1024):
|
||||
buf = buf2
|
||||
|
||||
return buf.value
|
||||
|
||||
def _get_win_folder_with_jna(csidl_name):
|
||||
import array
|
||||
from com.sun import jna
|
||||
from com.sun.jna.platform import win32
|
||||
|
||||
buf_size = win32.WinDef.MAX_PATH * 2
|
||||
buf = array.zeros('c', buf_size)
|
||||
shell = win32.Shell32.INSTANCE
|
||||
shell.SHGetFolderPath(None, getattr(win32.ShlObj, csidl_name), None, win32.ShlObj.SHGFP_TYPE_CURRENT, buf)
|
||||
dir = jna.Native.toString(buf.tostring()).rstrip("\0")
|
||||
|
||||
# Downgrade to short path name if have highbit chars. See
|
||||
# <http://bugs.activestate.com/show_bug.cgi?id=85099>.
|
||||
has_high_char = False
|
||||
for c in dir:
|
||||
if ord(c) > 255:
|
||||
has_high_char = True
|
||||
break
|
||||
if has_high_char:
|
||||
buf = array.zeros('c', buf_size)
|
||||
kernel = win32.Kernel32.INSTANCE
|
||||
if kernel.GetShortPathName(dir, buf, buf_size):
|
||||
dir = jna.Native.toString(buf.tostring()).rstrip("\0")
|
||||
|
||||
return dir
|
||||
|
||||
if system == "win32":
|
||||
try:
|
||||
from ctypes import windll
|
||||
except ImportError:
|
||||
try:
|
||||
import com.sun.jna
|
||||
except ImportError:
|
||||
_get_win_folder = _get_win_folder_from_registry
|
||||
else:
|
||||
_get_win_folder = _get_win_folder_with_jna
|
||||
else:
|
||||
_get_win_folder = _get_win_folder_with_ctypes
|
||||
|
||||
|
||||
#---- self test code
|
||||
|
||||
if __name__ == "__main__":
|
||||
appname = "MyApp"
|
||||
appauthor = "MyCompany"
|
||||
|
||||
props = ("user_data_dir",
|
||||
"user_config_dir",
|
||||
"user_cache_dir",
|
||||
"user_state_dir",
|
||||
"user_log_dir",
|
||||
"site_data_dir",
|
||||
"site_config_dir")
|
||||
|
||||
print("-- app dirs %s --" % __version__)
|
||||
|
||||
print("-- app dirs (with optional 'version')")
|
||||
dirs = AppDirs(appname, appauthor, version="1.0")
|
||||
for prop in props:
|
||||
print("%s: %s" % (prop, getattr(dirs, prop)))
|
||||
|
||||
print("\n-- app dirs (without optional 'version')")
|
||||
dirs = AppDirs(appname, appauthor)
|
||||
for prop in props:
|
||||
print("%s: %s" % (prop, getattr(dirs, prop)))
|
||||
|
||||
print("\n-- app dirs (without optional 'appauthor')")
|
||||
dirs = AppDirs(appname)
|
||||
for prop in props:
|
||||
print("%s: %s" % (prop, getattr(dirs, prop)))
|
||||
|
||||
print("\n-- app dirs (with disabled 'appauthor')")
|
||||
dirs = AppDirs(appname, appauthor=False)
|
||||
for prop in props:
|
||||
print("%s: %s" % (prop, getattr(dirs, prop)))
|
||||
381
jc/cli.py
381
jc/cli.py
@@ -1,24 +1,56 @@
|
||||
#!/usr/bin/env python3
|
||||
"""jc - JSON CLI output utility
|
||||
JC cli module
|
||||
"""
|
||||
|
||||
import sys
|
||||
import os
|
||||
import os.path
|
||||
import re
|
||||
import shlex
|
||||
import importlib
|
||||
import textwrap
|
||||
import signal
|
||||
import json
|
||||
import jc.utils
|
||||
import pygments
|
||||
from pygments import highlight
|
||||
from pygments.style import Style
|
||||
from pygments.token import (Name, Number, String, Keyword)
|
||||
from pygments.lexers import JsonLexer
|
||||
from pygments.formatters import Terminal256Formatter
|
||||
import jc.appdirs as appdirs
|
||||
|
||||
|
||||
class info():
|
||||
version = '1.14.0'
|
||||
description = 'JSON CLI output utility'
|
||||
author = 'Kelly Brazil'
|
||||
author_email = 'kellyjonbrazil@gmail.com'
|
||||
|
||||
|
||||
__version__ = info.version
|
||||
|
||||
parsers = [
|
||||
'airport',
|
||||
'airport-s',
|
||||
'arp',
|
||||
'blkid',
|
||||
'cksum',
|
||||
'crontab',
|
||||
'crontab-u',
|
||||
'csv',
|
||||
'date',
|
||||
'df',
|
||||
'dig',
|
||||
'dmidecode',
|
||||
'du',
|
||||
'env',
|
||||
'file',
|
||||
'free',
|
||||
'fstab',
|
||||
'group',
|
||||
'gshadow',
|
||||
'hash',
|
||||
'hashsum',
|
||||
'history',
|
||||
'hosts',
|
||||
'id',
|
||||
@@ -26,66 +58,182 @@ parsers = [
|
||||
'ini',
|
||||
'iptables',
|
||||
'jobs',
|
||||
'kv',
|
||||
'last',
|
||||
'ls',
|
||||
'lsblk',
|
||||
'lsmod',
|
||||
'lsof',
|
||||
'mount',
|
||||
'netstat',
|
||||
'ntpq',
|
||||
'passwd',
|
||||
'ping',
|
||||
'pip-list',
|
||||
'pip-show',
|
||||
'ps',
|
||||
'route',
|
||||
'shadow',
|
||||
'ss',
|
||||
'stat',
|
||||
'sysctl',
|
||||
'systemctl',
|
||||
'systemctl-lj',
|
||||
'systemctl-ls',
|
||||
'systemctl-luf',
|
||||
'timedatectl',
|
||||
'tracepath',
|
||||
'traceroute',
|
||||
'uname',
|
||||
'uptime',
|
||||
'w',
|
||||
'wc',
|
||||
'who',
|
||||
'xml',
|
||||
'yaml'
|
||||
]
|
||||
|
||||
# List of custom or override parsers.
|
||||
# Allow any <user_data_dir>/jc/jcparsers/*.py
|
||||
local_parsers = []
|
||||
data_dir = appdirs.user_data_dir('jc', 'jc')
|
||||
local_parsers_dir = os.path.join(data_dir, 'jcparsers')
|
||||
if os.path.isdir(local_parsers_dir):
|
||||
sys.path.append(data_dir)
|
||||
for name in os.listdir(local_parsers_dir):
|
||||
if re.match(r'\w+\.py', name) and os.path.isfile(os.path.join(local_parsers_dir, name)):
|
||||
plugin_name = name[0:-3]
|
||||
local_parsers.append(plugin_name)
|
||||
if plugin_name not in parsers:
|
||||
parsers.append(plugin_name)
|
||||
|
||||
|
||||
# We only support 2.3.0+, pygments changed color names in 2.4.0.
|
||||
# startswith is sufficient and avoids potential exceptions from split and int.
|
||||
if pygments.__version__.startswith('2.3.'):
|
||||
PYGMENT_COLOR = {
|
||||
'black': '#ansiblack',
|
||||
'red': '#ansidarkred',
|
||||
'green': '#ansidarkgreen',
|
||||
'yellow': '#ansibrown',
|
||||
'blue': '#ansidarkblue',
|
||||
'magenta': '#ansipurple',
|
||||
'cyan': '#ansiteal',
|
||||
'gray': '#ansilightgray',
|
||||
'brightblack': '#ansidarkgray',
|
||||
'brightred': '#ansired',
|
||||
'brightgreen': '#ansigreen',
|
||||
'brightyellow': '#ansiyellow',
|
||||
'brightblue': '#ansiblue',
|
||||
'brightmagenta': '#ansifuchsia',
|
||||
'brightcyan': '#ansiturquoise',
|
||||
'white': '#ansiwhite',
|
||||
}
|
||||
else:
|
||||
PYGMENT_COLOR = {
|
||||
'black': 'ansiblack',
|
||||
'red': 'ansired',
|
||||
'green': 'ansigreen',
|
||||
'yellow': 'ansiyellow',
|
||||
'blue': 'ansiblue',
|
||||
'magenta': 'ansimagenta',
|
||||
'cyan': 'ansicyan',
|
||||
'gray': 'ansigray',
|
||||
'brightblack': 'ansibrightblack',
|
||||
'brightred': 'ansibrightred',
|
||||
'brightgreen': 'ansibrightgreen',
|
||||
'brightyellow': 'ansibrightyellow',
|
||||
'brightblue': 'ansibrightblue',
|
||||
'brightmagenta': 'ansibrightmagenta',
|
||||
'brightcyan': 'ansibrightcyan',
|
||||
'white': 'ansiwhite',
|
||||
}
|
||||
|
||||
|
||||
def set_env_colors(env_colors=None):
|
||||
"""
|
||||
Return a dictionary to be used in Pygments custom style class.
|
||||
|
||||
Grab custom colors from JC_COLORS environment variable. JC_COLORS env variable takes 4 comma
|
||||
separated string values and should be in the format of:
|
||||
|
||||
JC_COLORS=<keyname_color>,<keyword_color>,<number_color>,<string_color>
|
||||
|
||||
Where colors are: black, red, green, yellow, blue, magenta, cyan, gray, brightblack, brightred,
|
||||
brightgreen, brightyellow, brightblue, brightmagenta, brightcyan, white, default
|
||||
|
||||
Default colors:
|
||||
|
||||
JC_COLORS=blue,brightblack,magenta,green
|
||||
or
|
||||
JC_COLORS=default,default,default,default
|
||||
|
||||
"""
|
||||
input_error = False
|
||||
|
||||
if env_colors:
|
||||
color_list = env_colors.split(',')
|
||||
else:
|
||||
color_list = ['default', 'default', 'default', 'default']
|
||||
|
||||
if len(color_list) != 4:
|
||||
input_error = True
|
||||
|
||||
for color in color_list:
|
||||
if color != 'default' and color not in PYGMENT_COLOR:
|
||||
input_error = True
|
||||
|
||||
# if there is an issue with the env variable, just set all colors to default and move on
|
||||
if input_error:
|
||||
print('jc: Warning: could not parse JC_COLORS environment variable\n', file=sys.stderr)
|
||||
color_list = ['default', 'default', 'default', 'default']
|
||||
|
||||
# Try the color set in the JC_COLORS env variable first. If it is set to default, then fall back to default colors
|
||||
return {
|
||||
Name.Tag: f'bold {PYGMENT_COLOR[color_list[0]]}' if not color_list[0] == 'default' else f"bold {PYGMENT_COLOR['blue']}", # key names
|
||||
Keyword: PYGMENT_COLOR[color_list[1]] if not color_list[1] == 'default' else PYGMENT_COLOR['brightblack'], # true, false, null
|
||||
Number: PYGMENT_COLOR[color_list[2]] if not color_list[2] == 'default' else PYGMENT_COLOR['magenta'], # numbers
|
||||
String: PYGMENT_COLOR[color_list[3]] if not color_list[3] == 'default' else PYGMENT_COLOR['green'] # strings
|
||||
}
|
||||
|
||||
|
||||
def piped_output():
|
||||
"""Return False if stdout is a TTY. True if output is being piped to another program"""
|
||||
if sys.stdout.isatty():
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
|
||||
|
||||
def ctrlc(signum, frame):
|
||||
"""Exit with error on SIGINT"""
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def parser_shortname(parser_argument):
|
||||
"""short name of the parser with dashes and no -- prefix"""
|
||||
"""Return short name of the parser with dashes and no -- prefix"""
|
||||
return parser_argument[2:]
|
||||
|
||||
|
||||
def parser_argument(parser):
|
||||
"""short name of the parser with dashes and with -- prefix"""
|
||||
"""Return short name of the parser with dashes and with -- prefix"""
|
||||
return f'--{parser}'
|
||||
|
||||
|
||||
def parser_mod_shortname(parser):
|
||||
"""short name of the parser's module name (no -- prefix and dashes converted to underscores)"""
|
||||
"""Return short name of the parser's module name (no -- prefix and dashes converted to underscores)"""
|
||||
return parser.replace('--', '').replace('-', '_')
|
||||
|
||||
|
||||
def parser_module(parser):
|
||||
"""import the module just in time and present the module object"""
|
||||
importlib.import_module('jc.parsers.' + parser_mod_shortname(parser))
|
||||
return getattr(jc.parsers, parser_mod_shortname(parser))
|
||||
|
||||
|
||||
class info():
|
||||
version = '1.7.1'
|
||||
description = 'jc cli output JSON conversion tool'
|
||||
author = 'Kelly Brazil'
|
||||
author_email = 'kellyjonbrazil@gmail.com'
|
||||
|
||||
|
||||
__version__ = info.version
|
||||
|
||||
|
||||
def ctrlc(signum, frame):
|
||||
sys.exit(1)
|
||||
"""Import the module just in time and return the module object"""
|
||||
shortname = parser_mod_shortname(parser)
|
||||
path = ('jcparsers.' if shortname in local_parsers else 'jc.parsers.')
|
||||
return importlib.import_module(path + shortname)
|
||||
|
||||
|
||||
def parsers_text(indent=0, pad=0):
|
||||
"""Return the argument and description information from each parser"""
|
||||
ptext = ''
|
||||
for parser in parsers:
|
||||
parser_arg = parser_argument(parser)
|
||||
@@ -103,6 +251,7 @@ def parsers_text(indent=0, pad=0):
|
||||
|
||||
|
||||
def about_jc():
|
||||
"""Return jc info and the contents of each parser.info as a dictionary"""
|
||||
parser_list = []
|
||||
|
||||
for parser in parsers:
|
||||
@@ -132,98 +281,196 @@ def about_jc():
|
||||
|
||||
|
||||
def helptext(message):
|
||||
"""Return the help text with the list of parsers"""
|
||||
parsers_string = parsers_text(indent=12, pad=17)
|
||||
|
||||
helptext_string = f'''
|
||||
jc: {message}
|
||||
|
||||
Usage: jc PARSER [OPTIONS]
|
||||
Usage: COMMAND | jc PARSER [OPTIONS]
|
||||
|
||||
or magic syntax:
|
||||
|
||||
jc [OPTIONS] COMMAND
|
||||
|
||||
Parsers:
|
||||
{parsers_string}
|
||||
Options:
|
||||
-a about jc
|
||||
-d debug - show trace messages
|
||||
-d debug - show traceback (-dd for verbose traceback)
|
||||
-m monochrome output
|
||||
-p pretty print output
|
||||
-q quiet - suppress warnings
|
||||
-q quiet - suppress parser warnings
|
||||
-r raw JSON output
|
||||
|
||||
Example:
|
||||
ls -al | jc --ls -p
|
||||
|
||||
or using the magic syntax:
|
||||
|
||||
jc -p ls -al
|
||||
'''
|
||||
print(textwrap.dedent(helptext_string), file=sys.stderr)
|
||||
return textwrap.dedent(helptext_string)
|
||||
|
||||
|
||||
def json_out(data, pretty=False):
|
||||
if pretty:
|
||||
print(json.dumps(data, indent=2))
|
||||
def json_out(data, pretty=False, env_colors=None, mono=False, piped_out=False):
|
||||
"""Return a JSON formatted string. String may include color codes or be pretty printed."""
|
||||
if not mono and not piped_out:
|
||||
# set colors
|
||||
class JcStyle(Style):
|
||||
styles = set_env_colors(env_colors)
|
||||
|
||||
if pretty:
|
||||
return str(highlight(json.dumps(data, indent=2), JsonLexer(), Terminal256Formatter(style=JcStyle))[0:-1])
|
||||
else:
|
||||
return str(highlight(json.dumps(data), JsonLexer(), Terminal256Formatter(style=JcStyle))[0:-1])
|
||||
else:
|
||||
print(json.dumps(data))
|
||||
if pretty:
|
||||
return json.dumps(data, indent=2)
|
||||
else:
|
||||
return json.dumps(data)
|
||||
|
||||
|
||||
def generate_magic_command(args):
|
||||
"""
|
||||
Return a tuple with a boolean and a command, where the boolean signifies that
|
||||
the command is valid, and the command is either a command string or None.
|
||||
"""
|
||||
|
||||
# Parse with magic syntax: jc -p ls -al
|
||||
if len(args) <= 1 or args[1].startswith('--'):
|
||||
return False, None
|
||||
|
||||
# correctly parse escape characters and spaces with shlex
|
||||
args_given = ' '.join(map(shlex.quote, args[1:])).split()
|
||||
options = []
|
||||
|
||||
# find the options
|
||||
for arg in list(args_given):
|
||||
# parser found - use standard syntax
|
||||
if arg.startswith('--'):
|
||||
return False, None
|
||||
|
||||
# option found - populate option list
|
||||
elif arg.startswith('-'):
|
||||
options.extend(args_given.pop(0)[1:])
|
||||
|
||||
# command found if iterator didn't already stop - stop iterating
|
||||
else:
|
||||
break
|
||||
|
||||
# all options popped and no command found - for case like 'jc -a'
|
||||
if len(args_given) == 0:
|
||||
return False, None
|
||||
|
||||
magic_dict = {}
|
||||
parser_info = about_jc()['parsers']
|
||||
|
||||
# create a dictionary of magic_commands to their respective parsers.
|
||||
for entry in parser_info:
|
||||
# Update the dict with all of the magic commands for this parser, if they exist.
|
||||
magic_dict.update({mc: entry['argument'] for mc in entry.get('magic_commands', [])})
|
||||
|
||||
# find the command and parser
|
||||
one_word_command = args_given[0]
|
||||
two_word_command = ' '.join(args_given[0:2])
|
||||
|
||||
# try to get a parser for two_word_command, otherwise get one for one_word_command
|
||||
found_parser = magic_dict.get(two_word_command, magic_dict.get(one_word_command))
|
||||
|
||||
# construct a new command line using the standard syntax: COMMAND | jc --PARSER -OPTIONS
|
||||
run_command = ' '.join(args_given)
|
||||
if found_parser:
|
||||
cmd_options = ('-' + ''.join(options)) if options else ''
|
||||
return True, ' '.join([run_command, '|', 'jc', found_parser, cmd_options])
|
||||
else:
|
||||
return False, run_command
|
||||
|
||||
|
||||
def magic():
|
||||
"""Runs the command generated by generate_magic_command() to support magic syntax"""
|
||||
valid_command, run_command = generate_magic_command(sys.argv)
|
||||
if valid_command:
|
||||
os.system(run_command)
|
||||
sys.exit(0)
|
||||
elif run_command is None:
|
||||
return
|
||||
else:
|
||||
print(helptext(f'parser not found for "{run_command}"'), file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def main():
|
||||
# break on ctrl-c keyboard interrupt
|
||||
signal.signal(signal.SIGINT, ctrlc)
|
||||
|
||||
debug = False
|
||||
pretty = False
|
||||
quiet = False
|
||||
raw = False
|
||||
# break on pipe error. need try/except for windows compatibility
|
||||
try:
|
||||
signal.signal(signal.SIGPIPE, signal.SIG_DFL)
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
jc_colors = os.getenv('JC_COLORS')
|
||||
|
||||
# try magic syntax first: e.g. jc -p ls -al
|
||||
magic()
|
||||
|
||||
options = []
|
||||
|
||||
# options
|
||||
if '-d' in sys.argv:
|
||||
debug = True
|
||||
for opt in sys.argv:
|
||||
if opt.startswith('-') and not opt.startswith('--'):
|
||||
options.extend(opt[1:])
|
||||
|
||||
if '-p' in sys.argv:
|
||||
pretty = True
|
||||
debug = 'd' in options
|
||||
verbose_debug = True if options.count('d') > 1 else False
|
||||
mono = 'm' in options
|
||||
pretty = 'p' in options
|
||||
quiet = 'q' in options
|
||||
raw = 'r' in options
|
||||
|
||||
if '-q' in sys.argv:
|
||||
quiet = True
|
||||
if verbose_debug:
|
||||
import jc.tracebackplus
|
||||
jc.tracebackplus.enable(context=11)
|
||||
|
||||
if '-r' in sys.argv:
|
||||
raw = True
|
||||
|
||||
if '-a' in sys.argv:
|
||||
json_out(about_jc(), pretty=pretty)
|
||||
exit()
|
||||
if 'a' in options:
|
||||
print(json_out(about_jc(), pretty=pretty, env_colors=jc_colors, mono=mono, piped_out=piped_output()))
|
||||
sys.exit(0)
|
||||
|
||||
if sys.stdin.isatty():
|
||||
helptext('missing piped data')
|
||||
print(helptext('missing piped data'), file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
data = sys.stdin.read()
|
||||
|
||||
found = False
|
||||
|
||||
if debug:
|
||||
for arg in sys.argv:
|
||||
parser_name = parser_shortname(arg)
|
||||
for arg in sys.argv:
|
||||
parser_name = parser_shortname(arg)
|
||||
|
||||
if parser_name in parsers:
|
||||
# load parser module just in time so we don't need to load all modules
|
||||
parser = parser_module(arg)
|
||||
if parser_name in parsers:
|
||||
# load parser module just in time so we don't need to load all modules
|
||||
parser = parser_module(arg)
|
||||
try:
|
||||
result = parser.parse(data, raw=raw, quiet=quiet)
|
||||
found = True
|
||||
break
|
||||
else:
|
||||
for arg in sys.argv:
|
||||
parser_name = parser_shortname(arg)
|
||||
|
||||
if parser_name in parsers:
|
||||
# load parser module just in time so we don't need to load all modules
|
||||
parser = parser_module(arg)
|
||||
try:
|
||||
result = parser.parse(data, raw=raw, quiet=quiet)
|
||||
found = True
|
||||
break
|
||||
except:
|
||||
jc.utils.error_message(f'{parser_name} parser could not parse the input data. Did you use the correct parser?\n For details use the -d option.')
|
||||
except Exception:
|
||||
if debug:
|
||||
raise
|
||||
else:
|
||||
import jc.utils
|
||||
jc.utils.error_message(
|
||||
f'{parser_name} parser could not parse the input data. Did you use the correct parser?\n'
|
||||
' For details use the -d or -dd option.')
|
||||
sys.exit(1)
|
||||
|
||||
if not found:
|
||||
helptext('missing or incorrect arguments')
|
||||
print(helptext('missing or incorrect arguments'), file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
json_out(result, pretty=pretty)
|
||||
print(json_out(result, pretty=pretty, env_colors=jc_colors, mono=mono, piped_out=piped_output()))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
151
jc/parsers/airport.py
Normal file
151
jc/parsers/airport.py
Normal file
@@ -0,0 +1,151 @@
|
||||
"""jc - JSON CLI output utility `airport -I` command output parser
|
||||
|
||||
The `airport` program can be found at `/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport`.
|
||||
|
||||
Usage (cli):
|
||||
|
||||
$ airport -I | jc --airport
|
||||
|
||||
or
|
||||
|
||||
$ jc airport -I
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.airport
|
||||
result = jc.parsers.airport.parse(airport_command_output)
|
||||
|
||||
Compatibility:
|
||||
|
||||
'darwin'
|
||||
|
||||
Examples:
|
||||
|
||||
$ airport -I | jc --airport -p
|
||||
{
|
||||
"agrctlrssi": -66,
|
||||
"agrextrssi": 0,
|
||||
"agrctlnoise": -90,
|
||||
"agrextnoise": 0,
|
||||
"state": "running",
|
||||
"op_mode": "station",
|
||||
"lasttxrate": 195,
|
||||
"maxrate": 867,
|
||||
"lastassocstatus": 0,
|
||||
"802_11_auth": "open",
|
||||
"link_auth": "wpa2-psk",
|
||||
"bssid": "3c:37:86:15:ad:f9",
|
||||
"ssid": "SnazzleDazzle",
|
||||
"mcs": 0,
|
||||
"channel": "48,80"
|
||||
}
|
||||
|
||||
$ airport -I | jc --airport -p -r
|
||||
{
|
||||
"agrctlrssi": "-66",
|
||||
"agrextrssi": "0",
|
||||
"agrctlnoise": "-90",
|
||||
"agrextnoise": "0",
|
||||
"state": "running",
|
||||
"op_mode": "station",
|
||||
"lasttxrate": "195",
|
||||
"maxrate": "867",
|
||||
"lastassocstatus": "0",
|
||||
"802_11_auth": "open",
|
||||
"link_auth": "wpa2-psk",
|
||||
"bssid": "3c:37:86:15:ad:f9",
|
||||
"ssid": "SnazzleDazzle",
|
||||
"mcs": "0",
|
||||
"channel": "48,80"
|
||||
}
|
||||
"""
|
||||
import jc.utils
|
||||
|
||||
|
||||
class info():
|
||||
version = '1.1'
|
||||
description = 'airport -I command parser'
|
||||
author = 'Kelly Brazil'
|
||||
author_email = 'kellyjonbrazil@gmail.com'
|
||||
# details = 'enter any other details here'
|
||||
|
||||
# compatible options: linux, darwin, cygwin, win32, aix, freebsd
|
||||
compatible = ['darwin']
|
||||
magic_commands = ['airport -I']
|
||||
|
||||
|
||||
__version__ = info.version
|
||||
|
||||
|
||||
def 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:
|
||||
|
||||
{
|
||||
"agrctlrssi": integer,
|
||||
"agrextrssi": integer,
|
||||
"agrctlnoise": integer,
|
||||
"agrextnoise": integer,
|
||||
"state": string,
|
||||
"op_mode": string,
|
||||
"lasttxrate": integer,
|
||||
"maxrate": integer,
|
||||
"lastassocstatus": integer,
|
||||
"802_11_auth": string,
|
||||
"link_auth": string,
|
||||
"bssid": string,
|
||||
"ssid": string,
|
||||
"mcs": integer,
|
||||
"channel": string
|
||||
}
|
||||
"""
|
||||
# integer changes
|
||||
int_list = ['agrctlrssi', 'agrextrssi', 'agrctlnoise', 'agrextnoise',
|
||||
'lasttxrate', 'maxrate', 'lastassocstatus', 'mcs']
|
||||
for key in proc_data:
|
||||
if key in int_list:
|
||||
try:
|
||||
proc_data[key] = int(proc_data[key])
|
||||
except (ValueError):
|
||||
proc_data[key] = None
|
||||
|
||||
return proc_data
|
||||
|
||||
|
||||
def 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.
|
||||
"""
|
||||
if not quiet:
|
||||
jc.utils.compatibility(__name__, info.compatible)
|
||||
|
||||
raw_output = {}
|
||||
|
||||
if jc.utils.has_data(data):
|
||||
|
||||
for line in filter(None, data.splitlines()):
|
||||
linedata = line.split(':', maxsplit=1)
|
||||
raw_output[linedata[0].strip().lower().replace(' ', '_').replace('.', '_')] = linedata[1].strip()
|
||||
|
||||
if raw:
|
||||
return raw_output
|
||||
else:
|
||||
return process(raw_output)
|
||||
196
jc/parsers/airport_s.py
Normal file
196
jc/parsers/airport_s.py
Normal file
@@ -0,0 +1,196 @@
|
||||
"""jc - JSON CLI output utility `airport -s` command output parser
|
||||
|
||||
The `airport` program can be found at `/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport`.
|
||||
|
||||
Usage (cli):
|
||||
|
||||
$ airport -s | jc --airport-s
|
||||
|
||||
or
|
||||
|
||||
$ jc airport -s
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.airport_s
|
||||
result = jc.parsers.airport_s.parse(airport_s_command_output)
|
||||
|
||||
Compatibility:
|
||||
|
||||
'darwin'
|
||||
|
||||
Examples:
|
||||
|
||||
$ airport -s | jc --airport-s -p
|
||||
[
|
||||
{
|
||||
"ssid": "DIRECT-4A-HP OfficeJet 3830",
|
||||
"bssid": "00:67:eb:2a:a7:3b",
|
||||
"rssi": -90,
|
||||
"channel": "6",
|
||||
"ht": true,
|
||||
"cc": "--",
|
||||
"security": [
|
||||
"WPA2(PSK/AES/AES)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"ssid": "Latitude38",
|
||||
"bssid": "c0:ff:d5:d2:7a:f3",
|
||||
"rssi": -85,
|
||||
"channel": "11",
|
||||
"ht": true,
|
||||
"cc": "US",
|
||||
"security": [
|
||||
"WPA2(PSK/AES/AES)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"ssid": "xfinitywifi",
|
||||
"bssid": "6e:e3:0e:b8:45:99",
|
||||
"rssi": -83,
|
||||
"channel": "11",
|
||||
"ht": true,
|
||||
"cc": "US",
|
||||
"security": [
|
||||
"NONE"
|
||||
]
|
||||
},
|
||||
...
|
||||
]
|
||||
|
||||
$ airport -s | jc --airport -p -r
|
||||
[
|
||||
{
|
||||
"ssid": "DIRECT-F3-HP ENVY 5660 series",
|
||||
"bssid": "b0:5a:da:6f:0a:d4",
|
||||
"rssi": "-93",
|
||||
"channel": "1",
|
||||
"ht": "Y",
|
||||
"cc": "--",
|
||||
"security": "WPA2(PSK/AES/AES)"
|
||||
},
|
||||
{
|
||||
"ssid": "YouAreInfected-5",
|
||||
"bssid": "5c:e3:0e:c2:85:da",
|
||||
"rssi": "-85",
|
||||
"channel": "36",
|
||||
"ht": "Y",
|
||||
"cc": "US",
|
||||
"security": "WPA(PSK/AES,TKIP/TKIP) WPA2(PSK/AES,TKIP/TKIP)"
|
||||
},
|
||||
{
|
||||
"ssid": "YuanFamily",
|
||||
"bssid": "5c:e3:0e:b8:5f:9a",
|
||||
"rssi": "-84",
|
||||
"channel": "11",
|
||||
"ht": "Y",
|
||||
"cc": "US",
|
||||
"security": "WPA(PSK/AES,TKIP/TKIP) WPA2(PSK/AES,TKIP/TKIP)"
|
||||
},
|
||||
...
|
||||
]
|
||||
"""
|
||||
import jc.utils
|
||||
import jc.parsers.universal
|
||||
|
||||
|
||||
class info():
|
||||
version = '1.2'
|
||||
description = 'airport -s command parser'
|
||||
author = 'Kelly Brazil'
|
||||
author_email = 'kellyjonbrazil@gmail.com'
|
||||
# details = 'enter any other details here'
|
||||
|
||||
# compatible options: linux, darwin, cygwin, win32, aix, freebsd
|
||||
compatible = ['darwin']
|
||||
magic_commands = ['airport -s']
|
||||
|
||||
|
||||
__version__ = info.version
|
||||
|
||||
|
||||
def process(proc_data):
|
||||
"""
|
||||
Final processing to conform to the schema.
|
||||
|
||||
Parameters:
|
||||
|
||||
proc_data: (dictionary) raw structured data to process
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Structured data with the following schema:
|
||||
[
|
||||
{
|
||||
"ssid": string,
|
||||
"bssid": string,
|
||||
"rssi": integer,
|
||||
"channel": string,
|
||||
"ht": boolean,
|
||||
"cc": string,
|
||||
"security": [
|
||||
string,
|
||||
]
|
||||
}
|
||||
]
|
||||
"""
|
||||
for entry in proc_data:
|
||||
|
||||
# integers
|
||||
int_list = ['rssi']
|
||||
for key in int_list:
|
||||
if key in entry:
|
||||
try:
|
||||
entry[key] = int(entry[key])
|
||||
except (ValueError):
|
||||
entry[key] = None
|
||||
|
||||
# booleans
|
||||
bool_list = ['ht']
|
||||
for key in entry:
|
||||
if key in bool_list:
|
||||
try:
|
||||
entry[key] = True if entry[key] == 'Y' else False
|
||||
except (ValueError):
|
||||
entry[key] = None
|
||||
|
||||
if 'security' in entry:
|
||||
entry['security'] = entry['security'].split()
|
||||
|
||||
return proc_data
|
||||
|
||||
|
||||
def 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:
|
||||
|
||||
List of dictionaries. Raw or processed structured data.
|
||||
"""
|
||||
if not quiet:
|
||||
jc.utils.compatibility(__name__, info.compatible)
|
||||
|
||||
raw_output = []
|
||||
cleandata = list(filter(None, data.splitlines()))
|
||||
|
||||
if jc.utils.has_data(data):
|
||||
# fix headers
|
||||
cleandata[0] = cleandata[0].lower()
|
||||
cleandata[0] = cleandata[0].replace('-', '_')
|
||||
cleandata[0] = cleandata[0].replace('security (auth/unicast/group)', 'security')
|
||||
|
||||
# parse the data
|
||||
raw_output = jc.parsers.universal.sparse_table_parse(cleandata)
|
||||
|
||||
if raw:
|
||||
return raw_output
|
||||
else:
|
||||
return process(raw_output)
|
||||
@@ -1,12 +1,19 @@
|
||||
"""jc - JSON CLI output utility arp Parser
|
||||
"""jc - JSON CLI output utility `arp` command output parser
|
||||
|
||||
Usage:
|
||||
Supports `arp` and `arp -a` output.
|
||||
|
||||
specify --arp as the first argument if the piped input is coming from:
|
||||
Usage (cli):
|
||||
|
||||
arp
|
||||
or
|
||||
arp -a
|
||||
$ arp | jc --arp
|
||||
|
||||
or
|
||||
|
||||
$ jc arp
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.arp
|
||||
result = jc.parsers.arp.parse(arp_command_output)
|
||||
|
||||
Compatibility:
|
||||
|
||||
@@ -58,6 +65,8 @@ Examples:
|
||||
"hwtype": "ether",
|
||||
"hwaddress": "00:50:56:f0:98:26",
|
||||
"iface": "ens33"
|
||||
"permanent": false,
|
||||
"expires": 1182
|
||||
},
|
||||
{
|
||||
"name": "gateway",
|
||||
@@ -65,6 +74,8 @@ Examples:
|
||||
"hwtype": "ether",
|
||||
"hwaddress": "00:50:56:f7:4a:fc",
|
||||
"iface": "ens33"
|
||||
"permanent": false,
|
||||
"expires": 110
|
||||
}
|
||||
]
|
||||
|
||||
@@ -76,6 +87,8 @@ Examples:
|
||||
"hwtype": "ether",
|
||||
"hwaddress": "00:50:56:fe:7a:b4",
|
||||
"iface": "ens33"
|
||||
"permanent": false,
|
||||
"expires": "1182"
|
||||
},
|
||||
{
|
||||
"name": "_gateway",
|
||||
@@ -83,6 +96,8 @@ Examples:
|
||||
"hwtype": "ether",
|
||||
"hwaddress": "00:50:56:f7:4a:fc",
|
||||
"iface": "ens33"
|
||||
"permanent": false,
|
||||
"expires": "110"
|
||||
}
|
||||
]
|
||||
"""
|
||||
@@ -91,13 +106,14 @@ import jc.parsers.universal
|
||||
|
||||
|
||||
class info():
|
||||
version = '1.1'
|
||||
description = 'arp parser'
|
||||
version = '1.6'
|
||||
description = 'arp command parser'
|
||||
author = 'Kelly Brazil'
|
||||
author_email = 'kellyjonbrazil@gmail.com'
|
||||
|
||||
# compatible options: linux, darwin, cygwin, win32, aix, freebsd
|
||||
compatible = ['linux', 'aix', 'freebsd', 'darwin']
|
||||
magic_commands = ['arp']
|
||||
|
||||
|
||||
__version__ = info.version
|
||||
@@ -122,7 +138,9 @@ def process(proc_data):
|
||||
"hwtype": string,
|
||||
"hwaddress": string,
|
||||
"flags_mask": string,
|
||||
"iface": string
|
||||
"iface": string,
|
||||
"permanent": boolean,
|
||||
"expires": integer
|
||||
}
|
||||
]
|
||||
"""
|
||||
@@ -132,6 +150,14 @@ def process(proc_data):
|
||||
if 'name' in entry and entry['name'] == '?':
|
||||
entry['name'] = None
|
||||
|
||||
int_list = ['expires']
|
||||
for key in int_list:
|
||||
if key in entry:
|
||||
try:
|
||||
entry[key] = int(entry[key])
|
||||
except (ValueError):
|
||||
entry[key] = None
|
||||
|
||||
return proc_data
|
||||
|
||||
|
||||
@@ -152,58 +178,65 @@ def parse(data, raw=False, quiet=False):
|
||||
if not quiet:
|
||||
jc.utils.compatibility(__name__, info.compatible)
|
||||
|
||||
cleandata = data.splitlines()
|
||||
raw_output = []
|
||||
cleandata = list(filter(None, data.splitlines()))
|
||||
|
||||
# remove final Entries row if -v was used
|
||||
if cleandata[-1].find('Entries:') == 0:
|
||||
cleandata.pop(-1)
|
||||
if jc.utils.has_data(data):
|
||||
|
||||
# detect if osx style was used
|
||||
if cleandata[0].find(' ifscope ') != -1:
|
||||
raw_output = []
|
||||
for line in cleandata:
|
||||
line = line.split()
|
||||
output_line = {}
|
||||
output_line['name'] = line[0]
|
||||
output_line['address'] = line[1].lstrip('(').rstrip(')')
|
||||
output_line['hwtype'] = line[-1].lstrip('[').rstrip(']')
|
||||
output_line['hwaddress'] = line[3]
|
||||
output_line['iface'] = line[5]
|
||||
raw_output.append(output_line)
|
||||
# remove final Entries row if -v was used
|
||||
if cleandata[-1].startswith('Entries:'):
|
||||
cleandata.pop(-1)
|
||||
|
||||
if raw:
|
||||
return raw_output
|
||||
# detect if freebsd/osx style was used
|
||||
if cleandata[0][-1] == ']':
|
||||
for line in cleandata:
|
||||
splitline = line.split()
|
||||
output_line = {
|
||||
'name': splitline[0],
|
||||
'address': splitline[1].lstrip('(').rstrip(')'),
|
||||
'hwtype': splitline[-1].lstrip('[').rstrip(']'),
|
||||
'hwaddress': splitline[3],
|
||||
'iface': splitline[5]
|
||||
}
|
||||
|
||||
if 'permanent' in splitline:
|
||||
output_line['permanent'] = True
|
||||
else:
|
||||
output_line['permanent'] = False
|
||||
|
||||
if 'expires' in splitline:
|
||||
output_line['expires'] = splitline[-3]
|
||||
|
||||
raw_output.append(output_line)
|
||||
|
||||
if raw:
|
||||
return raw_output
|
||||
else:
|
||||
return process(raw_output)
|
||||
|
||||
# detect if linux style was used
|
||||
elif cleandata[0].startswith('Address'):
|
||||
|
||||
# fix header row to change Flags Mask to flags_mask
|
||||
cleandata[0] = cleandata[0].replace('Flags Mask', 'flags_mask')
|
||||
cleandata[0] = cleandata[0].lower()
|
||||
|
||||
raw_output = jc.parsers.universal.simple_table_parse(cleandata)
|
||||
|
||||
# otherwise, try bsd style
|
||||
else:
|
||||
return process(raw_output)
|
||||
for line in cleandata:
|
||||
line = line.split()
|
||||
output_line = {
|
||||
'name': line[0],
|
||||
'address': line[1].lstrip('(').rstrip(')'),
|
||||
'hwtype': line[4].lstrip('[').rstrip(']'),
|
||||
'hwaddress': line[3],
|
||||
'iface': line[6],
|
||||
}
|
||||
raw_output.append(output_line)
|
||||
|
||||
# detect if linux style was used
|
||||
elif cleandata[0].find('Address') == 0:
|
||||
|
||||
# fix header row to change Flags Mask to flags_mask
|
||||
cleandata[0] = cleandata[0].replace('Flags Mask', 'flags_mask')
|
||||
cleandata[0] = cleandata[0].lower()
|
||||
|
||||
raw_output = jc.parsers.universal.simple_table_parse(cleandata)
|
||||
|
||||
if raw:
|
||||
return raw_output
|
||||
else:
|
||||
return process(raw_output)
|
||||
|
||||
# otherwise, try bsd style
|
||||
if raw:
|
||||
return raw_output
|
||||
else:
|
||||
raw_output = []
|
||||
for line in cleandata:
|
||||
line = line.split()
|
||||
output_line = {}
|
||||
output_line['name'] = line[0]
|
||||
output_line['address'] = line[1].lstrip('(').rstrip(')')
|
||||
output_line['hwtype'] = line[4].lstrip('[').rstrip(']')
|
||||
output_line['hwaddress'] = line[3]
|
||||
output_line['iface'] = line[6]
|
||||
raw_output.append(output_line)
|
||||
|
||||
if raw:
|
||||
return raw_output
|
||||
else:
|
||||
return process(raw_output)
|
||||
return process(raw_output)
|
||||
|
||||
228
jc/parsers/blkid.py
Normal file
228
jc/parsers/blkid.py
Normal file
@@ -0,0 +1,228 @@
|
||||
"""jc - JSON CLI output utility `blkid` command output parser
|
||||
|
||||
Usage (cli):
|
||||
|
||||
$ blkid | jc --blkid
|
||||
|
||||
or
|
||||
|
||||
$ jc blkid
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.blkid
|
||||
result = jc.parsers.blkid.parse(blkid_command_output)
|
||||
|
||||
Compatibility:
|
||||
|
||||
'linux'
|
||||
|
||||
Examples:
|
||||
|
||||
$ blkid | jc --blkid -p
|
||||
[
|
||||
{
|
||||
"device": "/dev/sda1",
|
||||
"uuid": "05d927ab-5875-49e4-ada1-7f46cb32c932",
|
||||
"type": "xfs"
|
||||
},
|
||||
{
|
||||
"device": "/dev/sda2",
|
||||
"uuid": "3klkIj-w1kk-DkJi-0XBJ-y3i7-i2Ac-vHqWBM",
|
||||
"type": "LVM2_member"
|
||||
},
|
||||
{
|
||||
"device": "/dev/mapper/centos-root",
|
||||
"uuid": "07d718ff-950c-4e5b-98f0-42a1147c77d9",
|
||||
"type": "xfs"
|
||||
},
|
||||
{
|
||||
"device": "/dev/mapper/centos-swap",
|
||||
"uuid": "615eb89a-bcbf-46fd-80e3-c483ff5c931f",
|
||||
"type": "swap"
|
||||
}
|
||||
]
|
||||
|
||||
$ sudo blkid -o udev -ip /dev/sda2 | jc --blkid -p
|
||||
[
|
||||
{
|
||||
"id_fs_uuid": "3klkIj-w1kk-DkJi-0XBJ-y3i7-i2Ac-vHqWBM",
|
||||
"id_fs_uuid_enc": "3klkIj-w1kk-DkJi-0XBJ-y3i7-i2Ac-vHqWBM",
|
||||
"id_fs_version": "LVM2\\x20001",
|
||||
"id_fs_type": "LVM2_member",
|
||||
"id_fs_usage": "raid",
|
||||
"id_iolimit_minimum_io_size": 512,
|
||||
"id_iolimit_physical_sector_size": 512,
|
||||
"id_iolimit_logical_sector_size": 512,
|
||||
"id_part_entry_scheme": "dos",
|
||||
"id_part_entry_type": "0x8e",
|
||||
"id_part_entry_number": 2,
|
||||
"id_part_entry_offset": 2099200,
|
||||
"id_part_entry_size": 39843840,
|
||||
"id_part_entry_disk": "8:0"
|
||||
}
|
||||
]
|
||||
|
||||
$ sudo blkid -ip /dev/sda1 | jc --blkid -p -r
|
||||
[
|
||||
{
|
||||
"devname": "/dev/sda1",
|
||||
"uuid": "05d927bb-5875-49e3-ada1-7f46cb31c932",
|
||||
"type": "xfs",
|
||||
"usage": "filesystem",
|
||||
"minimum_io_size": "512",
|
||||
"physical_sector_size": "512",
|
||||
"logical_sector_size": "512",
|
||||
"part_entry_scheme": "dos",
|
||||
"part_entry_type": "0x83",
|
||||
"part_entry_flags": "0x80",
|
||||
"part_entry_number": "1",
|
||||
"part_entry_offset": "2048",
|
||||
"part_entry_size": "2097152",
|
||||
"part_entry_disk": "8:0"
|
||||
}
|
||||
]
|
||||
"""
|
||||
import shlex
|
||||
import jc.utils
|
||||
|
||||
|
||||
class info():
|
||||
version = '1.2'
|
||||
description = 'blkid command parser'
|
||||
author = 'Kelly Brazil'
|
||||
author_email = 'kellyjonbrazil@gmail.com'
|
||||
# details = 'enter any other details here'
|
||||
|
||||
# compatible options: linux, darwin, cygwin, win32, aix, freebsd
|
||||
compatible = ['linux']
|
||||
magic_commands = ['blkid']
|
||||
|
||||
|
||||
__version__ = info.version
|
||||
|
||||
|
||||
def process(proc_data):
|
||||
"""
|
||||
Final processing to conform to the schema.
|
||||
|
||||
Parameters:
|
||||
|
||||
proc_data: (dictionary) raw structured data to process
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Structured data with the following schema:
|
||||
|
||||
[
|
||||
{
|
||||
"device": string,
|
||||
"uuid": string,
|
||||
"type": string,
|
||||
"usage": string,
|
||||
"part_entry_scheme": string,
|
||||
"part_entry_type": string,
|
||||
"part_entry_flags": string,
|
||||
"part_entry_number": integer,
|
||||
"part_entry_offset": integer,
|
||||
"part_entry_size": integer,
|
||||
"part_entry_disk": string,
|
||||
"id_fs_uuid": string,
|
||||
"id_fs_uuid_enc": string,
|
||||
"id_fs_version": string,
|
||||
"id_fs_type": string,
|
||||
"id_fs_usage": string,
|
||||
"id_part_entry_scheme": string,
|
||||
"id_part_entry_type": string,
|
||||
"id_part_entry_flags": string,
|
||||
"id_part_entry_number": integer,
|
||||
"id_part_entry_offset": integer,
|
||||
"id_part_entry_size": integer,
|
||||
"id_iolimit_minimum_io_size": integer,
|
||||
"id_iolimit_physical_sector_size": integer,
|
||||
"id_iolimit_logical_sector_size": integer,
|
||||
"id_part_entry_disk": string,
|
||||
"minimum_io_size": integer,
|
||||
"physical_sector_size": integer,
|
||||
"logical_sector_size": integer
|
||||
}
|
||||
]
|
||||
"""
|
||||
for entry in proc_data:
|
||||
if 'devname' in entry:
|
||||
entry['device'] = entry.pop('devname')
|
||||
|
||||
int_list = ['part_entry_number', 'part_entry_offset', 'part_entry_size', 'id_part_entry_number',
|
||||
'id_part_entry_offset', 'id_part_entry_size', 'minimum_io_size', 'physical_sector_size',
|
||||
'logical_sector_size', 'id_iolimit_minimum_io_size', 'id_iolimit_physical_sector_size',
|
||||
'id_iolimit_logical_sector_size']
|
||||
for key in int_list:
|
||||
if key in entry:
|
||||
try:
|
||||
entry[key] = int(entry[key])
|
||||
except (ValueError):
|
||||
entry[key] = None
|
||||
|
||||
return proc_data
|
||||
|
||||
|
||||
def 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:
|
||||
|
||||
List of dictionaries. Raw or processed structured data.
|
||||
"""
|
||||
if not quiet:
|
||||
jc.utils.compatibility(__name__, info.compatible)
|
||||
|
||||
raw_output = []
|
||||
|
||||
if jc.utils.has_data(data):
|
||||
|
||||
# if the first field is a device, use normal parsing:
|
||||
if data.split(maxsplit=1)[0][-1] == ':':
|
||||
linedata = data.splitlines()
|
||||
|
||||
for line in linedata:
|
||||
output_line = {}
|
||||
entries = shlex.split(line)
|
||||
output_line['device'] = entries.pop(0)[:-1]
|
||||
|
||||
for entry in entries:
|
||||
key = entry.split('=', maxsplit=1)[0].lower()
|
||||
value = entry.split('=', maxsplit=1)[1]
|
||||
output_line[key] = value
|
||||
|
||||
raw_output.append(output_line)
|
||||
|
||||
# else use key/value per line parsing
|
||||
else:
|
||||
linedata = data.splitlines()
|
||||
output_line = {}
|
||||
for line in linedata:
|
||||
if line == '':
|
||||
if output_line:
|
||||
raw_output.append(output_line)
|
||||
output_line = {}
|
||||
continue
|
||||
continue
|
||||
|
||||
key = line.split('=', maxsplit=1)[0].lower()
|
||||
value = line.split('=', maxsplit=1)[1]
|
||||
output_line[key] = value
|
||||
|
||||
if output_line:
|
||||
raw_output.append(output_line)
|
||||
|
||||
if raw:
|
||||
return raw_output
|
||||
else:
|
||||
return process(raw_output)
|
||||
128
jc/parsers/cksum.py
Normal file
128
jc/parsers/cksum.py
Normal file
@@ -0,0 +1,128 @@
|
||||
"""jc - JSON CLI output utility `cksum` command output parser
|
||||
|
||||
This parser works with the following checksum calculation utilities:
|
||||
- `sum`
|
||||
- `cksum`
|
||||
|
||||
Usage (cli):
|
||||
|
||||
$ cksum file.txt | jc --cksum
|
||||
|
||||
or
|
||||
|
||||
$ jc cksum file.txt
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.cksum
|
||||
result = jc.parsers.cksum.parse(cksum_command_output)
|
||||
|
||||
Compatibility:
|
||||
|
||||
'linux', 'darwin', 'cygwin', 'aix', 'freebsd'
|
||||
|
||||
Examples:
|
||||
|
||||
$ cksum * | jc --cksum -p
|
||||
[
|
||||
{
|
||||
"filename": "__init__.py",
|
||||
"checksum": 4294967295,
|
||||
"blocks": 0
|
||||
},
|
||||
{
|
||||
"filename": "airport.py",
|
||||
"checksum": 2208551092,
|
||||
"blocks": 3745
|
||||
},
|
||||
{
|
||||
"filename": "airport_s.py",
|
||||
"checksum": 1113817598,
|
||||
"blocks": 4572
|
||||
},
|
||||
...
|
||||
]
|
||||
"""
|
||||
import jc.utils
|
||||
|
||||
|
||||
class info():
|
||||
version = '1.0'
|
||||
description = 'cksum command parser'
|
||||
author = 'Kelly Brazil'
|
||||
author_email = 'kellyjonbrazil@gmail.com'
|
||||
details = 'Parses cksum and sum program output'
|
||||
|
||||
# compatible options: linux, darwin, cygwin, win32, aix, freebsd
|
||||
compatible = ['linux', 'darwin', 'cygwin', 'aix', 'freebsd']
|
||||
magic_commands = ['cksum', 'sum']
|
||||
|
||||
|
||||
__version__ = info.version
|
||||
|
||||
|
||||
def process(proc_data):
|
||||
"""
|
||||
Final processing to conform to the schema.
|
||||
|
||||
Parameters:
|
||||
|
||||
proc_data: (dictionary) raw structured data to process
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Structured data with the following schema:
|
||||
|
||||
[
|
||||
{
|
||||
"filename": string,
|
||||
"checksum": integer,
|
||||
"blocks": integer
|
||||
}
|
||||
]
|
||||
"""
|
||||
|
||||
for entry in proc_data:
|
||||
int_list = ['checksum', 'blocks']
|
||||
for key in int_list:
|
||||
if key in entry:
|
||||
try:
|
||||
entry[key] = int(entry[key])
|
||||
except (ValueError):
|
||||
entry[key] = None
|
||||
return proc_data
|
||||
|
||||
|
||||
def 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:
|
||||
|
||||
List of dictionaries. Raw or processed structured data.
|
||||
"""
|
||||
if not quiet:
|
||||
jc.utils.compatibility(__name__, info.compatible)
|
||||
|
||||
raw_output = []
|
||||
|
||||
if jc.utils.has_data(data):
|
||||
|
||||
for line in filter(None, data.splitlines()):
|
||||
item = {
|
||||
'filename': line.split(maxsplit=2)[2],
|
||||
'checksum': line.split(maxsplit=2)[0],
|
||||
'blocks': line.split(maxsplit=2)[1]
|
||||
}
|
||||
raw_output.append(item)
|
||||
|
||||
if raw:
|
||||
return raw_output
|
||||
else:
|
||||
return process(raw_output)
|
||||
@@ -1,8 +1,19 @@
|
||||
"""jc - JSON CLI output utility crontab file Parser
|
||||
"""jc - JSON CLI output utility `crontab -l` command output and crontab file parser
|
||||
|
||||
Usage:
|
||||
Supports `crontab -l` command output and crontab files.
|
||||
|
||||
specify --crontab as the first argument if the piped input is coming from a crontab file
|
||||
Usage (cli):
|
||||
|
||||
$ crontab -l | jc --crontab
|
||||
|
||||
or
|
||||
|
||||
$ jc crontab -l
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.crontab
|
||||
result = jc.parsers.crontab.parse(crontab_output)
|
||||
|
||||
Compatibility:
|
||||
|
||||
@@ -10,7 +21,7 @@ Compatibility:
|
||||
|
||||
Examples:
|
||||
|
||||
$ cat /etc/crontab | jc --crontab -p
|
||||
$ crontab -l | jc --crontab -p
|
||||
{
|
||||
"variables": [
|
||||
{
|
||||
@@ -132,14 +143,15 @@ import jc.parsers.universal
|
||||
|
||||
|
||||
class info():
|
||||
version = '1.1'
|
||||
description = 'crontab file parser'
|
||||
version = '1.4'
|
||||
description = 'crontab command and file parser'
|
||||
author = 'Kelly Brazil'
|
||||
author_email = 'kellyjonbrazil@gmail.com'
|
||||
# details = 'enter any other details here'
|
||||
|
||||
# compatible options: linux, darwin, cygwin, win32, aix, freebsd
|
||||
compatible = ['linux', 'darwin', 'aix', 'freebsd']
|
||||
magic_commands = ['crontab']
|
||||
|
||||
|
||||
__version__ = info.version
|
||||
@@ -224,44 +236,46 @@ def parse(data, raw=False, quiet=False):
|
||||
# Clear any blank lines
|
||||
cleandata = list(filter(None, cleandata))
|
||||
|
||||
# Clear any commented lines
|
||||
for i, line in reversed(list(enumerate(cleandata))):
|
||||
if line.strip().find('#') == 0:
|
||||
cleandata.pop(i)
|
||||
if jc.utils.has_data(data):
|
||||
|
||||
# Pop any variable assignment lines
|
||||
cron_var = []
|
||||
for i, line in reversed(list(enumerate(cleandata))):
|
||||
if line.find('=') != -1:
|
||||
var_line = cleandata.pop(i)
|
||||
var_name = var_line.split('=', maxsplit=1)[0].strip()
|
||||
var_value = var_line.split('=', maxsplit=1)[1].strip()
|
||||
cron_var.append({'name': var_name,
|
||||
'value': var_value})
|
||||
# Clear any commented lines
|
||||
for i, line in reversed(list(enumerate(cleandata))):
|
||||
if line.strip().startswith('#'):
|
||||
cleandata.pop(i)
|
||||
|
||||
raw_output['variables'] = cron_var
|
||||
# Pop any variable assignment lines
|
||||
cron_var = []
|
||||
for i, line in reversed(list(enumerate(cleandata))):
|
||||
if '=' in line and not line.strip()[0].isdigit() and not line.strip()[0] == '@':
|
||||
var_line = cleandata.pop(i)
|
||||
var_name = var_line.split('=', maxsplit=1)[0].strip()
|
||||
var_value = var_line.split('=', maxsplit=1)[1].strip()
|
||||
cron_var.append({'name': var_name,
|
||||
'value': var_value})
|
||||
|
||||
# Pop any shortcut lines
|
||||
shortcut_list = []
|
||||
for i, line in reversed(list(enumerate(cleandata))):
|
||||
if line.strip().startswith('@'):
|
||||
shortcut_line = cleandata.pop(i)
|
||||
occurrence = shortcut_line.split(maxsplit=1)[0].strip().lstrip('@')
|
||||
cmd = shortcut_line.split(maxsplit=1)[1].strip()
|
||||
shortcut_list.append({'occurrence': occurrence,
|
||||
'command': cmd})
|
||||
raw_output['variables'] = cron_var
|
||||
|
||||
# Add header row for parsing
|
||||
cleandata[:0] = ['minute hour day_of_month month day_of_week command']
|
||||
# Pop any shortcut lines
|
||||
shortcut_list = []
|
||||
for i, line in reversed(list(enumerate(cleandata))):
|
||||
if line.strip().startswith('@'):
|
||||
shortcut_line = cleandata.pop(i)
|
||||
occurrence = shortcut_line.split(maxsplit=1)[0].strip().lstrip('@')
|
||||
cmd = shortcut_line.split(maxsplit=1)[1].strip()
|
||||
shortcut_list.append({'occurrence': occurrence,
|
||||
'command': cmd})
|
||||
|
||||
if len(cleandata) > 1:
|
||||
cron_list = jc.parsers.universal.simple_table_parse(cleandata)
|
||||
# Add header row for parsing
|
||||
cleandata[:0] = ['minute hour day_of_month month day_of_week command']
|
||||
|
||||
raw_output['schedule'] = cron_list
|
||||
if len(cleandata) > 1:
|
||||
cron_list = jc.parsers.universal.simple_table_parse(cleandata)
|
||||
|
||||
# Add shortcut entries back in
|
||||
for item in shortcut_list:
|
||||
raw_output['schedule'].append(item)
|
||||
raw_output['schedule'] = cron_list
|
||||
|
||||
# Add shortcut entries back in
|
||||
for item in shortcut_list:
|
||||
raw_output['schedule'].append(item)
|
||||
|
||||
if raw:
|
||||
return raw_output
|
||||
|
||||
@@ -1,8 +1,15 @@
|
||||
"""jc - JSON CLI output utility crontab file Parser
|
||||
"""jc - JSON CLI output utility `crontab -l` command output and crontab file parser
|
||||
|
||||
Usage:
|
||||
This version of the `crontab -l` parser supports output that contains user information for processes.
|
||||
|
||||
specify --crontab-u as the first argument if the piped input is coming from a crontab file with User specified
|
||||
Usage (cli):
|
||||
|
||||
$ crontab -l | jc --crontab-u
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.crontab_u
|
||||
result = jc.parsers.crontab_u.parse(crontab_u_output)
|
||||
|
||||
Compatibility:
|
||||
|
||||
@@ -10,7 +17,7 @@ Compatibility:
|
||||
|
||||
Examples:
|
||||
|
||||
$ cat /etc/crontab | jc --crontab -p
|
||||
$ cat /etc/crontab | jc --crontab-u -p
|
||||
{
|
||||
"variables": [
|
||||
{
|
||||
@@ -133,7 +140,7 @@ import jc.parsers.universal
|
||||
|
||||
|
||||
class info():
|
||||
version = '1.0'
|
||||
version = '1.5'
|
||||
description = 'crontab file parser with user support'
|
||||
author = 'Kelly Brazil'
|
||||
author_email = 'kellyjonbrazil@gmail.com'
|
||||
@@ -226,46 +233,48 @@ def parse(data, raw=False, quiet=False):
|
||||
# Clear any blank lines
|
||||
cleandata = list(filter(None, cleandata))
|
||||
|
||||
# Clear any commented lines
|
||||
for i, line in reversed(list(enumerate(cleandata))):
|
||||
if line.strip().find('#') == 0:
|
||||
cleandata.pop(i)
|
||||
if jc.utils.has_data(data):
|
||||
|
||||
# Pop any variable assignment lines
|
||||
cron_var = []
|
||||
for i, line in reversed(list(enumerate(cleandata))):
|
||||
if line.find('=') != -1:
|
||||
var_line = cleandata.pop(i)
|
||||
var_name = var_line.split('=', maxsplit=1)[0].strip()
|
||||
var_value = var_line.split('=', maxsplit=1)[1].strip()
|
||||
cron_var.append({'name': var_name,
|
||||
'value': var_value})
|
||||
# Clear any commented lines
|
||||
for i, line in reversed(list(enumerate(cleandata))):
|
||||
if line.strip().startswith('#'):
|
||||
cleandata.pop(i)
|
||||
|
||||
raw_output['variables'] = cron_var
|
||||
# Pop any variable assignment lines
|
||||
cron_var = []
|
||||
for i, line in reversed(list(enumerate(cleandata))):
|
||||
if '=' in line and not line.strip()[0].isdigit() and not line.strip()[0] == '@':
|
||||
var_line = cleandata.pop(i)
|
||||
var_name = var_line.split('=', maxsplit=1)[0].strip()
|
||||
var_value = var_line.split('=', maxsplit=1)[1].strip()
|
||||
cron_var.append({'name': var_name,
|
||||
'value': var_value})
|
||||
|
||||
# Pop any shortcut lines
|
||||
shortcut_list = []
|
||||
for i, line in reversed(list(enumerate(cleandata))):
|
||||
if line.strip().startswith('@'):
|
||||
shortcut_line = cleandata.pop(i)
|
||||
occurrence = shortcut_line.split(maxsplit=1)[0].strip().lstrip('@')
|
||||
usr = shortcut_line.split(maxsplit=2)[1].strip()
|
||||
cmd = shortcut_line.split(maxsplit=2)[2].strip()
|
||||
shortcut_list.append({'occurrence': occurrence,
|
||||
'user': usr,
|
||||
'command': cmd})
|
||||
raw_output['variables'] = cron_var
|
||||
|
||||
# Add header row for parsing
|
||||
cleandata[:0] = ['minute hour day_of_month month day_of_week user command']
|
||||
# Pop any shortcut lines
|
||||
shortcut_list = []
|
||||
for i, line in reversed(list(enumerate(cleandata))):
|
||||
if line.strip().startswith('@'):
|
||||
shortcut_line = cleandata.pop(i)
|
||||
occurrence = shortcut_line.split(maxsplit=1)[0].strip().lstrip('@')
|
||||
usr = shortcut_line.split(maxsplit=2)[1].strip()
|
||||
cmd = shortcut_line.split(maxsplit=2)[2].strip()
|
||||
shortcut_list.append({'occurrence': occurrence,
|
||||
'user': usr,
|
||||
'command': cmd})
|
||||
|
||||
if len(cleandata) > 1:
|
||||
cron_list = jc.parsers.universal.simple_table_parse(cleandata)
|
||||
# Add header row for parsing
|
||||
cleandata[:0] = ['minute hour day_of_month month day_of_week user command']
|
||||
|
||||
raw_output['schedule'] = cron_list
|
||||
if len(cleandata) > 1:
|
||||
cron_list = jc.parsers.universal.simple_table_parse(cleandata)
|
||||
|
||||
# Add shortcut entries back in
|
||||
for item in shortcut_list:
|
||||
raw_output['schedule'].append(item)
|
||||
raw_output['schedule'] = cron_list
|
||||
|
||||
# Add shortcut entries back in
|
||||
for item in shortcut_list:
|
||||
raw_output['schedule'].append(item)
|
||||
|
||||
if raw:
|
||||
return raw_output
|
||||
|
||||
146
jc/parsers/csv.py
Normal file
146
jc/parsers/csv.py
Normal file
@@ -0,0 +1,146 @@
|
||||
"""jc - JSON CLI output utility `csv` file parser
|
||||
|
||||
The `csv` parser will attempt to automatically detect the delimiter character. If the delimiter cannot be detected it will default to comma. The first row of the file must be a header row.
|
||||
|
||||
Usage (cli):
|
||||
|
||||
$ cat file.csv | jc --csv
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.csv
|
||||
result = jc.parsers.csv.parse(csv_output)
|
||||
|
||||
Compatibility:
|
||||
|
||||
'linux', 'darwin', 'cygwin', 'win32', 'aix', 'freebsd'
|
||||
|
||||
Examples:
|
||||
|
||||
$ cat homes.csv
|
||||
"Sell", "List", "Living", "Rooms", "Beds", "Baths", "Age", "Acres", "Taxes"
|
||||
142, 160, 28, 10, 5, 3, 60, 0.28, 3167
|
||||
175, 180, 18, 8, 4, 1, 12, 0.43, 4033
|
||||
129, 132, 13, 6, 3, 1, 41, 0.33, 1471
|
||||
...
|
||||
|
||||
$ cat homes.csv | jc --csv -p
|
||||
[
|
||||
{
|
||||
"Sell": "142",
|
||||
"List": "160",
|
||||
"Living": "28",
|
||||
"Rooms": "10",
|
||||
"Beds": "5",
|
||||
"Baths": "3",
|
||||
"Age": "60",
|
||||
"Acres": "0.28",
|
||||
"Taxes": "3167"
|
||||
},
|
||||
{
|
||||
"Sell": "175",
|
||||
"List": "180",
|
||||
"Living": "18",
|
||||
"Rooms": "8",
|
||||
"Beds": "4",
|
||||
"Baths": "1",
|
||||
"Age": "12",
|
||||
"Acres": "0.43",
|
||||
"Taxes": "4033"
|
||||
},
|
||||
{
|
||||
"Sell": "129",
|
||||
"List": "132",
|
||||
"Living": "13",
|
||||
"Rooms": "6",
|
||||
"Beds": "3",
|
||||
"Baths": "1",
|
||||
"Age": "41",
|
||||
"Acres": "0.33",
|
||||
"Taxes": "1471"
|
||||
},
|
||||
...
|
||||
]
|
||||
"""
|
||||
import jc.utils
|
||||
import csv
|
||||
|
||||
|
||||
class info():
|
||||
version = '1.1'
|
||||
description = 'CSV file parser'
|
||||
author = 'Kelly Brazil'
|
||||
author_email = 'kellyjonbrazil@gmail.com'
|
||||
details = 'Using the python standard csv library'
|
||||
|
||||
# compatible options: linux, darwin, cygwin, win32, aix, freebsd
|
||||
compatible = ['linux', 'darwin', 'cygwin', 'win32', 'aix', 'freebsd']
|
||||
|
||||
|
||||
__version__ = info.version
|
||||
|
||||
|
||||
def process(proc_data):
|
||||
"""
|
||||
Final processing to conform to the schema.
|
||||
|
||||
Parameters:
|
||||
|
||||
proc_data: (dictionary) raw structured data to process
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Each dictionary represents a row in the csv file:
|
||||
|
||||
[
|
||||
{
|
||||
csv file converted to a Dictionary
|
||||
https://docs.python.org/3/library/csv.html
|
||||
}
|
||||
]
|
||||
"""
|
||||
|
||||
# No further processing
|
||||
return proc_data
|
||||
|
||||
|
||||
def 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:
|
||||
|
||||
List of dictionaries. Raw or processed structured data.
|
||||
"""
|
||||
if not quiet:
|
||||
jc.utils.compatibility(__name__, info.compatible)
|
||||
|
||||
raw_output = []
|
||||
cleandata = data.splitlines()
|
||||
|
||||
# Clear any blank lines
|
||||
cleandata = list(filter(None, cleandata))
|
||||
|
||||
if jc.utils.has_data(data):
|
||||
|
||||
dialect = None
|
||||
try:
|
||||
dialect = csv.Sniffer().sniff(data[:1024])
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
reader = csv.DictReader(cleandata, dialect=dialect)
|
||||
|
||||
for row in reader:
|
||||
raw_output.append(row)
|
||||
|
||||
if raw:
|
||||
return raw_output
|
||||
else:
|
||||
return process(raw_output)
|
||||
169
jc/parsers/date.py
Normal file
169
jc/parsers/date.py
Normal file
@@ -0,0 +1,169 @@
|
||||
"""jc - JSON CLI output utility `date` command output parser
|
||||
|
||||
Usage (cli):
|
||||
|
||||
$ date | jc --date
|
||||
|
||||
or
|
||||
|
||||
$ jc date
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.date
|
||||
result = jc.parsers.date.parse(date_command_output)
|
||||
|
||||
Compatibility:
|
||||
|
||||
'linux', 'darwin', 'freebsd'
|
||||
|
||||
Examples:
|
||||
|
||||
$ date | jc --date -p
|
||||
{
|
||||
"year": 2020,
|
||||
"month_num": 7,
|
||||
"day": 31,
|
||||
"hour": 16,
|
||||
"minute": 48,
|
||||
"second": 11,
|
||||
"month": "Jul",
|
||||
"weekday": "Fri",
|
||||
"weekday_num": 6,
|
||||
"timezone": "PDT"
|
||||
}
|
||||
|
||||
$ date | jc --date -p -r
|
||||
{
|
||||
"year": "2020",
|
||||
"month": "Jul",
|
||||
"day": "31",
|
||||
"weekday": "Fri",
|
||||
"hour": "16",
|
||||
"minute": "50",
|
||||
"second": "01",
|
||||
"timezone": "PDT"
|
||||
}
|
||||
"""
|
||||
import jc.utils
|
||||
|
||||
|
||||
class info():
|
||||
version = '1.0'
|
||||
description = 'date command parser'
|
||||
author = 'Kelly Brazil'
|
||||
author_email = 'kellyjonbrazil@gmail.com'
|
||||
|
||||
# compatible options: linux, darwin, cygwin, win32, aix, freebsd
|
||||
compatible = ['linux', 'darwin', 'freebsd']
|
||||
magic_commands = ['date']
|
||||
|
||||
|
||||
__version__ = info.version
|
||||
|
||||
|
||||
def 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:
|
||||
|
||||
{
|
||||
"year": integer,
|
||||
"month_num": integer,
|
||||
"day": integer,
|
||||
"hour": integer,
|
||||
"minute": integer,
|
||||
"second": integer,
|
||||
"month": string,
|
||||
"weekday": string,
|
||||
"weekday_num": integer,
|
||||
"timezone": string
|
||||
}
|
||||
"""
|
||||
month_map = {
|
||||
"Jan": 1,
|
||||
"Feb": 2,
|
||||
"Mar": 3,
|
||||
"Apr": 4,
|
||||
"May": 5,
|
||||
"Jun": 6,
|
||||
"Jul": 7,
|
||||
"Aug": 8,
|
||||
"Sep": 9,
|
||||
"Oct": 10,
|
||||
"Nov": 11,
|
||||
"Dec": 12
|
||||
}
|
||||
|
||||
weekday_map = {
|
||||
"Sun": 1,
|
||||
"Mon": 2,
|
||||
"Tue": 3,
|
||||
"Wed": 4,
|
||||
"Thu": 5,
|
||||
"Fri": 6,
|
||||
"Sat": 7
|
||||
}
|
||||
|
||||
if proc_data:
|
||||
return {
|
||||
"year": int(proc_data['year']),
|
||||
'month_num': month_map[proc_data['month']],
|
||||
"day": int(proc_data['day']),
|
||||
"hour": int(proc_data['hour']),
|
||||
"minute": int(proc_data['minute']),
|
||||
"second": int(proc_data['second']),
|
||||
"month": proc_data['month'],
|
||||
"weekday": proc_data['weekday'],
|
||||
"weekday_num": weekday_map[proc_data['weekday']],
|
||||
"timezone": proc_data['timezone']
|
||||
}
|
||||
else:
|
||||
return {}
|
||||
|
||||
|
||||
def 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.
|
||||
"""
|
||||
if not quiet:
|
||||
jc.utils.compatibility(__name__, info.compatible)
|
||||
|
||||
raw_output = {}
|
||||
|
||||
if jc.utils.has_data(data):
|
||||
data = data.replace(':', ' ')
|
||||
split_data = data.split()
|
||||
|
||||
raw_output = {
|
||||
"year": split_data[7],
|
||||
"month": split_data[1],
|
||||
"day": split_data[2],
|
||||
"weekday": split_data[0],
|
||||
"hour": split_data[3],
|
||||
"minute": split_data[4],
|
||||
"second": split_data[5],
|
||||
"timezone": split_data[6]
|
||||
}
|
||||
|
||||
if raw:
|
||||
return raw_output
|
||||
else:
|
||||
return process(raw_output)
|
||||
@@ -1,12 +1,21 @@
|
||||
"""jc - JSON CLI output utility df Parser
|
||||
"""jc - JSON CLI output utility `df` command output parser
|
||||
|
||||
Usage:
|
||||
Usage (cli):
|
||||
|
||||
specify --df as the first argument if the piped input is coming from df
|
||||
$ df | jc --df
|
||||
|
||||
or
|
||||
|
||||
$ jc df
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.df
|
||||
result = jc.parsers.df.parse(df_command_output)
|
||||
|
||||
Compatibility:
|
||||
|
||||
'linux', 'darwin'
|
||||
'linux', 'darwin', 'freebsd'
|
||||
|
||||
Examples:
|
||||
|
||||
@@ -73,13 +82,14 @@ import jc.parsers.universal
|
||||
|
||||
|
||||
class info():
|
||||
version = '1.1'
|
||||
description = 'df parser'
|
||||
version = '1.5'
|
||||
description = 'df command parser'
|
||||
author = 'Kelly Brazil'
|
||||
author_email = 'kellyjonbrazil@gmail.com'
|
||||
|
||||
# compatible options: linux, darwin, cygwin, win32, aix, freebsd
|
||||
compatible = ['linux', 'darwin']
|
||||
compatible = ['linux', 'darwin', 'freebsd']
|
||||
magic_commands = ['df']
|
||||
|
||||
|
||||
__version__ = info.version
|
||||
@@ -134,7 +144,7 @@ def process(proc_data):
|
||||
|
||||
# change any entry for key with '_blocks' in the name to int
|
||||
for k in entry:
|
||||
if str(k).find('_blocks') != -1:
|
||||
if '_blocks' in str(k):
|
||||
try:
|
||||
blocks_int = int(entry[k])
|
||||
entry[k] = blocks_int
|
||||
@@ -183,14 +193,17 @@ def parse(data, raw=False, quiet=False):
|
||||
jc.utils.compatibility(__name__, info.compatible)
|
||||
|
||||
cleandata = data.splitlines()
|
||||
raw_output = []
|
||||
|
||||
# fix headers
|
||||
cleandata[0] = cleandata[0].lower()
|
||||
cleandata[0] = cleandata[0].replace('-', '_')
|
||||
cleandata[0] = cleandata[0].replace('mounted on', 'mounted_on')
|
||||
if jc.utils.has_data(data):
|
||||
|
||||
# parse the data
|
||||
raw_output = jc.parsers.universal.sparse_table_parse(cleandata)
|
||||
# fix headers
|
||||
cleandata[0] = cleandata[0].lower()
|
||||
cleandata[0] = cleandata[0].replace('-', '_')
|
||||
cleandata[0] = cleandata[0].replace('mounted on', 'mounted_on')
|
||||
|
||||
# parse the data
|
||||
raw_output = jc.parsers.universal.sparse_table_parse(cleandata)
|
||||
|
||||
if raw:
|
||||
return raw_output
|
||||
|
||||
@@ -1,8 +1,17 @@
|
||||
"""jc - JSON CLI output utility dig Parser
|
||||
"""jc - JSON CLI output utility `dig` command output parser
|
||||
|
||||
Usage:
|
||||
Usage (cli):
|
||||
|
||||
Specify --dig as the first argument if the piped input is coming from dig
|
||||
$ dig example.com | jc --dig
|
||||
|
||||
or
|
||||
|
||||
$ jc dig example.com
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.dig
|
||||
result = jc.parsers.dig.parse(dig_command_output)
|
||||
|
||||
Compatibility:
|
||||
|
||||
@@ -324,13 +333,14 @@ import jc.utils
|
||||
|
||||
|
||||
class info():
|
||||
version = '1.0'
|
||||
description = 'dig parser'
|
||||
version = '1.3'
|
||||
description = 'dig command parser'
|
||||
author = 'Kelly Brazil'
|
||||
author_email = 'kellyjonbrazil@gmail.com'
|
||||
|
||||
# compatible options: linux, darwin, cygwin, win32, aix, freebsd
|
||||
compatible = ['linux', 'aix', 'freebsd', 'darwin']
|
||||
magic_commands = ['dig']
|
||||
|
||||
|
||||
__version__ = info.version
|
||||
@@ -360,6 +370,15 @@ def process(proc_data):
|
||||
"answer_num": integer,
|
||||
"authority_num": integer,
|
||||
"additional_num": integer,
|
||||
"axfr": [
|
||||
{
|
||||
"name": string,
|
||||
"class": string,
|
||||
"type": string,
|
||||
"ttl": integer,
|
||||
"data": string
|
||||
}
|
||||
],
|
||||
"question": {
|
||||
"name": string,
|
||||
"class": string,
|
||||
@@ -387,6 +406,7 @@ def process(proc_data):
|
||||
"server": string,
|
||||
"when": string,
|
||||
"rcvd": integer
|
||||
"size": string
|
||||
}
|
||||
]
|
||||
"""
|
||||
@@ -401,6 +421,14 @@ def process(proc_data):
|
||||
except (ValueError):
|
||||
entry[key] = None
|
||||
|
||||
if 'axfr' in entry:
|
||||
for ax in entry['axfr']:
|
||||
try:
|
||||
ttl_int = int(ax['ttl'])
|
||||
ax['ttl'] = ttl_int
|
||||
except (ValueError):
|
||||
ax['ttl'] = None
|
||||
|
||||
if 'answer' in entry:
|
||||
for ans in entry['answer']:
|
||||
try:
|
||||
@@ -507,6 +535,25 @@ def parse_answer(answer):
|
||||
'data': answer_data}
|
||||
|
||||
|
||||
def parse_axfr(axfr):
|
||||
# ; <<>> DiG 9.11.14-3-Debian <<>> @81.4.108.41 axfr zonetransfer.me +nocookie
|
||||
# ; (1 server found)
|
||||
# ;; global options: +cmd
|
||||
# zonetransfer.me. 7200 IN A 5.196.105.14
|
||||
axfr = axfr.split(maxsplit=4)
|
||||
axfr_name = axfr[0]
|
||||
axfr_ttl = axfr[1]
|
||||
axfr_class = axfr[2]
|
||||
axfr_type = axfr[3]
|
||||
axfr_data = axfr[4]
|
||||
|
||||
return {'name': axfr_name,
|
||||
'ttl': axfr_ttl,
|
||||
'class': axfr_class,
|
||||
'type': axfr_type,
|
||||
'data': axfr_data}
|
||||
|
||||
|
||||
def parse(data, raw=False, quiet=False):
|
||||
"""
|
||||
Main text parsing function
|
||||
@@ -533,80 +580,106 @@ def parse(data, raw=False, quiet=False):
|
||||
question = False
|
||||
authority = False
|
||||
answer = False
|
||||
axfr = False
|
||||
|
||||
output_entry = {}
|
||||
for line in cleandata:
|
||||
|
||||
if line.find(';; ->>HEADER<<-') == 0:
|
||||
output_entry = {}
|
||||
output_entry.update(parse_header(line))
|
||||
continue
|
||||
if jc.utils.has_data(data):
|
||||
for line in cleandata:
|
||||
|
||||
if line.find(';; flags:') == 0:
|
||||
output_entry.update(parse_flags_line(line))
|
||||
continue
|
||||
if line.startswith('; <<>> ') and ' axfr ' in line.lower():
|
||||
question = False
|
||||
authority = False
|
||||
answer = False
|
||||
axfr = True
|
||||
axfr_list = []
|
||||
continue
|
||||
|
||||
if line.find(';; QUESTION SECTION:') == 0:
|
||||
question = True
|
||||
authority = False
|
||||
answer = False
|
||||
continue
|
||||
if ';' not in line and axfr:
|
||||
axfr_list.append(parse_axfr(line))
|
||||
output_entry.update({'axfr': axfr_list})
|
||||
continue
|
||||
|
||||
if question:
|
||||
output_entry['question'] = parse_question(line)
|
||||
question = False
|
||||
authority = False
|
||||
answer = False
|
||||
continue
|
||||
if line.startswith(';; ->>HEADER<<-'):
|
||||
output_entry = {}
|
||||
output_entry.update(parse_header(line))
|
||||
continue
|
||||
|
||||
if line.find(';; AUTHORITY SECTION:') == 0:
|
||||
question = False
|
||||
authority = True
|
||||
answer = False
|
||||
authority_list = []
|
||||
continue
|
||||
if line.startswith(';; flags:'):
|
||||
output_entry.update(parse_flags_line(line))
|
||||
continue
|
||||
|
||||
if line.find(';') == -1 and authority:
|
||||
authority_list.append(parse_authority(line))
|
||||
output_entry.update({'authority': authority_list})
|
||||
continue
|
||||
if line.startswith(';; QUESTION SECTION:'):
|
||||
question = True
|
||||
authority = False
|
||||
answer = False
|
||||
axfr = False
|
||||
continue
|
||||
|
||||
if line.find(';; ANSWER SECTION:') == 0:
|
||||
question = False
|
||||
authority = False
|
||||
answer = True
|
||||
answer_list = []
|
||||
continue
|
||||
if question:
|
||||
output_entry['question'] = parse_question(line)
|
||||
question = False
|
||||
authority = False
|
||||
answer = False
|
||||
axfr = False
|
||||
continue
|
||||
|
||||
if line.find(';') == -1 and answer:
|
||||
answer_list.append(parse_answer(line))
|
||||
output_entry.update({'answer': answer_list})
|
||||
continue
|
||||
if line.startswith(';; AUTHORITY SECTION:'):
|
||||
question = False
|
||||
authority = True
|
||||
answer = False
|
||||
axfr = False
|
||||
authority_list = []
|
||||
continue
|
||||
|
||||
# footer consists of 4 lines
|
||||
# footer line 1
|
||||
if line.find(';; Query time:') == 0:
|
||||
output_entry.update({'query_time': line.split(':')[1].lstrip()})
|
||||
continue
|
||||
if ';' not in line and authority:
|
||||
authority_list.append(parse_authority(line))
|
||||
output_entry.update({'authority': authority_list})
|
||||
continue
|
||||
|
||||
# footer line 2
|
||||
if line.find(';; SERVER:') == 0:
|
||||
output_entry.update({'server': line.split(':')[1].lstrip()})
|
||||
continue
|
||||
if line.startswith(';; ANSWER SECTION:'):
|
||||
question = False
|
||||
authority = False
|
||||
answer = True
|
||||
axfr = False
|
||||
answer_list = []
|
||||
continue
|
||||
|
||||
# footer line 3
|
||||
if line.find(';; WHEN:') == 0:
|
||||
output_entry.update({'when': line.split(':', maxsplit=1)[1].lstrip()})
|
||||
continue
|
||||
if ';' not in line and answer:
|
||||
answer_list.append(parse_answer(line))
|
||||
output_entry.update({'answer': answer_list})
|
||||
continue
|
||||
|
||||
# footer line 4 (last line)
|
||||
if line.find(';; MSG SIZE rcvd:') == 0:
|
||||
output_entry.update({'rcvd': line.split(':')[1].lstrip()})
|
||||
# footer consists of 4 lines
|
||||
# footer line 1
|
||||
if line.startswith(';; Query time:'):
|
||||
output_entry.update({'query_time': line.split(':')[1].lstrip()})
|
||||
continue
|
||||
|
||||
if output_entry:
|
||||
raw_output.append(output_entry)
|
||||
# footer line 2
|
||||
if line.startswith(';; SERVER:'):
|
||||
output_entry.update({'server': line.split(':')[1].lstrip()})
|
||||
continue
|
||||
|
||||
# footer line 3
|
||||
if line.startswith(';; WHEN:'):
|
||||
output_entry.update({'when': line.split(':', maxsplit=1)[1].lstrip()})
|
||||
continue
|
||||
|
||||
# footer line 4 (last line)
|
||||
if line.startswith(';; MSG SIZE rcvd:'):
|
||||
output_entry.update({'rcvd': line.split(':')[1].lstrip()})
|
||||
|
||||
if output_entry:
|
||||
raw_output.append(output_entry)
|
||||
elif line.startswith(';; XFR size:'):
|
||||
output_entry.update({'size': line.split(':')[1].lstrip()})
|
||||
|
||||
if output_entry:
|
||||
raw_output.append(output_entry)
|
||||
|
||||
raw_output = list(filter(None, raw_output))
|
||||
|
||||
raw_output = list(filter(None, raw_output))
|
||||
if raw:
|
||||
return raw_output
|
||||
else:
|
||||
|
||||
350
jc/parsers/dmidecode.py
Normal file
350
jc/parsers/dmidecode.py
Normal file
@@ -0,0 +1,350 @@
|
||||
"""jc - JSON CLI output utility `dmidecode` command output parser
|
||||
|
||||
Usage (cli):
|
||||
|
||||
$ dmidecode | jc --dmidecode
|
||||
|
||||
or
|
||||
|
||||
$ jc dmidecode
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.dmidecode
|
||||
result = jc.parsers.dmidecode.parse(dmidecode_command_output)
|
||||
|
||||
Compatibility:
|
||||
|
||||
'linux'
|
||||
|
||||
Examples:
|
||||
|
||||
# dmidecode | jc --dmidecode -p
|
||||
[
|
||||
{
|
||||
"handle": "0x0000",
|
||||
"type": 0,
|
||||
"bytes": 24,
|
||||
"description": "BIOS Information",
|
||||
"values": {
|
||||
"vendor": "Phoenix Technologies LTD",
|
||||
"version": "6.00",
|
||||
"release_date": "04/13/2018",
|
||||
"address": "0xEA490",
|
||||
"runtime_size": "88944 bytes",
|
||||
"rom_size": "64 kB",
|
||||
"characteristics": [
|
||||
"ISA is supported",
|
||||
"PCI is supported",
|
||||
"PC Card (PCMCIA) is supported",
|
||||
"PNP is supported",
|
||||
"APM is supported",
|
||||
"BIOS is upgradeable",
|
||||
"BIOS shadowing is allowed",
|
||||
"ESCD support is available",
|
||||
"Boot from CD is supported",
|
||||
"Selectable boot is supported",
|
||||
"EDD is supported",
|
||||
"Print screen service is supported (int 5h)",
|
||||
"8042 keyboard services are supported (int 9h)",
|
||||
"Serial services are supported (int 14h)",
|
||||
"Printer services are supported (int 17h)",
|
||||
"CGA/mono video services are supported (int 10h)",
|
||||
"ACPI is supported",
|
||||
"Smart battery is supported",
|
||||
"BIOS boot specification is supported",
|
||||
"Function key-initiated network boot is supported",
|
||||
"Targeted content distribution is supported"
|
||||
],
|
||||
"bios_revision": "4.6",
|
||||
"firmware_revision": "0.0"
|
||||
}
|
||||
},
|
||||
...
|
||||
]
|
||||
|
||||
# dmidecode | jc --dmidecode -p -r
|
||||
[
|
||||
{
|
||||
"handle": "0x0000",
|
||||
"type": "0",
|
||||
"bytes": "24",
|
||||
"description": "BIOS Information",
|
||||
"values": {
|
||||
"vendor": "Phoenix Technologies LTD",
|
||||
"version": "6.00",
|
||||
"release_date": "04/13/2018",
|
||||
"address": "0xEA490",
|
||||
"runtime_size": "88944 bytes",
|
||||
"rom_size": "64 kB",
|
||||
"characteristics": [
|
||||
"ISA is supported",
|
||||
"PCI is supported",
|
||||
"PC Card (PCMCIA) is supported",
|
||||
"PNP is supported",
|
||||
"APM is supported",
|
||||
"BIOS is upgradeable",
|
||||
"BIOS shadowing is allowed",
|
||||
"ESCD support is available",
|
||||
"Boot from CD is supported",
|
||||
"Selectable boot is supported",
|
||||
"EDD is supported",
|
||||
"Print screen service is supported (int 5h)",
|
||||
"8042 keyboard services are supported (int 9h)",
|
||||
"Serial services are supported (int 14h)",
|
||||
"Printer services are supported (int 17h)",
|
||||
"CGA/mono video services are supported (int 10h)",
|
||||
"ACPI is supported",
|
||||
"Smart battery is supported",
|
||||
"BIOS boot specification is supported",
|
||||
"Function key-initiated network boot is supported",
|
||||
"Targeted content distribution is supported"
|
||||
],
|
||||
"bios_revision": "4.6",
|
||||
"firmware_revision": "0.0"
|
||||
}
|
||||
},
|
||||
...
|
||||
]
|
||||
"""
|
||||
import jc.utils
|
||||
|
||||
|
||||
class info():
|
||||
version = '1.1'
|
||||
description = 'dmidecode command parser'
|
||||
author = 'Kelly Brazil'
|
||||
author_email = 'kellyjonbrazil@gmail.com'
|
||||
# details = 'enter any other details here'
|
||||
|
||||
# compatible options: linux, darwin, cygwin, win32, aix, freebsd
|
||||
compatible = ['linux']
|
||||
magic_commands = ['dmidecode']
|
||||
|
||||
|
||||
__version__ = info.version
|
||||
|
||||
|
||||
def process(proc_data):
|
||||
"""
|
||||
Final processing to conform to the schema.
|
||||
|
||||
Parameters:
|
||||
|
||||
proc_data: (dictionary) raw structured data to process
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Structured data with the following schema:
|
||||
|
||||
[
|
||||
{
|
||||
"handle": string,
|
||||
"type": integer,
|
||||
"bytes": integer,
|
||||
"description": string,
|
||||
"values": { (null if empty)
|
||||
"lowercase_no_spaces_keys": string,
|
||||
"multiline_key_values": [
|
||||
string,
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
"""
|
||||
for entry in proc_data:
|
||||
int_list = ['type', 'bytes']
|
||||
for key in int_list:
|
||||
if key in entry:
|
||||
try:
|
||||
key_int = int(entry[key])
|
||||
entry[key] = key_int
|
||||
except (ValueError):
|
||||
entry[key] = None
|
||||
|
||||
if not entry['values']:
|
||||
entry['values'] = None
|
||||
|
||||
return proc_data
|
||||
|
||||
|
||||
def 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:
|
||||
|
||||
List of dictionaries. Raw or processed structured data.
|
||||
"""
|
||||
if not quiet:
|
||||
jc.utils.compatibility(__name__, info.compatible)
|
||||
|
||||
item_header = False
|
||||
item_values = False
|
||||
value_list = False
|
||||
|
||||
item = None
|
||||
header = None
|
||||
key = None
|
||||
val = None
|
||||
attribute = None
|
||||
values = None
|
||||
key_data = None
|
||||
|
||||
raw_output = []
|
||||
|
||||
if jc.utils.has_data(data):
|
||||
|
||||
data = data.splitlines()
|
||||
|
||||
# remove header rows
|
||||
for row in data.copy():
|
||||
if row:
|
||||
data.pop(0)
|
||||
else:
|
||||
break
|
||||
|
||||
# main parsing loop
|
||||
for line in data:
|
||||
# new item
|
||||
if not line:
|
||||
item_header = True
|
||||
item_values = False
|
||||
value_list = False
|
||||
|
||||
if item:
|
||||
if values:
|
||||
item['values'][attribute] = values
|
||||
if key_data:
|
||||
item['values'][f'{key}_data'] = key_data
|
||||
raw_output.append(item)
|
||||
|
||||
item = {}
|
||||
header = None
|
||||
key = None
|
||||
val = None
|
||||
attribute = None
|
||||
values = []
|
||||
key_data = []
|
||||
continue
|
||||
|
||||
# header
|
||||
if line.startswith('Handle ') and line.endswith('bytes'):
|
||||
|
||||
# Handle 0x0000, DMI type 0, 24 bytes
|
||||
header = line.replace(',', ' ').split()
|
||||
item = {
|
||||
'handle': header[1],
|
||||
'type': header[4],
|
||||
'bytes': header[5]
|
||||
}
|
||||
continue
|
||||
|
||||
# description
|
||||
if item_header:
|
||||
item_header = False
|
||||
item_values = True
|
||||
value_list = False
|
||||
|
||||
item['description'] = line
|
||||
item['values'] = {}
|
||||
continue
|
||||
|
||||
# new item if multiple descriptions in handle
|
||||
if not item_header and not line.startswith('\t'):
|
||||
item_header = False
|
||||
item_values = True
|
||||
value_list = False
|
||||
|
||||
if item:
|
||||
if values:
|
||||
item['values'][attribute] = values
|
||||
if key_data:
|
||||
item['values'][f'{key}_data'] = key_data
|
||||
raw_output.append(item)
|
||||
|
||||
item = {
|
||||
'handle': header[1],
|
||||
'type': header[4],
|
||||
'bytes': header[5],
|
||||
'description': line,
|
||||
'values': {}
|
||||
}
|
||||
|
||||
key = None
|
||||
val = None
|
||||
attribute = None
|
||||
values = []
|
||||
key_data = []
|
||||
continue
|
||||
|
||||
# keys and values
|
||||
if item_values \
|
||||
and len(line.split(':', maxsplit=1)) == 2 \
|
||||
and line.startswith('\t') \
|
||||
and not line.startswith('\t\t') \
|
||||
and not line.strip().endswith(':'):
|
||||
item_header = False
|
||||
item_values = True
|
||||
value_list = False
|
||||
|
||||
if values:
|
||||
item['values'][attribute] = values
|
||||
values = []
|
||||
if key_data:
|
||||
item['values'][f'{key}_data'] = key_data
|
||||
key_data = []
|
||||
|
||||
key = line.split(':', maxsplit=1)[0].strip().lower().replace(' ', '_')
|
||||
val = line.split(':', maxsplit=1)[1].strip()
|
||||
item['values'].update({key: val})
|
||||
continue
|
||||
|
||||
# multi-line key
|
||||
if item_values \
|
||||
and line.startswith('\t') \
|
||||
and not line.startswith('\t\t') \
|
||||
and line.strip().endswith(':'):
|
||||
item_header = False
|
||||
item_values = True
|
||||
value_list = True
|
||||
|
||||
if values:
|
||||
item['values'][attribute] = values
|
||||
values = []
|
||||
if key_data:
|
||||
item['values'][f'{key}_data'] = key_data
|
||||
key_data = []
|
||||
|
||||
attribute = line[:-1].strip().lower().replace(' ', '_')
|
||||
values = []
|
||||
continue
|
||||
|
||||
# multi-line values
|
||||
if value_list \
|
||||
and line.startswith('\t\t'):
|
||||
values.append(line.strip())
|
||||
continue
|
||||
|
||||
# data for hybrid multi-line objects
|
||||
if item_values \
|
||||
and not value_list \
|
||||
and line.startswith('\t\t'):
|
||||
if f'{key}_data' not in item['values']:
|
||||
item['values'][f'{key}_data'] = []
|
||||
key_data.append(line.strip())
|
||||
continue
|
||||
|
||||
if item:
|
||||
raw_output.append(item)
|
||||
|
||||
if raw:
|
||||
return raw_output
|
||||
else:
|
||||
return process(raw_output)
|
||||
@@ -1,8 +1,17 @@
|
||||
"""jc - JSON CLI output utility du Parser
|
||||
"""jc - JSON CLI output utility `du` command output parser
|
||||
|
||||
Usage:
|
||||
Usage (cli):
|
||||
|
||||
specify --du as the first argument if the piped input is coming from du
|
||||
$ du | jc --du
|
||||
|
||||
or
|
||||
|
||||
$ jc du
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.du
|
||||
result = jc.parsers.du.parse(du_command_output)
|
||||
|
||||
Compatibility:
|
||||
|
||||
@@ -73,14 +82,15 @@ import jc.parsers.universal
|
||||
|
||||
|
||||
class info():
|
||||
version = '1.1'
|
||||
description = 'du parser'
|
||||
version = '1.2'
|
||||
description = 'du command parser'
|
||||
author = 'Kelly Brazil'
|
||||
author_email = 'kellyjonbrazil@gmail.com'
|
||||
# details = 'enter any other details here'
|
||||
|
||||
# compatible options: linux, darwin, cygwin, win32, aix, freebsd
|
||||
compatible = ['linux', 'darwin', 'aix', 'freebsd']
|
||||
magic_commands = ['du']
|
||||
|
||||
|
||||
__version__ = info.version
|
||||
@@ -136,12 +146,12 @@ def parse(data, raw=False, quiet=False):
|
||||
jc.utils.compatibility(__name__, info.compatible)
|
||||
|
||||
raw_output = []
|
||||
cleandata = data.splitlines()
|
||||
|
||||
# Clear any blank lines
|
||||
cleandata = list(filter(None, cleandata))
|
||||
cleandata = list(filter(None, data.splitlines()))
|
||||
|
||||
if jc.utils.has_data(data):
|
||||
|
||||
if cleandata:
|
||||
cleandata.insert(0, 'size name')
|
||||
raw_output = jc.parsers.universal.simple_table_parse(cleandata)
|
||||
|
||||
|
||||
@@ -1,8 +1,19 @@
|
||||
"""jc - JSON CLI output utility env Parser
|
||||
"""jc - JSON CLI output utility `env` and `printenv` command output parser
|
||||
|
||||
Usage:
|
||||
This parser will output a list of dictionaries each containing `name` and `value` keys. If you would like a simple dictionary output, then use the `-r` command-line option or the `raw=True` argument in the `parse()` function.
|
||||
|
||||
specify --env as the first argument if the piped input is coming from env
|
||||
Usage (cli):
|
||||
|
||||
$ env | jc --env
|
||||
|
||||
or
|
||||
|
||||
$ jc env
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.env
|
||||
result = jc.parsers.env.parse(env_command_output)
|
||||
|
||||
Compatibility:
|
||||
|
||||
@@ -52,13 +63,14 @@ import jc.utils
|
||||
|
||||
|
||||
class info():
|
||||
version = '1.1'
|
||||
description = 'env parser'
|
||||
version = '1.2'
|
||||
description = 'env command parser'
|
||||
author = 'Kelly Brazil'
|
||||
author_email = 'kellyjonbrazil@gmail.com'
|
||||
|
||||
# compatible options: linux, darwin, cygwin, win32, aix, freebsd
|
||||
compatible = ['linux', 'darwin', 'cygwin', 'win32', 'aix', 'freebsd']
|
||||
magic_commands = ['env', 'printenv']
|
||||
|
||||
|
||||
__version__ = info.version
|
||||
@@ -115,12 +127,10 @@ def parse(data, raw=False, quiet=False):
|
||||
|
||||
raw_output = {}
|
||||
|
||||
linedata = data.splitlines()
|
||||
|
||||
# Clear any blank lines
|
||||
cleandata = list(filter(None, linedata))
|
||||
cleandata = list(filter(None, data.splitlines()))
|
||||
|
||||
if cleandata:
|
||||
if jc.utils.has_data(data):
|
||||
|
||||
for entry in cleandata:
|
||||
parsed_line = entry.split('=', maxsplit=1)
|
||||
|
||||
140
jc/parsers/file.py
Normal file
140
jc/parsers/file.py
Normal file
@@ -0,0 +1,140 @@
|
||||
"""jc - JSON CLI output utility `file` command output parser
|
||||
|
||||
Usage (cli):
|
||||
|
||||
$ file * | jc --file
|
||||
|
||||
or
|
||||
|
||||
$ jc file *
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.file
|
||||
result = jc.parsers.file.parse(file_command_output)
|
||||
|
||||
Compatibility:
|
||||
|
||||
'linux', 'aix', 'freebsd', 'darwin'
|
||||
|
||||
Examples:
|
||||
|
||||
$ file * | jc --file -p
|
||||
[
|
||||
{
|
||||
"filename": "Applications",
|
||||
"type": "directory"
|
||||
},
|
||||
{
|
||||
"filename": "another file with spaces",
|
||||
"type": "empty"
|
||||
},
|
||||
{
|
||||
"filename": "argstest.py",
|
||||
"type": "Python script text executable, ASCII text"
|
||||
},
|
||||
{
|
||||
"filename": "blkid-p.out",
|
||||
"type": "ASCII text"
|
||||
},
|
||||
{
|
||||
"filename": "blkid-pi.out",
|
||||
"type": "ASCII text, with very long lines"
|
||||
},
|
||||
{
|
||||
"filename": "cd_catalog.xml",
|
||||
"type": "XML 1.0 document text, ASCII text, with CRLF line terminators"
|
||||
},
|
||||
{
|
||||
"filename": "centosserial.sh",
|
||||
"type": "Bourne-Again shell script text executable, UTF-8 Unicode text"
|
||||
},
|
||||
...
|
||||
]
|
||||
"""
|
||||
import jc.utils
|
||||
import jc.parsers.universal
|
||||
|
||||
|
||||
class info():
|
||||
version = '1.2'
|
||||
description = 'file command parser'
|
||||
author = 'Kelly Brazil'
|
||||
author_email = 'kellyjonbrazil@gmail.com'
|
||||
|
||||
# compatible options: linux, darwin, cygwin, win32, aix, freebsd
|
||||
compatible = ['linux', 'aix', 'freebsd', 'darwin']
|
||||
magic_commands = ['file']
|
||||
|
||||
|
||||
__version__ = info.version
|
||||
|
||||
|
||||
def process(proc_data):
|
||||
"""
|
||||
Final processing to conform to the schema.
|
||||
|
||||
Parameters:
|
||||
|
||||
proc_data: (dictionary) raw structured data to process
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Structured data with the following schema:
|
||||
|
||||
[
|
||||
{
|
||||
"filename": string,
|
||||
"type ": string
|
||||
}
|
||||
]
|
||||
"""
|
||||
# No further processing
|
||||
return proc_data
|
||||
|
||||
|
||||
def 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:
|
||||
|
||||
List of dictionaries. Raw or processed structured data.
|
||||
"""
|
||||
if not quiet:
|
||||
jc.utils.compatibility(__name__, info.compatible)
|
||||
|
||||
raw_output = []
|
||||
|
||||
warned = False
|
||||
|
||||
if jc.utils.has_data(data):
|
||||
|
||||
for line in filter(None, data.splitlines()):
|
||||
linedata = line.rsplit(': ', maxsplit=1)
|
||||
|
||||
try:
|
||||
filename = linedata[0].strip()
|
||||
filetype = linedata[1].strip()
|
||||
|
||||
raw_output.append(
|
||||
{
|
||||
'filename': filename,
|
||||
'type': filetype
|
||||
}
|
||||
)
|
||||
except IndexError:
|
||||
if not warned:
|
||||
jc.utils.warning_message('Filenames with newline characters detected. Some filenames may be truncated.')
|
||||
warned = True
|
||||
|
||||
if raw:
|
||||
return raw_output
|
||||
else:
|
||||
return process(raw_output)
|
||||
@@ -1,8 +1,19 @@
|
||||
"""jc - JSON CLI output utility foo Parser
|
||||
"""jc - JSON CLI output utility `foo` command output parser
|
||||
|
||||
Usage:
|
||||
<<Short foo description and caveats>>
|
||||
|
||||
specify --foo as the first argument if the piped input is coming from foo
|
||||
Usage (cli):
|
||||
|
||||
$ foo | jc --foo
|
||||
|
||||
or
|
||||
|
||||
$ jc foo
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.foo
|
||||
result = jc.parsers.foo.parse(foo_command_output)
|
||||
|
||||
Compatibility:
|
||||
|
||||
@@ -21,13 +32,14 @@ import jc.utils
|
||||
|
||||
class info():
|
||||
version = '1.0'
|
||||
description = 'foo parser'
|
||||
description = 'foo command parser'
|
||||
author = 'John Doe'
|
||||
author_email = 'johndoe@gmail.com'
|
||||
# details = 'enter any other details here'
|
||||
|
||||
# compatible options: linux, darwin, cygwin, win32, aix, freebsd
|
||||
compatible = ['linux', 'darwin', 'cygwin', 'win32', 'aix', 'freebsd']
|
||||
magic_commands = ['foo']
|
||||
|
||||
|
||||
__version__ = info.version
|
||||
@@ -76,14 +88,12 @@ def parse(data, raw=False, quiet=False):
|
||||
jc.utils.compatibility(__name__, info.compatible)
|
||||
|
||||
raw_output = []
|
||||
cleandata = data.splitlines()
|
||||
|
||||
# Clear any blank lines
|
||||
cleandata = list(filter(None, cleandata))
|
||||
if jc.utils.has_data(data):
|
||||
|
||||
if cleandata:
|
||||
# parse the content
|
||||
pass
|
||||
for line in filter(None, data.splitlines()):
|
||||
# parse the content
|
||||
pass
|
||||
|
||||
if raw:
|
||||
return raw_output
|
||||
|
||||
@@ -1,8 +1,17 @@
|
||||
"""jc - JSON CLI output utility free Parser
|
||||
"""jc - JSON CLI output utility `free` command output parser
|
||||
|
||||
Usage:
|
||||
Usage (cli):
|
||||
|
||||
specify --free as the first argument if the piped input is coming from free
|
||||
$ free | jc --free
|
||||
|
||||
or
|
||||
|
||||
$ jc free
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.free
|
||||
result = jc.parsers.free.parse(free_command_output)
|
||||
|
||||
Compatibility:
|
||||
|
||||
@@ -53,13 +62,14 @@ import jc.parsers.universal
|
||||
|
||||
|
||||
class info():
|
||||
version = '1.0'
|
||||
description = 'free parser'
|
||||
version = '1.2'
|
||||
description = 'free command parser'
|
||||
author = 'Kelly Brazil'
|
||||
author_email = 'kellyjonbrazil@gmail.com'
|
||||
|
||||
# compatible options: linux, darwin, cygwin, win32, aix, freebsd
|
||||
compatible = ['linux']
|
||||
magic_commands = ['free']
|
||||
|
||||
|
||||
__version__ = info.version
|
||||
@@ -121,14 +131,18 @@ def parse(data, raw=False, quiet=False):
|
||||
jc.utils.compatibility(__name__, info.compatible)
|
||||
|
||||
cleandata = data.splitlines()
|
||||
cleandata[0] = cleandata[0].lower()
|
||||
cleandata[0] = cleandata[0].replace('buff/cache', 'buff_cache')
|
||||
cleandata[0] = 'type ' + cleandata[0]
|
||||
raw_output = []
|
||||
|
||||
raw_output = jc.parsers.universal.simple_table_parse(cleandata)
|
||||
if jc.utils.has_data(data):
|
||||
|
||||
for entry in raw_output:
|
||||
entry['type'] = entry['type'].rstrip(':')
|
||||
cleandata[0] = cleandata[0].lower()
|
||||
cleandata[0] = cleandata[0].replace('buff/cache', 'buff_cache')
|
||||
cleandata[0] = 'type ' + cleandata[0]
|
||||
|
||||
raw_output = jc.parsers.universal.simple_table_parse(cleandata)
|
||||
|
||||
for entry in raw_output:
|
||||
entry['type'] = entry['type'].rstrip(':')
|
||||
|
||||
if raw:
|
||||
return raw_output
|
||||
|
||||
@@ -1,12 +1,17 @@
|
||||
"""jc - JSON CLI output utility fstab Parser
|
||||
"""jc - JSON CLI output utility `fstab` file parser
|
||||
|
||||
Usage:
|
||||
Usage (cli):
|
||||
|
||||
specify --fstab as the first argument if the piped input is coming from a fstab file
|
||||
$ cat /etc/fstab | jc --fstab
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.fstab
|
||||
result = jc.parsers.fstab.parse(fstab_command_output)
|
||||
|
||||
Compatibility:
|
||||
|
||||
'linux'
|
||||
'linux', 'freebsd'
|
||||
|
||||
Examples:
|
||||
|
||||
@@ -70,13 +75,13 @@ import jc.utils
|
||||
|
||||
|
||||
class info():
|
||||
version = '1.0'
|
||||
description = '/etc/fstab file parser'
|
||||
version = '1.3'
|
||||
description = 'fstab file parser'
|
||||
author = 'Kelly Brazil'
|
||||
author_email = 'kellyjonbrazil@gmail.com'
|
||||
|
||||
# compatible options: linux, darwin, cygwin, win32, aix, freebsd
|
||||
compatible = ['linux']
|
||||
compatible = ['linux', 'freebsd']
|
||||
|
||||
|
||||
__version__ = info.version
|
||||
@@ -141,11 +146,12 @@ def parse(data, raw=False, quiet=False):
|
||||
# Clear any blank lines
|
||||
cleandata = list(filter(None, cleandata))
|
||||
|
||||
if cleandata:
|
||||
if jc.utils.has_data(data):
|
||||
|
||||
for line in cleandata:
|
||||
output_line = {}
|
||||
# ignore commented lines
|
||||
if line.strip().find('#') == 0:
|
||||
if line.strip().startswith('#'):
|
||||
continue
|
||||
|
||||
line_list = line.split(maxsplit=6)
|
||||
|
||||
196
jc/parsers/group.py
Normal file
196
jc/parsers/group.py
Normal file
@@ -0,0 +1,196 @@
|
||||
"""jc - JSON CLI output utility `/etc/group` file parser
|
||||
|
||||
Usage (cli):
|
||||
|
||||
$ cat /etc/group | jc --group
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.group
|
||||
result = jc.parsers.group.parse(group_file_output)
|
||||
|
||||
Compatibility:
|
||||
|
||||
'linux', 'darwin', 'aix', 'freebsd'
|
||||
|
||||
Examples:
|
||||
|
||||
$ cat /etc/group | jc --group -p
|
||||
[
|
||||
{
|
||||
"group_name": "nobody",
|
||||
"password": "*",
|
||||
"gid": -2,
|
||||
"members": []
|
||||
},
|
||||
{
|
||||
"group_name": "nogroup",
|
||||
"password": "*",
|
||||
"gid": -1,
|
||||
"members": []
|
||||
},
|
||||
{
|
||||
"group_name": "wheel",
|
||||
"password": "*",
|
||||
"gid": 0,
|
||||
"members": [
|
||||
"root"
|
||||
]
|
||||
},
|
||||
{
|
||||
"group_name": "certusers",
|
||||
"password": "*",
|
||||
"gid": 29,
|
||||
"members": [
|
||||
"root",
|
||||
"_jabber",
|
||||
"_postfix",
|
||||
"_cyrus",
|
||||
"_calendar",
|
||||
"_dovecot"
|
||||
]
|
||||
},
|
||||
...
|
||||
]
|
||||
|
||||
$ cat /etc/group | jc --group -p -r
|
||||
[
|
||||
{
|
||||
"group_name": "nobody",
|
||||
"password": "*",
|
||||
"gid": "-2",
|
||||
"members": [
|
||||
""
|
||||
]
|
||||
},
|
||||
{
|
||||
"group_name": "nogroup",
|
||||
"password": "*",
|
||||
"gid": "-1",
|
||||
"members": [
|
||||
""
|
||||
]
|
||||
},
|
||||
{
|
||||
"group_name": "wheel",
|
||||
"password": "*",
|
||||
"gid": "0",
|
||||
"members": [
|
||||
"root"
|
||||
]
|
||||
},
|
||||
{
|
||||
"group_name": "certusers",
|
||||
"password": "*",
|
||||
"gid": "29",
|
||||
"members": [
|
||||
"root",
|
||||
"_jabber",
|
||||
"_postfix",
|
||||
"_cyrus",
|
||||
"_calendar",
|
||||
"_dovecot"
|
||||
]
|
||||
},
|
||||
...
|
||||
]
|
||||
"""
|
||||
import jc.utils
|
||||
|
||||
|
||||
class info():
|
||||
version = '1.1'
|
||||
description = '/etc/group file parser'
|
||||
author = 'Kelly Brazil'
|
||||
author_email = 'kellyjonbrazil@gmail.com'
|
||||
# details = 'enter any other details here'
|
||||
|
||||
# compatible options: linux, darwin, cygwin, win32, aix, freebsd
|
||||
compatible = ['linux', 'darwin', 'aix', 'freebsd']
|
||||
|
||||
|
||||
__version__ = info.version
|
||||
|
||||
|
||||
def process(proc_data):
|
||||
"""
|
||||
Final processing to conform to the schema.
|
||||
|
||||
Parameters:
|
||||
|
||||
proc_data: (dictionary) raw structured data to process
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Structured data with the following schema:
|
||||
|
||||
[
|
||||
{
|
||||
"group_name": string,
|
||||
"password": string,
|
||||
"gid": integer,
|
||||
"members": [
|
||||
string
|
||||
]
|
||||
}
|
||||
]
|
||||
"""
|
||||
for entry in proc_data:
|
||||
int_list = ['gid']
|
||||
for key in int_list:
|
||||
if key in entry:
|
||||
try:
|
||||
key_int = int(entry[key])
|
||||
entry[key] = key_int
|
||||
except (ValueError):
|
||||
entry[key] = None
|
||||
|
||||
if entry['members'] == ['']:
|
||||
entry['members'] = []
|
||||
|
||||
return proc_data
|
||||
|
||||
|
||||
def 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:
|
||||
|
||||
List of dictionaries. Raw or processed structured data.
|
||||
"""
|
||||
if not quiet:
|
||||
jc.utils.compatibility(__name__, info.compatible)
|
||||
|
||||
raw_output = []
|
||||
cleandata = data.splitlines()
|
||||
|
||||
# Clear any blank lines
|
||||
cleandata = list(filter(None, cleandata))
|
||||
|
||||
if jc.utils.has_data(data):
|
||||
|
||||
for entry in cleandata:
|
||||
if entry.startswith('#'):
|
||||
continue
|
||||
|
||||
output_line = {}
|
||||
fields = entry.split(':')
|
||||
|
||||
output_line['group_name'] = fields[0]
|
||||
output_line['password'] = fields[1]
|
||||
output_line['gid'] = fields[2]
|
||||
output_line['members'] = fields[3].split(',')
|
||||
|
||||
raw_output.append(output_line)
|
||||
|
||||
if raw:
|
||||
return raw_output
|
||||
else:
|
||||
return process(raw_output)
|
||||
158
jc/parsers/gshadow.py
Normal file
158
jc/parsers/gshadow.py
Normal file
@@ -0,0 +1,158 @@
|
||||
"""jc - JSON CLI output utility `/etc/gshadow` file parser
|
||||
|
||||
Usage (cli):
|
||||
|
||||
$ cat /etc/gshadow | jc --gshadow
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.gshadow
|
||||
result = jc.parsers.gshadow.parse(gshadow_file_output)
|
||||
|
||||
Compatibility:
|
||||
|
||||
'linux', 'aix', 'freebsd'
|
||||
|
||||
Examples:
|
||||
|
||||
$ cat /etc/gshadow | jc --gshadow -p
|
||||
[
|
||||
{
|
||||
"group_name": "root",
|
||||
"password": "*",
|
||||
"administrators": [],
|
||||
"members": []
|
||||
},
|
||||
{
|
||||
"group_name": "adm",
|
||||
"password": "*",
|
||||
"administrators": [],
|
||||
"members": [
|
||||
"syslog",
|
||||
"joeuser"
|
||||
]
|
||||
},
|
||||
...
|
||||
]
|
||||
|
||||
$ cat /etc/gshadow | jc --gshadow -p -r
|
||||
[
|
||||
{
|
||||
"group_name": "root",
|
||||
"password": "*",
|
||||
"administrators": [
|
||||
""
|
||||
],
|
||||
"members": [
|
||||
""
|
||||
]
|
||||
},
|
||||
{
|
||||
"group_name": "adm",
|
||||
"password": "*",
|
||||
"administrators": [
|
||||
""
|
||||
],
|
||||
"members": [
|
||||
"syslog",
|
||||
"joeuser"
|
||||
]
|
||||
},
|
||||
...
|
||||
]
|
||||
"""
|
||||
import jc.utils
|
||||
|
||||
|
||||
class info():
|
||||
version = '1.1'
|
||||
description = '/etc/gshadow file parser'
|
||||
author = 'Kelly Brazil'
|
||||
author_email = 'kellyjonbrazil@gmail.com'
|
||||
# details = 'enter any other details here'
|
||||
|
||||
# compatible options: linux, darwin, cygwin, win32, aix, freebsd
|
||||
compatible = ['linux', 'aix', 'freebsd']
|
||||
|
||||
|
||||
__version__ = info.version
|
||||
|
||||
|
||||
def process(proc_data):
|
||||
"""
|
||||
Final processing to conform to the schema.
|
||||
|
||||
Parameters:
|
||||
|
||||
proc_data: (dictionary) raw structured data to process
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Structured data with the following schema:
|
||||
|
||||
[
|
||||
{
|
||||
"group_name": string,
|
||||
"password": string,
|
||||
"administrators": [
|
||||
string
|
||||
],
|
||||
"members": [
|
||||
string
|
||||
]
|
||||
}
|
||||
]
|
||||
"""
|
||||
for entry in proc_data:
|
||||
if entry['administrators'] == ['']:
|
||||
entry['administrators'] = []
|
||||
|
||||
if entry['members'] == ['']:
|
||||
entry['members'] = []
|
||||
|
||||
return proc_data
|
||||
|
||||
|
||||
def 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:
|
||||
|
||||
List of dictionaries. Raw or processed structured data.
|
||||
"""
|
||||
if not quiet:
|
||||
jc.utils.compatibility(__name__, info.compatible)
|
||||
|
||||
raw_output = []
|
||||
cleandata = data.splitlines()
|
||||
|
||||
# Clear any blank lines
|
||||
cleandata = list(filter(None, cleandata))
|
||||
|
||||
if jc.utils.has_data(data):
|
||||
|
||||
for entry in cleandata:
|
||||
if entry.startswith('#'):
|
||||
continue
|
||||
|
||||
output_line = {}
|
||||
fields = entry.split(':')
|
||||
|
||||
output_line['group_name'] = fields[0]
|
||||
output_line['password'] = fields[1]
|
||||
output_line['administrators'] = fields[2].split(',')
|
||||
output_line['members'] = fields[3].split(',')
|
||||
|
||||
raw_output.append(output_line)
|
||||
|
||||
if raw:
|
||||
return raw_output
|
||||
else:
|
||||
return process(raw_output)
|
||||
108
jc/parsers/hash.py
Normal file
108
jc/parsers/hash.py
Normal file
@@ -0,0 +1,108 @@
|
||||
"""jc - JSON CLI output utility `hash` command output parser
|
||||
|
||||
Usage (cli):
|
||||
|
||||
$ hash | jc --hash
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.hash
|
||||
result = jc.parsers.hash.parse(hash_command_output)
|
||||
|
||||
Compatibility:
|
||||
|
||||
'linux', 'darwin', 'cygwin', 'aix', 'freebsd'
|
||||
|
||||
Examples:
|
||||
|
||||
$ hash | jc --hash -p
|
||||
[
|
||||
{
|
||||
"hits": 2,
|
||||
"command": "/bin/cat"
|
||||
},
|
||||
{
|
||||
"hits": 1,
|
||||
"command": "/bin/ls"
|
||||
}
|
||||
]
|
||||
"""
|
||||
import jc.utils
|
||||
import jc.parsers.universal
|
||||
|
||||
|
||||
class info():
|
||||
version = '1.0'
|
||||
description = 'hash command parser'
|
||||
author = 'Kelly Brazil'
|
||||
author_email = 'kellyjonbrazil@gmail.com'
|
||||
|
||||
# compatible options: linux, darwin, cygwin, win32, aix, freebsd
|
||||
compatible = ['linux', 'darwin', 'cygwin', 'aix', 'freebsd']
|
||||
|
||||
|
||||
__version__ = info.version
|
||||
|
||||
|
||||
def process(proc_data):
|
||||
"""
|
||||
Final processing to conform to the schema.
|
||||
|
||||
Parameters:
|
||||
|
||||
proc_data: (dictionary) raw structured data to process
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Structured data with the following schema:
|
||||
|
||||
[
|
||||
{
|
||||
"command": string,
|
||||
"hits": integer
|
||||
}
|
||||
]
|
||||
"""
|
||||
for entry in proc_data:
|
||||
# change to int
|
||||
int_list = ['hits']
|
||||
for key in int_list:
|
||||
if key in entry:
|
||||
try:
|
||||
key_int = int(entry[key])
|
||||
entry[key] = key_int
|
||||
except (ValueError):
|
||||
entry[key] = None
|
||||
|
||||
return proc_data
|
||||
|
||||
|
||||
def 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:
|
||||
|
||||
List of dictionaries. Raw or processed structured data.
|
||||
"""
|
||||
if not quiet:
|
||||
jc.utils.compatibility(__name__, info.compatible)
|
||||
|
||||
cleandata = data.splitlines()
|
||||
raw_output = []
|
||||
|
||||
if jc.utils.has_data(data):
|
||||
|
||||
cleandata[0] = cleandata[0].lower()
|
||||
raw_output = jc.parsers.universal.simple_table_parse(cleandata)
|
||||
|
||||
if raw:
|
||||
return raw_output
|
||||
else:
|
||||
return process(raw_output)
|
||||
145
jc/parsers/hashsum.py
Normal file
145
jc/parsers/hashsum.py
Normal file
@@ -0,0 +1,145 @@
|
||||
"""jc - JSON CLI output utility `hash sum` command output parser
|
||||
|
||||
This parser works with the following hash calculation utilities:
|
||||
- `md5`
|
||||
- `md5sum`
|
||||
- `shasum`
|
||||
- `sha1sum`
|
||||
- `sha224sum`
|
||||
- `sha256sum`
|
||||
- `sha384sum`
|
||||
- `sha512sum`
|
||||
|
||||
Usage (cli):
|
||||
|
||||
$ md5sum file.txt | jc --hashsum
|
||||
|
||||
or
|
||||
|
||||
$ jc md5sum file.txt
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.hashsum
|
||||
result = jc.parsers.hashsum.parse(md5sum_command_output)
|
||||
|
||||
Compatibility:
|
||||
|
||||
'linux', 'darwin', 'cygwin', 'aix', 'freebsd'
|
||||
|
||||
Examples:
|
||||
|
||||
$ md5sum * | jc --hashsum -p
|
||||
[
|
||||
{
|
||||
"filename": "devtoolset-3-gcc-4.9.2-6.el7.x86_64.rpm",
|
||||
"hash": "65fc958c1add637ec23c4b137aecf3d3"
|
||||
},
|
||||
{
|
||||
"filename": "digout",
|
||||
"hash": "5b9312ee5aff080927753c63a347707d"
|
||||
},
|
||||
{
|
||||
"filename": "dmidecode.out",
|
||||
"hash": "716fd11c2ac00db109281f7110b8fb9d"
|
||||
},
|
||||
{
|
||||
"filename": "file with spaces in the name",
|
||||
"hash": "d41d8cd98f00b204e9800998ecf8427e"
|
||||
},
|
||||
{
|
||||
"filename": "id-centos.out",
|
||||
"hash": "4295be239a14ad77ef3253103de976d2"
|
||||
},
|
||||
{
|
||||
"filename": "ifcfg.json",
|
||||
"hash": "01fda0d9ba9a75618b072e64ff512b43"
|
||||
},
|
||||
...
|
||||
]
|
||||
"""
|
||||
import jc.utils
|
||||
|
||||
|
||||
class info():
|
||||
version = '1.0'
|
||||
description = 'hashsum command parser (md5sum, shasum, etc.)'
|
||||
author = 'Kelly Brazil'
|
||||
author_email = 'kellyjonbrazil@gmail.com'
|
||||
details = 'Parses MD5 and SHA hash program output'
|
||||
|
||||
# compatible options: linux, darwin, cygwin, win32, aix, freebsd
|
||||
compatible = ['linux', 'darwin', 'cygwin', 'aix', 'freebsd']
|
||||
magic_commands = ['md5sum', 'md5', 'shasum', 'sha1sum', 'sha224sum', 'sha256sum', 'sha384sum', 'sha512sum']
|
||||
|
||||
|
||||
__version__ = info.version
|
||||
|
||||
|
||||
def process(proc_data):
|
||||
"""
|
||||
Final processing to conform to the schema.
|
||||
|
||||
Parameters:
|
||||
|
||||
proc_data: (dictionary) raw structured data to process
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Structured data with the following schema:
|
||||
|
||||
[
|
||||
{
|
||||
"filename": string,
|
||||
"hash": string,
|
||||
}
|
||||
]
|
||||
"""
|
||||
|
||||
# no further processing for this parser
|
||||
return proc_data
|
||||
|
||||
|
||||
def 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:
|
||||
|
||||
List of dictionaries. Raw or processed structured data.
|
||||
"""
|
||||
if not quiet:
|
||||
jc.utils.compatibility(__name__, info.compatible)
|
||||
|
||||
raw_output = []
|
||||
|
||||
if jc.utils.has_data(data):
|
||||
|
||||
for line in filter(None, data.splitlines()):
|
||||
# check for legacy md5 command output
|
||||
if line.startswith('MD5 ('):
|
||||
file_hash = line.split('=', maxsplit=1)[1].strip()
|
||||
file_name = line.split('=', maxsplit=1)[0].strip()
|
||||
file_name = file_name[5:]
|
||||
file_name = file_name[:-1]
|
||||
# standard md5sum and shasum command output
|
||||
else:
|
||||
file_hash = line.split(maxsplit=1)[0]
|
||||
file_name = line.split(maxsplit=1)[1]
|
||||
|
||||
item = {
|
||||
'filename': file_name,
|
||||
'hash': file_hash
|
||||
}
|
||||
raw_output.append(item)
|
||||
|
||||
if raw:
|
||||
return raw_output
|
||||
else:
|
||||
return process(raw_output)
|
||||
@@ -1,8 +1,15 @@
|
||||
"""jc - JSON CLI output utility history Parser
|
||||
"""jc - JSON CLI output utility `history` command output parser
|
||||
|
||||
Usage:
|
||||
This parser will output a list of dictionaries each containing `line` and `command` keys. If you would like a simple dictionary output, then use the `-r` command-line option or the `raw=True` argument in the `parse()` function.
|
||||
|
||||
specify --history as the first argument if the piped input is coming from history
|
||||
Usage (cli):
|
||||
|
||||
$ history | jc --history
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.history
|
||||
result = jc.parsers.history.parse(history_command_output)
|
||||
|
||||
Compatibility:
|
||||
|
||||
@@ -40,14 +47,15 @@ Examples:
|
||||
...
|
||||
}
|
||||
"""
|
||||
import jc
|
||||
import jc.utils
|
||||
|
||||
|
||||
class info():
|
||||
version = '1.1'
|
||||
description = 'history parser'
|
||||
version = '1.3'
|
||||
description = 'history command parser'
|
||||
author = 'Kelly Brazil'
|
||||
author_email = 'kellyjonbrazil@gmail.com'
|
||||
details = 'Optimizations by https://github.com/philippeitis'
|
||||
|
||||
# compatible options: linux, darwin, cygwin, win32, aix, freebsd
|
||||
compatible = ['linux', 'darwin', 'cygwin', 'aix', 'freebsd']
|
||||
@@ -79,21 +87,11 @@ def process(proc_data):
|
||||
# rebuild output for added semantic information
|
||||
processed = []
|
||||
for k, v in proc_data.items():
|
||||
proc_line = {}
|
||||
proc_line['line'] = k
|
||||
proc_line['command'] = v
|
||||
proc_line = {
|
||||
'line': int(k) if k.isdigit() else None,
|
||||
'command': v,
|
||||
}
|
||||
processed.append(proc_line)
|
||||
|
||||
for entry in processed:
|
||||
int_list = ['line']
|
||||
for key in int_list:
|
||||
if key in entry:
|
||||
try:
|
||||
key_int = int(entry[key])
|
||||
entry[key] = key_int
|
||||
except (ValueError):
|
||||
entry[key] = None
|
||||
|
||||
return processed
|
||||
|
||||
|
||||
@@ -117,14 +115,13 @@ def parse(data, raw=False, quiet=False):
|
||||
|
||||
raw_output = {}
|
||||
|
||||
# split lines and clear out any non-ascii chars
|
||||
linedata = data.encode('ascii', errors='ignore').decode().splitlines()
|
||||
if jc.utils.has_data(data):
|
||||
|
||||
# Clear any blank lines
|
||||
cleandata = list(filter(None, linedata))
|
||||
# split lines and clear out any non-ascii chars
|
||||
linedata = data.encode('ascii', errors='ignore').decode().splitlines()
|
||||
|
||||
if cleandata:
|
||||
for entry in cleandata:
|
||||
# Skip any blank lines
|
||||
for entry in filter(None, linedata):
|
||||
try:
|
||||
parsed_line = entry.split(maxsplit=1)
|
||||
raw_output[parsed_line[0]] = parsed_line[1]
|
||||
|
||||
@@ -1,8 +1,13 @@
|
||||
"""jc - JSON CLI output utility hosts Parser
|
||||
"""jc - JSON CLI output utility `/etc/hosts` file parser
|
||||
|
||||
Usage:
|
||||
Usage (cli):
|
||||
|
||||
specify --hosts as the first argument if the piped input is coming from a hosts file
|
||||
$ cat /etc/hosts | jc --hosts
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.hosts
|
||||
result = jc.parsers.hosts.parse(hosts_file_output)
|
||||
|
||||
Compatibility:
|
||||
|
||||
@@ -61,7 +66,7 @@ import jc.utils
|
||||
|
||||
|
||||
class info():
|
||||
version = '1.0'
|
||||
version = '1.2'
|
||||
description = '/etc/hosts file parser'
|
||||
author = 'Kelly Brazil'
|
||||
author_email = 'kellyjonbrazil@gmail.com'
|
||||
@@ -117,16 +122,16 @@ def parse(data, raw=False, quiet=False):
|
||||
jc.utils.compatibility(__name__, info.compatible)
|
||||
|
||||
raw_output = []
|
||||
cleandata = data.splitlines()
|
||||
|
||||
# Clear any blank lines
|
||||
cleandata = list(filter(None, cleandata))
|
||||
cleandata = list(filter(None, data.splitlines()))
|
||||
|
||||
if jc.utils.has_data(data):
|
||||
|
||||
if cleandata:
|
||||
for line in cleandata:
|
||||
output_line = {}
|
||||
# ignore commented lines
|
||||
if line.strip().find('#') == 0:
|
||||
if line.strip().startswith('#'):
|
||||
continue
|
||||
|
||||
line_list = line.split(maxsplit=1)
|
||||
@@ -136,7 +141,7 @@ def parse(data, raw=False, quiet=False):
|
||||
|
||||
comment_found = False
|
||||
for i, item in enumerate(hosts_list):
|
||||
if item.find('#') != -1:
|
||||
if '#' in item:
|
||||
comment_found = True
|
||||
comment_item = i
|
||||
break
|
||||
|
||||
@@ -1,8 +1,17 @@
|
||||
"""jc - JSON CLI output utility id Parser
|
||||
"""jc - JSON CLI output utility `id` command output parser
|
||||
|
||||
Usage:
|
||||
Usage (cli):
|
||||
|
||||
specify --id as the first argument if the piped input is coming from id
|
||||
$ id | jc --id
|
||||
|
||||
or
|
||||
|
||||
$ jc id
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.id
|
||||
result = jc.parsers.id.parse(id_command_output)
|
||||
|
||||
Compatibility:
|
||||
|
||||
@@ -70,14 +79,15 @@ import jc.utils
|
||||
|
||||
|
||||
class info():
|
||||
version = '1.0'
|
||||
description = 'id parser'
|
||||
version = '1.1'
|
||||
description = 'id command parser'
|
||||
author = 'Kelly Brazil'
|
||||
author_email = 'kellyjonbrazil@gmail.com'
|
||||
# details = 'enter any other details here'
|
||||
|
||||
# compatible options: linux, darwin, cygwin, win32, aix, freebsd
|
||||
compatible = ['linux', 'darwin', 'aix', 'freebsd']
|
||||
magic_commands = ['id']
|
||||
|
||||
|
||||
__version__ = info.version
|
||||
@@ -165,12 +175,12 @@ def parse(data, raw=False, quiet=False):
|
||||
jc.utils.compatibility(__name__, info.compatible)
|
||||
|
||||
raw_output = {}
|
||||
cleandata = data.split()
|
||||
|
||||
# Clear any blank lines
|
||||
cleandata = list(filter(None, cleandata))
|
||||
cleandata = list(filter(None, data.split()))
|
||||
|
||||
if jc.utils.has_data(data):
|
||||
|
||||
if cleandata:
|
||||
for section in cleandata:
|
||||
if section.startswith('uid'):
|
||||
uid_parsed = section.replace('(', '=').replace(')', '=')
|
||||
|
||||
@@ -1,10 +1,19 @@
|
||||
"""jc - JSON CLI output utility ifconfig Parser
|
||||
"""jc - JSON CLI output utility `ifconfig` command output parser
|
||||
|
||||
Usage:
|
||||
Note: No `ifconfig` options are supported.
|
||||
|
||||
specify --ifconfig as the first argument if the piped input is coming from ifconfig
|
||||
Usage (cli):
|
||||
|
||||
no ifconfig options are supported.
|
||||
$ ifconfig | jc --ifconfig
|
||||
|
||||
or
|
||||
|
||||
$ jc ifconfig
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.ifconfig
|
||||
result = jc.parsers.ifconfig.parse(ifconfig_command_output)
|
||||
|
||||
Compatibility:
|
||||
|
||||
@@ -141,24 +150,240 @@ Examples:
|
||||
}
|
||||
]
|
||||
"""
|
||||
import re
|
||||
from collections import namedtuple
|
||||
import jc.utils
|
||||
from ifconfigparser import IfconfigParser
|
||||
|
||||
|
||||
class info():
|
||||
version = '1.5'
|
||||
description = 'ifconfig parser'
|
||||
version = '1.8'
|
||||
description = 'ifconfig command parser'
|
||||
author = 'Kelly Brazil'
|
||||
author_email = 'kellyjonbrazil@gmail.com'
|
||||
details = 'Using ifconfig-parser package from https://github.com/KnightWhoSayNi/ifconfig-parser'
|
||||
details = 'Using ifconfig-parser from https://github.com/KnightWhoSayNi/ifconfig-parser'
|
||||
|
||||
# compatible options: linux, darwin, cygwin, win32, aix, freebsd
|
||||
compatible = ['linux', 'aix', 'freebsd', 'darwin']
|
||||
magic_commands = ['ifconfig']
|
||||
|
||||
|
||||
__version__ = info.version
|
||||
|
||||
|
||||
class IfconfigParser(object):
|
||||
# Author: threeheadedknight@protonmail.com
|
||||
# Date created: 30.06.2018 17:03
|
||||
# Python Version: 3.7
|
||||
|
||||
# MIT License
|
||||
|
||||
# Copyright (c) 2018 threeheadedknight@protonmail.com
|
||||
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
# in the Software without restriction, including without limitation the rights
|
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
# copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
|
||||
# The above copyright notice and this permission notice shall be included in all
|
||||
# copies or substantial portions of the Software.
|
||||
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
# SOFTWARE.
|
||||
|
||||
attributes = ['name', 'type', 'mac_addr', 'ipv4_addr', 'ipv4_bcast', 'ipv4_mask', 'ipv6_addr', 'ipv6_mask',
|
||||
'ipv6_scope', 'state', 'mtu', 'metric', 'rx_packets', 'rx_errors', 'rx_dropped', 'rx_overruns',
|
||||
'rx_frame', 'tx_packets', 'tx_errors', 'tx_dropped', 'tx_overruns', 'tx_carrier', 'tx_collisions',
|
||||
'rx_bytes', 'tx_bytes']
|
||||
|
||||
def __init__(self, console_output):
|
||||
"""
|
||||
:param console_output:
|
||||
"""
|
||||
|
||||
if isinstance(console_output, list):
|
||||
source_data = " ".join(console_output)
|
||||
else:
|
||||
source_data = console_output.replace("\n", " ")
|
||||
self.interfaces = self.parser(source_data=source_data)
|
||||
|
||||
def list_interfaces(self):
|
||||
"""
|
||||
:return:
|
||||
"""
|
||||
return sorted(self.interfaces.keys())
|
||||
|
||||
def count_interfaces(self):
|
||||
"""
|
||||
:return:
|
||||
"""
|
||||
return len(self.interfaces.keys())
|
||||
|
||||
def filter_interfaces(self, **kwargs):
|
||||
"""
|
||||
:param kwargs:
|
||||
:return:
|
||||
"""
|
||||
for attr in kwargs.keys():
|
||||
if attr not in IfconfigParser.attributes:
|
||||
raise ValueError("Attribute [{}] not supported.".format(attr))
|
||||
|
||||
filtered_interfaces = []
|
||||
for name, details in self.interfaces.items():
|
||||
|
||||
if all(getattr(details, attr) == kwargs[attr] for attr in kwargs.keys()):
|
||||
filtered_interfaces.append(name)
|
||||
|
||||
return sorted(filtered_interfaces)
|
||||
|
||||
def get_interface(self, name):
|
||||
"""
|
||||
:param name:
|
||||
:return:
|
||||
"""
|
||||
if name in self.list_interfaces():
|
||||
return self.interfaces[name]
|
||||
else:
|
||||
raise InterfaceNotFound("Interface [{}] not found.".format(name))
|
||||
|
||||
def get_interfaces(self):
|
||||
"""
|
||||
:return:
|
||||
"""
|
||||
return self.interfaces
|
||||
|
||||
def is_available(self, name):
|
||||
"""
|
||||
:param name:
|
||||
:return:
|
||||
"""
|
||||
return name in self.interfaces
|
||||
|
||||
def parser(self, source_data):
|
||||
"""
|
||||
:param source_data:
|
||||
:return:
|
||||
"""
|
||||
|
||||
# Linux syntax
|
||||
re_linux_interface = re.compile(
|
||||
r"(?P<name>[a-zA-Z0-9:._-]+)\s+Link encap:(?P<type>\S+\s?\S+)(\s+HWaddr\s+\b"
|
||||
r"(?P<mac_addr>[0-9A-Fa-f:?]+))?",
|
||||
re.I)
|
||||
re_linux_ipv4 = re.compile(
|
||||
r"inet addr:(?P<ipv4_addr>(?:[0-9]{1,3}\.){3}[0-9]{1,3})(\s+Bcast:"
|
||||
r"(?P<ipv4_bcast>(?:[0-9]{1,3}\.){3}[0-9]{1,3}))?\s+Mask:(?P<ipv4_mask>(?:[0-9]{1,3}\.){3}[0-9]{1,3})",
|
||||
re.I)
|
||||
re_linux_ipv6 = re.compile(
|
||||
r"inet6 addr:\s+(?P<ipv6_addr>\S+)/(?P<ipv6_mask>[0-9]+)\s+Scope:(?P<ipv6_scope>Link|Host)",
|
||||
re.I)
|
||||
re_linux_state = re.compile(
|
||||
r"\W+(?P<state>(?:\w+\s)+)(?:\s+)?MTU:(?P<mtu>[0-9]+)\s+Metric:(?P<metric>[0-9]+)", re.I)
|
||||
re_linux_rx = re.compile(
|
||||
r"RX packets:(?P<rx_packets>[0-9]+)\s+errors:(?P<rx_errors>[0-9]+)\s+dropped:"
|
||||
r"(?P<rx_dropped>[0-9]+)\s+overruns:(?P<rx_overruns>[0-9]+)\s+frame:(?P<rx_frame>[0-9]+)",
|
||||
re.I)
|
||||
re_linux_tx = re.compile(
|
||||
r"TX packets:(?P<tx_packets>[0-9]+)\s+errors:(?P<tx_errors>[0-9]+)\s+dropped:"
|
||||
r"(?P<tx_dropped>[0-9]+)\s+overruns:(?P<tx_overruns>[0-9]+)\s+carrier:(?P<tx_carrier>[0-9]+)",
|
||||
re.I)
|
||||
re_linux_bytes = re.compile(r"\W+RX bytes:(?P<rx_bytes>\d+)\s+\(.*\)\s+TX bytes:(?P<tx_bytes>\d+)\s+\(.*\)", re.I)
|
||||
re_linux_tx_stats = re.compile(r"collisions:(?P<tx_collisions>[0-9]+)\s+txqueuelen:[0-9]+", re.I)
|
||||
re_linux = [re_linux_interface, re_linux_ipv4, re_linux_ipv6, re_linux_state, re_linux_rx, re_linux_tx,
|
||||
re_linux_bytes, re_linux_tx_stats]
|
||||
|
||||
# OpenBSD syntax
|
||||
re_openbsd_interface = re.compile(
|
||||
r"(?P<name>[a-zA-Z0-9:._-]+):\s+flags=(?P<flags>[0-9]+)<(?P<state>\S+)?>\s+mtu\s+(?P<mtu>[0-9]+)",
|
||||
re.I)
|
||||
re_openbsd_ipv4 = re.compile(
|
||||
r"inet (?P<ipv4_addr>(?:[0-9]{1,3}\.){3}[0-9]{1,3})\s+netmask\s+"
|
||||
r"(?P<ipv4_mask>(?:[0-9]{1,3}\.){3}[0-9]{1,3})(\s+broadcast\s+"
|
||||
r"(?P<ipv4_bcast>(?:[0-9]{1,3}\.){3}[0-9]{1,3}))?",
|
||||
re.I)
|
||||
re_openbsd_ipv6 = re.compile(
|
||||
r"inet6\s+(?P<ipv6_addr>\S+)\s+prefixlen\s+(?P<ipv6_mask>[0-9]+)\s+scopeid\s+(?P<ipv6_scope>\w+x\w+)<"
|
||||
r"(?:link|host)>",
|
||||
re.I)
|
||||
re_openbsd_details = re.compile(
|
||||
r"\S+\s+(?:(?P<mac_addr>[0-9A-Fa-f:?]+)\s+)?txqueuelen\s+[0-9]+\s+\((?P<type>\S+\s?\S+)\)", re.I)
|
||||
re_openbsd_rx = re.compile(r"RX packets (?P<rx_packets>[0-9]+)\s+bytes\s+(?P<rx_bytes>\d+)\s+.*", re.I)
|
||||
re_openbsd_rx_stats = re.compile(
|
||||
r"RX errors (?P<rx_errors>[0-9]+)\s+dropped\s+(?P<rx_dropped>[0-9]+)\s+overruns\s+"
|
||||
r"(?P<rx_overruns>[0-9]+)\s+frame\s+(?P<rx_frame>[0-9]+)",
|
||||
re.I)
|
||||
re_openbsd_tx = re.compile(r"TX packets (?P<tx_packets>[0-9]+)\s+bytes\s+(?P<tx_bytes>\d+)\s+.*", re.I)
|
||||
re_openbsd_tx_stats = re.compile(
|
||||
r"TX errors (?P<tx_errors>[0-9]+)\s+dropped\s+(?P<tx_dropped>[0-9]+)\s+overruns\s+"
|
||||
r"(?P<tx_overruns>[0-9]+)\s+carrier\s+(?P<tx_carrier>[0-9]+)\s+collisions\s+(?P<tx_collisions>[0-9]+)",
|
||||
re.I)
|
||||
re_openbsd = [re_openbsd_interface, re_openbsd_ipv4, re_openbsd_ipv6, re_openbsd_details, re_openbsd_rx,
|
||||
re_openbsd_rx_stats, re_openbsd_tx, re_openbsd_tx_stats]
|
||||
|
||||
# FreeBSD syntax
|
||||
re_freebsd_interface = re.compile(
|
||||
r"(?P<name>[a-zA-Z0-9:._-]+):\s+flags=(?P<flags>[0-9]+)<(?P<state>\S+)>\s+metric\s+"
|
||||
r"(?P<metric>[0-9]+)\s+mtu\s+(?P<mtu>[0-9]+)",
|
||||
re.I)
|
||||
re_freebsd_ipv4 = re.compile(
|
||||
r"inet (?P<ipv4_addr>(?:[0-9]{1,3}\.){3}[0-9]{1,3})\s+netmask\s+(?P<ipv4_mask>0x\S+)(\s+broadcast\s+"
|
||||
r"(?P<ipv4_bcast>(?:[0-9]{1,3}\.){3}[0-9]{1,3}))?",
|
||||
re.I)
|
||||
re_freebsd_ipv6 = re.compile(r"\s?inet6\s(?P<ipv6_addr>.*)(?:\%\w+\d+)\sprefixlen\s(?P<ipv6_mask>\d+)(?:\s\w+)?\sscopeid\s(?P<ipv6_scope>\w+x\w+)", re.I)
|
||||
re_freebsd_details = re.compile(r"ether\s+(?P<mac_addr>[0-9A-Fa-f:?]+)", re.I)
|
||||
re_freebsd = [re_freebsd_interface, re_freebsd_ipv4, re_freebsd_ipv6, re_freebsd_details]
|
||||
|
||||
available_interfaces = dict()
|
||||
|
||||
for pattern in [re_linux_interface, re_openbsd_interface, re_freebsd_interface]:
|
||||
network_interfaces = re.finditer(pattern, source_data)
|
||||
positions = []
|
||||
while True:
|
||||
try:
|
||||
pos = next(network_interfaces)
|
||||
positions.append(max(pos.start() - 1, 0))
|
||||
except StopIteration:
|
||||
break
|
||||
if positions:
|
||||
positions.append(len(source_data))
|
||||
break
|
||||
|
||||
if not positions:
|
||||
return available_interfaces
|
||||
|
||||
for l, r in zip(positions, positions[1:]):
|
||||
chunk = source_data[l:r]
|
||||
_interface = dict()
|
||||
for pattern in re_linux + re_openbsd + re_freebsd:
|
||||
match = re.search(pattern, chunk.replace('\t', '\n'))
|
||||
if match:
|
||||
details = match.groupdict()
|
||||
for k, v in details.items():
|
||||
if isinstance(v, str): details[k] = v.strip()
|
||||
_interface.update(details)
|
||||
if _interface is not None:
|
||||
available_interfaces[_interface['name']] = self.update_interface_details(_interface)
|
||||
|
||||
return available_interfaces
|
||||
|
||||
@staticmethod
|
||||
def update_interface_details(interface):
|
||||
for attr in IfconfigParser.attributes:
|
||||
if attr not in interface:
|
||||
interface[attr] = None
|
||||
return namedtuple('Interface', interface.keys())(**interface)
|
||||
|
||||
|
||||
class InterfaceNotFound(Exception):
|
||||
pass
|
||||
|
||||
|
||||
def process(proc_data):
|
||||
"""
|
||||
Final processing to conform to the schema.
|
||||
@@ -219,7 +444,7 @@ def process(proc_data):
|
||||
# convert OSX-style subnet mask to dotted quad
|
||||
if 'ipv4_mask' in entry:
|
||||
try:
|
||||
if entry['ipv4_mask'].find('0x') == 0:
|
||||
if entry['ipv4_mask'].startswith('0x'):
|
||||
new_mask = entry['ipv4_mask']
|
||||
new_mask = new_mask.lstrip('0x')
|
||||
new_mask = '.'.join(str(int(i, 16)) for i in [new_mask[i:i + 2] for i in range(0, len(new_mask), 2)])
|
||||
@@ -257,14 +482,16 @@ def parse(data, raw=False, quiet=False):
|
||||
|
||||
raw_output = []
|
||||
|
||||
parsed = IfconfigParser(console_output=data)
|
||||
interfaces = parsed.get_interfaces()
|
||||
if jc.utils.has_data(data):
|
||||
|
||||
# convert ifconfigparser output to a dictionary
|
||||
for iface in interfaces:
|
||||
d = interfaces[iface]._asdict()
|
||||
dct = dict(d)
|
||||
raw_output.append(dct)
|
||||
parsed = IfconfigParser(console_output=data)
|
||||
interfaces = parsed.get_interfaces()
|
||||
|
||||
# convert ifconfigparser output to a dictionary
|
||||
for iface in interfaces:
|
||||
d = interfaces[iface]._asdict()
|
||||
dct = dict(d)
|
||||
raw_output.append(dct)
|
||||
|
||||
if raw:
|
||||
return raw_output
|
||||
|
||||
@@ -1,8 +1,17 @@
|
||||
"""jc - JSON CLI output utility INI Parser
|
||||
"""jc - JSON CLI output utility `INI` file parser
|
||||
|
||||
Usage:
|
||||
Parses standard `INI` files and files containing simple key/value pairs. Delimiter can be `=` or `:`. Missing values are supported. Comment prefix can be `#` or `;`. Comments must be on their own line.
|
||||
|
||||
specify --ini as the first argument if the piped input is coming from an INI file
|
||||
Note: Values starting and ending with quotation marks will have the marks removed. If you would like to keep the quotation marks, use the `-r` command-line argument or the `raw=True` argument in `parse()`.
|
||||
|
||||
Usage (cli):
|
||||
|
||||
$ cat foo.ini | jc --ini
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.ini
|
||||
result = jc.parsers.ini.parse(ini_file_output)
|
||||
|
||||
Compatibility:
|
||||
|
||||
@@ -47,7 +56,7 @@ import configparser
|
||||
|
||||
|
||||
class info():
|
||||
version = '1.0'
|
||||
version = '1.3'
|
||||
description = 'INI file parser'
|
||||
author = 'Kelly Brazil'
|
||||
author_email = 'kellyjonbrazil@gmail.com'
|
||||
@@ -70,15 +79,33 @@ def process(proc_data):
|
||||
|
||||
Returns:
|
||||
|
||||
Dictionary representing an ini document:
|
||||
Dictionary representing an ini or simple key/value pair document:
|
||||
|
||||
{
|
||||
ini document converted to a dictionary
|
||||
see configparser standard library documentation for more details
|
||||
ini or key/value document converted to a dictionary - see configparser standard
|
||||
library documentation for more details.
|
||||
|
||||
Note: Values starting and ending with quotation marks will have the marks removed.
|
||||
If you would like to keep the quotation marks, use the -r or raw=True argument.
|
||||
}
|
||||
"""
|
||||
# remove quotation marks from beginning and end of values
|
||||
for heading in proc_data:
|
||||
# standard ini files with headers
|
||||
if isinstance(proc_data[heading], dict):
|
||||
for key, value in proc_data[heading].items():
|
||||
if value is not None and value.startswith('"') and value.endswith('"'):
|
||||
proc_data[heading][key] = value.lstrip('"').rstrip('"')
|
||||
elif value is None:
|
||||
proc_data[heading][key] = ''
|
||||
|
||||
# simple key/value files with no headers
|
||||
else:
|
||||
if proc_data[heading] is not None and proc_data[heading].startswith('"') and proc_data[heading].endswith('"'):
|
||||
proc_data[heading] = proc_data[heading].lstrip('"').rstrip('"')
|
||||
elif proc_data[heading] is None:
|
||||
proc_data[heading] = ''
|
||||
|
||||
# No further processing
|
||||
return proc_data
|
||||
|
||||
|
||||
@@ -101,10 +128,19 @@ def parse(data, raw=False, quiet=False):
|
||||
|
||||
raw_output = {}
|
||||
|
||||
if data:
|
||||
ini = configparser.ConfigParser()
|
||||
ini.read_string(data)
|
||||
raw_output = {s: dict(ini.items(s)) for s in ini.sections()}
|
||||
if jc.utils.has_data(data):
|
||||
|
||||
ini = configparser.ConfigParser(allow_no_value=True, interpolation=None)
|
||||
try:
|
||||
ini.read_string(data)
|
||||
raw_output = {s: dict(ini.items(s)) for s in ini.sections()}
|
||||
|
||||
except configparser.MissingSectionHeaderError:
|
||||
data = '[data]\n' + data
|
||||
ini.read_string(data)
|
||||
output_dict = {s: dict(ini.items(s)) for s in ini.sections()}
|
||||
for key, value in output_dict['data'].items():
|
||||
raw_output[key] = value
|
||||
|
||||
if raw:
|
||||
return raw_output
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user