From 5b0e401ca594d870a9ede615dc75b13d4b262f79 Mon Sep 17 00:00:00 2001 From: redPanther Date: Sat, 3 Dec 2016 21:11:52 +0100 Subject: [PATCH] always output latest version of config file to webui (#307) * always output latest version of config file to webui * fix permissions after default config export * tune code * set permissions for exported effects * use qt setperm instead of chmod update effects code style a bit * add fallback when config is not readable --- effects/knight-rider.py | 4 +--- effects/mood-blobs.py | 5 +---- effects/police.py | 20 +++++++++----------- effects/rainbow-mood.py | 14 ++++++-------- effects/rainbow-swirl.py | 2 +- effects/x-mas.py | 4 +--- libsrc/jsonserver/JsonClientConnection.cpp | 11 +++++++++-- src/hyperiond/main.cpp | 19 ++++++++++++++----- 8 files changed, 42 insertions(+), 37 deletions(-) diff --git a/effects/knight-rider.py b/effects/knight-rider.py index 38c8aabd..dfae89c7 100644 --- a/effects/knight-rider.py +++ b/effects/knight-rider.py @@ -1,6 +1,4 @@ -import hyperion -import time -import colorsys +import hyperion, time, colorsys # Get the parameters speed = float(hyperion.args.get('speed', 1.0)) diff --git a/effects/mood-blobs.py b/effects/mood-blobs.py index 45efff85..7165d873 100644 --- a/effects/mood-blobs.py +++ b/effects/mood-blobs.py @@ -1,7 +1,4 @@ -import hyperion -import time -import colorsys -import math +import hyperion, time, colorsys, math from random import random # Get the parameters diff --git a/effects/police.py b/effects/police.py index 2f4133d2..5eb76187 100644 --- a/effects/police.py +++ b/effects/police.py @@ -1,23 +1,21 @@ -import hyperion -import time -import colorsys +import hyperion, time, colorsys # Get the parameters rotationTime = float(hyperion.args.get('rotation-time', 2.0)) -colorOne = hyperion.args.get('color_one', (255,0,0)) -colorTwo = hyperion.args.get('color_two', (0,0,255)) -colorsCount = hyperion.args.get('colors_count', hyperion.ledCount/2) -reverse = bool(hyperion.args.get('reverse', False)) +colorOne = hyperion.args.get('color_one', (255,0,0)) +colorTwo = hyperion.args.get('color_two', (0,0,255)) +colorsCount = hyperion.args.get('colors_count', hyperion.ledCount/2) +reverse = bool(hyperion.args.get('reverse', False)) # Check parameters rotationTime = max(0.1, rotationTime) -colorsCount = min(hyperion.ledCount/2, colorsCount) +colorsCoun t = min(hyperion.ledCount/2, colorsCount) # Initialize the led data -hsv1 = colorsys.rgb_to_hsv(colorOne[0]/255.0, colorOne[1]/255.0, colorOne[2]/255.0) -hsv2 = colorsys.rgb_to_hsv(colorTwo[0]/255.0, colorTwo[1]/255.0, colorTwo[2]/255.0) +hsv1 = colorsys.rgb_to_hsv(colorOne[0]/255.0, colorOne[1]/255.0, colorOne[2]/255.0) +hsv2 = colorsys.rgb_to_hsv(colorTwo[0]/255.0, colorTwo[1]/255.0, colorTwo[2]/255.0) colorBlack = (0,0,0) -ledData = bytearray() +ledData = bytearray() for i in range(hyperion.ledCount): if i <= colorsCount: rgb = colorsys.hsv_to_rgb(hsv1[0], hsv1[1], hsv1[2]) diff --git a/effects/rainbow-mood.py b/effects/rainbow-mood.py index 2ce08edd..2efd216f 100644 --- a/effects/rainbow-mood.py +++ b/effects/rainbow-mood.py @@ -1,17 +1,15 @@ -import hyperion -import time -import colorsys +import hyperion, time, colorsys # Get the parameters rotationTime = float(hyperion.args.get('rotation-time', 30.0)) -brightness = float(hyperion.args.get('brightness', 1.0)) -saturation = float(hyperion.args.get('saturation', 1.0)) -reverse = bool(hyperion.args.get('reverse', False)) +brightness = float(hyperion.args.get('brightness', 1.0)) +saturation = float(hyperion.args.get('saturation', 1.0)) +reverse = bool(hyperion.args.get('reverse', False)) # Check parameters rotationTime = max(0.1, rotationTime) -brightness = max(0.0, min(brightness, 1.0)) -saturation = max(0.0, min(saturation, 1.0)) +brightness = max(0.0, min(brightness, 1.0)) +saturation = max(0.0, min(saturation, 1.0)) # Calculate the sleep time and hue increment sleepTime = 0.1 diff --git a/effects/rainbow-swirl.py b/effects/rainbow-swirl.py index 94f7877a..0cc0a6ab 100644 --- a/effects/rainbow-swirl.py +++ b/effects/rainbow-swirl.py @@ -8,7 +8,7 @@ centerY = float(hyperion.args.get('center_y', 0.5)) sleepTime = max(0.1, rotationTime) / 360 angle = 0 -centerX = int(round(hyperion.imageWidth)*centerX) +centerX = int(round(float(hyperion.imageWidth)*centerX)) centerY = int(round(float(hyperion.imageHeight)*centerY)) increment = -1 if reverse else 1 diff --git a/effects/x-mas.py b/effects/x-mas.py index 697d6f71..23552a6d 100644 --- a/effects/x-mas.py +++ b/effects/x-mas.py @@ -1,6 +1,4 @@ -import hyperion -import time -import colorsys +import hyperion, time, colorsys # Get the parameters sleepTime = float(hyperion.args.get('sleepTime', 1.0)) diff --git a/libsrc/jsonserver/JsonClientConnection.cpp b/libsrc/jsonserver/JsonClientConnection.cpp index 36e3e776..7c4b607e 100644 --- a/libsrc/jsonserver/JsonClientConnection.cpp +++ b/libsrc/jsonserver/JsonClientConnection.cpp @@ -1042,8 +1042,15 @@ void JsonClientConnection::handleConfigGetCommand(const QJsonObject& message, co result["success"] = true; result["command"] = command; result["tan"] = tan; - const QJsonObject & config = _hyperion->getQJsonConfig(); - result["result"] = config; + + try + { + result["result"] = QJsonFactory::readJson(QString::fromStdString(_hyperion->getConfigFileName())); + } + catch(...) + { + result["result"] = _hyperion->getQJsonConfig(); + } // send the result sendMessage(result); diff --git a/src/hyperiond/main.cpp b/src/hyperiond/main.cpp index a744b8b9..6f3af2eb 100644 --- a/src/hyperiond/main.cpp +++ b/src/hyperiond/main.cpp @@ -29,6 +29,8 @@ using namespace commandline; +#define PERM0664 QFileDevice::ReadOwner | QFileDevice::ReadGroup | QFileDevice::ReadOther | QFileDevice::WriteOwner | QFileDevice::WriteGroup + void signal_handler(const int signum) { QCoreApplication::quit(); @@ -128,16 +130,19 @@ int main(int argc, char** argv) { std::cout << "extract to folder: " << std::endl; QStringList filenames = directory.entryList(QStringList() << "*", QDir::Files, QDir::Name | QDir::IgnoreCase); + QString destFileName; foreach (const QString & filename, filenames) { - if (QFile::exists(destDir.dirName()+"/"+filename)) + destFileName = destDir.dirName()+"/"+filename; + if (QFile::exists(destFileName)) { - QFile::remove(destDir.dirName()+"/"+filename); + QFile::remove(destFileName); } std::cout << "Extract: " << filename.toStdString() << " ... "; - if (QFile::copy(QString(":/effects/")+filename, destDir.dirName()+"/"+filename)) + if (QFile::copy(QString(":/effects/")+filename, destFileName)) { + QFile::setPermissions(destFileName, PERM0664 ); std::cout << "ok" << std::endl; } else @@ -176,11 +181,15 @@ int main(int argc, char** argv) QDir().mkpath(FileUtils::getDirName(exportConfigFileTarget)); if (QFile::copy(":/hyperion_default.config",exportConfigFileTarget)) { + QFile::setPermissions(exportConfigFileTarget, PERM0664 ); Info(log, "export complete."); if (exitAfterexportDefaultConfig) return 0; } - Error(log, "can not export to %s",exportConfigFileTarget.toLocal8Bit().constData()); - if (exitAfterexportDefaultConfig) return 1; + else + { + Error(log, "error while export to %s",exportConfigFileTarget.toLocal8Bit().constData()); + if (exitAfterexportDefaultConfig) return 1; + } } if (configFiles.size() == 0)