Various pep8 and comments removal + converted shell module to use run_through_shell command
This commit is contained in:
parent
bc15eb4e6b
commit
69c1cd6460
@ -8,13 +8,12 @@ from i3pystatus.core.util import formatp
|
||||
import logging
|
||||
import os
|
||||
|
||||
h=logging.FileHandler(".i3pystatus-" + str(os.getpid()));
|
||||
h = logging.FileHandler(".i3pystatus-" + str(os.getpid()), delay=True)
|
||||
|
||||
logger = logging.getLogger("i3pystatus")
|
||||
logger.addHandler(h)
|
||||
logger.setLevel(logging.DEBUG)
|
||||
#~/.i3pystatus-<pid>-<module>
|
||||
logger.error("Start !")
|
||||
|
||||
|
||||
__path__ = extend_path(__path__, __name__)
|
||||
|
||||
|
@ -1,28 +1,23 @@
|
||||
from subprocess import check_output, CalledProcessError
|
||||
from subprocess import CalledProcessError
|
||||
import subprocess
|
||||
from i3pystatus import logger
|
||||
# class Command(Object):
|
||||
|
||||
# ,*args
|
||||
def run_through_shell(command,enable_log):
|
||||
|
||||
def run_through_shell(command, enable_log, enable_shell=False):
|
||||
"""
|
||||
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)
|
||||
proc = subprocess.Popen(command, stderr=subprocess.PIPE, stdout=subprocess.PIPE, shell=enable_shell)
|
||||
|
||||
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
|
||||
@ -34,4 +29,4 @@ def run_through_shell(command,enable_log):
|
||||
except:
|
||||
out = ""
|
||||
|
||||
return result, out
|
||||
return out, result
|
||||
|
@ -1,7 +1,4 @@
|
||||
import subprocess
|
||||
|
||||
from i3pystatus import SettingsBase, IntervalModule
|
||||
from i3pystatus.core.util import internet, require
|
||||
from i3pystatus.core.command import run_through_shell
|
||||
|
||||
|
||||
@ -72,6 +69,5 @@ class Mail(IntervalModule):
|
||||
if self.email_client:
|
||||
run_through_shell(self.email_client, self.enable_log)
|
||||
|
||||
|
||||
def on_rightclick(self):
|
||||
self.run()
|
||||
|
@ -1,5 +1,5 @@
|
||||
from i3pystatus import IntervalModule
|
||||
from subprocess import check_output, CalledProcessError
|
||||
from i3pystatus.core.command import run_through_shell
|
||||
|
||||
|
||||
class Shell(IntervalModule):
|
||||
@ -19,21 +19,8 @@ class Shell(IntervalModule):
|
||||
required = ("command",)
|
||||
|
||||
def run(self):
|
||||
try:
|
||||
out = check_output(self.command, shell=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 = ""
|
||||
|
||||
out, success = run_through_shell(self.command, self.enable_log, enable_shell=True)
|
||||
self.output = {
|
||||
"full_text": out,
|
||||
"color": color
|
||||
"color": self.color if success else self.error_color
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user