You are not logged in.
Hi guys;
Konversation 1.5 command: /sysinfo not working
/sysinfo command rewritten
konversation on terminal output (/sysinfo)
Traceback (most recent call last):
File "/usr/share/apps/konversation/scripts/sysinfo", line 250, in <module>
report(output)
File "/usr/share/apps/konversation/scripting_support/python/konversation/dbus.py", line 72, in say
_dispatch('say', connection, target, _prefix(message, prefix))
File "/usr/share/apps/konversation/scripting_support/python/konversation/dbus.py", line 87, in _dispatch
subprocess.call(_dbus_command + args)
File "/usr/lib/python3.3/subprocess.py", line 520, in call
with Popen(*popenargs, **kwargs) as p:
File "/usr/lib/python3.3/subprocess.py", line 820, in __init__
restore_signals, start_new_session)
File "/usr/lib/python3.3/subprocess.py", line 1438, in _execute_child
raise child_exception_type(errno_num, err_msg)
FileNotFoundError: [Errno 2] No such file or directory: 'qdbus'
qdbus-qt4 supposed to be.
konversation 1.5 new sysinfo script: (what is solution)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of
# the License or (at your option) version 3 or any later version
# accepted by the membership of KDE e.V. (or its successor appro-
# ved by the membership of KDE e.V.), which shall act as a proxy
# defined in Section 14 of version 3 of the license.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see http://www.gnu.org/licenses/.
#
# Copyright (C) 2012 Eike Hein
# The overall format of this script's output. The format of the individual
# elements referenced here is specified further below.
output_format = "Sysinfo for '$host': Running $kde $distro $kernel, $cpu, $ram, $storage, $procs, $uptime"
# The formats for the individual elements referenced in output_format.
format_strings = {
'host' : '$hostname',
'distro' : 'on $name $version',
'kernel' : 'powered by $name $version',
'kde' : '$mode KDE $version', # $mode is 'inside' or 'against'.
'cpu' : 'CPU: $model at $mhz MHz',
'ram' : 'RAM: $used/$total MB', # Also available: $free.
'storage' : 'Storage: $used/$total GB', # Also available: $free.
'procs' : '$count procs',
'uptime' : '${hours}h up'
}
# ===== Do not change anything below this line. =====
import abc
import os
import re
import socket
import string
import subprocess
import sys
try:
import konversation.dbus
except ImportError:
sys.exit("This script is intended to be run from within Konversation.")
if sys.hexversion < 0x02070000:
import konversation.i18n
konversation.i18n.init()
err = i18n("The sysinfo script requires Python %1 or higher.", '2.7')
konversation.dbus.error(err)
sys.exit(err)
sensors = list()
class MetaSensor(abc.ABCMeta):
def __init__(cls, name, *rest):
global sensors
try:
if cls.__base__ == Sensor:
sensors.append(cls)
cls.template = string.Template(format_strings[name])
except NameError:
pass
return abc.ABCMeta.__init__(cls, name, *rest)
# This is for papering over the syntax differences for specifying a
# metaclass in Python 2 and 3.
Shunt = MetaSensor('Shunt', (object,), {})
class Sensor(Shunt):
__metaclass__ = MetaSensor
def __init__(self):
self.data = dict()
self.gather()
@abc.abstractmethod
def gather(self):
pass
def format(self):
substituted = self.template.safe_substitute(self.data)
for match in self.template.pattern.findall(substituted):
substituted = substituted.replace('${' + match[2] + '}', '').replace('$' + match[1], '')
return substituted
class host(Sensor):
def gather(self):
self.data['hostname'] = socket.gethostname()
class kde(Sensor):
def gather(self):
kde = 'KDE_FULL_SESSION' in os.environ
self.data['mode'] = ('against', 'inside')[kde]
if kde and os.environ['KDE_SESSION_VERSION'] == '3':
cmd = ['kde-config']
else:
cmd = ['kde4-config']
cmd.append('--version')
version = subprocess.check_output(cmd, stderr=subprocess.STDOUT).decode()
for line in version.splitlines():
if line.startswith('KDE'):
self.data['version'] = line.split(':')[1].split()[0]
break
class distro(Sensor):
def gather(self):
if os.path.exists('/etc/os-release'):
with open('/etc/os-release', 'rb') as osrelease:
for line in osrelease:
key, value = line.decode('utf-8', 'replace').split('=', 1)
if key == 'NAME':
self.data['name'] = value.strip(string.whitespace + '"')
elif key == 'VERSION':
self.data['version'] = value.strip(string.whitespace + '"')
else:
try:
lsbrelease = subprocess.check_output(['lsb_release', '-i', '-r'], stderr=subprocess.STDOUT)
for line in lsbrelease.decode().splitlines():
key, value = line.split(':', 1)
if key == 'Distributor ID':
self.data['name'] = value.strip()
elif key == 'Release':
self.data['version'] = value.strip()
except (OSError, subprocess.CalledProcessError):
pass
def format(self):
return Sensor.format(self) if 'name' in self.data else ''
class kernel(Sensor):
def gather(self):
uname = os.uname()
self.data['name'] = uname[0]
self.data['version'] = uname[2]
class cpu(Sensor):
def gather(self):
curfreqs = set()
self.data['model'] = 'Unknown model'
with open('/proc/cpuinfo', 'r') as cpuinfo:
for line in (line for line in cpuinfo if len(line.strip()) > 1):
key, value = line.split(':', 1)
if key.strip() == 'model name':
self.data['model'] = value.strip()
elif key.strip() == 'cpu MHz':
curfreqs.add(int(float(value.strip())))
if not curfreqs:
try:
dir = '/sys/devices/system/cpu/'
for cpu in (cpu for cpu in os.listdir(dir) if re.match('cpu[0-9]+', cpu)):
with open(os.path.join(dir, cpu, 'cpufreq/scaling_cur_freq'), 'r') as curfreqf:
curfreqs.add(int(curfreqf.read())/1000)
except IOError:
self.data['mhz'] = 'unknown'
return
curfreqs = sorted(curfreqs)
if len(curfreqs) > 1:
curfreq = '{0}-{1}'.format(curfreqs[0], curfreqs[-1])
else:
curfreq = curfreqs[0]
maxfreq = 0
try:
dir = '/sys/devices/system/cpu/'
for cpu in (cpu for cpu in os.listdir(dir) if re.match('cpu[0-9]+', cpu)):
with open(os.path.join(dir, cpu, 'cpufreq/cpuinfo_max_freq'), 'r') as maxfreqf:
new = int(maxfreqf.read())
maxfreq = new if new > maxfreq else maxfreq
maxfreq = int(maxfreq / 1000)
except IOError:
pass
if curfreqs[0] < maxfreq:
self.data['mhz'] = '{0}/{1}'.format(curfreq, maxfreq)
else:
self.data['mhz'] = curfreq
class ram(Sensor):
def gather(self):
with open('/proc/meminfo', 'r') as meminfo:
for line in meminfo:
key, value = line.split(':', 1)
if key == 'MemTotal':
self.data['total'] = int(value.split()[0])
elif key == 'MemFree':
self.data['free'] = int(value.split()[0])
self.data['used'] = self.data['total'] - self.data['free']
for (key, value) in self.data.items():
self.data[key] = int(value / 1024)
class storage(Sensor):
def gather(self):
try:
df = subprocess.check_output(['df', '-lP'], stderr=subprocess.STDOUT).decode()
except subprocess.CalledProcessError as e:
df = e.output.decode()
volumes = {line.split()[0] : line.split()[1:4] for line in df.splitlines() if line.startswith('/dev')}
for (key, index) in zip(['total', 'used', 'free'], range(2)):
self.data[key] = int(sum(int(volume[index]) for volume in volumes.values()) / 1048576)
class procs(Sensor):
def gather(self):
self.data['count'] = len([pid for pid in os.listdir('/proc') if pid.isdigit()])
class uptime(Sensor):
def gather(self):
with open('/proc/uptime', 'r') as uptimef:
self.data['hours'] = round(float(uptimef.read().split()[0]) / 3600, 2)
if __name__ == '__main__':
sensors = {cls.__name__ : cls().format() for cls in sensors}
output = string.Template(output_format).safe_substitute(sensors)
output = ' '.join(output.split()) # Simplify whitespace.
report = konversation.dbus.say if konversation.dbus.target else konversation.dbus.info
report(output)
Offline
Konversation /sysinfo command now working
Solution
open the:
/konversation/scripting_support/python/konversation/dbus.py
find:
_dbus_command = ('qdbus', 'org.kde.konversation', '/irc')
replace:
_dbus_command = ('qdbus-qt4', 'org.kde.konversation', '/irc')
save and close.
thanks @tulliana
Offline
that is a wrong fix
the real fix for missing qdbus is install qtchooser
Last edited by sl1pkn07 (2014-01-27 00:01:21)
Offline
qtchooser installed (rebooted) and /sysinfo command not worked
Do you have a suggestion?
Last edited by tulliana (2014-01-26 18:31:13)
Offline
my output is:
Traceback (most recent call last):
File "/usr/share/apps/konversation/scripts/sysinfo", line 244, in <module>
sensors = {cls.__name__ : cls().format() for cls in sensors}
File "/usr/share/apps/konversation/scripts/sysinfo", line 244, in <dictcomp>
sensors = {cls.__name__ : cls().format() for cls in sensors}
File "/usr/share/apps/konversation/scripts/sysinfo", line 88, in __init__
self.gather()
File "/usr/share/apps/konversation/scripts/sysinfo", line 129, in gather
key, value = line.decode('utf-8', 'replace').split('=', 1)
ValueError: need more than 1 value to unpack
Offline
The qdbus-qt4 rename is an Arch-specific thing, so you should report this to bugs.archlinux.org
Offline
Offline
found the problem
/etc/os-release have 2 blank lines http://wstaw.org/m/2014/01/29/plasma-desktopDj5465.png
this break the script, removing one of those lines, sysinfo script works again
Thanks to Sho_ in konverstion IRC channel on freenode
greetings
Offline