Format Registry API
src.core.format_registry
¶
Format Registry for Diabetes Device Data Formats.
This module provides functionality to discover and load device format definitions from the devices directory. It supports dynamic loading of formats and maintains a registry of available formats for use in format detection.
The registry
- Recursively scans the devices directory
- Validates format definitions
- Provides access to available formats
- Handles format loading errors gracefully
Example
registry = FormatRegistry() formats = registry.formats xdrip_format = registry.get_format("xdrip_sqlite")
logger = logging.getLogger(__name__)
module-attribute
¶
parser = argparse.ArgumentParser(description='Diabetes Data Format Detection Tool')
module-attribute
¶
args = parser.parse_args()
module-attribute
¶
registry = FormatRegistry()
module-attribute
¶
file_path = Path(args.file_path)
module-attribute
¶
matching_formats = registry.get_formats_for_file(file_path)
module-attribute
¶
status = 'primary' if col.is_primary else 'secondary'
module-attribute
¶
FormatRegistry
¶
Registry for device formats that dynamically loads from devices directory.
The registry maintains a collection of device formats and provides methods to
- Load formats from the devices directory
- Validate format definitions
- Access registered formats
- Filter formats by file type or data type
Attributes:
Name | Type | Description |
---|---|---|
formats | List[DeviceFormat] | List of all registered formats |
Example
registry = FormatRegistry() sqlite_formats = registry.get_formats_by_type(FileType.SQLITE) cgm_formats = registry.get_formats_with_data_type(DataType.CGM)
Source code in src/core/format_registry.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 |
|
_formats: Dict[str, DeviceFormat] = {}
instance-attribute
¶
formats: List[DeviceFormat]
property
¶
Get list of all registered formats.
Returns:
Type | Description |
---|---|
List[DeviceFormat] | List of all registered DeviceFormat instances |
__init__()
¶
Initialize the format registry and load available formats.
_load_formats() -> None
¶
Load all format definitions from the devices directory structure.
Raises:
Type | Description |
---|---|
FileAccessError | If manufacturers directory cannot be accessed |
FormatLoadingError | If there's an error loading format files |
Source code in src/core/format_registry.py
_load_format_file(path: Path) -> None
¶
Load and process a single format definition file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path | Path | Path to the format definition file | required |
Raises:
Type | Description |
---|---|
FormatLoadingError | If there's an error loading the file |
Source code in src/core/format_registry.py
_validate_and_register_format(format_def: DeviceFormat, source_file: Path) -> None
¶
Validate and register a format definition.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
format_def | DeviceFormat | The format definition to validate and register | required |
source_file | Path | Path to the source file (for error reporting) | required |
Raises:
Type | Description |
---|---|
FormatValidationError | If the format fails validation |
Source code in src/core/format_registry.py
get_format(name: str) -> Optional[DeviceFormat]
¶
Get a specific format by name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name | str | Name of the format to retrieve | required |
Returns:
Type | Description |
---|---|
Optional[DeviceFormat] | The requested DeviceFormat or None if not found |
Source code in src/core/format_registry.py
get_formats_by_type(file_type: FileType) -> List[DeviceFormat]
¶
Get all formats that handle a specific file type.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_type | FileType | The file type to filter by | required |
Returns:
Type | Description |
---|---|
List[DeviceFormat] | List of formats that support the specified file type |
Source code in src/core/format_registry.py
get_formats_for_file(path: Path) -> List[DeviceFormat]
¶
Get all formats that could match this file based on extension.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path | Path | Path to the file to check | required |
Returns:
Type | Description |
---|---|
List[DeviceFormat] | List of potential matching formats |
Raises:
Type | Description |
---|---|
FileExtensionError | If file extension is not supported |
Source code in src/core/format_registry.py
get_formats_with_data_type(data_type: DataType) -> List[DeviceFormat]
¶
Get all formats that contain a specific data type.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_type | DataType | The data type to filter by | required |
Returns:
Type | Description |
---|---|
List[DeviceFormat] | List of formats that contain the specified data type |
Source code in src/core/format_registry.py
get_available_data_types() -> Set[DataType]
¶
Get all data types available across all formats.
Returns:
Type | Description |
---|---|
Set[DataType] | Set of all available data types |