From 6a8de48502a85fbd4592d7cc43cdde4f610ae894 Mon Sep 17 00:00:00 2001 From: Alessio Sergi Date: Mon, 23 Mar 2015 00:35:53 +0100 Subject: [PATCH] Replace list creation with list literal --- glances/core/glances_logs.py | 35 +++++++++++++------------- glances/plugins/glances_processlist.py | 3 +-- glances/plugins/glances_uptime.py | 12 ++------- 3 files changed, 20 insertions(+), 30 deletions(-) diff --git a/glances/core/glances_logs.py b/glances/core/glances_logs.py index 0e15b5fb..108613f3 100644 --- a/glances/core/glances_logs.py +++ b/glances/core/glances_logs.py @@ -118,24 +118,23 @@ class GlancesLogs(object): # Create the new log item # Time is stored in Epoch format # Epoch -> DMYHMS = datetime.fromtimestamp(epoch) - item = [] - # START DATE - item.append(time.mktime(datetime.now().timetuple())) - item.append(-1) # END DATE - item.append(item_state) # STATE: WARNING|CRITICAL - item.append(item_type) # TYPE: CPU, LOAD, MEM... - item.append(item_value) # MAX - item.append(item_value) # AVG - item.append(item_value) # MIN - item.append(item_value) # SUM - item.append(1) # COUNT - # Process list is sorted automaticaly - # Overwrite the user choise - # topprocess = sorted(proc_list, key=lambda process: process[process_auto_by], - # reverse=True) - # item.append(topprocess[0:3]) # TOP 3 PROCESS LIST - item.append([]) # TOP 3 PROCESS LIST - item.append(proc_desc) # MONITORED PROCESSES DESC + item = [ + time.mktime(datetime.now().timetuple()), # START DATE + -1, # END DATE + item_state, # STATE: WARNING|CRITICAL + item_type, # TYPE: CPU, LOAD, MEM... + item_value, # MAX + item_value, # AVG + item_value, # MIN + item_value, # SUM + 1, # COUNT + # Process list is sorted automatically + # Overwrite the user choice + # topprocess = sorted(proc_list, key=lambda process: process[process_auto_by], + # reverse=True) + # topprocess[0:3], # TOP 3 PROCESS LIST + [], # TOP 3 PROCESS LIST + proc_desc] # MONITORED PROCESSES DESC # Add the item to the list self.logs_list.insert(0, item) diff --git a/glances/plugins/glances_processlist.py b/glances/plugins/glances_processlist.py index a7eefac8..902cbef9 100644 --- a/glances/plugins/glances_processlist.py +++ b/glances/plugins/glances_processlist.py @@ -154,8 +154,7 @@ class Plugin(GlancesPlugin): def get_process_curses_data(self, p, first, args): """ Get curses data to display for a process. """ - ret = [] - ret.append(self.curse_new_line()) + ret = [self.curse_new_line()] # CPU if 'cpu_percent' in p and p['cpu_percent'] is not None and p['cpu_percent'] != '': msg = '{0:>6.1f}'.format(p['cpu_percent']) diff --git a/glances/plugins/glances_uptime.py b/glances/plugins/glances_uptime.py index 3b7724f8..764c9d08 100644 --- a/glances/plugins/glances_uptime.py +++ b/glances/plugins/glances_uptime.py @@ -63,8 +63,7 @@ class Plugin(GlancesPlugin): if self.input_method == 'local': # Update stats using the standard system lib - uptime = datetime.now() - \ - datetime.fromtimestamp(psutil.boot_time()) + uptime = datetime.now() - datetime.fromtimestamp(psutil.boot_time()) # Convert uptime to string (because datetime is not JSONifi) self.stats = str(uptime).split('.')[0] @@ -82,11 +81,4 @@ class Plugin(GlancesPlugin): def msg_curse(self, args=None): """Return the string to display in the curse interface.""" - # Init the return message - ret = [] - - # Add the line with decoration - ret.append(self.curse_add_line(_("Uptime: {0}").format(self.stats))) - - # Return the message with decoration - return ret + return [self.curse_add_line(_("Uptime: {0}").format(self.stats))]