mirror of
https://github.com/lcdr/utils.git
synced 2024-08-30 17:32:16 +00:00
Better usability of INI configuration.
This commit is contained in:
@ -1,3 +1,5 @@
|
|||||||
Various utilities.
|
Various utilities.
|
||||||
|
|
||||||
|
Requires Python 3, versions below 3.4 might work but are not tested.
|
||||||
|
|
||||||
## License: GPL v3
|
## License: GPL v3
|
7
captureviewer.ini
Normal file
7
captureviewer.ini
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
[paths]
|
||||||
|
db_path=<path to cdclient.sqlite>
|
||||||
|
[parse]
|
||||||
|
creations=True
|
||||||
|
serializations=True
|
||||||
|
game_messages=True
|
||||||
|
normal_packets=True
|
@ -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")
|
||||||
|
try:
|
||||||
self.db = sqlite3.connect(config["paths"]["db_path"])
|
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
2
luzviewer.ini
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
[paths]
|
||||||
|
db_path=<path to cdclient.sqlite>
|
@ -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")
|
||||||
|
try:
|
||||||
self.db = sqlite3.connect(config["paths"]["db_path"])
|
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):
|
||||||
|
Reference in New Issue
Block a user