From 669571e8035c9018fdec0b7402163f0c3fb1db80 Mon Sep 17 00:00:00 2001 From: arcan1s Date: Mon, 26 Aug 2013 03:52:43 +0400 Subject: [PATCH] Start rebuild dataengine from Python to CPP --- PKGBUILD | 46 +++++ ext-sysmon-1.1.zip | Bin 0 -> 2550 bytes ext-sysmon/CMakeLists.txt | 25 +++ ext-sysmon/CMakeLists.txt.user | 182 +++++++++++++++++ ext-sysmon/contents/code/main.py | 95 --------- ext-sysmon/extsysmon.cpp | 188 ++++++++++++++++++ ext-sysmon/extsysmon.h | 21 ++ ...esktop => plasma-engine-extsysmon.desktop} | 9 +- .../ext-sysmon-1.0.zip | Bin 9 files changed, 466 insertions(+), 100 deletions(-) create mode 100644 PKGBUILD create mode 100644 ext-sysmon-1.1.zip create mode 100644 ext-sysmon/CMakeLists.txt create mode 100644 ext-sysmon/CMakeLists.txt.user delete mode 100644 ext-sysmon/contents/code/main.py create mode 100644 ext-sysmon/extsysmon.cpp create mode 100644 ext-sysmon/extsysmon.h rename ext-sysmon/{metadata.desktop => plasma-engine-extsysmon.desktop} (77%) rename ext-sysmon-1.0.zip => old_versions/ext-sysmon-1.0.zip (100%) diff --git a/PKGBUILD b/PKGBUILD new file mode 100644 index 0000000..2c18cc7 --- /dev/null +++ b/PKGBUILD @@ -0,0 +1,46 @@ +# Author: Evgeniy "arcanis" Alexeev +# Maintainer: Evgeniy "arcanis" Alexeev + +pkgname=kdeplasma-applets-pytextmonitor +_pkgname=py-text-monitor +pkgver=1.3.4 +pkgrel=1 +_dtengine=ext-sysmon +_dtver=1.1 +pkgdesc="Minimalistic Plasmoid script written on Python2. It looks like widgets in awesome-wm" +arch=(any) +url="https://github.com/arcan1s/pytextmonitor" +license=('GPL') +depends=('kdebindings-python2' 'lm_sensors' 'net-tools') +optdepends=('catalyst: for GPU monitor' + 'nvidia-utils: for GPU monitor') +makedepends=('unzip') +source=(https://github.com/arcan1s/pytextmonitor/releases/download/V.1.3.4/${_pkgname}-${pkgver}.plasmoid + https://github.com/arcan1s/pytextmonitor/releases/download/V.1.3.4/${_dtengine}-${_dtver}.zip) +md5sums=('cdc55960177a07b52ab0a2713f5df212' + '84fde352850f4d46309e5077a7db22a6') + +build () +{ +# build dataengine + unzip -o -q ${srcdir}/${_dtengine}-${_dtver}.zip -d ${srcdir}/${_dtengine} + if [ -d ${srcdir}/${_dtengine}/build ]; then + rm -r build + fi + mkdir ${srcdir}/${_dtengine}/build && cd ${srcdir}/${_dtengine}/build + cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Release ../ + make +} + +package() +{ +# install dataengine + cd ${srcdir}/${_dtengine}/build + make DESTDIR=${pkgdir} install + +# install plasmoid + unzip -o -q ${srcdir}/${_pkgname}-${pkgver}.plasmoid -d ${srcdir}/${_pkgname} + install -D ${srcdir}/${_pkgname}/metadata.desktop ${pkgdir}/`kde4-config --prefix`/share/kde4/services/${_pkgname}.desktop + mkdir -p ${pkgdir}/`kde4-config --prefix`/share/apps/plasma/plasmoids/${_pkgname} + cp -r ${srcdir}/${_pkgname}/* ${pkgdir}/`kde4-config --prefix`/share/apps/plasma/plasmoids/${_pkgname}/ +} \ No newline at end of file diff --git a/ext-sysmon-1.1.zip b/ext-sysmon-1.1.zip new file mode 100644 index 0000000000000000000000000000000000000000..2ca4f1be5c5ffa8362110e1cca92dd3eb0787a66 GIT binary patch literal 2550 zcmWIWW@Zs#W?$n!ZK4_V;d|yMhc4NTROx5%keoa}1E7OjD(~*1~@Z_%haqlh$-_^~0B0neo zsV}Yl&3&4|a39+f%+i8+4Z6l6hwW*zJ{ix872^y6eHMW6m{yzeT+0(XBYgz3)X?#*Kwf zCZ^0hb$Pk^UV)QA2d~yNuU9Q=S6!FZzNGxEiCOgZ1z|>^1zmOeyYqrf^Zy?>7s65Z zLeMAn@Ug2~E=sGTra`H*sZ+u*DIh)B}cjcaFmdnC1 z*VnClQT2{rEbfuZhnZ$2OSMmKd9Xd}f90!Yk1MrCseQ9|A7j5|rYE#BrL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~BWjwDZsWhX;cFX z^_78vVHP6;12;+um61Ea*ZZ)8K->G@+H6d!qKe-`Y*uh9U6a_}G4E7bxls6}yF27v z1^@3(4$9@0d;YLiK26Pd?bRDh^--Pa8`r$Mc3np~K}XJTn&j$VO9aootClp|v}00W z(e1zwa|~T|80z~y%yjJzU5eC5^zh9W@#)=kC;Wyw^NQx#!BY_@AKZxvv5-pSa{d=q7g5c(>K4 z3tW`GeeldF-k|d7{>{?_kKXuYZpU@}kiK+y#l@({-x{3Em)LJQ@B4Ma`Q_GPZ@RCY zdy#P2DNx2v=7u>UbecJ(oZq=G_^!{$z!1*Fz#z}Sz)+BrSe%=vo0^xNnU|`ID9uw+ zi?d7e3tA`oW*s&VX#H;2$``OS<$CXe%s106Y+;!+%}Fyc$yY`&J7q~>M}GXxQ%Vmm z%8joT4B|)y|4Q95I}g_lhwuB>WHc=(U&dtvFt zl~7ku`>c8d+V^DL{}_OI}oX_U(Q z*Ii54Pc870+l~c$CvTp{e{S`o5XG5(XR>UR=ds8*Ht09{NIVx2^I2=)AY>o*w>rqm zdfLC=|J8pbJStc=`K83U#*IZAZ*Q@<$iA1=Z2O#|oJZ4|r6#A&(P9nJU;VToa2U#z+niiykfdQmwt} q7C>l?WJA`Pfvgc*>Og2LXD66e0=!w-KpI#WSQ!2?Ffcsk0Pz4isc=#N literal 0 HcmV?d00001 diff --git a/ext-sysmon/CMakeLists.txt b/ext-sysmon/CMakeLists.txt new file mode 100644 index 0000000..437f774 --- /dev/null +++ b/ext-sysmon/CMakeLists.txt @@ -0,0 +1,25 @@ +project (extsysmon) + +# Find the required Libaries +find_package (KDE4 REQUIRED) +include (KDE4Defaults) + +add_definitions (${QT_DEFINITIONS} ${KDE4_DEFINITIONS}) +include_directories (${CMAKE_SOURCE_DIR} + ${CMAKE_BINARY_DIR} + ${KDE4_INCLUDES}) + +set (CMAKE_CXX_FLAGS "-fexceptions") +set (extsysmon_engine_SRCS extsysmon.cpp) + +# Now make sure all files get to the right place +kde4_add_plugin (plasma_engine_extsysmon ${extsysmon_engine_SRCS}) +target_link_libraries(plasma_engine_extsysmon + ${KDE4_KDECORE_LIBS} + ${KDE4_PLASMA_LIBS}) + +install(TARGETS plasma_engine_extsysmon + DESTINATION ${PLUGIN_INSTALL_DIR}) + +install(FILES plasma-engine-extsysmon.desktop + DESTINATION ${SERVICES_INSTALL_DIR}) diff --git a/ext-sysmon/CMakeLists.txt.user b/ext-sysmon/CMakeLists.txt.user new file mode 100644 index 0000000..aa23587 --- /dev/null +++ b/ext-sysmon/CMakeLists.txt.user @@ -0,0 +1,182 @@ + + + + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + true + 1 + true + 0 + true + 0 + 8 + true + 1 + true + true + true + false + + + + ProjectExplorer.Project.PluginSettings + + + + ProjectExplorer.Project.Target.0 + + Desktop + Desktop + {a22d6db7-e0a5-452b-9173-b8efacd95ba3} + 0 + 0 + 0 + + /home/arcanis/Documents/github/pytextmonitor/ext-sysmon-build + false + + + + + all + + false + false + true + Сборка + + CMakeProjectManager.MakeStep + + 1 + Сборка + + ProjectExplorer.BuildSteps.Build + + + + clean + + true + false + true + Сборка + + CMakeProjectManager.MakeStep + + 1 + Очистка + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + all + + CMakeProjectManager.CMakeBuildConfiguration + + 1 + + + 0 + Установка + + ProjectExplorer.BuildSteps.Deploy + + 1 + Локальная установка + + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + true + + false + false + false + false + true + 0.01 + 10 + true + 25 + + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + + + false + %{buildDir} + Запуск std::exception &E + + ProjectExplorer.CustomExecutableRunConfiguration + 3768 + true + false + false + false + true + + 1 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.EnvironmentId + {ab3ec085-9c1a-4bfc-af86-f7898da68a64} + + + ProjectExplorer.Project.Updater.FileVersion + 14 + + diff --git a/ext-sysmon/contents/code/main.py b/ext-sysmon/contents/code/main.py deleted file mode 100644 index 7ca3cea..0000000 --- a/ext-sysmon/contents/code/main.py +++ /dev/null @@ -1,95 +0,0 @@ -# -*- coding: utf-8 -*- - -from PyQt4.QtCore import * -from PyKDE4.kdecore import * -from PyKDE4 import plasmascript -import commands - - - -class ExtendedSysMon(plasmascript.DataEngine): - def __init__(self, parent, args=None): - """dataengine definition""" - plasmascript.DataEngine.__init__(self, parent) - - - def init(self): - """initialization""" - self.setMinimumPollingInterval(333) - - # setup gpu device - self.gpudev = '' - commandOut = commands.getoutput("lspci") - if (commandOut.lower().find('nvidia') > -1): - self.gpudev = 'nvidia' - elif (commandOut.lower().find('radeon') > -1): - self.gpudev = 'ati' - - # setup hdd devices - self.hdddev = [] - commandOut = commands.getoutput("ls -1 /dev/sd[a-z] && ls -1 /dev/hd[a-z]") - for device in commandOut.split('\n'): - if (device[:3] != "ls:"): - self.hdddev.append(device) - - - def sources(self): - """create sources""" - sources = ["gpu", "gputemp", "hddtemp"] - return sources - - - def sourceRequestEvent(self, name): - return self.updateSourceEvent(name) - - - def updateSourceEvent(self, source): - """update sources and setup values""" - if (source == "gpu"): - key = "GPU" - if (self.gpudev == 'nvidia'): - commandOut = commands.getoutput("nvidia-smi -q -d UTILIZATION | grep Gpu | tail -n1") - try: - value = "%5s" % (str(round(float(commandOut.split()[2][:-1]), 1))) - except: - value = " N\A" - elif (self.gpudev == 'ati'): - commandOut = commands.getoutput("aticonfig --od-getclocks | grep load | tail -n1") - try: - value = "%5s" % (str(round(float(commandOut.split()[3][:-1]), 1))) - except: - value = " N\A" - else: - value = " N\A" - self.setData(source, "GPU", QString(value)) - elif (source == "gputemp"): - if (self.gpudev == 'nvidia'): - commandOut = commands.getoutput("nvidia-smi -q -d TEMPERATURE | grep Gpu | tail -n1") - try: - value = "%4s" % (str(round(float(commandOut.split()[2]), 1))) - except: - value = " N\A" - elif (self.gpudev == 'ati'): - commandOut = commands.getoutput("aticonfig --od-gettemperature | grep Temperature | tail -n1") - try: - value = "%4s" % (str(round(float(commandOut.split()[4]), 1))) - except: - value = " N\A" - else: - value = " N\A" - self.setData(source, "GPUTemp", QString(value)) - elif (source == "hddtemp"): - for device in self.hdddev: - commandOut = commands.getoutput("hddtemp " + device) - try: - value = "%4s" % (str(round(float(commandOut.split(':')[2][:-3]), 1))) - except: - value = " N\A" - self.setData(source, device, QString(value)) - - return True - - - -def CreateDataEngine(parent): - return ExtendedSysMon(parent) diff --git a/ext-sysmon/extsysmon.cpp b/ext-sysmon/extsysmon.cpp new file mode 100644 index 0000000..e1f25c6 --- /dev/null +++ b/ext-sysmon/extsysmon.cpp @@ -0,0 +1,188 @@ +#include "extsysmon.h" +#include +#include + +ExtendedSysMon::ExtendedSysMon(QObject* parent, const QVariantList& args) + : Plasma::DataEngine(parent, args) +{ + Q_UNUSED(args) + + setMinimumPollingInterval(333); + + FILE *f_out; + f_out = popen("lspci 2>&1", "r"); + char device[256]; + QString dev; + while (fgets(device, 256, f_out) != NULL) + { + dev = QString(device); + if (dev.toLower().contains("nvidia")) + gpudev = QString("nvidia"); + else if (dev.toLower().contains("radeon")) + gpudev = QString("ati"); + } + pclose(f_out); + + f_out = popen("ls -1 /dev/sd[a-z] && ls -1 /dev/hd[a-z] 2>&1", "r"); + while (fgets(device, 256, f_out) != NULL) + { + dev = QString(device); + if (dev[0] == '/') + hdddev.append(dev); + } + pclose(f_out); +} + +QStringList ExtendedSysMon::sources() const +{ + QStringList source; + source.append(QString("gpu")); + source.append(QString("gputemp")); + source.append(QString("hddtemp")); + return source; +} + +bool ExtendedSysMon::sourceRequestEvent(const QString &name) +{ + return updateSourceEvent(name); +} + +bool ExtendedSysMon::updateSourceEvent(const QString &source) +{ + QLocale::setDefault(QLocale::C); + + FILE *f_out; + QString key, out, tmp_out, value; + bool ok = false; + char output[256], val[5]; + if (source == QString("gpu")) + { + key = QString("GPU"); + if (gpudev == QString("nvidia")) + { + try + { + f_out = popen("nvidia-smi -q -d UTILIZATION | grep Gpu | tail -n1 2>&1", "r"); + fgets (output, 256, f_out); + if (output[0] == '\0') + throw; + out = QString(output).split(QString(" "), QString::SkipEmptyParts)[2]; + sprintf (val, "%5.1f", out.left(out.count()-2).toFloat(&ok)); + value = QString(val); + pclose(f_out); + } + catch(std::exception &e) + { + value = QString(" N\\A"); + } + } + else if (gpudev == QString("ati")) + { + try + { + f_out = popen("aticonfig --od-getclocks | grep load | tail -n1 2>&1", "r"); + fgets (output, 256, f_out); + if (output[0] == '\0') + throw; + printf ("lol?"); + out = QString(output).split(QString(" "), QString::SkipEmptyParts)[3]; + sprintf (val, "%5.1f", out.left(out.count()-2).toFloat(&ok)); + value = QString(val); + pclose(f_out); + } + catch(std::exception &e) + { + value = QString(" N\\A"); + } + } + else + { + value = QString(" N\\A"); + } + if (ok == false) + value = QString(" N\\A"); + setData(source, key, value); + } + else if (source == QString("gputemp")) + { + key = QString("GPUTemp"); + if (gpudev == QString("nvidia")) + { + try + { + f_out = popen("nvidia-smi -q -d TEMPERATURE | grep Gpu | tail -n1 2>&1", "r"); + fgets (output, 256, f_out); + if (output[0] == '\0') + throw; + out = QString(output).split(QString(" "), QString::SkipEmptyParts)[2]; + sprintf (val, "%4.1f", out.toFloat(&ok)); + value = QString(val); + pclose(f_out); + } + catch(std::exception &e) + { + value = QString(" N\\A"); + } + } + else if (gpudev == QString("ati")) + { + try + { + f_out = popen("aticonfig --od-gettemperature | grep Temperature | tail -n1 2>&1", "r"); + fgets (output, 256, f_out); + if (output[0] == '\0') + throw; + out = QString(output).split(QString(" "), QString::SkipEmptyParts)[4]; + sprintf (val, "%4.1f", out.toFloat(&ok)); + value = QString(val); + } + catch(std::exception &e) + { + value = QString(" N\\A"); + } + pclose(f_out); + } + else + { + value = QString(" N\\A"); + } + if (ok == false) + value = QString(" N\\A"); + setData(source, key, value); + } + else if (source == QString("hddtemp")) + { + char command[256], *dev; + QByteArray qb; + for (int i=0; i&1", dev); + try + { + f_out = popen(command, "r"); + fgets(output, 256, f_out); + if (output[0] == '\0') + throw; + out = QString(output).split(QString(":"), QString::SkipEmptyParts)[2]; + sprintf (val, "%4.1f", out.left(out.count()-4).toFloat(&ok)); + value = QString(val); + pclose(f_out); + } + catch(std::exception &e) + { + value = QString(" N\\A"); + } + if (ok == false) + value = QString(" N\\A"); + setData(source, hdddev[i], value); + } + } + + return true; +} + +K_EXPORT_PLASMA_DATAENGINE(extsysmon, ExtendedSysMon) + +#include "extsysmon.moc" diff --git a/ext-sysmon/extsysmon.h b/ext-sysmon/extsysmon.h new file mode 100644 index 0000000..5a38081 --- /dev/null +++ b/ext-sysmon/extsysmon.h @@ -0,0 +1,21 @@ +#ifndef EXTSYSMON_H +#define EXTSYSMON_H + +#include + +class ExtendedSysMon : public Plasma::DataEngine +{ + Q_OBJECT + +public: + ExtendedSysMon(QObject *parent, const QVariantList &args); + +protected: + bool sourceRequestEvent(const QString &name); + bool updateSourceEvent(const QString &source); + QStringList hdddev; + QString gpudev; + QStringList sources() const; +}; + +#endif // EXTSYSMON_H diff --git a/ext-sysmon/metadata.desktop b/ext-sysmon/plasma-engine-extsysmon.desktop similarity index 77% rename from ext-sysmon/metadata.desktop rename to ext-sysmon/plasma-engine-extsysmon.desktop index fbb6af4..c57609e 100644 --- a/ext-sysmon/metadata.desktop +++ b/ext-sysmon/plasma-engine-extsysmon.desktop @@ -6,14 +6,13 @@ ServiceTypes=Plasma/DataEngine Type=Service Icon=utilities-system-monitor -X-Plasma-API=python -X-Plasma-MainScript=code/main.py - +X-KDE-ServiceTypes=Plasma/DataEngine +X-KDE-Library=plasma_engine_extsysmon +X-Plasma-EngineName=ext-sysmon X-KDE-PluginInfo-Author=Evgeniy Alexeev aka arcanis X-KDE-PluginInfo-Email=esalexeev@gmail.com X-KDE-PluginInfo-Name=ext-sysmon -X-KDE-PluginInfo-Version=1.0 -X-KDE-PluginInfo-Website=http://kde-look.org/ +X-KDE-PluginInfo-Version=1.1 X-KDE-PluginInfo-Category=System Information X-KDE-PluginInfo-Depends= X-KDE-PluginInfo-License=GPL diff --git a/ext-sysmon-1.0.zip b/old_versions/ext-sysmon-1.0.zip similarity index 100% rename from ext-sysmon-1.0.zip rename to old_versions/ext-sysmon-1.0.zip