diff --git a/pyproject.toml b/pyproject.toml index b7fe1b5..11f6471 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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" diff --git a/src/jsonid/file_processing.py b/src/jsonid/file_processing.py index 1d083a4..9608f9c 100644 --- a/src/jsonid/file_processing.py +++ b/src/jsonid/file_processing.py @@ -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") diff --git a/src/jsonid/jsonid.py b/src/jsonid/jsonid.py index 0dfa6b8..8928667 100644 --- a/src/jsonid/jsonid.py +++ b/src/jsonid/jsonid.py @@ -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", @@ -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, diff --git a/src/utils/json2json.py b/src/utils/json2json.py index bdbbf21..510a72a 100644 --- a/src/utils/json2json.py +++ b/src/utils/json2json.py @@ -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",