Various pep8 and comments removal + converted shell module to use run_through_shell command

This commit is contained in:
Matthieu Coudron 2014-12-17 23:51:10 +01:00
parent bc15eb4e6b
commit 69c1cd6460
4 changed files with 16 additions and 39 deletions

View File

@ -8,13 +8,12 @@ from i3pystatus.core.util import formatp
import logging import logging
import os import os
h=logging.FileHandler(".i3pystatus-" + str(os.getpid())); h = logging.FileHandler(".i3pystatus-" + str(os.getpid()), delay=True)
logger = logging.getLogger("i3pystatus") logger = logging.getLogger("i3pystatus")
logger.addHandler(h) logger.addHandler(h)
logger.setLevel(logging.DEBUG) logger.setLevel(logging.DEBUG)
#~/.i3pystatus-<pid>-<module>
logger.error("Start !")
__path__ = extend_path(__path__, __name__) __path__ = extend_path(__path__, __name__)

View File

@ -1,28 +1,23 @@
from subprocess import check_output, CalledProcessError from subprocess import CalledProcessError
import subprocess import subprocess
from i3pystatus import logger 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 Retrieves output of shell command
Returns tuple boolean (success)/ string (error msg, output) Returns tuple boolean (success)/ string (error msg, output)
""" """
result = False result = False
try: try:
#stderr=subprocess.STDOUT proc = subprocess.Popen(command, stderr=subprocess.PIPE, stdout=subprocess.PIPE, shell=enable_shell)
#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() out, stderr = proc.communicate()
if stderr and enable_log: if stderr and enable_log:
logger.error(stderr) logger.error(stderr)
# out = check_output(command, stderr=subprocess.STDOUT, shell=True)
result = True result = True
# color = self.color
except CalledProcessError as e: except CalledProcessError as e:
out = e.output out = e.output
# color = self.error_color # color = self.error_color
@ -34,4 +29,4 @@ def run_through_shell(command,enable_log):
except: except:
out = "" out = ""
return result, out return out, result

View File

@ -1,7 +1,4 @@
import subprocess
from i3pystatus import SettingsBase, IntervalModule from i3pystatus import SettingsBase, IntervalModule
from i3pystatus.core.util import internet, require
from i3pystatus.core.command import run_through_shell from i3pystatus.core.command import run_through_shell
@ -72,6 +69,5 @@ class Mail(IntervalModule):
if self.email_client: if self.email_client:
run_through_shell(self.email_client, self.enable_log) run_through_shell(self.email_client, self.enable_log)
def on_rightclick(self): def on_rightclick(self):
self.run() self.run()

View File

@ -1,5 +1,5 @@
from i3pystatus import IntervalModule from i3pystatus import IntervalModule
from subprocess import check_output, CalledProcessError from i3pystatus.core.command import run_through_shell
class Shell(IntervalModule): class Shell(IntervalModule):
@ -19,21 +19,8 @@ class Shell(IntervalModule):
required = ("command",) required = ("command",)
def run(self): def run(self):
try: out, success = run_through_shell(self.command, self.enable_log, enable_shell=True)
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 = ""
self.output = { self.output = {
"full_text": out, "full_text": out,
"color": color "color": self.color if success else self.error_color
} }