From 0de4670e502aa92efee42c430920119ce972f47c Mon Sep 17 00:00:00 2001 From: Jaculabilis Date: Tue, 29 May 2018 13:04:35 -0700 Subject: [PATCH] Implement init command --- lexipython.py | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/lexipython.py b/lexipython.py index 160de7a..9872d5f 100644 --- a/lexipython.py +++ b/lexipython.py @@ -7,6 +7,7 @@ if sys.version_info[0] < 3: import argparse import os +import re def is_lexicon(name): """ @@ -104,7 +105,30 @@ def command_init(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): """