Example #1
0
File: cli.py Project: edelgm6/draft
def trim(filename=None):
    """Removes all duplicate spaces from text.
    Acts on every file in project unless filepath argument passed.

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

    Usage:
      >>> draft trim '01-Meeting Ishmael.md'

    """
    settings = get_settings()
    present_warning = settings["warnings"]["trim"]

    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()

        if filename:
            filename = _get_filepath(filename)
        formatter = Formatter(filename)
        formatter.remove_duplicate_spaces()

    click.secho("Duplicate spaces removed.", fg="green")
Example #2
0
File: cli.py Project: edelgm6/draft
def split(filename=None):
    """Splits multi-line sentences into separate lines.
    Affects all project files unless filepath is passed as an argument.

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

    Usage:
      >>> draft split '01-Meeting Ishmael.md'
    """
    settings = get_settings()
    present_warning = settings["warnings"]["split"]

    answer = False
    if present_warning:
        if not filename:
            click.secho(
                "WARNING: You are about to split sentences across the " +
                "entire project tree.",
                fg="red",
                bold=True)
        answer = click.confirm(
            click.style(
                "Highly recommend changes are COMMITed before proceeding. Continue?",
                fg="red",
                bold=True))

    if answer or not present_warning:
        if filename:
            filename = _get_filepath(filename)
        formatter = Formatter(filename)
        formatter.split_sentences()

        click.secho("Sentence split complete.", fg="green")
Example #3
0
    def test_split_sentences_in_full_project(self):
        fp = open("project/testfile.md", "w+")
        fp.write(
            "\"It's the end of the world as we know it.\" \"And I feel fine.\""
        )
        fp.write(" \"You are nice!\" she said.")
        fp.close()
        formatter = Formatter(None)
        formatter.split_sentences()

        fp = open("project/testfile.md", "r")

        lines = fp.readlines()
        fp.close()

        self.assertEqual(lines[0],
                         "\"It's the end of the world as we know it.\"\n")
        self.assertEqual(lines[1], "\"And I feel fine.\"\n")
        self.assertEqual(lines[2], "\"You are nice!\" she said.")
        self.assertEqual(len(lines), 3)

        fp = open("project/testfile1.md", "w+")
        fp.write("It's the end of the world as we know it. And I feel fine.")
        fp.close()
        formatter = Formatter(None)
        formatter.split_sentences()

        fp = open("project/testfile1.md", "r")
        lines = fp.readlines()
        fp.close()

        self.assertEqual(lines[0],
                         "It's the end of the world as we know it.\n")
        self.assertEqual(lines[1], "And I feel fine.")
        self.assertEqual(len(lines), 2)
Example #4
0
    def test_split_sentences_on_question_mark(self):

        fp = open("testfile.txt", "w+")
        fp.write("It's the end of the world as we know it? And I feel fine.")
        fp.close()
        formatter = Formatter(fp.name)
        formatter.split_sentences()

        fp = open("testfile.txt", "r")
        lines = fp.readlines()
        fp.close()

        self.assertEqual(lines[0],
                         "It's the end of the world as we know it?\n")
        self.assertEqual(lines[1], "And I feel fine.")
        self.assertEqual(len(lines), 2)
Example #5
0
    def test_split_sentences_skips_already_split_file(self):
        fp = open("project/testfile.md", "w+")
        fp.write(
            'She blushed-automatically conferring on me the social poise I\'d\nbeen missing. "Well. Most of the Americans I\'ve seen act like\nanimals. They\'re forever punching one another about, and insulting\neveryone, and--You know what one of them did?"\nI shook my head.\n"One of them threw an empty whiskey bottle through my aunt\'s\nwindow. Fortunately, the window was open. But does that sound\nvery intelligent to you?"\nIt didn\'t especially, but I didn\'t say so. I said that many soldiers, all\nover the world, were a long way from home, and that few of them\nhad had many real advantages in life. I said I\'d thought that most\npeople could figure that out for themselves.\n'
        )
        fp.close()
        formatter = Formatter(None)
        formatter.split_sentences()

        fp = open("project/testfile.md", "r")
        text = fp.read()
        fp.close()

        self.assertEqual(
            text,
            'She blushed-automatically conferring on me the social poise I\'d\n\nbeen missing.\n"Well.\nMost of the Americans I\'ve seen act like\n\nanimals.\nThey\'re forever punching one another about, and insulting\n\neveryone, and--You know what one of them did?"\n\nI shook my head.\n\n"One of them threw an empty whiskey bottle through my aunt\'s\n\nwindow.\nFortunately, the window was open.\nBut does that sound\n\nvery intelligent to you?"\n\nIt didn\'t especially, but I didn\'t say so.\nI said that many soldiers, all\n\nover the world, were a long way from home, and that few of them\n\nhad had many real advantages in life.\nI said I\'d thought that most\n\npeople could figure that out for themselves.\n\n'
        )
Example #6
0
    def test_clean_spaces_no_args(self):
        fp = open("project/testfile.md", "w+")
        fp.write(
            "\"     It's the end of the world as  we know it.\" \"And I    feel fine.     \""
        )
        fp.close()
        formatter = Formatter(None)
        formatter.remove_duplicate_spaces()

        fp = open("project/testfile.md", "r")
        lines = fp.readlines()
        fp.close()

        self.assertEqual(
            lines[0],
            "\" It's the end of the world as we know it.\" \"And I feel fine. \""
        )
Example #7
0
    def test_split_sentences_on_abbreviations(self):

        fp = open("testfile.txt", "w+")
        fp.write(
            "It's the end of the world as we know it, etc.? And I feel fine Mrs. Miller, seriously. I.e., don't do anything stupid."
        )
        fp.close()
        formatter = Formatter(fp.name)
        formatter.split_sentences()

        fp = open("testfile.txt", "r")
        lines = fp.readlines()
        fp.close()

        self.assertEqual(lines[0],
                         "It's the end of the world as we know it, etc.?\n")
        self.assertEqual(lines[1], "And I feel fine Mrs. Miller, seriously.\n")
        self.assertEqual(lines[2], "I.e., don't do anything stupid.")
        self.assertEqual(len(lines), 3)
Example #8
0
    def test_split_sentences_on_quotes(self):

        fp = open("testfile.txt", "w+")
        fp.write(
            "\"It's the end of the world as we know it.\" \"And I feel fine.\""
        )
        fp.write(" \"You are nice,\" she said.")
        fp.close()
        formatter = Formatter(fp.name)
        formatter.split_sentences()

        fp = open("testfile.txt", "r")
        lines = fp.readlines()
        fp.close()

        self.assertEqual(lines[0],
                         "\"It's the end of the world as we know it.\"\n")
        self.assertEqual(lines[1], "\"And I feel fine.\"\n")
        self.assertEqual(lines[2], "\"You are nice,\" she said.")
        self.assertEqual(len(lines), 3)