Limit the plugins text length
This commit is contained in:
parent
3581e17700
commit
ef863983c1
|
@ -1,4 +1,4 @@
|
|||
safeeyes (1.2.0a7-3) xenial; urgency=low
|
||||
safeeyes (1.2.0-1) xenial; urgency=low
|
||||
|
||||
* Move to Python 3
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ class Plugins:
|
|||
if os.path.isfile(os.path.join(plugins_directory, plugin['name'] + '.py')):
|
||||
module = importlib.import_module(plugin['name'])
|
||||
if self.__has_method(module, 'start') and self.__has_method(module, 'pre_notification') and self.__has_method(module, 'pre_break') and self.__has_method(module, 'post_break') and self.__has_method(module, 'exit'):
|
||||
self.__plugins.append({'module': module, 'location': plugin['location'].lower()})
|
||||
self.__plugins.append({'name': plugin['name'], 'module': module, 'location': plugin['location'].lower()})
|
||||
else:
|
||||
logging.warning('Ignoring the plugin ' + str(plugin['name']) + ' due to invalid method signature')
|
||||
else:
|
||||
|
@ -88,10 +88,15 @@ class Plugins:
|
|||
try:
|
||||
result = multiple_results[i].get(timeout=1)
|
||||
if result:
|
||||
# Limit the line length to 50 characters
|
||||
large_lines = list(filter(lambda x: len(x) > 50, Utility.html_to_text(result).splitlines()))
|
||||
if large_lines:
|
||||
logging.warning('Ignoring lengthy result from the plugin ' + self.__plugins[i]['name'])
|
||||
continue
|
||||
output[self.__plugins[i]['location']] += (result + '\n\n')
|
||||
except Exception:
|
||||
# Something went wrong in the plugin
|
||||
pass
|
||||
raise
|
||||
|
||||
return output
|
||||
|
||||
|
|
|
@ -34,8 +34,6 @@ class SafeEyesCore:
|
|||
self.break_count = -1
|
||||
self.long_break_message_index = -1
|
||||
self.short_break_message_index = -1
|
||||
self.skipped = False
|
||||
self.postponed = False
|
||||
self.active = False
|
||||
self.running = False
|
||||
self.show_notification = show_notification
|
||||
|
@ -47,6 +45,8 @@ class SafeEyesCore:
|
|||
self.idle_condition = threading.Condition()
|
||||
self.lock = threading.Lock()
|
||||
self.context = context
|
||||
self.context['skipped'] = False
|
||||
self.context['postponed'] = False
|
||||
|
||||
|
||||
"""
|
||||
|
@ -174,13 +174,13 @@ class SafeEyesCore:
|
|||
User skipped the break using Skip button
|
||||
"""
|
||||
def skip_break(self):
|
||||
self.skipped = True
|
||||
self.context['skipped'] = True
|
||||
|
||||
"""
|
||||
User postponed the break using Postpone button
|
||||
"""
|
||||
def postpone_break(self):
|
||||
self.postponed = True
|
||||
self.context['postponed'] = True
|
||||
|
||||
|
||||
"""
|
||||
|
@ -192,7 +192,7 @@ class SafeEyesCore:
|
|||
|
||||
time_to_wait = self.break_interval # In minutes
|
||||
|
||||
if self.postponed:
|
||||
if self.context['postponed']:
|
||||
# Reduce the break count by 1 to show the same break again
|
||||
if self.break_count == 0:
|
||||
self.break_count = -1
|
||||
|
@ -205,7 +205,7 @@ class SafeEyesCore:
|
|||
|
||||
# Wait until the postpone time
|
||||
time_to_wait = self.postpone_duration
|
||||
self.postponed = False
|
||||
self.context['postponed'] = False
|
||||
|
||||
next_break_time = datetime.datetime.now() + datetime.timedelta(minutes=time_to_wait)
|
||||
self.update_next_break_info(next_break_time)
|
||||
|
@ -303,7 +303,7 @@ class SafeEyesCore:
|
|||
self.start_break(message, image)
|
||||
|
||||
# Use self.active instead of self.__is_running to avoid idle pause interrupting the break
|
||||
while seconds and self.active and not self.skipped and not self.postponed:
|
||||
while seconds and self.active and not self.context['skipped'] and not self.context['postponed']:
|
||||
self.context['count_down'] = total_break_time - seconds
|
||||
mins, secs = divmod(seconds, 60)
|
||||
timeformat = '{:02d}:{:02d}'.format(mins, secs)
|
||||
|
@ -312,12 +312,12 @@ class SafeEyesCore:
|
|||
seconds -= 1
|
||||
|
||||
# Loop terminated because of timeout (not skipped) -> Close the break alert
|
||||
if not self.skipped and not self.postponed:
|
||||
if not self.context['skipped'] and not self.context['postponed']:
|
||||
logging.info("Break is terminated automatically")
|
||||
self.end_break(audible_alert)
|
||||
|
||||
# Reset the skipped flag
|
||||
self.skipped = False
|
||||
self.context['skipped'] = False
|
||||
|
||||
# Resume
|
||||
if self.__is_running():
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
import gi
|
||||
gi.require_version('Gdk', '3.0')
|
||||
from gi.repository import Gdk, GLib
|
||||
from html.parser import HTMLParser
|
||||
import babel.dates, os, errno, re, subprocess, threading, logging, locale, json
|
||||
import pyaudio, wave
|
||||
|
||||
|
@ -45,9 +46,9 @@ def play_notification():
|
|||
# Create a sound stream
|
||||
wrapper = pyaudio.PyAudio()
|
||||
stream = wrapper.open(format=wrapper.get_format_from_width(sound.getsampwidth()),
|
||||
channels=sound.getnchannels(),
|
||||
rate=sound.getframerate(),
|
||||
output=True)
|
||||
channels=sound.getnchannels(),
|
||||
rate=sound.getframerate(),
|
||||
output=True)
|
||||
|
||||
# Write file data into the sound stream
|
||||
data = sound.readframes(CHUNK)
|
||||
|
@ -136,17 +137,17 @@ def is_active_window_skipped(skip_break_window_classes, take_break_window_classe
|
|||
# Extract the process name
|
||||
process_names = re.findall('"(.+?)"', stdout)
|
||||
if process_names:
|
||||
process = process_names[1].lower()
|
||||
if process in skip_break_window_classes:
|
||||
return True
|
||||
elif process in take_break_window_classes:
|
||||
if is_fullscreen and unfullscreen_allowed:
|
||||
try:
|
||||
active_window.unfullscreen()
|
||||
except:
|
||||
logging.error('Error in unfullscreen the window ' + process)
|
||||
pass
|
||||
return False
|
||||
process = process_names[1].lower()
|
||||
if process in skip_break_window_classes:
|
||||
return True
|
||||
elif process in take_break_window_classes:
|
||||
if is_fullscreen and unfullscreen_allowed:
|
||||
try:
|
||||
active_window.unfullscreen()
|
||||
except:
|
||||
logging.error('Error in unfullscreen the window ' + process)
|
||||
pass
|
||||
return False
|
||||
|
||||
return is_fullscreen
|
||||
|
||||
|
@ -289,3 +290,29 @@ def lock_desktop(user_defined_command):
|
|||
subprocess.Popen(command)
|
||||
except Exception as e:
|
||||
logging.error('Error in executing the commad' + str(command) + ' to lock screen', e)
|
||||
|
||||
|
||||
def html_to_text(html):
|
||||
"""
|
||||
Convert HTML to plain text
|
||||
"""
|
||||
extractor = __HTMLTextExtractor()
|
||||
extractor.feed(html)
|
||||
return extractor.get_data()
|
||||
|
||||
|
||||
class __HTMLTextExtractor(HTMLParser):
|
||||
"""
|
||||
Helper class to convert HTML to text
|
||||
"""
|
||||
def __init__(self):
|
||||
self.reset()
|
||||
self.strict = False
|
||||
self.convert_charrefs= True
|
||||
self.fed = []
|
||||
|
||||
def handle_data(self, d):
|
||||
self.fed.append(d)
|
||||
|
||||
def get_data(self):
|
||||
return ''.join(self.fed)
|
|
@ -44,7 +44,7 @@ system_style_sheet_path = os.path.join(Utility.bin_directory, "config/style/safe
|
|||
|
||||
is_active = True
|
||||
CONFIGURATION_VERSION = 4
|
||||
SAFE_EYES_VERSION = "1.2.0a7"
|
||||
SAFE_EYES_VERSION = "1.2.0"
|
||||
|
||||
"""
|
||||
Listen to tray icon Settings action and send the signal to Settings dialog.
|
||||
|
|
Loading…
Reference in New Issue