58 lines
1.7 KiB
Python
58 lines
1.7 KiB
Python
from . import _env, config
|
|
from argparse import ArgumentParser
|
|
from typing import NamedTuple, Literal
|
|
|
|
class ArgumentTuple(NamedTuple):
|
|
config: str
|
|
action: Literal["gui", "backup", "restore"]
|
|
|
|
def parse_args():
|
|
p = ArgumentParser()
|
|
p.add_argument(
|
|
"-c", "--config",
|
|
dest="config",
|
|
help="Config .toml file path.",
|
|
required=False,
|
|
default="",
|
|
)
|
|
p.set_defaults(action="gui")
|
|
# sub commands
|
|
sps = p.add_subparsers(title="Commands")
|
|
p_gui = sps.add_parser("gui")
|
|
p_gui.set_defaults(action="gui")
|
|
p_backup = sps.add_parser("backup")
|
|
p_backup.set_defaults(action="backup")
|
|
p_restore = sps.add_parser("restore")
|
|
p_restore.set_defaults(action="restore")
|
|
# parse args
|
|
args: ArgumentTuple = p.parse_args() # type: ignore # type: ArgumentTuple
|
|
# load config file
|
|
config.init_default_config()
|
|
if args.config:
|
|
config.apply_user_config(args.config)
|
|
print("Args:", args)
|
|
|
|
async def a_main():
|
|
parse_args()
|
|
print("Config:", config.get_config())
|
|
print("Hello World")
|
|
from .storage.local_storage import LocalStorage
|
|
from .storage.storage import AsyncFileContextManager as FCTX
|
|
from pathlib import PurePosixPath
|
|
cfg = config.get_config()
|
|
stm: config.StorageItem = { "type": "LocalStorageItem", "path": "" }
|
|
for stm in cfg["storage"].values():
|
|
break
|
|
fs = LocalStorage.from_config(stm)
|
|
async for rt in fs.sync_storage():
|
|
print(rt)
|
|
async with FCTX(fs.open(PurePosixPath("app.txt"), "w")) as fp:
|
|
await fp.write(b"Hello Wyvern!")
|
|
await fs.set_last_modify_time(PurePosixPath("app.txt"), 0)
|
|
print(fs.dump_fs_tree())
|
|
|
|
def main():
|
|
import asyncio
|
|
asyncio.run(a_main())
|
|
|