Example #1
0
    def test_file_tree_hundred(self):
        fp = open("legacy.txt", "w+")
        fp.write("# Gatsby\n")
        fp.write("\n")
        fp.write("## Part 1: The Reckoning\n")
        fp.write("\n")
        fp.write("### Chapter 1: The Promise\n")
        fp.write("\n")
        fp.write("#### New York, 1942\n")

        for scene in range(0, 101):
            fp.write("##### The Bar" + str(scene) + "\n")
            fp.write("\n")
            fp.write("It was a fall day.\n")
            fp.write("It was cold.\n")
        fp.close()

        outliner = Outliner()
        outliner.generate_file_tree("legacy.txt")
        os.remove('settings.yml')

        self.assertTrue(
            os.path.isfile(
                "project/Gatsby/1-Part 1 The Reckoning/1-Chapter 1 The Promise/1-New York 1942/001-The Bar0.md"
            ))
Example #2
0
File: cli.py Project: edelgm6/draft
def parse(filename):
    """Generates a project tree based on a Markdown formatted file.
    Useful for generating project trees based on legacy projects or an outline file.

    Will automatically strip punctuation out of Markdown headers for folder names, but will preserve them in the 'overrides' section of settings.yml for use in compiling.

    :param str filename: Filename (i.e., not the full path) to be parsed (must include extension).
    :return: None

    Usage:
      >>> draft parse mobydick.md
    """
    settings = get_settings()
    present_warning = settings["warnings"]["parse"]

    answer = False
    if present_warning:
        answer = click.confirm(
            click.style(
                "Highly recommend changes are COMMITed before proceeding. Continue?",
                fg="red",
                bold=True))

    if answer or not present_warning:
        generator = Generator()
        generator.confirm_project_layout()

        outliner = Outliner()
        filepath = _get_filepath(filename)
        outliner.generate_file_tree(filepath)

        click.secho("Tree generated.", fg="green")
Example #3
0
    def test_returns_error_if_no_title(self):

        fp = open("legacy.txt", "w+")
        fp.write("## Part 1: The Reckoning\n")
        fp.write("\n")
        fp.write("### Chapter 1: The Promise\n")
        fp.write("\n")
        fp.write("#### New York, 1942\n")
        fp.write("\n")
        fp.write("## Part 2: The Whatever\n")
        fp.write("\n")

        fp.close()

        outliner = Outliner()
        with self.assertRaises(StructureError):
            outliner.generate_file_tree("legacy.txt")
Example #4
0
    def test_existing_settings_not_overwritten(self):
        fp = open("legacy.txt", "w+")
        fp.write("# Gatsby\n")
        fp.write("\n")
        fp.write("## Part 1: The Reckoning\n")
        fp.write("\n")
        fp.write("### Chapter 1: The Promise\n")
        fp.write("\n")
        fp.write("#### New York, 1942\n")
        fp.write("##### The Bar\n")
        fp.write("\n")
        fp.write("It was a fall day.\n")
        fp.write("It was cold.\n")
        fp.close()

        with open("settings.yml", "w+") as settings_file:
            settings_file.write(yaml.dump(get_settings()))

        outliner = Outliner()
        outliner.generate_file_tree("legacy.txt")

        with open("settings.yml", "r") as settings_file:
            settings = yaml.safe_load(settings_file)

        self.assertEqual(
            settings, {
                "author": None,
                "headers": {
                    "chapter": True,
                    "section": True,
                    "sub_chapter": True
                },
                "overrides": {
                    "Chapter 1 The Promise": "Chapter 1: The Promise",
                    "New York 1942": "New York, 1942",
                    "Part 1 The Reckoning": "Part 1: The Reckoning"
                },
                "warnings": {
                    "parse": True,
                    "sequence": True,
                    "split": True,
                    "trim": True
                }
            })

        os.remove("settings.yml")
Example #5
0
    def test_generate_file_tree(self):

        fp = open("legacy.txt", "w+")
        fp.write("# Gatsby\n")
        fp.write("\n")
        fp.write("## Part 1: The Reckoning\n")
        fp.write("\n")
        fp.write("### Chapter 1: The Promise\n")
        fp.write("\n")
        fp.write("#### New York, 1942\n")
        fp.write("\n")
        fp.write("## Part 2: The Whatever\n")
        fp.write("\n")

        fp.write("##### The Bar\n")
        fp.write("\n")
        fp.write("It was a fall day.\n")
        fp.write("It was cold.\n")
        fp.write("## Part 3: Tomorrow\n")
        fp.write("\n")
        fp.write("##### The Next Day\n")
        fp.write("\n")
        fp.write("Now it's tomorrow.\n")
        fp.write("It's still cold.\n")
        fp.write("## Part 4 Test\n")

        fp.close()

        outliner = Outliner()
        outliner.generate_file_tree("legacy.txt")

        self.assertEqual(len(os.listdir("project/Gatsby/")), 4)

        self.assertTrue(os.path.isdir("project/Gatsby/1-Part 1 The Reckoning"))
        self.assertTrue(
            os.path.isdir(
                "project/Gatsby/1-Part 1 The Reckoning/1-Chapter 1 The Promise"
            ))
        self.assertTrue(
            os.path.isdir(
                "project/Gatsby/1-Part 1 The Reckoning/1-Chapter 1 The Promise/1-New York 1942"
            ))
        self.assertTrue(os.path.isdir("project/Gatsby/2-Part 2 The Whatever"))
        self.assertTrue(os.path.isdir("project/Gatsby/3-Part 3 Tomorrow"))
        self.assertTrue(
            os.path.isfile(
                "project/Gatsby/2-Part 2 The Whatever/1-The Bar.md"))

        with open("project/Gatsby/2-Part 2 The Whatever/1-The Bar.md",
                  "r") as fp:
            lines = fp.readlines()
            self.assertEqual(lines[0], "It was a fall day.\n")
            self.assertEqual(lines[1], "It was cold.\n")
            self.assertEqual(len(lines), 2)

        with open("settings.yml", "r") as settings_file:
            settings = yaml.safe_load(settings_file)

        self.assertEqual(
            settings, {
                "overrides": {
                    "Chapter 1 The Promise": "Chapter 1: The Promise",
                    "New York 1942": "New York, 1942",
                    "Part 1 The Reckoning": "Part 1: The Reckoning",
                    "Part 2 The Whatever": "Part 2: The Whatever",
                    "Part 3 Tomorrow": "Part 3: Tomorrow"
                }
            })

        os.remove("settings.yml")
Example #6
0
 def test_non_mdtxt_raises_error(self):
     outliner = Outliner()
     with self.assertRaises(Exception):
         outliner.generate_file_tree("legacy.doc")