use pathlib everywhere
This commit is contained in:
@@ -1,22 +1,15 @@
|
||||
import argparse
|
||||
from pathlib import Path
|
||||
|
||||
from .state import init_state
|
||||
|
||||
|
||||
def read_file(file_path: str) -> str:
|
||||
with open(file_path) as file:
|
||||
return file.read()
|
||||
|
||||
|
||||
def init_config(args: argparse.Namespace) -> None:
|
||||
key = read_file(args.key)
|
||||
certificate = read_file(args.certificate)
|
||||
|
||||
init_state(certificate, key)
|
||||
init_state(args.certificate.read_text(), args.key.read_text())
|
||||
print("Finished initializing moonlight state.")
|
||||
|
||||
|
||||
def register_config_initialization_parser(parser: argparse.ArgumentParser) -> None:
|
||||
parser.add_argument("--certificate")
|
||||
parser.add_argument("--key")
|
||||
parser.add_argument("--certificate", type=Path)
|
||||
parser.add_argument("--key", type=Path)
|
||||
parser.set_defaults(func=init_config)
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import contextlib
|
||||
import os
|
||||
import random
|
||||
import string
|
||||
from configparser import ConfigParser, DuplicateSectionError, NoOptionError
|
||||
@@ -45,12 +44,12 @@ def convert_bytearray_to_string(byte_array: str) -> str:
|
||||
# this must be created before moonlight is first run
|
||||
def init_state(certificate: str, key: str) -> None:
|
||||
print("Initializing moonlight state.")
|
||||
os.makedirs(moonlight_config_dir(), exist_ok=True)
|
||||
moonlight_config_dir().mkdir(parents=True, exist_ok=True)
|
||||
print("Initialized moonlight config directory.")
|
||||
|
||||
print("Writing moonlight state file.")
|
||||
# write the initial bootstrap config file
|
||||
with open(moonlight_state_file(), "w") as file:
|
||||
with moonlight_state_file().open("w") as file:
|
||||
config = ConfigParser()
|
||||
# bytearray ojbects are not supported by ConfigParser,
|
||||
# so we need to adjust them ourselves
|
||||
|
||||
Reference in New Issue
Block a user