Skip to content
31 changes: 28 additions & 3 deletions jc/parsers/hashsum.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
[
{
"filename": string,
"mode": string,
"hash": string,
}
]
Expand All @@ -38,31 +39,39 @@
[
{
"filename": "devtoolset-3-gcc-4.9.2-6.el7.x86_64.rpm",
"mode": "text",
"hash": "65fc958c1add637ec23c4b137aecf3d3"
},
{
"filename": "digout",
"mode": "text",
"hash": "5b9312ee5aff080927753c63a347707d"
},
{
"filename": "dmidecode.out",
"mode": "text",
"hash": "716fd11c2ac00db109281f7110b8fb9d"
},
{
"filename": "file with spaces in the name",
"mode": "text",
"hash": "d41d8cd98f00b204e9800998ecf8427e"
},
{
"filename": "id-centos.out",
"mode": "text",
"hash": "4295be239a14ad77ef3253103de976d2"
},
{
"filename": "ifcfg.json",
"mode": "text",
"hash": "01fda0d9ba9a75618b072e64ff512b43"
},
...
]
"""
import re

import jc.utils


Expand All @@ -81,6 +90,15 @@ class info():

__version__ = info.version

_mode_friendly_names = {
" ": "text",
"*": "binary",
# Perl shasum -- specific
"U": "universal",
"^": "bits",
# BSD-style format only supports binary mode
None: "binary"
}

def _process(proc_data):
"""
Expand All @@ -95,7 +113,9 @@ def _process(proc_data):
List of Dictionaries. Structured data to conform to the schema.
"""

# no further processing for this parser
for entry in proc_data:
entry['mode'] = _mode_friendly_names.get(entry['mode'],entry['mode'])

return proc_data


Expand Down Expand Up @@ -127,13 +147,18 @@ def parse(data, raw=False, quiet=False):
file_name = line.split('=', maxsplit=1)[0].strip()
file_name = file_name[5:]
file_name = file_name[:-1]
# filler, legacy md5 always uses binary mode
file_mode = None
# standard md5sum and shasum command output
else:
file_hash = line.split(maxsplit=1)[0]
file_name = line.split(maxsplit=1)[1]
m = re.match('([0-9a-f]+) (.)(.*)$', line)
if not m:
raise ValueError(f'Invalid line format: "{line}"')
file_hash, file_mode, file_name = m.groups()

item = {
'filename': file_name,
'mode': file_mode,
'hash': file_hash
}
raw_output.append(item)
Expand Down
1 change: 1 addition & 0 deletions tests/fixtures/centos-7.7/md5sum-raw.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"filename": "devtoolset-3-gcc-4.9.2-6.el7.x86_64.rpm", "mode": " ", "hash": "65fc958c1add637ec23c4b137aecf3d3"}, {"filename": "digout", "mode": " ", "hash": "5b9312ee5aff080927753c63a347707d"}, {"filename": "dmidecode.out", "mode": " ", "hash": "716fd11c2ac00db109281f7110b8fb9d"}, {"filename": "file with spaces in the name", "mode": " ", "hash": "d41d8cd98f00b204e9800998ecf8427e"}, {"filename": "id-centos.out", "mode": " ", "hash": "4295be239a14ad77ef3253103de976d2"}, {"filename": "ifcfg.json", "mode": " ", "hash": "01fda0d9ba9a75618b072e64ff512b43"}, {"filename": "ifconfig.out", "mode": " ", "hash": "e3bff970404527b132dca58031c7286f"}, {"filename": "jc", "mode": " ", "hash": "b8b604dc8213d9a6515f2c04bdccfb3b"}, {"filename": "jc-1.10.5-linux.sha256", "mode": " ", "hash": "14236ca18714d2b6282758e9b7b46000"}, {"filename": "jc-1.10.5-linux.tar.gz", "mode": " ", "hash": "a13b2843c1e8029a98503bc07613862c"}, {"filename": "jc-1.10.5.rpm", "mode": " ", "hash": "d0e05de2651857155f8673dc113272ae"}, {"filename": "jc-1.11.1-linux.sha256", "mode": " ", "hash": "53e4b33fa99c53c28972db666de9b7b3"}, {"filename": "jc-1.11.1-linux.tar.gz", "mode": " ", "hash": "ea4145789224b142361016412cd613b7"}, {"filename": "jc-1.11.1.sha256", "mode": " ", "hash": "c6c5fd21ef572dd6d2629c44ad566425"}, {"filename": "jc-1.11.1.tar.gz", "mode": " ", "hash": "d838680555f84aff7f286dd440b2490b"}, {"filename": "jc-1.11.2-linux.sha256", "mode": " ", "hash": "e7d5c22044848539c2cbd9f5b562de9a"}, {"filename": "jc-1.11.2-linux.tar.gz", "mode": " ", "hash": "e6d842ead8cfc9a58df9dce7814ee657"}, {"filename": "jc-1.11.8-linux.sha256", "mode": " ", "hash": "24a5005717ab949fd7608aaa77bfeade"}, {"filename": "jc-1.11.8-linux.tar.gz", "mode": " ", "hash": "6a84320c7551c51051a748c873d91194"}, {"filename": "jc-1.13.1-linux.sha256", "mode": " ", "hash": "54431e32a1ffa7a90f520a6d8ae966fc"}, {"filename": "jc-1.13.1-linux.tar.gz", "mode": " ", "hash": "c7a084d9de6bf1193ea0601a2239fc2b"}, {"filename": "jc-1.13.2-linux.sha256", "mode": " ", "hash": "1adf518be9a071131ab105155fee176a"}, {"filename": "jc-1.13.2-linux.tar.gz", "mode": " ", "hash": "4d8dd74578bc7817de0834e2349c4466"}, {"filename": "jc-1.13.4-linux.sha256", "mode": " ", "hash": "3b63bfaff06d9c825aa0a1e0d062a10e"}, {"filename": "jc-1.13.4-linux.tar.gz", "mode": " ", "hash": "a5d7feae690e2c3d6bc4acef4205b308"}, {"filename": "jello-1.2.8-linux.sha256", "mode": " ", "hash": "90d4fe29d8860adb46f14c99bd27306f"}, {"filename": "jello-1.2.8-linux.tar.gz", "mode": " ", "hash": "ea4eadde3abe740d23feb38225e8fe46"}, {"filename": "jello-1.2.9-linux.sha256", "mode": " ", "hash": "c690e9126ed296535046e68bfa02de94"}, {"filename": "jello-1.2.9-linux.tar.gz", "mode": " ", "hash": "28d6899def6cb63e69d6bb8f53365ecd"}, {"filename": "journaljson", "mode": " ", "hash": "5fed1973e223d1f1e45fccec089cb285"}, {"filename": "jp", "mode": " ", "hash": "e49f9acb33479f59b7be1f94e8daa3db"}, {"filename": "jp_1.1.12_linux_x86_64.zip", "mode": " ", "hash": "ef49750c3f69ae22b8c456e38e4ea39c"}, {"filename": "jq_twitter.json", "mode": " ", "hash": "b86c4c8487e3c0bb656d068886c413b7"}, {"filename": "jtbl-1.1.6-linux.sha256", "mode": " ", "hash": "d1427e00cbe4e0d1b5b239993ca474b5"}, {"filename": "jtbl-1.1.6-linux.tar.gz", "mode": " ", "hash": "87d36c9c35c5ce23f691634d3faad06e"}, {"filename": "kbls.out", "mode": " ", "hash": "b3d0c62d77c4f2861cb1dd7464faaa24"}, {"filename": "lastb.out", "mode": " ", "hash": "7907a2a62c9f3e1a558ad24ff93fac2c"}, {"filename": "lsblk-cols", "mode": " ", "hash": "d9920641b832e86c52e1ef380f777f63"}, {"filename": "ping-ip-O-D.out", "mode": " ", "hash": "9ab7407b788aa94b95fe49dbc131b2cb"}, {"filename": "ping-ip-O.out", "mode": " ", "hash": "969a0243a76a3bf407e3a24082af8068"}, {"filename": "psfile.txt", "mode": " ", "hash": "e1e61d18b3e96359940a22c10f30ad34"}, {"filename": "resizeterm.sh", "mode": " ", "hash": "9aa6b53e55b3134219c061441d5c0b3f"}, {"filename": "route-6-n.out", "mode": " ", "hash": "e1e1084c23889b46a055d0f8101c0947"}, {"filename": "route-6.out", "mode": " ", "hash": "4e75a36fcbf5b1f74c42849c641eb7d4"}, {"filename": "routeout", "mode": " ", "hash": "fbb00b1c066988b8d4ce285309fc2a55"}, {"filename": "shafile.txt", "mode": " ", "hash": "a54b97e7ffb498130a5807c492fd06bd"}, {"filename": "ss-aeep.out", "mode": " ", "hash": "4aa7a33ccd4d863f2dc34570bc9a4761"}, {"filename": "ssout", "mode": " ", "hash": "9e61faf4a86f484745e9361a6c33249b"}, {"filename": "systemctl.out", "mode": " ", "hash": "eea802ae7bcbb6b63678b5ec68df6212"}, {"filename": "top.out", "mode": " ", "hash": "8fc90c98a0b0455ba359199e98a3951a"}, {"filename": "tracepath6.out", "mode": " ", "hash": "cdbfa0898a3c089a24ecdab4b62e0241"}, {"filename": "tracepath-cnn.out", "mode": " ", "hash": "c5a2a5d40fcf6617d3ca1fae4766f70c"}, {"filename": "tr.out", "mode": " ", "hash": "dedcbcfcf486d1620c7495c7c9700a02"}, {"filename": "who-aH.out", "mode": " ", "hash": "6a90a054f9df3abdfe936c03e53b71d4"}, {"filename": "who.out", "mode": " ", "hash": "d5c25156c301c14125aaa5d1e8f5adbb"}, {"filename": "whotext", "mode": " ", "hash": "cbe28a0722637d2ea2c07378eba2206e"}]
2 changes: 1 addition & 1 deletion tests/fixtures/centos-7.7/md5sum.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"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"}, {"filename": "ifconfig.out", "hash": "e3bff970404527b132dca58031c7286f"}, {"filename": "jc", "hash": "b8b604dc8213d9a6515f2c04bdccfb3b"}, {"filename": "jc-1.10.5-linux.sha256", "hash": "14236ca18714d2b6282758e9b7b46000"}, {"filename": "jc-1.10.5-linux.tar.gz", "hash": "a13b2843c1e8029a98503bc07613862c"}, {"filename": "jc-1.10.5.rpm", "hash": "d0e05de2651857155f8673dc113272ae"}, {"filename": "jc-1.11.1-linux.sha256", "hash": "53e4b33fa99c53c28972db666de9b7b3"}, {"filename": "jc-1.11.1-linux.tar.gz", "hash": "ea4145789224b142361016412cd613b7"}, {"filename": "jc-1.11.1.sha256", "hash": "c6c5fd21ef572dd6d2629c44ad566425"}, {"filename": "jc-1.11.1.tar.gz", "hash": "d838680555f84aff7f286dd440b2490b"}, {"filename": "jc-1.11.2-linux.sha256", "hash": "e7d5c22044848539c2cbd9f5b562de9a"}, {"filename": "jc-1.11.2-linux.tar.gz", "hash": "e6d842ead8cfc9a58df9dce7814ee657"}, {"filename": "jc-1.11.8-linux.sha256", "hash": "24a5005717ab949fd7608aaa77bfeade"}, {"filename": "jc-1.11.8-linux.tar.gz", "hash": "6a84320c7551c51051a748c873d91194"}, {"filename": "jc-1.13.1-linux.sha256", "hash": "54431e32a1ffa7a90f520a6d8ae966fc"}, {"filename": "jc-1.13.1-linux.tar.gz", "hash": "c7a084d9de6bf1193ea0601a2239fc2b"}, {"filename": "jc-1.13.2-linux.sha256", "hash": "1adf518be9a071131ab105155fee176a"}, {"filename": "jc-1.13.2-linux.tar.gz", "hash": "4d8dd74578bc7817de0834e2349c4466"}, {"filename": "jc-1.13.4-linux.sha256", "hash": "3b63bfaff06d9c825aa0a1e0d062a10e"}, {"filename": "jc-1.13.4-linux.tar.gz", "hash": "a5d7feae690e2c3d6bc4acef4205b308"}, {"filename": "jello-1.2.8-linux.sha256", "hash": "90d4fe29d8860adb46f14c99bd27306f"}, {"filename": "jello-1.2.8-linux.tar.gz", "hash": "ea4eadde3abe740d23feb38225e8fe46"}, {"filename": "jello-1.2.9-linux.sha256", "hash": "c690e9126ed296535046e68bfa02de94"}, {"filename": "jello-1.2.9-linux.tar.gz", "hash": "28d6899def6cb63e69d6bb8f53365ecd"}, {"filename": "journaljson", "hash": "5fed1973e223d1f1e45fccec089cb285"}, {"filename": "jp", "hash": "e49f9acb33479f59b7be1f94e8daa3db"}, {"filename": "jp_1.1.12_linux_x86_64.zip", "hash": "ef49750c3f69ae22b8c456e38e4ea39c"}, {"filename": "jq_twitter.json", "hash": "b86c4c8487e3c0bb656d068886c413b7"}, {"filename": "jtbl-1.1.6-linux.sha256", "hash": "d1427e00cbe4e0d1b5b239993ca474b5"}, {"filename": "jtbl-1.1.6-linux.tar.gz", "hash": "87d36c9c35c5ce23f691634d3faad06e"}, {"filename": "kbls.out", "hash": "b3d0c62d77c4f2861cb1dd7464faaa24"}, {"filename": "lastb.out", "hash": "7907a2a62c9f3e1a558ad24ff93fac2c"}, {"filename": "lsblk-cols", "hash": "d9920641b832e86c52e1ef380f777f63"}, {"filename": "ping-ip-O-D.out", "hash": "9ab7407b788aa94b95fe49dbc131b2cb"}, {"filename": "ping-ip-O.out", "hash": "969a0243a76a3bf407e3a24082af8068"}, {"filename": "psfile.txt", "hash": "e1e61d18b3e96359940a22c10f30ad34"}, {"filename": "resizeterm.sh", "hash": "9aa6b53e55b3134219c061441d5c0b3f"}, {"filename": "route-6-n.out", "hash": "e1e1084c23889b46a055d0f8101c0947"}, {"filename": "route-6.out", "hash": "4e75a36fcbf5b1f74c42849c641eb7d4"}, {"filename": "routeout", "hash": "fbb00b1c066988b8d4ce285309fc2a55"}, {"filename": "shafile.txt", "hash": "a54b97e7ffb498130a5807c492fd06bd"}, {"filename": "ss-aeep.out", "hash": "4aa7a33ccd4d863f2dc34570bc9a4761"}, {"filename": "ssout", "hash": "9e61faf4a86f484745e9361a6c33249b"}, {"filename": "systemctl.out", "hash": "eea802ae7bcbb6b63678b5ec68df6212"}, {"filename": "top.out", "hash": "8fc90c98a0b0455ba359199e98a3951a"}, {"filename": "tracepath6.out", "hash": "cdbfa0898a3c089a24ecdab4b62e0241"}, {"filename": "tracepath-cnn.out", "hash": "c5a2a5d40fcf6617d3ca1fae4766f70c"}, {"filename": "tr.out", "hash": "dedcbcfcf486d1620c7495c7c9700a02"}, {"filename": "who-aH.out", "hash": "6a90a054f9df3abdfe936c03e53b71d4"}, {"filename": "who.out", "hash": "d5c25156c301c14125aaa5d1e8f5adbb"}, {"filename": "whotext", "hash": "cbe28a0722637d2ea2c07378eba2206e"}]
[{"filename": "devtoolset-3-gcc-4.9.2-6.el7.x86_64.rpm", "mode": "text", "hash": "65fc958c1add637ec23c4b137aecf3d3"}, {"filename": "digout", "mode": "text", "hash": "5b9312ee5aff080927753c63a347707d"}, {"filename": "dmidecode.out", "mode": "text", "hash": "716fd11c2ac00db109281f7110b8fb9d"}, {"filename": "file with spaces in the name", "mode": "text", "hash": "d41d8cd98f00b204e9800998ecf8427e"}, {"filename": "id-centos.out", "mode": "text", "hash": "4295be239a14ad77ef3253103de976d2"}, {"filename": "ifcfg.json", "mode": "text", "hash": "01fda0d9ba9a75618b072e64ff512b43"}, {"filename": "ifconfig.out", "mode": "text", "hash": "e3bff970404527b132dca58031c7286f"}, {"filename": "jc", "mode": "text", "hash": "b8b604dc8213d9a6515f2c04bdccfb3b"}, {"filename": "jc-1.10.5-linux.sha256", "mode": "text", "hash": "14236ca18714d2b6282758e9b7b46000"}, {"filename": "jc-1.10.5-linux.tar.gz", "mode": "text", "hash": "a13b2843c1e8029a98503bc07613862c"}, {"filename": "jc-1.10.5.rpm", "mode": "text", "hash": "d0e05de2651857155f8673dc113272ae"}, {"filename": "jc-1.11.1-linux.sha256", "mode": "text", "hash": "53e4b33fa99c53c28972db666de9b7b3"}, {"filename": "jc-1.11.1-linux.tar.gz", "mode": "text", "hash": "ea4145789224b142361016412cd613b7"}, {"filename": "jc-1.11.1.sha256", "mode": "text", "hash": "c6c5fd21ef572dd6d2629c44ad566425"}, {"filename": "jc-1.11.1.tar.gz", "mode": "text", "hash": "d838680555f84aff7f286dd440b2490b"}, {"filename": "jc-1.11.2-linux.sha256", "mode": "text", "hash": "e7d5c22044848539c2cbd9f5b562de9a"}, {"filename": "jc-1.11.2-linux.tar.gz", "mode": "text", "hash": "e6d842ead8cfc9a58df9dce7814ee657"}, {"filename": "jc-1.11.8-linux.sha256", "mode": "text", "hash": "24a5005717ab949fd7608aaa77bfeade"}, {"filename": "jc-1.11.8-linux.tar.gz", "mode": "text", "hash": "6a84320c7551c51051a748c873d91194"}, {"filename": "jc-1.13.1-linux.sha256", "mode": "text", "hash": "54431e32a1ffa7a90f520a6d8ae966fc"}, {"filename": "jc-1.13.1-linux.tar.gz", "mode": "text", "hash": "c7a084d9de6bf1193ea0601a2239fc2b"}, {"filename": "jc-1.13.2-linux.sha256", "mode": "text", "hash": "1adf518be9a071131ab105155fee176a"}, {"filename": "jc-1.13.2-linux.tar.gz", "mode": "text", "hash": "4d8dd74578bc7817de0834e2349c4466"}, {"filename": "jc-1.13.4-linux.sha256", "mode": "text", "hash": "3b63bfaff06d9c825aa0a1e0d062a10e"}, {"filename": "jc-1.13.4-linux.tar.gz", "mode": "text", "hash": "a5d7feae690e2c3d6bc4acef4205b308"}, {"filename": "jello-1.2.8-linux.sha256", "mode": "text", "hash": "90d4fe29d8860adb46f14c99bd27306f"}, {"filename": "jello-1.2.8-linux.tar.gz", "mode": "text", "hash": "ea4eadde3abe740d23feb38225e8fe46"}, {"filename": "jello-1.2.9-linux.sha256", "mode": "text", "hash": "c690e9126ed296535046e68bfa02de94"}, {"filename": "jello-1.2.9-linux.tar.gz", "mode": "text", "hash": "28d6899def6cb63e69d6bb8f53365ecd"}, {"filename": "journaljson", "mode": "text", "hash": "5fed1973e223d1f1e45fccec089cb285"}, {"filename": "jp", "mode": "text", "hash": "e49f9acb33479f59b7be1f94e8daa3db"}, {"filename": "jp_1.1.12_linux_x86_64.zip", "mode": "text", "hash": "ef49750c3f69ae22b8c456e38e4ea39c"}, {"filename": "jq_twitter.json", "mode": "text", "hash": "b86c4c8487e3c0bb656d068886c413b7"}, {"filename": "jtbl-1.1.6-linux.sha256", "mode": "text", "hash": "d1427e00cbe4e0d1b5b239993ca474b5"}, {"filename": "jtbl-1.1.6-linux.tar.gz", "mode": "text", "hash": "87d36c9c35c5ce23f691634d3faad06e"}, {"filename": "kbls.out", "mode": "text", "hash": "b3d0c62d77c4f2861cb1dd7464faaa24"}, {"filename": "lastb.out", "mode": "text", "hash": "7907a2a62c9f3e1a558ad24ff93fac2c"}, {"filename": "lsblk-cols", "mode": "text", "hash": "d9920641b832e86c52e1ef380f777f63"}, {"filename": "ping-ip-O-D.out", "mode": "text", "hash": "9ab7407b788aa94b95fe49dbc131b2cb"}, {"filename": "ping-ip-O.out", "mode": "text", "hash": "969a0243a76a3bf407e3a24082af8068"}, {"filename": "psfile.txt", "mode": "text", "hash": "e1e61d18b3e96359940a22c10f30ad34"}, {"filename": "resizeterm.sh", "mode": "text", "hash": "9aa6b53e55b3134219c061441d5c0b3f"}, {"filename": "route-6-n.out", "mode": "text", "hash": "e1e1084c23889b46a055d0f8101c0947"}, {"filename": "route-6.out", "mode": "text", "hash": "4e75a36fcbf5b1f74c42849c641eb7d4"}, {"filename": "routeout", "mode": "text", "hash": "fbb00b1c066988b8d4ce285309fc2a55"}, {"filename": "shafile.txt", "mode": "text", "hash": "a54b97e7ffb498130a5807c492fd06bd"}, {"filename": "ss-aeep.out", "mode": "text", "hash": "4aa7a33ccd4d863f2dc34570bc9a4761"}, {"filename": "ssout", "mode": "text", "hash": "9e61faf4a86f484745e9361a6c33249b"}, {"filename": "systemctl.out", "mode": "text", "hash": "eea802ae7bcbb6b63678b5ec68df6212"}, {"filename": "top.out", "mode": "text", "hash": "8fc90c98a0b0455ba359199e98a3951a"}, {"filename": "tracepath6.out", "mode": "text", "hash": "cdbfa0898a3c089a24ecdab4b62e0241"}, {"filename": "tracepath-cnn.out", "mode": "text", "hash": "c5a2a5d40fcf6617d3ca1fae4766f70c"}, {"filename": "tr.out", "mode": "text", "hash": "dedcbcfcf486d1620c7495c7c9700a02"}, {"filename": "who-aH.out", "mode": "text", "hash": "6a90a054f9df3abdfe936c03e53b71d4"}, {"filename": "who.out", "mode": "text", "hash": "d5c25156c301c14125aaa5d1e8f5adbb"}, {"filename": "whotext", "mode": "text", "hash": "cbe28a0722637d2ea2c07378eba2206e"}]
Loading
Loading