Implement init command

This commit is contained in:
Jaculabilis 2018-05-29 13:04:35 -07:00
parent e1b2d7b96d
commit 0de4670e50
1 changed files with 25 additions and 1 deletions

View File

@ -7,6 +7,7 @@ if sys.version_info[0] < 3:
import argparse import argparse
import os import os
import re
def is_lexicon(name): def is_lexicon(name):
""" """
@ -104,7 +105,30 @@ def command_init(name):
""" """
Sets up a Lexicon game with the given name. Sets up a Lexicon game with the given name.
""" """
pass # Create the folder structure
lex_path = os.path.join("lexicon", name)
os.mkdir(lex_path)
os.mkdir(os.path.join(lex_path, "src"))
os.mkdir(os.path.join(lex_path, "article"))
os.mkdir(os.path.join(lex_path, "contents"))
os.mkdir(os.path.join(lex_path, "formatting"))
os.mkdir(os.path.join(lex_path, "rules"))
os.mkdir(os.path.join(lex_path, "session"))
os.mkdir(os.path.join(lex_path, "statistics"))
# Open the default config file
config = None
with open(os.path.join("src", "resources", "lexicon.cfg")) as def_cfg:
config = def_cfg.read()
# Edit the name field
config = re.sub("Lexicon Title", "Lexicon {}".format(name), config)
# Create the Lexicon's config file
with open(os.path.join(lex_path, "lexicon.cfg"), "w") as config_file:
config_file.write(config)
# Create an example page
with open(os.path.join("src", "resources", "example-page.txt")) as srcfile:
with open(os.path.join(lex_path, "src", "example-page.txt"), "w") as destfile:
destfile.write(srcfile.read())
print("Created Lexicon {}".format(name))
def command_build(name): def command_build(name):
""" """