Better usability of INI configuration.

This commit is contained in:
lcdr
2015-11-19 21:25:16 +01:00
parent aca5f16e28
commit 024c1f9a72
5 changed files with 31 additions and 7 deletions

View File

@ -1,3 +1,5 @@
Various utilities. Various utilities.
## License: GPL v3 Requires Python 3, versions below 3.4 might work but are not tested.
## License: GPL v3

7
captureviewer.ini Normal file
View File

@ -0,0 +1,7 @@
[paths]
db_path=<path to cdclient.sqlite>
[parse]
creations=True
serializations=True
game_messages=True
normal_packets=True

View File

@ -2,7 +2,9 @@ import configparser
import math import math
import os import os
import sqlite3 import sqlite3
import sys
import tkinter.filedialog as filedialog import tkinter.filedialog as filedialog
import tkinter.messagebox as messagebox
import xml.etree.ElementTree as ET import xml.etree.ElementTree as ET
import zipfile import zipfile
from collections import OrderedDict from collections import OrderedDict
@ -111,7 +113,12 @@ class CaptureViewer(viewer.Viewer):
super().__init__() super().__init__()
config = configparser.ConfigParser() config = configparser.ConfigParser()
config.read("captureviewer.ini") config.read("captureviewer.ini")
self.db = sqlite3.connect(config["paths"]["db_path"]) try:
self.db = sqlite3.connect(config["paths"]["db_path"])
except:
messagebox.showerror("Can not open database", "Make sure db_path in the INI is set correctly.")
sys.exit()
self.enable_game_messages = "gamemessages_path" in config["paths"] self.enable_game_messages = "gamemessages_path" in config["paths"]
if self.enable_game_messages: if self.enable_game_messages:
gamemsg_xml = ET.parse(config["paths"]["gamemessages_path"]) gamemsg_xml = ET.parse(config["paths"]["gamemessages_path"])
@ -122,13 +129,13 @@ class CaptureViewer(viewer.Viewer):
self.objects = [] self.objects = []
self.lot_data = {} self.lot_data = {}
self.parse_creations = BooleanVar(value=config["parse"].get("creations", True)) self.parse_creations = BooleanVar(value=config["parse"]["creations"])
self.parse_serializations = BooleanVar(value=config["parse"].get("serializations", True)) self.parse_serializations = BooleanVar(value=config["parse"]["serializations"])
if self.enable_game_messages: if self.enable_game_messages:
self.parse_game_messages = BooleanVar(value=config["parse"].get("game_messages", True)) self.parse_game_messages = BooleanVar(value=config["parse"]["game_messages"])
else: else:
self.parse_game_messages = BooleanVar(value=False) self.parse_game_messages = BooleanVar(value=False)
self.parse_normal_packets = BooleanVar(value=config["parse"].get("normal_packets", True)) self.parse_normal_packets = BooleanVar(value=config["parse"]["normal_packets"])
self.create_widgets() self.create_widgets()
def create_widgets(self): def create_widgets(self):

2
luzviewer.ini Normal file
View File

@ -0,0 +1,2 @@
[paths]
db_path=<path to cdclient.sqlite>

View File

@ -1,8 +1,10 @@
import configparser import configparser
import os.path import os.path
import sqlite3 import sqlite3
import sys
import tkinter.filedialog as filedialog import tkinter.filedialog as filedialog
import tkinter.messagebox as messagebox
from tkinter import END, Menu from tkinter import END, Menu
import viewer import viewer
@ -13,7 +15,11 @@ class LUZViewer(viewer.Viewer):
super().__init__() super().__init__()
config = configparser.ConfigParser() config = configparser.ConfigParser()
config.read("luzviewer.ini") config.read("luzviewer.ini")
self.db = sqlite3.connect(config["paths"]["db_path"]) try:
self.db = sqlite3.connect(config["paths"]["db_path"])
except:
messagebox.showerror("Can not open database", "Make sure db_path in the INI is set correctly.")
sys.exit()
self.create_widgets() self.create_widgets()
def create_widgets(self): def create_widgets(self):