Fix lock when trying to stop while enforce sequence is active.
This commit is contained in:
29
antidrift.py
29
antidrift.py
@@ -14,7 +14,7 @@ DBusGMainLoop(set_as_default=True)
|
||||
signal.signal(signal.SIGINT, signal.SIG_DFL)
|
||||
|
||||
|
||||
def init_logging(log_file: Path, mode: str):
|
||||
def init_logging(log_file: Path):
|
||||
class DuplicateFilter(logging.Filter):
|
||||
def filter(self, record) -> bool:
|
||||
current_log = (record.module, record.levelno, record.msg)
|
||||
@@ -22,10 +22,12 @@ def init_logging(log_file: Path, mode: str):
|
||||
self.last_log = current_log
|
||||
return True
|
||||
return False
|
||||
format_str = f'%(asctime)s | %(levelname)-8s | {mode} | %(message)s'
|
||||
format_str = '[bold pale_green3]%(asctime)s[/bold pale_green3] | ' \
|
||||
'[light_steel_blue]%(levelname)-8s[/light_steel_blue] | ' \
|
||||
'%(message)s'
|
||||
logging.basicConfig(filename=log_file,
|
||||
format=format_str,
|
||||
datefmt='%H:%M:%S',
|
||||
datefmt='%a %H:%M:%S',
|
||||
encoding='utf-8',
|
||||
level=logging.DEBUG)
|
||||
logger = logging.getLogger()
|
||||
@@ -40,33 +42,16 @@ def check_for_xdotool():
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def tailf(config):
|
||||
import time
|
||||
from rich import print
|
||||
with open(config.log_file, 'r') as f:
|
||||
f.seek(0, 2)
|
||||
while True:
|
||||
line = f.readline()
|
||||
if not line:
|
||||
time.sleep(0.1)
|
||||
else:
|
||||
print(line.strip())
|
||||
|
||||
|
||||
def main() -> None:
|
||||
""" Main routine that dispatches to client or daemon """
|
||||
config = Config.load("config.yaml")
|
||||
|
||||
if len(sys.argv) > 1 and sys.argv[1] == "tailf":
|
||||
tailf(config)
|
||||
return
|
||||
|
||||
check_for_xdotool()
|
||||
if client.antidrift_daemon_is_running():
|
||||
init_logging(config.log_file, "[blue]client[/blue]")
|
||||
init_logging(config.client_log_file)
|
||||
client.client_mode(config)
|
||||
else:
|
||||
init_logging(config.log_file, "[red]server[/red]")
|
||||
init_logging(config.daemon_log_file)
|
||||
add = AntiDriftDaemon(config)
|
||||
add.run()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user