Skip to content

Commit

Permalink
Add option to skip guided setup
Browse files Browse the repository at this point in the history
  • Loading branch information
th3-z committed Sep 25, 2019
1 parent 06ab3d1 commit 72dc783
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 7 deletions.
12 changes: 10 additions & 2 deletions magicked_admin/magicked_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import os
import signal
import sys
import argparse

from colorama import init

Expand All @@ -20,12 +21,19 @@

init()

banner()
parser = argparse.ArgumentParser(
description='Killing Floor 2 Magicked Administrator'
)
parser.add_argument('-s', '--skip_setup', action='store_true',
help='Skips the guided setup process')
args = parser.parse_args()

settings = Settings()
banner()
settings = Settings(skip_setup=args.skip_setup)

REQUESTS_CA_BUNDLE_PATH = find_data_file("./certifi/cacert.pem")


if hasattr(sys, "frozen"):
import certifi.core

Expand Down
39 changes: 34 additions & 5 deletions magicked_admin/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
from utils import die, fatal, find_data_file, info
from utils.net import resolve_address

CONFIG_PATH = find_data_file("./conf/magicked_admin.conf")
CONFIG_PATH = find_data_file("conf/magicked_admin.conf")
CONFIG_PATH_DISPLAY = "conf/magicked_admin.conf"

SETTINGS_DEFAULT = {
'server_name': 'server_one',
Expand All @@ -29,16 +30,25 @@


class Settings:

def __init__(self):
def __init__(self, skip_setup=False):
if not os.path.exists(CONFIG_PATH):
info("No configuration was found, first time setup is required!")
print(" Please input your web admin details below.")
config = self.construct_config_interactive()

if not skip_setup:
config = self.construct_config_interactive()
else:
config = self.construct_config_template()

with open(CONFIG_PATH, 'w') as config_file:
config.write(config_file)

if skip_setup:
info("Guided setup was skipped, a template has been generated.")
die(
"Setup is not complete yet, please amend '{}' with your "
"server details.".format(CONFIG_PATH_DISPLAY)
)

try:
self.config = configparser.ConfigParser()
self.config.read(CONFIG_PATH)
Expand Down Expand Up @@ -69,6 +79,7 @@ def sections(self):

@staticmethod
def construct_config_interactive():
print(" Please input your web admin details below.")
new_config = configparser.ConfigParser()
new_config.add_section(SETTINGS_DEFAULT['server_name'])

Expand Down Expand Up @@ -98,6 +109,24 @@ def construct_config_interactive():

return new_config

@staticmethod
def construct_config_template():
new_config = configparser.ConfigParser()
new_config.add_section(SETTINGS_DEFAULT['server_name'])

for setting in SETTINGS_DEFAULT:
new_config.set(SETTINGS_DEFAULT['server_name'], setting,
SETTINGS_DEFAULT[setting])

new_config.set(
SETTINGS_DEFAULT['server_name'],
'address',
"http://localhost:8080"
)
new_config.set(SETTINGS_DEFAULT['server_name'], 'username', "Admin")
new_config.set(SETTINGS_DEFAULT['server_name'], 'password', "123")
return new_config

@staticmethod
def validate_config(config):
sections = config.sections()
Expand Down

0 comments on commit 72dc783

Please sign in to comment.