Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ dependencies = {file = ["requirements/requirements.txt"]}

[project.scripts]
jsonid = "jsonid.jsonid:main"
jsonida = "jsonid.jsonid:analysis"
momoa = "jsonid.jsonid:main"
json2json = "utils.json2json:main"

Expand Down
1 change: 1 addition & 0 deletions src/jsonid/file_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ async def analyse_json(paths: list[str], strategy: list):
res = await analysis.analyse_input(base_obj.data, base_obj.content_for_analysis)
res["doctype"] = base_obj.doctype
res["encoding"] = base_obj.encoding
res["agent"] = version.get_agent()
if base_obj.doctype == registry.DOCTYPE_JSONL:
res["compression"] = base_obj.compression
res.pop("content_length")
Expand Down
99 changes: 96 additions & 3 deletions src/jsonid/jsonid.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,107 @@ def _get_strategy(args: argparse.Namespace):
return strategy


def analysis() -> None:
"""Secondary entry point for analysis functionality.

Enables us to call analysis from the command line once installed
via PyPi.
"""
parser = argparse.ArgumentParser(
prog="jsonida",
description="JSONID(A)nalysis",
epilog="for more information visit https://github.com/ffdev-info/jsonid",
)
parser.add_argument(
"--debug",
help="use debug loggng",
required=False,
action="store_true",
)
parser.add_argument(
"--nojson",
"-nj",
action="store_true",
required=False,
)
parser.add_argument(
"--nojsonl",
"-njl",
action="store_true",
required=False,
)
parser.add_argument(
"--noyaml",
"-ny",
action="store_true",
required=False,
)
parser.add_argument(
"--notoml",
"-nt",
action="store_true",
required=False,
)
parser.add_argument(
"--language",
help="return results in different languages",
required=False,
)
parser.add_argument(
"--path",
"-p",
help="analyse a file in support of ruleset development and data preservation",
required=False,
type=str,
metavar="PATH",
)
args = parser.parse_args()

if not args.path:
parser.print_help(sys.stderr)
sys.exit()

# Initialize logging.
init_logging(args.debug)

# Attempt lookup in the registry. This should come first as it
# doesn't involve reading files.
_attempt_lookup(args)

# Determine which decode strategy to adopt.
strategy = _get_strategy(args)
if not strategy:
logger.error(
"please ensure there is one remaining decode strategy, e.g. %s",
",".join(decode_strategies),
)
sys.exit(1)

# Enable graceful exit via signal handler...
def signal_handler(*args): # pylint: disable=W0613
logger.info("exiting...")
sys.exit(0)

signal.signal(signal.SIGINT, signal_handler)

if args.path:
asyncio.run(
file_processing.analyse_data(
path=args.path,
strategy=strategy,
)
)


def main() -> None:
"""Primary entry point for this script."""

# pylint: disable=R0912,R0915

parser = argparse.ArgumentParser(
prog="json-id",
description="proof-of-concept identifier for JSON objects on disk based on identifying valid objects and their key-values",
epilog="for more information visit https://github.com/ffdev-info/json-id",
prog="jsonid",
description="JSON(ID)entification of objects on disk based on identifying valid objects and their key-values",
epilog="for more information visit https://github.com/ffdev-info/jsonid",
)
parser.add_argument(
"--debug",
Expand Down Expand Up @@ -187,6 +279,7 @@ def main() -> None:
parser.add_argument(
"--analyse",
"--analyze",
"--analysis",
"-a",
help="analyse a file in support of ruleset development and data preservation",
required=False,
Expand Down
2 changes: 1 addition & 1 deletion src/utils/json2json.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def main() -> None:
parser = argparse.ArgumentParser(
prog="json2json",
description="parse JSON UTF-16 (BE-LE) objects and output them as UTF-8 for the sake of developer ergonomics",
epilog="for more information visit https://github.com/ffdev-info/json-id",
epilog="for more information visit https://github.com/ffdev-info/jsonid",
)
parser.add_argument(
"--debug",
Expand Down