Documentation for the casman.parts
package.
CAsMan parts subpackage: unified API for part management.
This init.py exposes the main part management functions, classes, and types.
Part number and barcode generation utilities for CAsMan.
Functions:
get_last_part_number()
- Get the last part number for a given part typegenerate_part_numbers()
- Generate new part numbers for a given part typeInteractive CLI utilities for CAsMan parts management.
Functions:
display_parts_interactive()
- Interactive function to display parts with user inputadd_parts_interactive()
- Interactive function to add new partsmain()
- Main function for command-line usageh()
- No docstring availableDatabase access utilities for CAsMan parts.
Functions:
read_parts()
- Read parts from the database with optional filteringAdvanced search functionality for CAsMan parts.
This module provides enhanced search capabilities for finding parts based on various criteria and patterns.
Functions:
search_parts()
- Advanced search for parts with multiple criteriaget_all_parts()
- Get all parts from the databasesearch_by_prefix()
- Search for parts by prefix (eget_part_statistics()
- Get statistics about parts in the databasefind_part()
- Find a specific part by part numberget_recent_parts()
- Get the most recently created partsPart class and core part functionality for CAsMan.
This module provides the main Part class for representing individual parts and their properties, along with related utility functions.
Functions:
create_part()
- Convenience function to create a Part instanceto_dict()
- Convert part to dictionary representationfrom_dict()
- Create Part instance from dictionaryfrom_database_row()
- Create Part instance from database rowis_valid()
- Check if the part is validget_barcode_filename()
- Get the expected barcode filename for this partupdate_modified_time()
- Update the modified timestamp to current timeClasses:
Part
- Represents a CAsMan part with validation and utility methodsPart validation utilities for CAsMan.
This module provides validation functions for part numbers, part types, and other part-related data integrity checks.
Functions:
validate_part_number()
- Validate a part number formatvalidate_part_type()
- Validate if a part type is supportedvalidate_polarization()
- Validate polarization formatget_part_info()
- Extract part information from a valid part numbernormalize_part_number()
- Normalize a part number to standard formatPart type configuration utilities for CAsMan.
Functions:
load_part_types()
- Load part types from configSignature: get_last_part_number(part_type: str, db_dir: Optional[str]) -> Optional[str]
Get the last part number for a given part type.
Signature: generate_part_numbers(part_type: str, count: int, polarization: str, db_dir: Optional[str]) -> List[str]
Generate new part numbers for a given part type.
Signature: display_parts_interactive() -> None
Interactive function to display parts with user input.
Signature: add_parts_interactive() -> None
Interactive function to add new parts.
Signature: main() -> None
Main function for command-line usage.
Signature: h(char: str, width: int) -> str
No docstring available.
Signature: read_parts(part_type: Optional[str], polarization: Optional[str], db_dir: Optional[str]) -> List[Tuple]
Read parts from the database with optional filtering.
This module provides enhanced search capabilities for finding parts based on various criteria and patterns.
Signature: search_parts(part_type: Optional[str], polarization: Optional[str], part_number_pattern: Optional[str], created_after: Optional[str], created_before: Optional[str], limit: Optional[int], db_dir: Optional[str]) -> List[Part]
Advanced search for parts with multiple criteria.
Parameters:
part_type : Optional[str] Filter by part type (e.g., “ANTENNA”) polarization : Optional[str] Filter by polarization (e.g., “P1”) part_number_pattern : Optional[str] Filter by part number pattern (supports SQL LIKE syntax) created_after : Optional[str] Filter parts created after this date (YYYY-MM-DD format) created_before : Optional[str] Filter parts created before this date (YYYY-MM-DD format) limit : Optional[int] Maximum number of results to return db_dir : Optional[str] Custom database directory
Returns:
List[Part] List of matching Part instances
Signature: get_all_parts(db_dir: Optional[str]) -> List[Part]
Get all parts from the database.
Parameters:
db_dir : Optional[str] Custom database directory
Returns:
List[Part] List of all Part instances
Signature: search_by_prefix(prefix: str, db_dir: Optional[str]) -> List[Part]
Search for parts by prefix (e.g., “ANT”, “LNA”).
Parameters:
prefix : str The part prefix to search for db_dir : Optional[str] Custom database directory
Returns:
List[Part] List of matching Part instances
Signature: get_part_statistics(db_dir: Optional[str]) -> Dict[str, Any]
Get statistics about parts in the database.
Parameters:
db_dir : Optional[str] Custom database directory
Returns:
Dict[str, Any] Dictionary containing part statistics
Signature: find_part(part_number: str, db_dir: Optional[str]) -> Optional[Part]
Find a specific part by part number.
Parameters:
part_number : str The exact part number to find db_dir : Optional[str] Custom database directory
Returns:
Optional[Part] The Part instance if found, None otherwise
Signature: get_recent_parts(count: int, db_dir: Optional[str]) -> List[Part]
Get the most recently created parts.
Parameters:
count : int Number of recent parts to return (default: 10) db_dir : Optional[str] Custom database directory
Returns:
List[Part] List of recently created Part instances
This module provides the main Part class for representing individual parts and their properties, along with related utility functions.
Signature: create_part(part_number: str, **kwargs) -> Part
Convenience function to create a Part instance.
Parameters:
part_number : str The part number **kwargs Additional Part constructor arguments
Returns:
Part New Part instance
Signature: to_dict() -> Dict[str, Any]
Convert part to dictionary representation.
Returns:
Dict[str, Any] Dictionary containing all part properties
@classmethod
Signature: from_dict(cls, data: Dict[str, Any]) -> 'Part'
Create Part instance from dictionary.
Parameters:
data : Dict[str, Any] Dictionary containing part data
Returns:
Part New Part instance
@classmethod
Signature: from_database_row(cls, row: tuple) -> 'Part'
Create Part instance from database row. Assumes row format: (id, part_number, part_type, polarization, date_created, date_modified)
Parameters:
row : tuple Database row tuple
Returns:
Part New Part instance
Signature: is_valid() -> bool
Check if the part is valid.
Returns:
bool True if all part properties are valid
Signature: get_barcode_filename() -> str
Get the expected barcode filename for this part.
Returns:
str Barcode filename (e.g., “ANT-P1-00001.png”)
Signature: update_modified_time() -> None
Update the modified timestamp to current time.
Class: Part
Represents a CAsMan part with validation and utility methods.
This class encapsulates all properties and behaviors of a part, including validation, formatting, and database representation.
Signature: __init__(part_number: str, part_type: Optional[str], polarization: Optional[str], date_created: Optional[str], date_modified: Optional[str]) -> None
Initialize a Part instance.
Parameters:
part_number : str The part number (e.g., “ANT-P1-00001”) part_type : Optional[str] The part type (e.g., “ANTENNA”). If None, extracted from part_number polarization : Optional[str] The polarization (e.g., “P1”). If None, extracted from part_number date_created : Optional[str] Creation timestamp. If None, uses current time date_modified : Optional[str] Modification timestamp. If None, uses current time
Raises:
ValueError If the part number is invalid or incompatible with provided type/polarization
Signature: __str__() -> str
String representation of the part.
Signature: __repr__() -> str
Detailed string representation of the part.
Signature: to_dict() -> Dict[str, Any]
Convert part to dictionary representation.
Returns:
Dict[str, Any] Dictionary containing all part properties
@classmethod
Signature: from_dict(cls, data: Dict[str, Any]) -> 'Part'
Create Part instance from dictionary.
Parameters:
data : Dict[str, Any] Dictionary containing part data
Returns:
Part New Part instance
@classmethod
Signature: from_database_row(cls, row: tuple) -> 'Part'
Create Part instance from database row. Assumes row format: (id, part_number, part_type, polarization, date_created, date_modified)
Parameters:
row : tuple Database row tuple
Returns:
Part New Part instance
Signature: is_valid() -> bool
Check if the part is valid.
Returns:
bool True if all part properties are valid
Signature: get_barcode_filename() -> str
Get the expected barcode filename for this part.
Returns:
str Barcode filename (e.g., “ANT-P1-00001.png”)
Signature: update_modified_time() -> None
Update the modified timestamp to current time.
This module provides validation functions for part numbers, part types, and other part-related data integrity checks.
Signature: validate_part_number(part_number: str) -> bool
Validate a part number format. Expected format: {PREFIX}-P{POLARIZATION}-{NUMBER}
Parameters:
part_number : str The part number to validate
Returns:
bool True if the part number is valid, False otherwise
Examples:
Signature: validate_part_type(part_type: str) -> bool
Validate if a part type is supported.
Parameters:
part_type : str The part type to validate
Returns:
bool True if the part type is valid, False otherwise
Signature: validate_polarization(polarization: str) -> bool
Validate polarization format. Valid polarizations: P1, P2, PV (and potentially others)
Parameters:
polarization : str The polarization to validate
Returns:
bool True if the polarization is valid, False otherwise
Signature: get_part_info(part_number: str) -> Optional[Dict[str, str]]
Extract part information from a valid part number.
Parameters:
part_number : str The part number to parse
Returns:
Optional[Dict[str, str]] Dictionary with part info (prefix, type, polarization, number) or None if invalid
Signature: normalize_part_number(part_number: str) -> Optional[str]
Normalize a part number to standard format.
Parameters:
part_number : str The part number to normalize
Returns:
Optional[str] Normalized part number or None if invalid
Signature: load_part_types() -> Dict[int, Tuple[str, str]]
Load part types from config.yaml, parsing keys as int and values as tuple.
Returns:
Dict[int, Tuple[str, str]] Mapping from integer key to (full_name, abbreviation).