From 5fc328ec0545c1183b0a2bcb26196fbd06b2be95 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sun, 31 Aug 2014 19:37:08 +0200 Subject: do not spawn new processes all the time MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/plugins/clock.py | 9 ++++++--- src/plugins/uname.py | 8 +++----- 2 files changed, 9 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/plugins/clock.py b/src/plugins/clock.py index 129269c..fc99ca4 100644 --- a/src/plugins/clock.py +++ b/src/plugins/clock.py @@ -18,6 +18,7 @@ along with this program. If not, see . ''' import time +from datetime import datetime, timezone from util import * @@ -47,10 +48,9 @@ class Clock: @param utc:bool Show time in UTC, otherwise local time @param sync_to:float The time parameter to sync to, the number of seconds between the reads ''' - self.format = format + self.format = format if not utc else format.replace('%Z', 'UTC') self.utc = utc self.sync_to = sync_to - self.command = ['date'] + (['--utc'] if utc else []) + ['+' + format] def read(self): @@ -59,7 +59,10 @@ class Clock: @return :str The time and date in the format specified at construction ''' - return spawn_read(*(self.command)) + if not self.utc: + return time.strftime(self.format) + else: + datetime.fromtimestamp(time.time(), tz = timezone.utc).strftime(self.format)) def sync(self): diff --git a/src/plugins/uname.py b/src/plugins/uname.py index 6b05a96..19c8fca 100644 --- a/src/plugins/uname.py +++ b/src/plugins/uname.py @@ -17,6 +17,8 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . ''' +import os + from util import * @@ -40,11 +42,7 @@ class Uname: Constructor ''' u = lambda s : None if s == 'unknown' else s - self.kernel_name = spawn_read('uname', '-s') - self.nodename = spawn_read('uname', '-n') - self.kernel_release = spawn_read('uname', '-r') - self.kernel_version = spawn_read('uname', '-v') - self.machine = spawn_read('uname', '-m') + (self.kernel_name, self.nodename, self.kernel_release, self.kernel_version, self.machine) = os.uname() self.processor = u(spawn_read('uname', '-p')) self.hardware_platform = u(spawn_read('uname', '-i')) self.operating_system = spawn_read('uname', '-o') -- cgit v1.2.3-70-g09d2