Skip to content

Commit

Permalink
fix: complete error fix, more import cleanup, add helper func and a test
Browse files Browse the repository at this point in the history
* this commit removes support for legacy AppIndicator3 in favor of
  AyatanaAppIndicator3 only

Signed-off-by: Stephen Arnold <[email protected]>
  • Loading branch information
sarnold committed Sep 2, 2024
1 parent 26d5dc7 commit eb89737
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 13 deletions.
2 changes: 2 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ repos:
- "PyYAML"
- "munch"
- "munch-stubs"
- "PyGObject"
- "PyGObject-stubs"
#files: src/

- repo: "https://github.com/asottile/blacken-docs"
Expand Down
19 changes: 7 additions & 12 deletions scripts/timew-status-indicator
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,14 @@ from threading import Thread
from typing import cast

import gi
from munch import Munch

gi.require_version("Gtk", "3.0")
gi.require_version('Notify', '0.7')
gi.require_version('AyatanaAppIndicator3', '0.1')

try:
gi.require_version('AyatanaAppIndicator3', '0.1')
from gi.repository import AyatanaAppIndicator3 as appindicator
except ValueError:
gi.require_version('AppIndicator3', '0.1')
from gi.repository import AppIndicator3 as appindicator

from gi.repository import AyatanaAppIndicator3 as appindicator
from gi.repository import Gdk, Gtk, Notify
from munch import Munch

from timew_status import (
CFG,
Expand Down Expand Up @@ -123,7 +118,7 @@ class Indicator:
new_state = 'INACTIVE'
print(f'{new_state} state msg: {result.stdout.decode().strip()}')
else:
proc, _ = run_cmd()
proc, _ = run_cmd(CFG)
msg, new_state = get_state_str(proc, current_tick_count, CFG)
print(f'{new_state} state msg: {msg.strip()}')
# if there is a change in state, update the icon
Expand Down Expand Up @@ -238,18 +233,18 @@ class Indicator:

def startd(self, source):
my_tag = TAG["text"]
_, svc_msg = run_cmd(action='start', tag=my_tag)
_, svc_msg = run_cmd(CFG, action='start', tag=my_tag)
self.indicator.set_icon_full(get_state_icon('ACTIVE', CFG), 'ACTIVE')
Notify.Notification.new("Timew status", svc_msg, None).show()

def statusd(self, source):
_, svc_msg = run_cmd()
_, svc_msg = run_cmd(CFG)
seat_minutes = round(Decimal(COUNT["SeatTick"] / 60), 1)
svc_msg = f'INFO: current seat time is {seat_minutes} mins \n' + svc_msg
Notify.Notification.new("Timew status", svc_msg, None).show()

def stopd(self, source):
_, svc_msg = run_cmd(action='stop')
_, svc_msg = run_cmd(CFG, action='stop')
if svc_msg:
self.last_tag = svc_msg
if CFG['use_last_tag']:
Expand Down
20 changes: 19 additions & 1 deletion src/timew_status/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
import datetime
import os
import subprocess
import sys
from datetime import timedelta
from pathlib import Path
from shutil import which
from typing import Dict, NewType, Optional

from munch import Munch
Expand Down Expand Up @@ -34,6 +36,21 @@
}


def check_for_timew():
"""
Make sure we can find the ``timew`` binary in the user environment
and return a path string.
:return timew_path: program path strings
:rtype tuple: path to program if found, else None
"""
timew_path = which('timew')
if not timew_path:
print('Cannot continue, no path found for timew')
sys.exit(1)
return timew_path


def do_install(cfg: Dict):
"""
Install report extensions to timew extensions directory. The default src
Expand Down Expand Up @@ -232,9 +249,10 @@ def run_cmd(cfg: Dict, action: str = 'status', tag: Optional[str] = None):
:param action: one of <start|stop|status>
:return: completed proc obj and result msg
"""
timew_cmd = check_for_timew()
extension = cfg["extension_script"]
actions = ['start', 'stop', 'status']
svc_list = ['timew']
svc_list = [timew_cmd]
sts_list = [extension, "today"]
cmd = svc_list
act_list = [action]
Expand Down
9 changes: 9 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from munch import Munch

from timew_status.utils import (
check_for_timew,
do_install,
get_config,
get_delta_limits,
Expand Down Expand Up @@ -38,6 +39,14 @@
"""


def test_timew_check():
timew = check_for_timew()
print(timew)
assert 'timew' in timew
assert 'bin' in timew
assert isinstance(timew, str)


def test_do_install(script_loc, tmpdir_session):
cfg = Munch.fromDict(CFG)
# destination dir
Expand Down

0 comments on commit eb89737

Please sign in to comment.