Добавил чтение конфига
This commit is contained in:
parent
28b98a9127
commit
539d53d209
4
config.ini
Normal file
4
config.ini
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
[DB]
|
||||||
|
host=localhost
|
||||||
|
port=27017
|
||||||
|
name=pycms
|
22
main.py
22
main.py
@ -15,18 +15,30 @@ class Config:
|
|||||||
"""
|
"""
|
||||||
Init init
|
Init init
|
||||||
"""
|
"""
|
||||||
mongoclient = pymongo.MongoClient('localhost', 27017)
|
self.readConfig()
|
||||||
database = mongoclient['pycms']
|
|
||||||
|
mongoclient = pymongo.MongoClient(self.host, self.port)
|
||||||
|
database = mongoclient[self.dbname]
|
||||||
|
|
||||||
|
# TODO: Create table if not exists
|
||||||
posts = database['posts']
|
posts = database['posts']
|
||||||
self.posts = posts
|
self.posts = posts
|
||||||
|
|
||||||
def readConfig():
|
def readConfig(self):
|
||||||
"""
|
"""
|
||||||
Read config file, if not exists - call Init.createConfig()
|
Read config file, if not exists - call Init.createConfig()
|
||||||
"""
|
"""
|
||||||
pass
|
import configparser
|
||||||
|
config = configparser.ConfigParser()
|
||||||
|
config.read('config.ini')
|
||||||
|
|
||||||
def createConfig():
|
db = config['DB']
|
||||||
|
|
||||||
|
self.host = db['host']
|
||||||
|
self.port = int(db['port'])
|
||||||
|
self.dbname = db['name']
|
||||||
|
|
||||||
|
def createConfig(self):
|
||||||
"""
|
"""
|
||||||
Create config file
|
Create config file
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user