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 zcmai0c{CJiA07rHgN!sGTf_)6g=S<)jIGOHXwoJbjj?1WTSMepL$+qF(qy~Vn@lE4 zvSbaJY?C3frG$jbOh|L*p6{Hm?m726-~0aYJMVkW^ZxNXzxR25SR0^#6c7Lq2ITCK zHLKV1!QJKq01ohO!~p<+nJxaBJH{(GBp4AA9ulAR!td=d(S$G2B85vY^a-WSG1oL> zu}m*jj|ID1-rD8FZnl=p688P1RkuwFz_v0@Txu)x+s*4yJK#QmcC!$7^vgIAYPul? zt)fY|NJM@+S+4*W=J-S=8jlZTuV60Z!qFrO?O?`oV83b~G4on)WHonA#_tstbV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<5>)Ho`=f{GMt+^ra^?f-VAuy-hVFE>hmsparPL!q2z;17o~m5?>F(`1Qk@|@`& zFI>R?a41jT3|pIa6N!W`JDNiLs{0Rda7JZdPdZ;L(p4?)jVwrEx^q? zr%`a@wxJ8^_|vxjQkb+S6X#ekVA&|MQ>?{V8#Qn3)}8Xa>fSjV#7^kbVAmNeBSCnx zXv1))zf8q%-O_qzAyV`mf@Ew;IIoK+uEOz2B%1^hOk(ih+ZV5T#T>&Z_HkrL zCu>{JSfsn{=)rU0gBR!6F=)NwQ%_#oZf3kLHH0qTe#2OB9Y#CI8OyQsey|hAi`^Bg ze9loGGw1jL07V`<0Y3O(Up(C1&%?{l9sa}33GTtyLi_{bGi|-wk4eOHjN`?zzY|8& z^1YVH19X8bGWrPK%~lR_jZhqz@7B`iVhMlOU=tFUV(>94DLY zo~I#*J6buPMidT3E|wy?PtuW^Y&fw6Ys1HX3i!W=93J7kr4&;f`*;24$n!Jy-;(xk z#DB1LJpFzs#mn8Fq5t*;en2k>{S5W|8TfDA@dFqJ`oFz`wGrgK4gd)7_Aal^3IBci E3p%NAQUCw| 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