示例#1
0
import subprocess
from Helpers import Helpers

print("Where do you want to create files for a new CRUD API?")

filePath = Helpers.confirm_choice(
    "Please enter the full file path for API files: ")

confirm = Helpers.confirm_path(filePath)

if confirm:

    apiName = Helpers.confirm_choice(
        "What is the name of the API you are making?  ")

    print(
        "We are going to create a virtual environment for the API to run in.  Please wait..."
    )
    subprocess.run(
        ["python3", "-m", "venv", filePath + '/' + apiName + "_venv"])

    fullApiPath = filePath + '/' + apiName

    # Replace the placeholders in the API files with passed-in user input
    print("Updating template script file...")

    subprocess.run(["mkdir", fullApiPath])

    subprocess.run(["cp", "Helpers.py", fullApiPath + "/Helpers.py"])
    subprocess.run(["cp", "MongoHelpers.py", fullApiPath + "/MongoHelpers.py"])
    subprocess.run([
示例#2
0
subprocess.run(["chmod", "+x", api_path + "/run.sh"])

print("Updating MongoApi file")
Helpers.update_file(fullApiPath + "/MongoApi.py", fullApiPath + "/MongoApi.py",
                    [{
                        "search": "[apiName]",
                        "replace": api_name
                    }])

print("Updating MongoApiConfig file")
databaseUrl = MongoHelpers.confirm_mongo_db()
databaseName = MongoHelpers.confirm_mongo_db_name(databaseUrl)
databaseTable = MongoHelpers.confirm_mongo_collection_name(
    databaseUrl, databaseName)

apiBroadcastIp = Helpers.confirm_choice(
    "Please enter the IP for the API to broadcast: [ex: 127.0.0.1] ")
apiBroadcastHttp = input("Do you want to use HTTPS? [y/n] ")

if apiBroadcastHttp == "Y" or apiBroadcastHttp == "y":
    apiBroadcastHttp = "https://"
else:
    apiBroadcastHttp = "http://"

apiBroadcastPort = Helpers.confirm_choice(
    "Please enter the port for the API to broadcast: ")

print("Updating __init__ file")
Helpers.update_file(fullApiPath + "/__init__.py", fullApiPath + "/__init__.py",
                    [{
                        "search": "[apiName]",
                        "replace": api_name