diff --git a/cli/__init__.py b/cli/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/cli/django.py b/cli/django.py new file mode 100644 index 0000000..e398de4 --- /dev/null +++ b/cli/django.py @@ -0,0 +1,45 @@ +#!/usr/bin/python3 + +import typer + +from pythonanywhere.django_project import DjangoProject +from pythonanywhere.snakesay import snakesay +from pythonanywhere.utils import ensure_domain + +app = typer.Typer() + + +@app.command() +def autoconfigure( + repo_url: str, + domain_name: str = typer.Option("your-username.pythonanywhere.com", help="Domain name, eg www.mydomain.com"), + python_version: str = typer.Option("3.6", help=""), + nuke: bool = typer.Option( + False, help="*Irrevocably* delete any existing web app config on this domain. Irrevocably." + ), +): + """ + Autoconfigure a Django project from on a github URL. + + \b + - downloads the repo + - creates a virtualenv and installs django (or detects a requirements.txt if available) + - creates webapp via api + - creates django wsgi configuration file + - adds static files config + """ + domain = ensure_domain(domain_name) + project = DjangoProject(domain, python_version) + project.sanity_checks(nuke=nuke) + project.download_repo(repo_url, nuke=nuke), + project.create_virtualenv(nuke=nuke) + project.create_webapp(nuke=nuke) + project.add_static_file_mappings() + project.find_django_files() + project.update_wsgi_file() + project.update_settings_file() + project.run_collectstatic() + project.run_migrate() + project.webapp.reload() + typer.echo(snakesay(f"All done! Your site is now live at https://{domain_name}\n")) + project.start_bash() diff --git a/cli/pa b/cli/pa new file mode 100755 index 0000000..a1affb2 --- /dev/null +++ b/cli/pa @@ -0,0 +1,19 @@ +#!/usr/bin/python3 + +import typer + +from cli import django +from cli import webapp + +help = """This is a new experimental PythonAnywhere cli client. + +It was build with typer & click under the hood. +""" + +app = typer.Typer(help=help) +app.add_typer(webapp.app, name="webapp", help="Everything for web apps") +app.add_typer(django.app, name="django", help="Makes Django Girls tutorial projects deployment easy") + + +if __name__ == "__main__": + app() diff --git a/cli/webapp.py b/cli/webapp.py new file mode 100644 index 0000000..6b5c37e --- /dev/null +++ b/cli/webapp.py @@ -0,0 +1,19 @@ +#!/usr/bin/python3 + +import typer + +from pythonanywhere.api.webapp import Webapp +from pythonanywhere.snakesay import snakesay +from pythonanywhere.utils import ensure_domain + +app = typer.Typer() + + +@app.command() +def reload( + domain_name: str = typer.Option("your-username.pythonanywhere.com", help="Domain name") +): + domain_name = ensure_domain(domain_name) + webapp = Webapp(domain_name) + webapp.reload() + typer.echo(snakesay(f"{domain_name} has been reloaded")) diff --git a/requirements.txt b/requirements.txt index 2b91151..3c5481d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -9,4 +9,5 @@ requests==2.23.0 responses==0.10.14 schema==0.7.2 tabulate==0.8.7 +typer==0.3.2 virtualenvwrapper==4.8.4 diff --git a/setup.py b/setup.py index 60a03c4..7b68639 100644 --- a/setup.py +++ b/setup.py @@ -28,13 +28,14 @@ ], keywords="pythonanywhere api cloud web hosting", packages=["pythonanywhere", "pythonanywhere.api"], - install_requires=["docopt", "python-dateutil", "requests", "schema", "tabulate"], + install_requires=["docopt", "python-dateutil", "requests", "schema", "tabulate", "typer"], extras_require={}, python_requires=">=3.6", package_data={}, data_files=[], entry_points={}, scripts=[ + "cli/pa", "pythonanywhere/snakesay.py", "scripts/pa_autoconfigure_django.py", "scripts/pa_create_scheduled_task.py",