Added debugger setup, cleanup

This commit is contained in:
2023-04-29 09:44:22 -05:00
parent f82541b37a
commit 33cde33e6f
12 changed files with 316 additions and 21 deletions

View File

@@ -18,7 +18,6 @@ from app import Application
def run():
try:
locale.setlocale(locale.LC_NUMERIC, 'C')

View File

@@ -1,26 +1,25 @@
# Python imports
import signal
import os
import inspect
# Lib imports
# Application imports
from utils.debugging import debug_signal_handler
from utils.ipc_server import IPCServer
from core.window import Window
class AppLaunchException(Exception):
...
class Application(IPCServer):
""" Inherit from IPCServer; create Controller classe; bind any signal(s) to Builder. """
""" docstring for Application. """
def __init__(self, args, unknownargs):
super(Application, self).__init__()
self.args, self.unknownargs = args, unknownargs
if not settings.is_trace_debug():
try:
@@ -36,4 +35,14 @@ class Application(IPCServer):
raise AppLaunchException(f"{app_name} IPC Server Exists: Will send path(s) to it and close...")
try:
# kill -SIGUSR2 <pid> from Linux/Unix or SIGBREAK signal from Windows
signal.signal(
vars(signal).get("SIGBREAK") or vars(signal).get("SIGUSR1"),
debug_signal_handler
)
except ValueError:
# Typically: ValueError: signal only works in main thread
...
Window(args, unknownargs)

View File

@@ -101,4 +101,4 @@ class FileActionSignalsMixin:
items = icon_grid.get_selected_items()
if len(items) > 0:
icon_grid.scroll_to_path(items[0], False, 0.5, 0.5)
icon_grid.scroll_to_path(items[0], False, 0.5, 0.5)

View File

@@ -2,6 +2,7 @@
import os
import json
from os.path import join
from dataclasses import dataclass
# Lib imports
@@ -14,6 +15,7 @@ class ManifestProcessorException(Exception):
...
@dataclass(slots=True)
class PluginInfo:
path: str = None
name: str = None
@@ -89,4 +91,4 @@ class ManifestProcessor:
if isinstance(requests["bind_keys"], list):
loading_data["bind_keys"] = requests["bind_keys"]
return self._plugin, loading_data
return self._plugin, loading_data

View File

@@ -34,14 +34,14 @@ class FileHandler:
return True
def delete_file(self, toDeleteFile):
def delete_file(self, to_delete_file):
try:
print(f"Deleting: {toDeleteFile}")
if os.path.exists(toDeleteFile):
if os.path.isfile(toDeleteFile):
os.remove(toDeleteFile)
elif os.path.isdir(toDeleteFile):
shutil.rmtree(toDeleteFile)
print(f"Deleting: {to_delete_file}")
if os.path.exists(to_delete_file):
if os.path.isfile(to_delete_file):
os.remove(to_delete_file)
elif os.path.isdir(to_delete_file):
shutil.rmtree(to_delete_file)
else:
print("An error occured deleting the file:")
return False
@@ -73,7 +73,7 @@ class FileHandler:
return True
def copy_file(self,fFile, tFile, symlinks=False, ignore=None):
def copy_file(self, fFile, tFile, symlinks = False, ignore = None):
try:
if os.path.isdir(fFile):
shutil.copytree(fFile, tFile, symlinks, ignore)

View File

@@ -0,0 +1,35 @@
# Python imports
# Lib imports
# Application imports
# Break into a Python console upon SIGUSR1 (Linux) or SIGBREAK (Windows:
# CTRL+Pause/Break). To be included in all production code, just in case.
def debug_signal_handler(signal, frame):
del signal
del frame
try:
import rpdb2
logger.debug("\n\nStarting embedded RPDB2 debugger. Password is 'foobar'\n\n")
rpdb2.start_embedded_debugger("foobar", True, True)
rpdb2.setbreak(depth=1)
return
except StandardError:
pass
try:
from rfoo.utils import rconsole
logger.debug("\n\nStarting embedded rconsole debugger...\n\n")
rconsole.spawn_server()
except StandardError as ex:
...
try:
import code
code.interact()
except StandardError as ex:
logger.debug(f"{ex}, returning to normal program flow...")