Merge lp:~ken-vandine/ubuntu-system-settings/click_framework_check into lp:ubuntu-system-settings

Proposed by Ken VanDine
Status: Merged
Approved by: Ken VanDine
Approved revision: 1408
Merged at revision: 1404
Proposed branch: lp:~ken-vandine/ubuntu-system-settings/click_framework_check
Merge into: lp:ubuntu-system-settings
Diff against target: 264 lines (+153/-6)
6 files modified
debian/control (+1/-1)
plugins/system-update/network/network.cpp (+67/-5)
plugins/system-update/network/network.h (+8/-0)
tests/plugins/system-update/CMakeLists.txt (+17/-0)
tests/plugins/system-update/tst_network.cpp (+58/-0)
tests/plugins/system-update/ubuntu-sdk-15.04.framework (+2/-0)
To merge this branch: bzr merge lp:~ken-vandine/ubuntu-system-settings/click_framework_check
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Approve
Manuel de la Peña (community) Approve
Review via email: mp+257828@code.launchpad.net

Commit message

Include supported frameworks and arch when checking for updates

Description of the change

Include supported frameworks and arch when checking for updates

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Manuel de la Peña (mandel) wrote :

Comments are inline.

review: Needs Fixing
1408. By Ken VanDine

cleaned up based on review feedback

Revision history for this message
Manuel de la Peña (mandel) wrote :

Comments are inline.

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
1409. By Ken VanDine

Refactored network test to not require ubuntu-sdk-libs

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'debian/control'
--- debian/control 2015-04-07 10:46:52 +0000
+++ debian/control 2015-04-30 19:36:05 +0000
@@ -43,7 +43,7 @@
43 python3-gi,43 python3-gi,
44 python3-dbus,44 python3-dbus,
45 python3-xdg,45 python3-xdg,
46 gir1.2-glib-2.046 gir1.2-glib-2.0,
47Standards-Version: 3.9.647Standards-Version: 3.9.6
48Homepage: https://launchpad.net/ubuntu-system-settings48Homepage: https://launchpad.net/ubuntu-system-settings
49# If you aren't a member of ~system-settings-touch but need to upload packaging49# If you aren't a member of ~system-settings-touch but need to upload packaging
5050
=== modified file 'plugins/system-update/network/network.cpp'
--- plugins/system-update/network/network.cpp 2014-09-30 14:40:53 +0000
+++ plugins/system-update/network/network.cpp 2015-04-30 19:36:05 +0000
@@ -17,6 +17,7 @@
17 */17 */
1818
19#include "network.h"19#include "network.h"
20#include <sstream>
20#include <QJsonDocument>21#include <QJsonDocument>
21#include <QJsonObject>22#include <QJsonObject>
22#include <QJsonArray>23#include <QJsonArray>
@@ -25,9 +26,13 @@
25#include <QUrl>26#include <QUrl>
26#include <QProcessEnvironment>27#include <QProcessEnvironment>
2728
28#define URL_APPS "https://myapps.developer.ubuntu.com/dev/api/click-metadata/"29namespace {
2930 const QString URL_APPS = "https://search.apps.ubuntu.com/api/v1/click-metadata";
30#define APPS_DATA "APPS_DATA"31 const QString APPS_DATA = "APPS_DATA";
32 constexpr static const char* FRAMEWORKS_FOLDER {"/usr/share/click/frameworks/"};
33 constexpr static const char* FRAMEWORKS_PATTERN {"*.framework"};
34 constexpr static const int FRAMEWORKS_EXTENSION_LENGTH = 10; // strlen(".framework")
35}
3136
32namespace UpdatePlugin {37namespace UpdatePlugin {
3338
@@ -39,10 +44,55 @@
39 this, SLOT(onReply(QNetworkReply*)));44 this, SLOT(onReply(QNetworkReply*)));
40}45}
4146
47std::string Network::getArchitecture()
48{
49 static const std::string deb_arch {architectureFromDpkg()};
50 return deb_arch;
51}
52
53std::vector<std::string> Network::getAvailableFrameworks()
54{
55 std::vector<std::string> result;
56 for (auto f: listFolder(getFrameworksDir().toStdString(), FRAMEWORKS_PATTERN)) {
57 result.push_back(f.substr(0, f.size()-FRAMEWORKS_EXTENSION_LENGTH));
58 }
59 return result;
60}
61
62std::string Network::architectureFromDpkg()
63{
64 QString program("dpkg");
65 QStringList arguments;
66 arguments << "--print-architecture";
67 QProcess archDetector;
68 archDetector.start(program, arguments);
69 if(!archDetector.waitForFinished()) {
70 qWarning() << "Architecture detection failed.";
71 }
72 auto output = archDetector.readAllStandardOutput();
73 auto ostr = QString::fromUtf8(output);
74
75 return ostr.trimmed().toStdString();
76}
77
78std::vector<std::string> Network::listFolder(const std::string& folder, const std::string& pattern)
79{
80 std::vector<std::string> result;
81
82 QDir dir(QString::fromStdString(folder), QString::fromStdString(pattern),
83 QDir::Unsorted, QDir::Readable | QDir::Files);
84 QStringList entries = dir.entryList();
85 for (int i = 0; i < entries.size(); ++i) {
86 QString filename = entries.at(i);
87 result.push_back(filename.toStdString());
88 }
89
90 return result;
91}
92
42void Network::checkForNewVersions(QHash<QString, Update*> &apps)93void Network::checkForNewVersions(QHash<QString, Update*> &apps)
43{94{
44 m_apps = apps;95 m_apps = apps;
45
46 QJsonObject serializer;96 QJsonObject serializer;
47 QJsonArray array;97 QJsonArray array;
48 foreach(QString id, m_apps.keys()) {98 foreach(QString id, m_apps.keys()) {
@@ -50,13 +100,18 @@
50 }100 }
51101
52 serializer.insert("name", array);102 serializer.insert("name", array);
103 std::stringstream frameworks;
104 for (auto f: getAvailableFrameworks()) {
105 frameworks << "," << f;
106 }
53 QJsonDocument doc(serializer);107 QJsonDocument doc(serializer);
54
55 QByteArray content = doc.toJson();108 QByteArray content = doc.toJson();
56109
57 QString urlApps = getUrlApps();110 QString urlApps = getUrlApps();
58 QNetworkRequest request;111 QNetworkRequest request;
59 request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");112 request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
113 request.setRawHeader(QByteArray("X-Ubuntu-Frameworks"), QByteArray::fromStdString(frameworks.str()));
114 request.setRawHeader(QByteArray("X-Ubuntu-Architecture"), QByteArray::fromStdString(getArchitecture()));
60 request.setUrl(QUrl(urlApps));115 request.setUrl(QUrl(urlApps));
61 RequestObject* reqObject = new RequestObject(QString(APPS_DATA));116 RequestObject* reqObject = new RequestObject(QString(APPS_DATA));
62 request.setOriginatingObject(reqObject);117 request.setOriginatingObject(reqObject);
@@ -70,6 +125,13 @@
70 return command;125 return command;
71}126}
72127
128QString Network::getFrameworksDir()
129{
130 QProcessEnvironment environment = QProcessEnvironment::systemEnvironment();
131 QString command = environment.value("FRAMEWORKS_FOLDER", QString(FRAMEWORKS_FOLDER));
132 return command;
133}
134
73void Network::onReply(QNetworkReply *reply)135void Network::onReply(QNetworkReply *reply)
74{136{
75 if (reply->error() == QNetworkReply::NoError) {137 if (reply->error() == QNetworkReply::NoError) {
76138
=== modified file 'plugins/system-update/network/network.h'
--- plugins/system-update/network/network.h 2014-10-07 17:50:03 +0000
+++ plugins/system-update/network/network.h 2015-04-30 19:36:05 +0000
@@ -51,6 +51,8 @@
51 void checkForNewVersions(QHash<QString, Update*> &apps);51 void checkForNewVersions(QHash<QString, Update*> &apps);
52 void getClickToken(Update *app, const QString &url,52 void getClickToken(Update *app, const QString &url,
53 const QString &authHeader);53 const QString &authHeader);
54 virtual std::vector<std::string> getAvailableFrameworks();
55 virtual std::string getArchitecture();
5456
55Q_SIGNALS:57Q_SIGNALS:
56 void updatesFound();58 void updatesFound();
@@ -68,6 +70,12 @@
68 QHash<QString, Update*> m_apps;70 QHash<QString, Update*> m_apps;
6971
70 QString getUrlApps();72 QString getUrlApps();
73 QString getFrameworksDir();
74
75protected:
76 virtual std::string architectureFromDpkg();
77 virtual std::vector<std::string> listFolder(const std::string &folder, const std::string &pattern);
78
71};79};
7280
73}81}
7482
=== modified file 'tests/plugins/system-update/CMakeLists.txt'
--- tests/plugins/system-update/CMakeLists.txt 2014-10-23 13:27:05 +0000
+++ tests/plugins/system-update/CMakeLists.txt 2015-04-30 19:36:05 +0000
@@ -25,6 +25,12 @@
25 ../../../plugins/system-update/update.cpp25 ../../../plugins/system-update/update.cpp
26)26)
2727
28add_executable(tst-network
29 tst_network.cpp
30 ../../../plugins/system-update/update.cpp
31 ../../../plugins/system-update/network/network.cpp
32)
33
28# set the path to the library folder34# set the path to the library folder
29include_directories(/usr/include/apt-pkg/)35include_directories(/usr/include/apt-pkg/)
3036
@@ -36,7 +42,18 @@
36target_link_libraries(tst-update apt-pkg update-plugin)42target_link_libraries(tst-update apt-pkg update-plugin)
37add_test(NAME tst-update COMMAND ${XVFB_CMD} ${CMAKE_CURRENT_BINARY_DIR}/tst-update)43add_test(NAME tst-update COMMAND ${XVFB_CMD} ${CMAKE_CURRENT_BINARY_DIR}/tst-update)
3844
45qt5_use_modules(tst-network Qml Quick Core DBus Xml Network Test)
46target_link_libraries(tst-network apt-pkg update-plugin)
47add_test(NAME tst-network COMMAND ${XVFB_CMD} ${CMAKE_CURRENT_BINARY_DIR}/tst-network)
48set_tests_properties(tst-network
49 PROPERTIES ENVIRONMENT "FRAMEWORKS_FOLDER=${CMAKE_CURRENT_BINARY_DIR}")
50
39add_custom_command(51add_custom_command(
40 TARGET tst-update-manager52 TARGET tst-update-manager
41 COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_LIST_DIR}/click.result ${CMAKE_CURRENT_BINARY_DIR}/click.result53 COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_LIST_DIR}/click.result ${CMAKE_CURRENT_BINARY_DIR}/click.result
42)54)
55
56add_custom_command(
57 TARGET tst-network
58 COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_LIST_DIR}/ubuntu-sdk-15.04.framework ${CMAKE_CURRENT_BINARY_DIR}/ubuntu-sdk-15.04.framework
59)
4360
=== added file 'tests/plugins/system-update/tst_network.cpp'
--- tests/plugins/system-update/tst_network.cpp 1970-01-01 00:00:00 +0000
+++ tests/plugins/system-update/tst_network.cpp 2015-04-30 19:36:05 +0000
@@ -0,0 +1,58 @@
1/*
2 * This file is part of system-settings
3 *
4 * Copyright (C) 2015 Canonical Ltd.
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 3, as published
8 * by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranties of
12 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
13 * PURPOSE. See the GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#include <QDebug>
20#include <QtQml>
21#include <QtQml/QQmlContext>
22#include <QObject>
23#include <QTest>
24#include <QString>
25#include "network/network.h"
26#include "update.h"
27
28using namespace UpdatePlugin;
29
30class NetworkTest: public QObject
31{
32 Q_OBJECT
33
34public:
35 NetworkTest() {};
36
37private Q_SLOTS:
38 void testArch();
39 void testFrameworks();
40
41};
42
43void NetworkTest::testFrameworks()
44{
45 Network net;
46 auto frameworks = net.getAvailableFrameworks();
47 QCOMPARE(frameworks.empty(), false);
48}
49
50void NetworkTest::testArch()
51{
52 Network net;
53 auto arch = net.getArchitecture();
54 QCOMPARE(arch.empty(), false);
55}
56
57QTEST_MAIN(NetworkTest)
58#include "tst_network.moc"
059
=== added file 'tests/plugins/system-update/ubuntu-sdk-15.04.framework'
--- tests/plugins/system-update/ubuntu-sdk-15.04.framework 1970-01-01 00:00:00 +0000
+++ tests/plugins/system-update/ubuntu-sdk-15.04.framework 2015-04-30 19:36:05 +0000
@@ -0,0 +1,2 @@
1Base-Name: ubuntu-sdk
2Base-Version: 15.04

Subscribers

People subscribed via source and target branches