mirror of
https://gitlab.com/crafty-controller/crafty-4.git
synced 2024-08-30 18:23:09 +00:00
Merge branch 'feature/crafty-version-check' into 'dev'
Add version checking helper and notices See merge request crafty-controller/crafty-4!411
This commit is contained in:
commit
a454632ef1
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
## --- [4.0.8] - 2022/TBD
|
## --- [4.0.8] - 2022/TBD
|
||||||
### New features
|
### New features
|
||||||
TBD
|
- Add Crafty Version Check and notification ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/411))
|
||||||
### Bug fixes
|
### Bug fixes
|
||||||
- Fix SU status not sticking on user creation ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/410))
|
- Fix SU status not sticking on user creation ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/410))
|
||||||
- Handle Missing Java From Win Registry ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/413))
|
- Handle Missing Java From Win Registry ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/413))
|
||||||
|
@ -20,6 +20,7 @@ import itertools
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from socket import gethostname
|
from socket import gethostname
|
||||||
from contextlib import redirect_stderr, suppress
|
from contextlib import redirect_stderr, suppress
|
||||||
|
from packaging import version as pkg_version
|
||||||
|
|
||||||
from app.classes.shared.null_writer import NullWriter
|
from app.classes.shared.null_writer import NullWriter
|
||||||
from app.classes.shared.console import Console
|
from app.classes.shared.console import Console
|
||||||
@ -75,6 +76,7 @@ class Helpers:
|
|||||||
|
|
||||||
self.websocket_helper = WebSocketHelper(self)
|
self.websocket_helper = WebSocketHelper(self)
|
||||||
self.translation = Translation(self)
|
self.translation = Translation(self)
|
||||||
|
self.update_available = False
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def auto_installer_fix(ex):
|
def auto_installer_fix(ex):
|
||||||
@ -82,6 +84,29 @@ class Helpers:
|
|||||||
print(f"Import Error: Unable to load {ex.name} module")
|
print(f"Import Error: Unable to load {ex.name} module")
|
||||||
installer.do_install()
|
installer.do_install()
|
||||||
|
|
||||||
|
def check_remote_version(self):
|
||||||
|
"""
|
||||||
|
Check if the remote version is newer than the local version
|
||||||
|
Returning remote version if it is newer, otherwise False.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
# Get tags from Gitlab, select the latest and parse the semver
|
||||||
|
response = get(
|
||||||
|
"https://gitlab.com/api/v4/projects/20430749/repository/tags"
|
||||||
|
)
|
||||||
|
if response.status_code == 200:
|
||||||
|
remote_version = pkg_version.parse(json.loads(response.text)[0]["name"])
|
||||||
|
|
||||||
|
# Get local version data from the file and parse the semver
|
||||||
|
local_version = pkg_version.parse(self.get_version_string())
|
||||||
|
|
||||||
|
if remote_version > local_version:
|
||||||
|
return remote_version
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Unable to check for new crafty version! \n{e}")
|
||||||
|
return False
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def find_java_installs():
|
def find_java_installs():
|
||||||
# If we're windows return oracle java versions,
|
# If we're windows return oracle java versions,
|
||||||
|
@ -3,7 +3,7 @@ import time
|
|||||||
import logging
|
import logging
|
||||||
import threading
|
import threading
|
||||||
import asyncio
|
import asyncio
|
||||||
import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
from tzlocal import get_localzone
|
from tzlocal import get_localzone
|
||||||
from tzlocal.utils import ZoneInfoNotFoundError
|
from tzlocal.utils import ZoneInfoNotFoundError
|
||||||
@ -193,6 +193,14 @@ class TasksManager:
|
|||||||
schedules = HelpersManagement.get_schedules_enabled()
|
schedules = HelpersManagement.get_schedules_enabled()
|
||||||
self.scheduler.add_listener(self.schedule_watcher, mask=EVENT_JOB_EXECUTED)
|
self.scheduler.add_listener(self.schedule_watcher, mask=EVENT_JOB_EXECUTED)
|
||||||
self.scheduler.start()
|
self.scheduler.start()
|
||||||
|
self.check_for_updates()
|
||||||
|
self.scheduler.add_job(
|
||||||
|
self.check_for_updates,
|
||||||
|
"interval",
|
||||||
|
hours=12,
|
||||||
|
id="update_watcher",
|
||||||
|
start_date=datetime.now(),
|
||||||
|
)
|
||||||
# self.scheduler.add_job(
|
# self.scheduler.add_job(
|
||||||
# self.scheduler.print_jobs, "interval", seconds=10, id="-1"
|
# self.scheduler.print_jobs, "interval", seconds=10, id="-1"
|
||||||
# )
|
# )
|
||||||
@ -646,6 +654,16 @@ class TasksManager:
|
|||||||
)
|
)
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
|
def check_for_updates(self):
|
||||||
|
logger.info("Checking for Crafty updates...")
|
||||||
|
self.helper.update_available = self.helper.check_remote_version()
|
||||||
|
if self.helper.update_available:
|
||||||
|
logger.info(f"Found new version {self.helper.update_available}")
|
||||||
|
else:
|
||||||
|
logger.info(
|
||||||
|
"No updates found! You are on the most up to date Crafty version."
|
||||||
|
)
|
||||||
|
|
||||||
def log_watcher(self):
|
def log_watcher(self):
|
||||||
self.controller.servers.check_for_old_logs()
|
self.controller.servers.check_for_old_logs()
|
||||||
self.scheduler.add_job(
|
self.scheduler.add_job(
|
||||||
|
@ -284,7 +284,7 @@ class PanelHandler(BaseHandler):
|
|||||||
|
|
||||||
page_data: t.Dict[str, t.Any] = {
|
page_data: t.Dict[str, t.Any] = {
|
||||||
# todo: make this actually pull and compare version data
|
# todo: make this actually pull and compare version data
|
||||||
"update_available": False,
|
"update_available": self.helper.update_available,
|
||||||
"serverTZ": tz,
|
"serverTZ": tz,
|
||||||
"version_data": self.helper.get_version_string(),
|
"version_data": self.helper.get_version_string(),
|
||||||
"user_data": exec_user,
|
"user_data": exec_user,
|
||||||
|
@ -92,6 +92,7 @@ class ServerHandler(BaseHandler):
|
|||||||
template = "public/404.html"
|
template = "public/404.html"
|
||||||
|
|
||||||
page_data = {
|
page_data = {
|
||||||
|
"update_available": self.helper.update_available,
|
||||||
"version_data": self.helper.get_version_string(),
|
"version_data": self.helper.get_version_string(),
|
||||||
"user_data": exec_user,
|
"user_data": exec_user,
|
||||||
"user_role": exec_user_role,
|
"user_role": exec_user_role,
|
||||||
|
@ -1,12 +1,27 @@
|
|||||||
<!-- partial:partials/_footer.html -->
|
<!-- partial:partials/_footer.html -->
|
||||||
<footer class="footer">
|
<footer class="footer">
|
||||||
<div class="container-fluid ">
|
<div class="container-fluid ">
|
||||||
|
<span class="text-muted d-block text-center text-sm-left d-sm-inline-block">{{ translate('footer', 'copyright', data['lang']) }} © 2021 - <span x-data x-text="new Date().getFullYear()"></span> <a href="https://craftycontrol.com/" target="_blank">Crafty Controller</a>. {{ translate('footer', 'allRightsReserved', data['lang']) }}.</span>
|
||||||
<span class="text-muted d-block text-center text-sm-left d-sm-inline-block">{{ translate('footer', 'copyright', data['lang']) }} © 2021 - <span x-data x-text="new Date().getFullYear()"></span> <a href="https://craftycontrol.com/" target="_blank">Crafty Controller</a>. {{ translate('footer', 'allRightsReserved', data['lang']) }}.</span>
|
<span class="float-none float-sm-right d-block mt-1 mt-sm-0"> {{ translate('footer', 'version', data['lang']) }}: {{ data['version_data'] }}</span>
|
||||||
|
{% if data['update_available'] %}
|
||||||
<span class="float-none float-sm-right d-block mt-1 mt-sm-0 text-center">{{ translate('footer', 'version', data['lang']) }}: {{ data['version_data'] }}
|
<span class="float-none float-sm-right d-block mt-1 mt-sm-0"><a target="_blank" class="blink-text" href="https://gitlab.com/crafty-controller/crafty-4/-/releases">Update Available!</a></span>
|
||||||
</span>
|
{% end %}
|
||||||
</div>
|
</div>
|
||||||
|
<style>
|
||||||
|
a:hover {
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
.blink-text{
|
||||||
|
color: #000;
|
||||||
|
font-weight: bold;
|
||||||
|
font-size: 2rem;
|
||||||
|
animation: blinkingText 2s infinite;
|
||||||
|
}
|
||||||
|
@keyframes blinkingText{
|
||||||
|
0% { color: grey;}
|
||||||
|
50% { color: red;}
|
||||||
|
100% { color: grey;}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
</footer>
|
</footer>
|
||||||
<!-- partial -->
|
<!-- partial -->
|
||||||
|
16
main.py
16
main.py
@ -7,8 +7,9 @@ import argparse
|
|||||||
import logging.config
|
import logging.config
|
||||||
import signal
|
import signal
|
||||||
import peewee
|
import peewee
|
||||||
from app.classes.shared.file_helpers import FileHelpers
|
from packaging import version as pkg_version
|
||||||
|
|
||||||
|
from app.classes.shared.file_helpers import FileHelpers
|
||||||
from app.classes.shared.import3 import Import3
|
from app.classes.shared.import3 import Import3
|
||||||
from app.classes.shared.console import Console
|
from app.classes.shared.console import Console
|
||||||
from app.classes.shared.helpers import Helpers
|
from app.classes.shared.helpers import Helpers
|
||||||
@ -225,6 +226,19 @@ if __name__ == "__main__":
|
|||||||
controller_setup_thread.join()
|
controller_setup_thread.join()
|
||||||
|
|
||||||
Console.info("Crafty has fully started and is now ready for use!")
|
Console.info("Crafty has fully started and is now ready for use!")
|
||||||
|
|
||||||
|
# Check if new version available
|
||||||
|
remote_ver = helper.check_remote_version()
|
||||||
|
if remote_ver:
|
||||||
|
notice = f"""
|
||||||
|
A new version of Crafty is available!
|
||||||
|
{'/' * 37}
|
||||||
|
New version available: {remote_ver}
|
||||||
|
Current version: {pkg_version.parse(helper.get_version_string())}
|
||||||
|
{'/' * 37}
|
||||||
|
"""
|
||||||
|
Console.yellow(notice)
|
||||||
|
|
||||||
crafty_prompt.prompt = f"Crafty Controller v{helper.get_version_string()} > "
|
crafty_prompt.prompt = f"Crafty Controller v{helper.get_version_string()} > "
|
||||||
try:
|
try:
|
||||||
logger.info("Removing old temp dirs")
|
logger.info("Removing old temp dirs")
|
||||||
|
Loading…
Reference in New Issue
Block a user