GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — add configurations. · yumaojun03/blog-python-app@c3d282d

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • www
    • config.py
    • config_default.py
    • config_overwrite.py
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎www/config.py‎

Copy file name to clipboard
+49Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
"""
5+
Configuration
6+
"""
7+
8+
from transwarp.db import Dict
9+
10+
import config_default
11+
12+
13+
def merge(defaults, override):
14+
"""
15+
合并override 和 default 配置文档,返回字典
16+
"""
17+
r = {}
18+
for k, v in defaults.iteritems():
19+
if k in override:
20+
if isinstance(v, dict):
21+
r[k] = merge(v, override[k])
22+
else:
23+
r[k] = override[k]
24+
else:
25+
r[k] = v
26+
return r
27+
28+
29+
def toDict(d):
30+
"""
31+
将一个字典对象转换成 一个Dict对象
32+
"""
33+
D = Dict()
34+
for k, v in d.iteritems():
35+
D[k] = toDict(v) if isinstance(v, dict) else v
36+
return D
37+
38+
configs = config_default.configs
39+
40+
41+
42+
try:
43+
import config_override
44+
configs = merge(configs, config_override.configs)
45+
except ImportError:
46+
pass
47+
48+
configs = toDict(configs)
49+
Collapse file

‎www/config_default.py‎

Copy file name to clipboard
+20Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
5+
"""
6+
Default configurations.
7+
"""
8+
9+
configs = {
10+
'db': {
11+
'host': '127.0.0.1',
12+
'port': 3306,
13+
'user': 'www-data',
14+
'password': 'www-data',
15+
'database': 'awesome'
16+
},
17+
'session': {
18+
'secret': 'AwEsOmE'
19+
}
20+
}
Collapse file

‎www/config_overwrite.py‎

Copy file name to clipboard
+13Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
"""
5+
Override configurations.
6+
"""
7+
8+
9+
configs = {
10+
'db': {
11+
'host': '127.0.0.1'
12+
}
13+
}

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.