Skip to content

Commit

Permalink
Fix something.
Browse files Browse the repository at this point in the history
  • Loading branch information
HsOjo committed Aug 25, 2019
1 parent 66bb148 commit bc6530a
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 17 deletions.
15 changes: 0 additions & 15 deletions app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,21 +263,6 @@ def callback_refresh(self, sender: rumps.Timer):
sender.stop()
self.callback_exception()

def event_trigger(self, source, params: dict, path_event: str):
if path_event != '':
params_pop = []
for k, v in params.items():
if type(v) not in [None.__class__, bool, int, float, str, list, dict]:
params_pop.append(k)
for k in params_pop:
params.pop(k)

[stat, out, err] = common.execute(
path_event, env={Const.app_env: object_convert.to_json(params)}, sys_env=False,
timeout=self.config.process_timeout)
log.append(source, 'Event',
{'path': path_event, 'status': stat, 'output': out, 'error': err})

def callback_idle_status_changed(self, idle_time: float):
params = locals()

Expand Down
17 changes: 16 additions & 1 deletion app/base/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from app.res.const import Const
from app.res.language import LANGUAGES, load_language
from app.res.language.english import English
from app.util import system_api, osa_api, pyinstaller, log, github
from app.util import system_api, osa_api, pyinstaller, log, github, object_convert


class ApplicationBase:
Expand Down Expand Up @@ -285,3 +285,18 @@ def clear_config(self, sender: rumps.MenuItem):
self.config.clear()
if osa_api.alert(sender.title, self.lang.description_clear_config_restart):
self.restart()

def event_trigger(self, source, params: dict, path_event: str):
if path_event != '':
params_pop = []
for k, v in params.items():
if type(v) not in [None.__class__, bool, int, float, str, list, dict]:
params_pop.append(k)
for k in params_pop:
params.pop(k)

[stat, out, err] = common.execute(
path_event, env={Const.app_env: object_convert.to_json(params)}, sys_env=False,
timeout=self.config.process_timeout)
log.append(source, 'Event',
{'path': path_event, 'status': stat, 'output': out, 'error': err})
1 change: 1 addition & 0 deletions app/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def execute(cmd, input=None, timeout=None, **kwargs):
p = popen(cmd, **kwargs)
if input is not None:
p.stdin.write(input)
p.stdin.close()
out = p.stdout.read()
err = p.stderr.read()
stat = p.wait(timeout)
Expand Down
5 changes: 4 additions & 1 deletion app/util/object_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ def to_json(obj):


def from_json(obj_str):
return json.loads(obj_str)
try:
return json.loads(obj_str)
except:
return None


def object_to_dict(obj):
Expand Down

0 comments on commit bc6530a

Please sign in to comment.