Process list: Highlight process basename

Neither regex, nor str.find() were used. Yeah!
This commit is contained in:
Alessio Sergi 2014-05-06 13:00:00 +02:00
parent d452b5b76f
commit 15ea33461f

View File

@ -18,6 +18,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Import sys libs
import os
from datetime import timedelta
# Import Glances libs
@ -82,8 +83,6 @@ class Plugin(GlancesPlugin):
sort_style = 'SORT'
# Header
msg = "{0:15}".format(" ")
ret.append(self.curse_add_line(msg))
msg = "{0:>6}".format(_("CPU%"))
ret.append(self.curse_add_line(msg, sort_style if process_sort_key == 'cpu_percent' else 'DEFAULT'))
msg = "{0:>6}".format(_("MEM%"))
@ -115,9 +114,6 @@ class Plugin(GlancesPlugin):
# Loop over processes (sorted by the sort key previously compute)
for p in self.sortlist(process_sort_key):
ret.append(self.curse_new_line())
# Name
msg = "{0:15}".format(p['name'][:15])
ret.append(self.curse_add_line(msg))
# CPU
msg = "{0:>6}".format(format(p['cpu_percent'], '>5.1f'))
ret.append(self.curse_add_line(msg,
@ -185,11 +181,30 @@ class Plugin(GlancesPlugin):
ret.append(self.curse_add_line(msg, optional=True))
ret.append(self.curse_add_line(msg, optional=True))
# Command line
try:
msg = " {0}".format(p['cmdline'])
except UnicodeEncodeError:
msg = ""
ret.append(self.curse_add_line(msg, optional=True, splittable=True))
# If no command line for the process is available, fallback to
# the bare process name instead
cmdline = p['cmdline']
if cmdline == "":
msg = " {0}".format(p['name'])
ret.append(self.curse_add_line(msg, optional=True, splittable=True))
else:
try:
cmd = cmdline.split()[0]
args = ' '.join(cmdline.split()[1:])
path, basename = os.path.split(cmd)
if os.path.isdir(path):
msg = " {0}".format(path) + os.sep
ret.append(self.curse_add_line(msg, optional=True, splittable=True))
ret.append(self.curse_add_line(basename, decoration='OK', optional=True, splittable=True))
msg = " {0}".format(args)
ret.append(self.curse_add_line(msg, optional=True, splittable=True))
else:
msg = " {0}".format(basename)
ret.append(self.curse_add_line(msg, decoration='OK', optional=True, splittable=True))
msg = " {0}".format(args)
ret.append(self.curse_add_line(msg, optional=True, splittable=True))
except UnicodeEncodeError:
ret.append(self.curse_add_line("", optional=True, splittable=True))
# Return the message with decoration
return ret