i3pystatus creates a logger that can be imported via import i3pystatus.logger . Thus when modules enable the 'enable_log' setting, it should log i3pystatus errors to a file called '.i3pystatus-<pid>'. This commit only solves the case when email_client was called in the email module and would output things into stderr/stdout.
This commit is contained in:
parent
523975cf39
commit
bc15eb4e6b
@ -5,6 +5,17 @@ from i3pystatus.core.modules import Module, IntervalModule
|
||||
from i3pystatus.core.settings import SettingsBase
|
||||
from i3pystatus.core.util import formatp
|
||||
|
||||
import logging
|
||||
import os
|
||||
|
||||
h=logging.FileHandler(".i3pystatus-" + str(os.getpid()));
|
||||
|
||||
logger = logging.getLogger("i3pystatus")
|
||||
logger.addHandler(h)
|
||||
logger.setLevel(logging.DEBUG)
|
||||
#~/.i3pystatus-<pid>-<module>
|
||||
logger.error("Start !")
|
||||
|
||||
__path__ = extend_path(__path__, __name__)
|
||||
|
||||
__all__ = [
|
||||
@ -12,6 +23,7 @@ __all__ = [
|
||||
"Module", "IntervalModule",
|
||||
"SettingsBase",
|
||||
"formatp",
|
||||
"logger",
|
||||
]
|
||||
|
||||
|
||||
|
37
i3pystatus/core/command.py
Normal file
37
i3pystatus/core/command.py
Normal file
@ -0,0 +1,37 @@
|
||||
from subprocess import check_output, CalledProcessError
|
||||
import subprocess
|
||||
from i3pystatus import logger
|
||||
# class Command(Object):
|
||||
|
||||
# ,*args
|
||||
def run_through_shell(command,enable_log):
|
||||
"""
|
||||
Retrieves output of shell command
|
||||
Returns tuple boolean (success)/ string (error msg, output)
|
||||
"""
|
||||
result=False
|
||||
try:
|
||||
#stderr=subprocess.STDOUT
|
||||
#stderr=subprocess.PIPE
|
||||
# with subprocess.Popen() as proc:
|
||||
# logger.error(proc.stderr.read())
|
||||
proc = subprocess.Popen(command,stderr=subprocess.PIPE,stdout=subprocess.PIPE)
|
||||
|
||||
out, stderr = proc.communicate()
|
||||
if stderr and enable_log:
|
||||
logger.error(stderr)
|
||||
# out = check_output(command, stderr=subprocess.STDOUT, shell=True)
|
||||
result=True
|
||||
# color = self.color
|
||||
except CalledProcessError as e:
|
||||
out = e.output
|
||||
# color = self.error_color
|
||||
|
||||
out = out.decode("UTF-8").replace("\n", " ")
|
||||
try:
|
||||
if out[-1] == " ":
|
||||
out = out[:-1]
|
||||
except:
|
||||
out = ""
|
||||
|
||||
return result, out
|
@ -2,6 +2,7 @@ import subprocess
|
||||
|
||||
from i3pystatus import SettingsBase, IntervalModule
|
||||
from i3pystatus.core.util import internet, require
|
||||
from i3pystatus.core.command import run_through_shell
|
||||
|
||||
|
||||
class Backend(SettingsBase):
|
||||
@ -69,7 +70,8 @@ class Mail(IntervalModule):
|
||||
|
||||
def on_leftclick(self):
|
||||
if self.email_client:
|
||||
subprocess.Popen(self.email_client.split())
|
||||
run_through_shell(self.email_client,self.enable_log)
|
||||
|
||||
|
||||
def on_rightclick(self):
|
||||
self.run()
|
||||
|
Loading…
Reference in New Issue
Block a user