print local and remote app urls when app host is set to "0.0.0.0"

+ update app version in settings.py
This commit is contained in:
geoffrey45 2023-01-20 22:21:40 +03:00
parent 5dad45f188
commit 3dc9bc1f15
8 changed files with 790 additions and 650 deletions

View File

@ -20,6 +20,12 @@ CREATE TABLE IF NOT EXISTS favorites (
hash text not null,
type text not null
);
CREATE TABLE IF NOT EXISTS settings (
id integer PRIMARY KEY,
root_dirs text NOT NULL,
exclude_dirs text
)
"""
CREATE_APPDB_TABLES = """

50
app/db/sqlite/settings.py Normal file
View File

@ -0,0 +1,50 @@
import json
from app.db.sqlite.utils import SQLiteManager
class SettingsSQLMethods:
"""
Methods for interacting with the settings table.
"""
@staticmethod
def update_root_dirs(dirs: list[str]):
"""
Updates custom root directories in the database.
"""
sql = "UPDATE settings SET root_dirs = ?"
dirs_str = json.dumps(dirs)
with SQLiteManager(userdata_db=True) as cur:
cur.execute(sql, (dirs_str,))
@staticmethod
def get_root_dirs() -> list[str]:
"""
Gets custom root directories from the database.
"""
sql = "SELECT value FROM settings"
with SQLiteManager(userdata_db=True) as cur:
cur.execute(sql)
data = cur.fetchone()
if data is not None:
return json.loads(data[0])
return []
@staticmethod
def update_exclude_dirs(dirs: list[str]):
"""
Updates excluded directories in the database.
"""
sql = "UPDATE settings SET exclude_dirs = ?"
dirs_str = json.dumps(dirs)
with SQLiteManager(userdata_db=True) as cur:
cur.execute(sql, (dirs_str,))

View File

@ -4,7 +4,7 @@ Contains default configs
import multiprocessing
import os
APP_VERSION = "Swing v0.0.1.alpha"
APP_VERSION = "Swing v.1.0.0.beta.1"
# paths
CONFIG_FOLDER = ".swing"

View File

@ -4,6 +4,7 @@ Contains the functions to prepare the server for use.
import os
import shutil
from configparser import ConfigParser
import caribou # pylint: disable=import-error
from app import settings
from app.db.sqlite import create_connection, create_tables, queries
@ -11,7 +12,6 @@ from app.db.store import Store
from app.settings import APP_DB_PATH, USERDATA_DB_PATH
from app.utils import get_home_res_path
config = ConfigParser()
config_path = get_home_res_path("pyinstaller.config.ini")
@ -114,6 +114,19 @@ def setup_sqlite():
create_tables(app_db_conn, queries.CREATE_APPDB_TABLES)
create_tables(playlist_db_conn, queries.CREATE_USERDATA_TABLES)
userdb_migrations = get_home_res_path("app") / "migrations" / "userdata"
maindb_migrations = get_home_res_path("app") / "migrations" / "main"
caribou.upgrade(
APP_DB_PATH,
maindb_migrations,
)
caribou.upgrade(
str(USERDATA_DB_PATH),
str(userdb_migrations),
)
app_db_conn.close()
playlist_db_conn.close()

View File

@ -1,14 +1,17 @@
"""
This module contains mini functions for the server.
"""
import os
import hashlib
from pathlib import Path
import threading
from datetime import datetime
from unidecode import unidecode
import os
import socket as Socket
import hashlib
import threading
import requests
from unidecode import unidecode
from app import models
from app.settings import SUPPORTED_FILES
@ -224,3 +227,15 @@ def get_home_res_path(filename: str):
Returns a path to resources in the home directory of this project. Used to resolve resources in builds.
"""
return (CWD / ".." / filename).resolve()
def get_ip():
"""
Returns the IP address of this device.
"""
soc = Socket.socket(Socket.AF_INET, Socket.SOCK_DGRAM)
soc.connect(("8.8.8.8", 80))
ip_address = str(soc.getsockname()[0])
soc.close()
return ip_address

View File

@ -13,7 +13,7 @@ from app.functions import run_periodic_checks
from app.lib.watchdogg import Watcher as WatchDog
from app.settings import APP_VERSION, HELP_MESSAGE, TCOLOR
from app.setup import run_setup
from app.utils import background, get_home_res_path
from app.utils import background, get_home_res_path, get_ip
werkzeug = logging.getLogger("werkzeug")
werkzeug.setLevel(logging.ERROR)
@ -154,13 +154,21 @@ def start_watchdog():
def log_info():
lines = " -------------------------------------"
lines = " ---------------------------------------"
os.system("cls" if os.name == "nt" else "echo -e \\\\033c")
print(lines)
print(f" {TCOLOR.HEADER}{APP_VERSION} {TCOLOR.ENDC}")
print(
f" Started app on: {TCOLOR.OKGREEN}http://{Variables.FLASK_HOST}:{Variables.FLASK_PORT}{TCOLOR.ENDC}"
)
adresses = [Variables.FLASK_HOST]
if Variables.FLASK_HOST == "0.0.0.0":
adresses = ["localhost", get_ip()]
for address in adresses:
print(
f" Started app on: {TCOLOR.OKGREEN}http://{address}:{Variables.FLASK_PORT}{TCOLOR.ENDC}"
)
print(lines)
print("\n")
@ -180,4 +188,4 @@ if __name__ == "__main__":
# TODO: Find out how to print in color: red for errors, etc.
# TODO: Find a way to verify the host string
# TODO: Organize code in this file: move args to new file, etc.
# TODO: Organize code in this file: move args to new file, etc.

1319
poetry.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -5,7 +5,7 @@ description = ""
authors = ["geoffrey45 <geoffreymungai45@gmail.com>"]
[tool.poetry.dependencies]
python = ">=3.10"
python = ">=3.10,<3.12"
Flask = "^2.0.2"
Flask-Cors = "^3.0.10"
requests = "^2.27.1"
@ -18,11 +18,12 @@ rapidfuzz = "^2.13.7"
tinytag = "^1.8.1"
hypothesis = "^6.56.3"
pytest = "^7.1.3"
pylint = "^2.15.5"
Unidecode = "^1.3.6"
pyinstaller = "^5.7.0"
caribou = "^0.3.0"
[tool.poetry.dev-dependencies]
pylint = "^2.15.5"
black = {version = "^22.6.0", allow-prereleases = true}
[build-system]