Skip to content

Commit 32ee6c7

Browse files
committed
Provide analysis only entry-point
1 parent 28861bd commit 32ee6c7

2 files changed

Lines changed: 94 additions & 1 deletion

File tree

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ dependencies = {file = ["requirements/requirements.txt"]}
3838

3939
[project.scripts]
4040
jsonid = "jsonid.jsonid:main"
41+
jsonida = "jsonid.jsonid:analysis"
4142
momoa = "jsonid.jsonid:main"
4243
json2json = "utils.json2json:main"
4344
json2pronom = "utils.jsonid2pronom:main"

src/jsonid/jsonid.py

Lines changed: 93 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,106 @@ def _get_strategy(args: argparse.Namespace):
9292
return strategy
9393

9494

95+
def analysis() -> None:
96+
"""Secondary entry point for analysis functionality.
97+
98+
Enables us to call analysis from the command line once installed
99+
via PyPi.
100+
"""
101+
parser = argparse.ArgumentParser(
102+
prog="jsonida",
103+
description="JSONID(A)nalysis",
104+
epilog="for more information visit https://github.com/ffdev-info/jsonid",
105+
)
106+
parser.add_argument(
107+
"--debug",
108+
help="use debug loggng",
109+
required=False,
110+
action="store_true",
111+
)
112+
parser.add_argument(
113+
"--nojson",
114+
"-nj",
115+
action="store_true",
116+
required=False,
117+
)
118+
parser.add_argument(
119+
"--nojsonl",
120+
"-njl",
121+
action="store_true",
122+
required=False,
123+
)
124+
parser.add_argument(
125+
"--noyaml",
126+
"-ny",
127+
action="store_true",
128+
required=False,
129+
)
130+
parser.add_argument(
131+
"--notoml",
132+
"-nt",
133+
action="store_true",
134+
required=False,
135+
)
136+
parser.add_argument(
137+
"--language",
138+
help="return results in different languages",
139+
required=False,
140+
)
141+
parser.add_argument(
142+
"--path",
143+
"-p",
144+
help="analyse a file in support of ruleset development and data preservation",
145+
required=False,
146+
type=str,
147+
metavar="PATH",
148+
)
149+
args = parser.parse_args()
150+
151+
if not args.path:
152+
parser.print_help(sys.stderr)
153+
sys.exit()
154+
155+
# Initialize logging.
156+
init_logging(args.debug)
157+
158+
# Attempt lookup in the registry. This should come first as it
159+
# doesn't involve reading files.
160+
_attempt_lookup(args)
161+
162+
# Determine which decode strategy to adopt.
163+
strategy = _get_strategy(args)
164+
if not strategy:
165+
logger.error(
166+
"please ensure there is one remaining decode strategy, e.g. %s",
167+
",".join(decode_strategies),
168+
)
169+
sys.exit(1)
170+
171+
# Enable graceful exit via signal handler...
172+
def signal_handler(*args): # pylint: disable=W0613
173+
logger.info("exiting...")
174+
sys.exit(0)
175+
176+
signal.signal(signal.SIGINT, signal_handler)
177+
178+
if args.path:
179+
asyncio.run(
180+
file_processing.analyse_data(
181+
path=args.path,
182+
strategy=strategy,
183+
)
184+
)
185+
186+
95187
def main() -> None:
96188
"""Primary entry point for this script."""
97189

98190
# pylint: disable=R0912,R0915
99191

100192
parser = argparse.ArgumentParser(
101193
prog="jsonid",
102-
description="proof-of-concept identifier for JSON objects on disk based on identifying valid objects and their key-values",
194+
description="JSON(ID)entification of objects on disk based on identifying valid objects and their key-values",
103195
epilog="for more information visit https://github.com/ffdev-info/jsonid",
104196
)
105197
parser.add_argument(

0 commit comments

Comments
 (0)