1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-06-19 00:17:51 +02:00

added zipinfo.py nested version

This commit is contained in:
Matt J
2021-12-20 14:29:50 -08:00
parent 46faac1a12
commit bc520fcbcd
2 changed files with 63 additions and 53 deletions

View File

@ -20,7 +20,17 @@ Usage (module):
Schema:
[
{
"archive": [
{
"name": string,
"size": integer,
"size_unit": string,
"number_entries": integer,
"number_files": integer,
"bytes_uncompressed": integer,
"bytes_compressed": integer,
"contents": [
{
"flags": string,
"zipversion": float,
@ -31,37 +41,40 @@ Schema:
"date": string,
"time": string,
"filename": string
"archive": string,
"bytes_compressed": integer,
"bytes_uncompressed": integer,
"number_entries": integer,
"number_files": integer,
"size_unit": string,
}
]
}
]
}
Examples:
$ zipinfo log4j-core-2.16.0.jar | jc --zipinfo -p
[
{
"archive": [
{
"name": "log4j-core-2.16.0.jar",
"size": "1789565",
"size_unit": "bytes,",
"number_entries": "1218",
"number_files": "1218",
"bytes_uncompressed": "3974141",
"bytes_compressed": "1515455",
"contents": [
{
"flags": "-rw-r--r--",
"zipversion": "2.0",
"zipunder": "unx",
"size": "1789565",
"size": "19810",
"type": "bl",
"method": "defN",
"date": "21-Dec-12",
"time": "23:35",
"filename": "META-INF/MANIFEST.MF",
"archive": "log4j-core-2.16.0.jar",
"bytes_compressed": "1515455",
"bytes_uncompressed": "3974141",
"number_entries": "1218",
"number_files": "1218",
"size_unit": "bytes,"
"filename": "META-INF/MANIFEST.MF"
},
...
"""
import jc.utils
import jc.parsers.universal
@ -122,13 +135,12 @@ def parse(data, raw=False, quiet=False):
if jc.utils.has_data(data):
archive_info = {}
contents_list = []
archive_info = []
# 1st line
line = datalist.pop(0)
parsed_line = line.split()
archive = parsed_line[1]
name = parsed_line[1]
# 2nd line
line = datalist.pop(0)
@ -144,22 +156,20 @@ def parse(data, raw=False, quiet=False):
bytes_uncompressed = parsed_line[2]
bytes_compressed = parsed_line[5]
archive_info = {'archive': archive,
'bytes_compressed': bytes_compressed,
'bytes_uncompressed': bytes_uncompressed,
'number_entries': number_entries,
'number_files': number_files,
'size': size,
'size_unit': size_unit}
# Add header row for parsing
datalist[:0] = ['flags zipversion zipunder size type method date time filename']
contents_list = jc.parsers.universal.simple_table_parse(datalist)
for line in contents_list:
line.update(archive_info)
archive_info.append({'name': name,
'size': size,
'size_unit': size_unit,
'number_entries': number_entries,
'number_files': number_files,
'bytes_uncompressed': bytes_uncompressed,
'bytes_compressed': bytes_compressed,
'contents': contents_list})
raw_output = contents_list
raw_output['archive'] = archive_info
return raw_output if raw else _process(raw_output)

File diff suppressed because one or more lines are too long