~/.config working XDG_CONFIG_HOME
This commit is contained in:
parent
a41f909abe
commit
8fdf190f2e
30
main.py
30
main.py
@ -577,15 +577,31 @@ class ApplicationWindow(QMainWindow, Ui_MainWindow):
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
# logging setup
|
||||||
|
file_handler = logging.FileHandler(filename="log", encoding="utf-8")
|
||||||
|
stdout_handler = logging.StreamHandler(stream=sys.stdout)
|
||||||
|
handlers = [file_handler, stdout_handler]
|
||||||
|
# basicConfig(filename="log", encoding="utf-8", level=logging.DEBUG)
|
||||||
|
basicConfig(
|
||||||
|
level=DEBUG,
|
||||||
|
format="[%(asctime)s] {%(filename)s:%(lineno)d} %(levelname)s - %(message)s",
|
||||||
|
handlers=handlers,
|
||||||
|
)
|
||||||
# Initialization
|
# Initialization
|
||||||
|
|
||||||
cfg_file = (
|
cfg_file = (
|
||||||
Path(user_config_dir(appname="musicpom", appauthor="billypom")) / "config.ini"
|
Path(user_config_dir(appname="musicpom", appauthor="billypom")) / "config.ini"
|
||||||
)
|
)
|
||||||
cfg_path = str(Path(user_config_dir(appname="musicpom", appauthor="billypom")))
|
cfg_path = str(Path(user_config_dir(appname="musicpom", appauthor="billypom")))
|
||||||
|
debug(f'config file: {cfg_file}')
|
||||||
|
debug(f'config path: {cfg_path}')
|
||||||
|
|
||||||
|
# If config path doesn't exist, create it
|
||||||
|
if not os.path.exists(cfg_path):
|
||||||
|
os.makedirs(cfg_path)
|
||||||
# If the config file doesn't exist, create it from the sample config
|
# If the config file doesn't exist, create it from the sample config
|
||||||
if not os.path.exists(cfg_file):
|
if not os.path.exists(cfg_file):
|
||||||
|
debug('copying sample config')
|
||||||
# Create config file from sample
|
# Create config file from sample
|
||||||
run(["cp", "sample_config.ini", cfg_file])
|
run(["cp", "sample_config.ini", cfg_file])
|
||||||
config = ConfigParser()
|
config = ConfigParser()
|
||||||
@ -594,7 +610,9 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
# If the database location isnt set at the config location, move it
|
# If the database location isnt set at the config location, move it
|
||||||
if not db_filepath.startswith(cfg_path):
|
if not db_filepath.startswith(cfg_path):
|
||||||
config["db"]["database"] = f"{cfg_path}/{db_filepath}"
|
new_path = f"{cfg_path}/{db_filepath}"
|
||||||
|
debug(f'setting new db-database path: {new_path}')
|
||||||
|
config["db"]["database"] = new_path
|
||||||
# Save the config
|
# Save the config
|
||||||
with open(cfg_file, "w") as configfile:
|
with open(cfg_file, "w") as configfile:
|
||||||
config.write(configfile)
|
config.write(configfile)
|
||||||
@ -618,16 +636,6 @@ if __name__ == "__main__":
|
|||||||
for statement in lines.split(";"):
|
for statement in lines.split(";"):
|
||||||
debug(f"executing [{statement}]")
|
debug(f"executing [{statement}]")
|
||||||
db.execute(statement, ())
|
db.execute(statement, ())
|
||||||
# logging setup
|
|
||||||
file_handler = logging.FileHandler(filename="log", encoding="utf-8")
|
|
||||||
stdout_handler = logging.StreamHandler(stream=sys.stdout)
|
|
||||||
handlers = [file_handler, stdout_handler]
|
|
||||||
# basicConfig(filename="log", encoding="utf-8", level=logging.DEBUG)
|
|
||||||
basicConfig(
|
|
||||||
level=DEBUG,
|
|
||||||
format="[%(asctime)s] {%(filename)s:%(lineno)d} %(levelname)s - %(message)s",
|
|
||||||
handlers=handlers,
|
|
||||||
)
|
|
||||||
# Allow for dynamic imports of my custom classes and utilities?
|
# Allow for dynamic imports of my custom classes and utilities?
|
||||||
project_root = os.path.abspath(os.path.dirname(__file__))
|
project_root = os.path.abspath(os.path.dirname(__file__))
|
||||||
sys.path.append(project_root)
|
sys.path.append(project_root)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user