Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Ellipsis] Improve Regex Error Handling and Code Cleanup #102

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions aw_watcher_window/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
default_config = """
[aw-watcher-window]
exclude_title = false
exclude_titles = []
poll_time = 1.0
strategy_macos = "swift"
""".strip()
Expand All @@ -19,6 +20,7 @@ def parse_args():

default_poll_time = config["poll_time"]
default_exclude_title = config["exclude_title"]
default_exclude_titles = config["exclude_titles"]
default_strategy_macos = config["strategy_macos"]

parser = argparse.ArgumentParser(
Expand All @@ -33,6 +35,13 @@ def parse_args():
action="store_true",
default=default_exclude_title,
)
parser.add_argument(
"--exclude-titles",
dest="exclude_titles",
nargs='+',
default=default_exclude_titles,
help="List of regular expression patterns to exclude from tracking. Each pattern can match any part of a window title. Use standard regex syntax. For example, to exclude windows containing 'Game', simply use 'Game'. Can specify multiple patterns."
)
parser.add_argument("--verbose", dest="verbose", action="store_true")
parser.add_argument(
"--poll-time", dest="poll_time", type=float, default=default_poll_time
Expand Down
13 changes: 8 additions & 5 deletions aw_watcher_window/main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
import os
import re
import signal
import subprocess
import sys
Expand All @@ -22,15 +23,13 @@
if log_level:
logger.setLevel(logging.__getattribute__(log_level.upper()))


def kill_process(pid):
logger.info("Killing process {}".format(pid))
try:
os.kill(pid, signal.SIGTERM)
except ProcessLookupError:
logger.info("Process {} already dead".format(pid))


def main():
args = parse_args()

Expand Down Expand Up @@ -92,10 +91,10 @@
poll_time=args.poll_time,
strategy=args.strategy,
exclude_title=args.exclude_title,
exclude_titles=[try: re.compile(title, re.IGNORECASE) except re.error: re.compile(re.escape(title), re.IGNORECASE) for title in args.exclude_titles]

Check failure

Code scanning / CodeQL

Syntax error Error

Syntax Error (in Python 3).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol, Ellipsis really butchered this.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hey @ErikBjare , looking into what happened here...

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ErikBjare you can get much higher quality out of Ellipsis by adding a Dockerfile and build/test commands so that it can verify its changes - see docs here https://docs.ellipsis.dev/build. We have a playground as well where you can test it out at https://app.ellipsis.dev/

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

happy to help get you onboarded to that 🙏

)


def heartbeat_loop(client, bucket_id, poll_time, strategy, exclude_title=False):
def heartbeat_loop(client, bucket_id, poll_time, strategy, exclude_title=False, exclude_titles=[]):
while True:
if os.getppid() == 1:
logger.info("window-watcher stopped because parent process died")
Expand Down Expand Up @@ -128,6 +127,10 @@
if current_window is None:
logger.debug("Unable to fetch window, trying again on next poll")
else:
for pattern in exclude_titles:
if pattern.search(current_window["title"]):
current_window["title"] = "excluded"

if exclude_title:
current_window["title"] = "excluded"

Expand All @@ -141,4 +144,4 @@
bucket_id, current_window_event, pulsetime=poll_time + 1.0, queued=True
)

sleep(poll_time)
sleep(poll_time)
Loading