Сделал создание конфига при его отсутствии

This commit is contained in:
Lulzette 2021-09-17 15:57:50 +03:00
parent 539d53d209
commit f72c941a3a
2 changed files with 15 additions and 6 deletions

View File

@ -2,3 +2,4 @@
host = localhost
port = 27017
name = pycms

14
main.py
View File

@ -30,7 +30,8 @@ class Config:
"""
import configparser
config = configparser.ConfigParser()
config.read('config.ini')
if not config.read('config.ini'):
self.createConfig(config)
db = config['DB']
@ -38,11 +39,18 @@ class Config:
self.port = int(db['port'])
self.dbname = db['name']
def createConfig(self):
def createConfig(self, config):
"""
Create config file
"""
pass
config['DB'] = {}
db = config['DB']
db['host'] = 'localhost'
db['port'] = '27017'
db['name'] = 'pycms'
with open('config.ini', 'w') as cfgfile:
config.write(cfgfile)
class Back():