-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathproject.py
More file actions
54 lines (43 loc) · 1.96 KB
/
project.py
File metadata and controls
54 lines (43 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from pathlib import Path
import uuid
from pythonanywhere.api import Webapp
from pythonanywhere.exceptions import SanityException
from pythonanywhere.virtualenvs import Virtualenv
from pythonanywhere.launch_bash_in_virtualenv import launch_bash_in_virtualenv
from pythonanywhere.snakesay import snakesay
class Project:
def __init__(self, domain, python_version):
self.domain = domain
self.python_version = python_version
self.project_path = Path('~/{domain}'.format(domain=domain)).expanduser()
self.virtualenv = Virtualenv(self.domain, self.python_version)
self.wsgi_file_path = Path(
'/var/www/{mangled_domain}_wsgi.py'.format(mangled_domain=domain.replace(".", "_"))
)
self.webapp = Webapp(domain)
def sanity_checks(self, nuke):
self.webapp.sanity_checks(nuke=nuke)
if nuke:
return
if self.virtualenv.path.exists():
raise SanityException(
"You already have a virtualenv for {domain}.\n\n"
"Use the --nuke option if you want to replace it.".format(
domain=self.domain
)
)
if self.project_path.exists():
raise SanityException(
"You already have a project folder at {project_path}.\n\n"
"Use the --nuke option if you want to replace it.".format(
project_path=self.project_path
)
)
def create_webapp(self, nuke):
self.webapp.create(self.python_version, self.virtualenv.path, self.project_path, nuke=nuke)
def add_static_file_mappings(self):
self.webapp.add_default_static_files_mappings(self.project_path)
def start_bash(self):
print(snakesay('Starting Bash shell with activated virtualenv in project directory. Press Ctrl+D to exit.'))
unique_id = str(uuid.uuid4())
launch_bash_in_virtualenv(self.virtualenv.path, unique_id, self.project_path)