Skip to content

Commit

Permalink
#5 draft of the new typer based cli client.
Browse files Browse the repository at this point in the history
  • Loading branch information
filiplajszczak authored and caseneuve committed Mar 13, 2021
1 parent 3340235 commit 182518c
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 1 deletion.
Empty file added cli/__init__.py
Empty file.
45 changes: 45 additions & 0 deletions cli/django.py
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()
19 changes: 19 additions & 0 deletions cli/pa
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()
19 changes: 19 additions & 0 deletions cli/webapp.py
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"))
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 182518c

Please sign in to comment.