1
0
Files
coconut-leaf/backend/coconut-leaf.py

77 lines
2.0 KiB
Python
Raw Permalink Normal View History

import sys
import logging
from argparse import ArgumentParser
from typing import cast
from pathlib import Path
import server
import config
import utils
import database
def GetUsernamePassword():
print("What is the first username of this calendar system?")
cache = input()
while not utils.IsValidUsername(cache):
print("Sorry, invalid data. Please try again.")
cache = input()
username = cache
print("Input this user password:")
cache = input()
while not utils.IsValidPassword(cache):
print("Sorry, invalid data. Please try again.")
cache = input()
password = cache
return (username, password)
if __name__ == "__main__":
print("Coconut-leaf")
print("A self-host, multi-account calendar system.")
print("Project: https://github.com/yyc12345/coconut-leaf")
print("===================")
# Receive arguments
parser = ArgumentParser(description="Coconut-leaf")
parser.add_argument(
"-c",
"--config",
required=True,
type=Path,
action="store",
metavar="CONFIG_TOML",
dest="config",
help="The configuration file for coconut-leaf",
)
parser.add_argument(
"-i",
"--init",
action="store_true",
dest="init",
help="Set for initialize the calendar system",
)
args = parser.parse_args()
# Load config file
try:
config.setup_config(cast(Path, args.config))
except Exception as e:
print(f"Error loading config file: {e}")
sys.exit(1)
# Setup logging level
logging_level = logging.DEBUG if config.get_config().others.debug else logging.INFO
logging.basicConfig(format='[%(levelname)s] %(message)s', level=logging_level)
# Initialize the calendar system if needed
if cast(bool, args.init):
gotten_data = GetUsernamePassword()
calendar = database.CalendarDatabase()
calendar.init(*gotten_data)
calendar.close()
logging.info("Staring server...")
server.run()