feat: support login
- migrate old API into typescript but not finished (only webLogin works now) - seperate the logger of backend due to the shitty behavior of Flask (change logging level)
This commit is contained in:
@@ -1,12 +1,14 @@
|
||||
import sys
|
||||
import logging
|
||||
from argparse import ArgumentParser
|
||||
from typing import cast
|
||||
from pathlib import Path
|
||||
|
||||
import server
|
||||
import config
|
||||
import utils
|
||||
import database
|
||||
import logger
|
||||
from logger import LOGGER, LoggerLevel
|
||||
|
||||
|
||||
def GetUsernamePassword() -> tuple[str, str]:
|
||||
@@ -26,15 +28,10 @@ def GetUsernamePassword() -> tuple[str, str]:
|
||||
|
||||
return (username, password)
|
||||
|
||||
|
||||
def SetLoggingStyle(level: int) -> None:
|
||||
logging.basicConfig(format="[%(levelname)s] %(message)s", level=level)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Set as INFO level in default first,
|
||||
# and we will change it once we load the configuration file.
|
||||
SetLoggingStyle(logging.INFO)
|
||||
logger.set_level(LoggerLevel.INFO)
|
||||
|
||||
# Receive arguments
|
||||
parser = ArgumentParser(
|
||||
@@ -60,21 +57,21 @@ if __name__ == "__main__":
|
||||
args = parser.parse_args()
|
||||
|
||||
# Show splash
|
||||
logging.info("Coconut-leaf")
|
||||
logging.info("A light, self-host and multi-account calendar system")
|
||||
logging.info("Project: https://github.com/yyc12345/coconut-leaf")
|
||||
logging.info("===================")
|
||||
LOGGER.info("Coconut-leaf")
|
||||
LOGGER.info("A light, self-host and multi-account calendar system")
|
||||
LOGGER.info("Project: https://github.com/yyc12345/coconut-leaf")
|
||||
LOGGER.info("===================")
|
||||
|
||||
# Load config file
|
||||
try:
|
||||
config.setup_config(cast(Path, args.config))
|
||||
except Exception as e:
|
||||
logging.critical(f"Error loading config file: {e}")
|
||||
LOGGER.critical(f"Error loading config file: {e}")
|
||||
sys.exit(1)
|
||||
|
||||
# Change logging level again according to whether enable debug mode
|
||||
logging_level = logging.DEBUG if config.get_config().others.debug else logging.INFO
|
||||
SetLoggingStyle(logging_level)
|
||||
logging_level = LoggerLevel.DEBUG if config.get_config().others.debug else LoggerLevel.INFO
|
||||
logger.set_level(logging_level)
|
||||
|
||||
# Initialize the calendar system if needed
|
||||
if cast(bool, args.init):
|
||||
@@ -83,5 +80,5 @@ if __name__ == "__main__":
|
||||
calendar.init(*gotten_data)
|
||||
calendar.close()
|
||||
|
||||
logging.info("Staring server...")
|
||||
LOGGER.info("Staring server...")
|
||||
server.run()
|
||||
|
||||
Reference in New Issue
Block a user