feat: add site prefix column to device and rack tables
- derive prefix from the first word of the site name - display prefix as the first data column - support NetBox 4.6.5 through 4.6.x - add packaging, installation documentation, and tests
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
import ast
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
MODULE = Path(__file__).parents[1] / "netbox_site_prefix" / "tables.py"
|
||||
|
||||
|
||||
def _load_first_word():
|
||||
"""Load the pure helper without requiring a local NetBox installation."""
|
||||
module = ast.parse(MODULE.read_text(encoding="utf-8"))
|
||||
function = next(
|
||||
node for node in module.body
|
||||
if isinstance(node, ast.FunctionDef) and node.name == "first_word"
|
||||
)
|
||||
namespace = {}
|
||||
exec(compile(ast.Module(body=[function], type_ignores=[]), str(MODULE), "exec"), namespace)
|
||||
return namespace["first_word"]
|
||||
|
||||
|
||||
def test_first_word():
|
||||
first_word = _load_first_word()
|
||||
|
||||
assert first_word("Berlin Campus West") == "Berlin"
|
||||
assert first_word(" DC01\tFrankfurt ") == "DC01"
|
||||
|
||||
|
||||
def test_first_word_handles_missing_or_blank_value():
|
||||
first_word = _load_first_word()
|
||||
|
||||
assert first_word(None) is None
|
||||
assert first_word(" ") is None
|
||||
|
||||
Reference in New Issue
Block a user