From 0ea4f4eaf675b9a17083e74cae8a3e1974470dae Mon Sep 17 00:00:00 2001 From: Brianna Smart Date: Wed, 21 Aug 2024 11:10:46 -0700 Subject: [PATCH] Add get_schema_id to Schema class --- .../alert/packet/bin/syncAllSchemasToRegistry.py | 1 - python/lsst/alert/packet/schema.py | 13 ++++++++++++- python/lsst/alert/packet/schemaRegistry.py | 2 -- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/python/lsst/alert/packet/bin/syncAllSchemasToRegistry.py b/python/lsst/alert/packet/bin/syncAllSchemasToRegistry.py index c307121..6b75eb6 100644 --- a/python/lsst/alert/packet/bin/syncAllSchemasToRegistry.py +++ b/python/lsst/alert/packet/bin/syncAllSchemasToRegistry.py @@ -23,7 +23,6 @@ import argparse import json -import re import fastavro import requests diff --git a/python/lsst/alert/packet/schema.py b/python/lsst/alert/packet/schema.py index d55c5ad..75d8026 100644 --- a/python/lsst/alert/packet/schema.py +++ b/python/lsst/alert/packet/schema.py @@ -26,11 +26,13 @@ import io import tempfile +import re +import fastavro from importlib import resources from pathlib import PurePath + from lsst.resources import ResourcePath -import fastavro __all__ = ["get_schema_root", "get_latest_schema_version", "get_schema_path", "Schema", "get_path_to_latest_schema", "get_schema_root_uri", @@ -428,3 +430,12 @@ def from_file(cls, filename=None): if schema['name'] == root_name) return cls(schema_definition) + + def get_schema_id(self): + """Retrieve the schema id used in the schema registry. + """ + numbers = re.findall(r'\d+', self.definition['name']) + numbers[1] = str(numbers[1]).zfill(2) + schema_id = int(''.join(numbers)) + + return schema_id diff --git a/python/lsst/alert/packet/schemaRegistry.py b/python/lsst/alert/packet/schemaRegistry.py index 672af94..d47fc46 100644 --- a/python/lsst/alert/packet/schemaRegistry.py +++ b/python/lsst/alert/packet/schemaRegistry.py @@ -22,10 +22,8 @@ """Provide a lookup table for alert schemas. """ -import json import os import re -import zlib __all__ = ["SchemaRegistry"]