-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#5 draft of the new typer based cli client.
- Loading branch information
1 parent
3340235
commit 182518c
Showing
6 changed files
with
86 additions
and
1 deletion.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,4 +10,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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters