mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-09 09:08:15 -06:00
Closes #15908: Establish canonical & local sources for release info
This commit is contained in:
parent
1952d3e63a
commit
27016ab367
@ -18,6 +18,7 @@ from django.utils.translation import gettext_lazy as _
|
||||
from netbox.config import PARAMS as CONFIG_PARAMS
|
||||
from netbox.constants import RQ_QUEUE_DEFAULT, RQ_QUEUE_HIGH, RQ_QUEUE_LOW
|
||||
from netbox.plugins import PluginConfig
|
||||
from utilities.release import load_release_data
|
||||
from utilities.string import trailing_slash
|
||||
|
||||
|
||||
@ -25,7 +26,8 @@ from utilities.string import trailing_slash
|
||||
# Environment setup
|
||||
#
|
||||
|
||||
VERSION = '4.0.6-dev'
|
||||
RELEASE = load_release_data()
|
||||
VERSION = RELEASE.full_version # Retained for backward compatibility
|
||||
HOSTNAME = platform.node()
|
||||
# Set the base directory two levels up
|
||||
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
|
2
netbox/release.yaml
Normal file
2
netbox/release.yaml
Normal file
@ -0,0 +1,2 @@
|
||||
version: "4.1.0"
|
||||
designation: "dev"
|
@ -188,12 +188,9 @@ Blocks:
|
||||
|
||||
{# Footer text #}
|
||||
<ul class="list-inline list-inline-dots fs-5 mb-0" id="footer-stamp" hx-swap-oob="true">
|
||||
<li class="list-inline-item">
|
||||
{% now 'Y-m-d H:i:s T' %}
|
||||
</li>
|
||||
<li class="list-inline-item">
|
||||
{{ settings.HOSTNAME }} (v{{ settings.VERSION }})
|
||||
</li>
|
||||
<li class="list-inline-item">{% now 'Y-m-d H:i:s T' %}</li>
|
||||
<li class="list-inline-item">{{ settings.HOSTNAME }}</li>
|
||||
<li class="list-inline-item">{{ settings.RELEASE.name }}</li>
|
||||
</ul>
|
||||
{# /Footer text #}
|
||||
|
||||
|
57
netbox/utilities/release.py
Normal file
57
netbox/utilities/release.py
Normal file
@ -0,0 +1,57 @@
|
||||
import datetime
|
||||
import os
|
||||
import yaml
|
||||
from dataclasses import dataclass
|
||||
from typing import Union
|
||||
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
|
||||
RELEASE_PATH = 'release.yaml'
|
||||
LOCAL_RELEASE_PATH = 'local/release.yaml'
|
||||
|
||||
|
||||
@dataclass
|
||||
class ReleaseInfo:
|
||||
version: str
|
||||
edition: str = 'Community'
|
||||
published: Union[datetime.date, None] = None
|
||||
designation: Union[str, None] = None
|
||||
|
||||
@property
|
||||
def full_version(self):
|
||||
if self.designation:
|
||||
return f"{self.version}-{self.designation}"
|
||||
return self.version
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
return f"NetBox {self.edition} v{self.full_version}"
|
||||
|
||||
|
||||
def load_release_data():
|
||||
"""
|
||||
Load any locally-defined release attributes and return a ReleaseInfo instance.
|
||||
"""
|
||||
base_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
|
||||
# Load canonical release attributes
|
||||
with open(os.path.join(base_path, RELEASE_PATH), 'r') as release_file:
|
||||
data = yaml.safe_load(release_file)
|
||||
|
||||
# Overlay any local release date (if defined)
|
||||
try:
|
||||
with open(os.path.join(base_path, LOCAL_RELEASE_PATH), 'r') as release_file:
|
||||
local_data = yaml.safe_load(release_file)
|
||||
except FileNotFoundError:
|
||||
local_data = {}
|
||||
if type(local_data) is not dict:
|
||||
raise ImproperlyConfigured(
|
||||
f"{LOCAL_RELEASE_PATH}: Local release data must be defined as a dictionary."
|
||||
)
|
||||
data.update(local_data)
|
||||
|
||||
# Convert the published date to a date object
|
||||
if 'published' in data:
|
||||
data['published'] = datetime.date.fromisoformat(data['published'])
|
||||
|
||||
return ReleaseInfo(**data)
|
Loading…
Reference in New Issue
Block a user