Improved error handling for configs that don't exist.
parent
89bf3b0ba7
commit
d3998aa1cd
|
@ -1,6 +1,5 @@
|
||||||
import codecs
|
import codecs
|
||||||
import configparser
|
import configparser
|
||||||
import os
|
|
||||||
|
|
||||||
|
|
||||||
def create_config(config, path):
|
def create_config(config, path):
|
||||||
|
@ -35,9 +34,9 @@ def create_config(config, path):
|
||||||
|
|
||||||
def read_config(path):
|
def read_config(path):
|
||||||
config = configparser.ConfigParser()
|
config = configparser.ConfigParser()
|
||||||
|
try:
|
||||||
config.read_file(codecs.open(path, "r", "utf8"))
|
config.read_file(codecs.open(path, "r", "utf8"))
|
||||||
|
except FileNotFoundError:
|
||||||
if len(config.sections()) == 0:
|
|
||||||
create_config(config, path)
|
create_config(config, path)
|
||||||
print("Config generated.")
|
print("Config generated.")
|
||||||
quit(0)
|
quit(0)
|
||||||
|
|
Loading…
Reference in New Issue