Skip to content

Commit dcb6bb0

Browse files
committed
Re-config cherrypy app
1 parent bf90c84 commit dcb6bb0

File tree

15 files changed

+119
-53
lines changed

15 files changed

+119
-53
lines changed

cherrypy-bootstrap/entrypoint.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
3+
python src/cherrypy_bootstrap/main.py
4+

cherrypy-bootstrap/poetry.lock

Lines changed: 16 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cherrypy-bootstrap/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ packages = [{include = "cherrypy_bootstrap", from = "src"}]
1010
python = "^3.12"
1111
cherrypy = "^18.9.0"
1212
jinja2 = "^3.1.3"
13+
cherrypy-jinja2 = "^2.2"
1314

1415

1516
[build-system]
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import sys
2+
import pathlib
3+
4+
APP_DIR = str(pathlib.Path(__file__).absolute().parent)
5+
6+
sys.path.append(APP_DIR)

cherrypy-bootstrap/src/cherrypy_bootstrap/config.py

Lines changed: 0 additions & 43 deletions
This file was deleted.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import pathlib
2+
3+
4+
APP_DIR = pathlib.Path(__file__).parents[1].absolute()
5+
6+
TEMPLATE_DIR = APP_DIR.joinpath('templates')
7+
8+
STATIC_ROOTDIR = APP_DIR.joinpath('static')
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
from .base import *
2+
3+
config = {
4+
# Global configuration
5+
'global' : {
6+
'server.socket_host' : '127.0.0.1',
7+
'server.socket_port' : 8080,
8+
'server.thread_pool' : 8,
9+
'log.screen': True,
10+
# 'log.access_file': './logs/access.log',
11+
# 'log.error_file': './logs/error.log',
12+
13+
# Engine
14+
'engine.autoreload.on' : True,
15+
16+
# Static files
17+
'tools.staticdir.root': STATIC_ROOTDIR,
18+
'tools.trailing_slash.on' : False,
19+
20+
# Session
21+
'tools.sessions.on': True,
22+
'tools.sessions.storage_type': 'file',
23+
'tools.sessions.storage_path': './sessions',
24+
'tools.sessions.timeout': 60,
25+
26+
},
27+
28+
# Application configuration
29+
'/static' : {
30+
'tools.staticdir.on' : True,
31+
'tools.staticdir.content_types': {
32+
'jpg': 'image/jpeg',
33+
'png': 'image/png',
34+
'gif': 'image/gif',
35+
'css': 'text/css',
36+
'js': 'application/javascript',
37+
},
38+
}
39+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
from .base import *
2+
3+
4+
config = {
5+
'global': {
6+
'server.socket_host': '0.0.0.0',
7+
'server.socket_port': 80,
8+
'server.thread_pool': 100,
9+
'server.environment': 'production',
10+
'engine.autoreload.on': False,
11+
'log.screen': False,
12+
'log.access_file': '/var/log/cherrypy/access.log',
13+
'log.error_file': '/var/log/cherrypy/error.log',
14+
'tools.staticdir.root': STATIC_ROOTDIR,
15+
'tools.sessions.on': True,
16+
'tools.sessions.storage_type': 'file',
17+
'tools.sessions.storage_path': '/var/lib/cherrypy/sessions',
18+
'tools.sessions.timeout': 3600,
19+
20+
# Templates
21+
'tools.jinja2.on': True,
22+
'tools.jinja2.template_dir': TEMPLATE_DIR
23+
},
24+
'/static': {
25+
'tools.staticdir.on': True,
26+
'tools.staticdir.content_types': {
27+
'jpg': 'image/jpeg',
28+
'png': 'image/png',
29+
'gif': 'image/gif',
30+
'css': 'text/css',
31+
'js': 'application/javascript',
32+
},
33+
},
34+
}

cherrypy-bootstrap/src/cherrypy_bootstrap/entrypoint.sh

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import cherrypy
22

3-
from src.cherrypy_bootstrap import config
4-
from src.cherrypy_bootstrap.application import controllers
3+
from cherrypy_bootstrap.config import development
4+
from cherrypy_bootstrap.myapp import controllers
55

66

77
if __name__ == "__main__":
88
cherrypy.tree.mount(
99
controllers.CherryApp(),
1010
"/",
11-
config=config.app_config
11+
config=development.config
1212
)
13+
cherrypy.engine.start()
14+
cherrypy.engine.block()

cherrypy-bootstrap/src/cherrypy_bootstrap/application/controllers.py renamed to cherrypy-bootstrap/src/cherrypy_bootstrap/myapp/controllers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import cherrypy
22

3-
from src.cherrypy_bootstrap.utilities import render
3+
from cherrypy_bootstrap.utilities import render
44

55

66
class CherryApp(object):

cherrypy-bootstrap/src/cherrypy_bootstrap/templates/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ <h1>Welcome to CherryPy Bootstrap5 App</h1>
99
<a href="#" class="btn btn-light btn-lg">Learn More</a>
1010
</div>
1111
</header>
12-
{% endblock %}
12+
{% endblock %}
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
import cherrypy
12
from jinja2 import Environment, FileSystemLoader
3+
from cherrypy_bootstrap.config.base import TEMPLATE_DIR
4+
5+
env = Environment(loader=FileSystemLoader(TEMPLATE_DIR))
26

37

48
def render(template_name, **kwargs):
5-
env = Environment(loader=FileSystemLoader("./templates"))
69
template = env.get_template(template_name)
710
return template.render(**kwargs)

0 commit comments

Comments
 (0)