Skip to content

Commit

Permalink
feat: Add clear_logs utility function
Browse files Browse the repository at this point in the history
This commit adds a new utility function, `clear_logs()`, that clears the contents of the `logs.log` file on startup. The function is implemented in the `clear_logs.py` file located in the `app/utils` directory. This utility is necessary to ensure that the log file starts with a clean slate each time the application is launched.

- The `clear_logs()` function deletes the contents of the `logs.log` file using the `w` mode of the `open()` function.
- The function is called in the application's initialization file, `__init__.py`, alongside other startup tasks.
- The commit also includes changes to the `.gitignore` file to include `swagger.json` and updates the version number in the `package.json` file to `3.0.4`.

Note: The `compile_swagger()` function in the `compile_swagger.py` file is commented out for now, as its implementation is no longer needed.
  • Loading branch information
realashleybailey committed Aug 25, 2023
1 parent 5ed7d06 commit 55a1374
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ testing/cypress/videos
docker/
delete/
*.backup
swagger.json

# Created by https://www.toptal.com/developers/gitignore/api/pycharm,flask,python
# Edit at https://www.toptal.com/developers/gitignore?templates=pycharm,flask,python
Expand Down
4 changes: 3 additions & 1 deletion app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from .utils.babel_locale import get_locale
from .utils.check_enviroment import check_enviroment
from .utils.compile_swagger import compile_swagger
from .utils.clear_logs import clear_logs

BASE_DIR = path.abspath(path.dirname(__file__))

Expand Down Expand Up @@ -75,7 +76,8 @@
# Clear cache on startup
with app.app_context():
cache.clear()
compile_swagger(api)
clear_logs()
# compile_swagger(api)

# Register Jinja2 filters
register_filters(app)
Expand Down
8 changes: 6 additions & 2 deletions app/configs/settings.json.j2
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,18 @@
"roles": ["moderator", "user"],
"icon": "fas fa-bell",
"url": "/partials/admin/settings/notifications",
"push_url": "/admin/settings/notifications"
"push_url": "/admin/settings/notifications",
"class": "coming-soon",
"disabled": true
},
{
"title": "{{ _('Discord Bot') }}",
"description": "{{ _('Configure Discord bot settings') }}",
"icon": "fab fa-discord",
"url": "/partials/admin/settings/discord-bot",
"push_url": "/admin/settings/discord-bot"
"push_url": "/admin/settings/discord-bot",
"class": "coming-soon",
"disabled": true
}
]
},
Expand Down
2 changes: 1 addition & 1 deletion app/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def scan_users():
info("Scanning for new users")
global_sync_users()

@schedule.task("interval", id="checkForUpdates", minutes=10, misfire_grace_time=900)
@schedule.task("interval", id="checkForUpdates", hours=1, misfire_grace_time=900)
def check_for_updates():
# Import the function here to avoid circular imports
from app.utils.software_lifecycle import need_update
Expand Down
12 changes: 12 additions & 0 deletions app/utils/clear_logs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from flask_restx import Api
from json import dumps
from os import path

def clear_logs():
"""Clear the logs.log file on startup"""
base_dir = path.dirname(path.dirname(path.dirname(path.abspath(__file__))))

# Clear log file contents on startup
if path.exists(path.join(base_dir, "../", "database", "logs.log")):
with open(path.join(base_dir, "../", "database", "logs.log"), "w", encoding="utf-8") as f:
f.write("")
4 changes: 0 additions & 4 deletions app/utils/compile_swagger.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,3 @@ def compile_swagger(api: Api):
with open(path.join(base_dir, "../", "swagger.json"), "w", encoding="utf-8") as f:
f.write(dumps(swagger_data))

# Clear log file contents on startup
if path.exists(path.join(base_dir, "../", "database", "logs.log")):
with open(path.join(base_dir, "../", "database", "logs.log"), "w", encoding="utf-8") as f:
f.write("")
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Wizarr",
"version": "3.0.3",
"version": "3.0.4",
"description": "Wizarr is a web application that allows you to share your media library with your friends and family with ease.",
"scripts": {
"server:start": "APP_URL=127.0.0.1:5000 flask run",
Expand Down
1 change: 0 additions & 1 deletion swagger.json

This file was deleted.

0 comments on commit 55a1374

Please sign in to comment.