How to stop python development server from terminal?

岁酱吖の 提交于 2020-07-23 06:55:14

问题


I am writing a my_migration_script.py in the root directory of my django project to remove all the migration files from different apps of my django project. It is like this:

import os
import shutil


migration_folders_names = [
    '/app1/migrations/',
    '/app2/migrations/',
    '/app3/migrations/',
    '/app4/migrations/',
    '/app5/migrations/',
    '/app6/migrations/',
    '/app7/migrations/',
]

cwd = os.getcwd()

migration_folder_paths = [cwd + migration_folder_name for migration_folder_name in migration_folders_names]

[shutil.rmtree(migration_folder_path, ignore_errors=False, onerror=None) for migration_folder_path in migration_folder_paths]

[os.mkdir(migration_folder_path) for migration_folder_path in migration_folder_paths]

[open(migration_folder_path + "__init__.py", "x") for migration_folder_path in migration_folder_paths]

It works fine. I then want to do the following:

1) Stop runserver: I have a tab for running python manage.py runserver in my Pycharm IDE. What I normally do is that I go to the abovementioned terminal tab and hit Ctrl+C . However, I now want to automate it by adding a piece of code to my_migration_script.py . What should I add to my_migration_script.py ?

2) I have a tab for running python manage.py shell in my Pycharm IDE. What I normally do is that I go to the abovementioned terminal tab type and enter exit() . However, I now want to automate it by adding a piece of code to my_migration_script.py . What should I add to my_migration_script.py ?

3) I have a tab for running psql -U postgres in my Pycharm IDE. I then run the following:

CREATE DATABASE myproject OWNER projectuser;
GRANT ALL PRIVILLAGES ON DATABASE myproject to projectuser;
quit

However, I now want to automate it by adding a piece of code to my_migration_script.py . What should I add to my_migration_script.py ?

4) I then go another tab and run:

python manage.py makemigrations

python manage.py migrate

However, I now want to automate it by adding a piece of code to my_migration_script.py . What should I add to my_migration_script.py ?

来源:https://stackoverflow.com/questions/62331129/how-to-stop-python-development-server-from-terminal

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!