def cmd_serve():
    print("Serving book...")
    filenameArray = glob.glob(
        os.path.dirname(os.path.realpath(__file__)) + "/*.html")
    filebufferString = ""

    for filenameString in filenameArray:
        newfilenameString = os.path.basename(filenameString)
        chapternameString = os.path.splitext(newfilenameString)[0]
        chapternameString = chapternameString.replace("-", " ", 1)
        chapternameString = chapternameString.capitalize()
        filebufferString += "<h1>" + chapternameString + "</h1>"
        filecontentsString = codecs.open(newfilenameString, "r",
                                         "utf-8").read()
        filebufferString += markdown.markdown(filecontentsString)
        filebufferString += "<hr/>"
    filebufferString += "<center><h1>THE END!</h1></center>"
    filebufferString = augment(filebufferString)
    reviewfileFile = codecs.open("review-book.html", "w", "utf-8")
    reviewfileFile.write(filebufferString)
    reviewfileFile.close()
    webbrowser.open("file://" + os.path.dirname(os.path.realpath(__file__)) +
                    "/review-book.html")
    print(
        "Success! Your book is served. Press RETURN when you are done reviewing it."
    )

    get_input("")
    os.remove("review-book.html")
def cmd_docs():
    print("Serving documentation...")
    docnameString = os.path.dirname(os.path.realpath(__file__)) + "/README.md"

    newdocnameString = os.path.basename(docnameString)
    doccontentsString = codecs.open(newdocnameString, "r", "utf-8").read()
    newdoccontentsString = markdown.markdown(doccontentsString)
    newdoccontentsString = "<!DOCTYPE html><html><head><title>" + "eBooker Documentation" + \
        "</title></head>" + newdoccontentsString + "</body></html>"
    docfileFile = codecs.open("docs.html", "w", "utf-8")
    docfileFile.write(newdoccontentsString)
    docfileFile.close()
    webbrowser.open("file://" + os.path.dirname(os.path.realpath(__file__)) +
                    "/docs.html")
    print(
        "Success! The documentation has been served. Press RETURN when you are done reading it."
    )

    get_input("")
    os.remove("docs.html")
def cmd_exit():
    exitloopBool = True
    while exitloopBool:
        exitBool = get_input("Would you like to quit? (y/n) ")
        if exitBool == "y":
            exitloopBool = False
            clear()
            sys.exit()
        elif exitBool == "n":
            exitloopBool = False
            print("OK, not exited!")
        else:
            print("Please type in \"y\" or  \"n\".")
Exemple #4
0
def cmd_exit():
    exitLoopBool = True
    while exitLoopBool:
        exitBool = get_input("Would you like to quit? (y/n) ")

        if exitBool.lower() == "y":
            clear()
            sys.exit()

        elif exitBool.lower() == "n":
            exitLoopBool = False
            print("OK, not exiting!")

        else:
            print('Please type in "y" or  "n".')
Exemple #5
0
def main():
    while True:
        cmd = get_input("eBooker > ")

        if cmd == "help":
            cmd_help()
        elif cmd == "exit":
            cmd_exit()
        elif cmd == "about":
            cmd_about()
        elif cmd == "edit":
            cmd_edit()
        elif cmd == "serve":
            cmd_serve()
        elif cmd == "clear":
            cmd_clear()
        elif cmd == "debug":
            cmd_debug()
        else:
            print("\"" + cmd +
                  "\" is not a valid command. Type \"help\" for more options")
def cmd_edit():
    editloopBool = True

    while editloopBool:
        editBool = get_input("Would you like to create a new chapter? (y/n) ")

        if editBool == "y":
            editloopBool = False
            print("You want to create a new chapter.")

            while True:
                newfileString = get_input(
                    "What would you like the chapter number to be? ")
                if (newfileString
                        == "") or (newfileString is None) or (newfileString
                                                              == " "):
                    print("You must enter a chapter number.")
                else:
                    try:
                        newfileString = int(newfileString)
                        break
                    except ValueError:
                        print("You must enter a number.")

            print("Creating file...")

            newfileFile = codecs.open(
                "chapter-" + str(newfileString) + ".html", "a", "utf-8")
            newfileFile.write(
                "Press CTRL-O then hit return to save. Press CTRL-X to exit.\n"
            )
            newfileFile.write(
                "Don't worry if you can't see part of your lines; they will\n")

            newfileFile.write("be saved anyway.")
            newfileFile.close()

            print("Your file is created!")

            open_editor("chapter-" + str(newfileString) + ".html")

            print("If you got an error, use the \"debug\" command.")

        elif editBool == "n":
            editloopBool = False
            print("You want to edit an existing chapter!")

            while True:
                editfileString = get_input(
                    "Please type in the chapter number. ")
                if (editfileString
                        == "") or (editfileString is None) or (editfileString
                                                               == " "):
                    print("You must enter a chapter number.")
                else:
                    try:
                        editfileString = int(editfileString)
                        break
                    except ValueError:
                        print("You must enter a number.")

            print("Opening file for editing...")

            open_editor("chapter-" + str(editfileString) + ".html")

            print("If you got an error, use the \"debug\" command.")

        else:
            print("Please type in \"y\" or  \"n\".")
Exemple #7
0
def main():
    while True:
        cmd = get_input("eBooker > ")
        run_command(cmd)
Exemple #8
0
def cmd_edit():
    editLoopBool = True

    while editLoopBool:
        editBool = get_input(
            "Would you like to create a new chapter? (y/n) ").lower()

        if editBool == "y":
            editLoopBool = False
            print("You want to create a new chapter.")

            while True:
                newChapterNumber = get_input(
                    "What would you like the chapter number to be? ")
                try:
                    newChapterNumber = int(newChapterNumber)
                    break

                except (TypeError, ValueError):
                    print("You must enter a number.")

            print("Creating file...")

            newChapterFile = codecs.open(
                "chapter-" + str(newChapterNumber) + ".html", "a", "utf-8")
            newChapterFile.write(
                "Press CTRL-O then hit return to save. Press CTRL-X to exit.\n"
            )
            newChapterFile.write(
                "Don't worry if you can't see part of your lines; they will\n")

            newChapterFile.write("be saved anyway.")
            newChapterFile.close()

            print("Your file is created!")

            open_editor("chapter-" + str(newChapterNumber) + ".html")

            print('If you got an error, use the "debug" command.')

        elif editBool == "n":
            editLoopBool = False
            print("You want to edit an existing chapter!")

            while True:
                editChapterNumber = get_input(
                    "Please type in the chapter number. ")
                try:
                    editChapterNumber = int(editChapterNumber)
                    break

                except (TypeError, ValueError):
                    print("You must enter a number.")

            print("Opening file for editing...")

            open_editor("chapter-" + str(editChapterNumber) + ".html")

            print('If you got an error, use the "debug" command.')

        else:
            print('Please type in "y" or  "n".')