mirror of
https://codeberg.org/Cyberpro123/AO3-DL.git
synced 2026-07-19 20:55:35 +00:00
101 lines
2.9 KiB
Python
Executable file
101 lines
2.9 KiB
Python
Executable file
#!/usr/bin/env python3
|
|
# This file is part of AOMO, "Archive Of My Own", a collection of Python and PHP
|
|
# scripts designed act as an improved local backup system
|
|
# for works published on https://archiveofourown.org
|
|
#
|
|
# Copyright (c) 2025 Cyberpro123, except where otherwise noted.
|
|
#
|
|
# This project is available under the GNU General Public License (GPL) v2.0,
|
|
# available at https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html
|
|
# or in the 'LICENSE.md' file that should be distributed alongside this one.
|
|
#
|
|
# Report issues to https://codeberg.org/Cyberpro123/AOMO
|
|
# Contact author at cyberpro123@posteo.com
|
|
import os.path
|
|
import shutil
|
|
|
|
import common
|
|
import sql
|
|
|
|
|
|
def dirCopy(
|
|
src: str,
|
|
dst: str,
|
|
) -> str:
|
|
for root, dirs, files in os.walk(src):
|
|
for i in dirs:
|
|
local = os.path.join(root, i)
|
|
target = os.path.join(dst, os.path.relpath(root, src), i)
|
|
if not os.path.exists(target):
|
|
os.mkdir(target)
|
|
for i in files:
|
|
local = os.path.join(root, i)
|
|
target = os.path.join(dst, os.path.relpath(root, src), i)
|
|
common.logger.debug(f"Copying file [{local}] to [{target}]")
|
|
shutil.copyfile(src=local, dst=target)
|
|
return f"Copied directory [{src}] to [{dst}]"
|
|
|
|
|
|
common.init(
|
|
description="Initializes the database, copies AO3 CSS to where other scripts will expect it, and installs the Web UI.",
|
|
all="Non-interactively perform a full installation with Web UI",
|
|
auto="Non-interactively perform a minimal installation without WebUI",
|
|
)
|
|
config = common.config
|
|
|
|
filesdir = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
|
|
|
|
if common.args.all:
|
|
installWebUI = True
|
|
loopNo = 100
|
|
elif common.args.auto:
|
|
installWebUI = False
|
|
loopNo = 100
|
|
else:
|
|
loopNo = 0
|
|
installWebUI = None
|
|
while loopNo < 10:
|
|
loopNo += 1
|
|
inRaw = input(
|
|
"""
|
|
Do you want to do a minimal installation or a full installation?
|
|
[1] Minimal installation
|
|
[2] Full Installation (Also install Web UI)
|
|
"""
|
|
)
|
|
if inRaw.isdecimal():
|
|
match int(inRaw):
|
|
case 1:
|
|
installWebUI = False
|
|
loopNo = 100
|
|
case 2:
|
|
installWebUI = True
|
|
loopNo = 100
|
|
|
|
|
|
filepaths = [
|
|
config["dirRaws"],
|
|
config["dirAo3Css"],
|
|
config["dirImg"],
|
|
os.path.dirname(config["ao3UsernameFile"]),
|
|
os.path.dirname(config["ao3PasswordFile"]),
|
|
os.path.dirname(config["ao3SessionPickle"]),
|
|
]
|
|
if installWebUI:
|
|
filepaths.append(config["dirWebUi"])
|
|
for i in filepaths:
|
|
common.logger.debug(f"Making directory [{i}]")
|
|
os.makedirs(i, exist_ok=True)
|
|
del filepaths
|
|
common.logger.info("Made Directories")
|
|
|
|
|
|
if installWebUI:
|
|
common.logger.info(dirCopy(src=f"{filesdir}/webui/", dst=config["dirWebUi"]))
|
|
|
|
common.logger.info(dirCopy(src=f"{filesdir}/ao3css/", dst=config["dirAo3Css"]))
|
|
|
|
sql.init(config=common.config, logger=common.logger)
|
|
|
|
|
|
common.logger.info("AOMO successfully installed.")
|