Merge lp:~ken-vandine/ubuntu-system-settings/rtm_click_framework_check into lp:ubuntu-system-settings/rtm-14.09

Proposed by Ken VanDine
Status: Merged
Approved by: Ken VanDine
Approved revision: 1018
Merged at revision: 1012
Proposed branch: lp:~ken-vandine/ubuntu-system-settings/rtm_click_framework_check
Merge into: lp:ubuntu-system-settings/rtm-14.09
Diff against target: 233 lines (+136/-5)
5 files modified
debian/control (+1/-0)
plugins/system-update/network/network.cpp (+60/-5)
plugins/system-update/network/network.h (+7/-0)
tests/plugins/system-update/CMakeLists.txt (+10/-0)
tests/plugins/system-update/tst_network.cpp (+58/-0)
To merge this branch: bzr merge lp:~ken-vandine/ubuntu-system-settings/rtm_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+257781@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.
1013. By Ken VanDine

Added tests to ensure framework and arch are included in check for click updates

1014. By Ken VanDine

Use rawHeader on the request to pass framework and arch

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)
1015. By Ken VanDine

Don't use QByteArray::fromStdString, it was just introduced in 5.4

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

Added build depends on ubuntu-sdk-libs to get click frameworks needed by tests

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

fixed url for click updates

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)
1018. By Ken VanDine

cleaned up based on review feedback

Revision history for this message
Manuel de la Peña (mandel) :
review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
1019. By Ken VanDine

Fixed function rename missed in merge from trunk

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'debian/control'
--- debian/control 2015-02-17 12:55:11 +0000
+++ debian/control 2015-04-30 14:58:55 +0000
@@ -40,6 +40,7 @@
40 pep8,40 pep8,
41 python3-pep8,41 python3-pep8,
42 pyflakes,42 pyflakes,
43 ubuntu-sdk-libs,
43Standards-Version: 3.9.644Standards-Version: 3.9.6
44Homepage: https://launchpad.net/ubuntu-system-settings45Homepage: https://launchpad.net/ubuntu-system-settings
45# If you aren't a member of ~system-settings-touch but need to upload packaging46# If you aren't a member of ~system-settings-touch but need to upload packaging
4647
=== modified file 'plugins/system-update/network/network.cpp'
--- plugins/system-update/network/network.cpp 2014-09-18 13:50:15 +0000
+++ plugins/system-update/network/network.cpp 2015-04-30 14:58:55 +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(FRAMEWORKS_FOLDER, 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(frameworks.str().c_str()));
114 request.setRawHeader(QByteArray("X-Ubuntu-Architecture"), QByteArray(getArchitecture().c_str()));
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);
63118
=== 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 14:58:55 +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,11 @@
68 QHash<QString, Update*> m_apps;70 QHash<QString, Update*> m_apps;
6971
70 QString getUrlApps();72 QString getUrlApps();
73
74protected:
75 virtual std::string architectureFromDpkg();
76 virtual std::vector<std::string> listFolder(const std::string &folder, const std::string &pattern);
77
71};78};
7279
73}80}
7481
=== 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 14:58:55 +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,6 +42,10 @@
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)
48
39add_custom_command(49add_custom_command(
40 TARGET tst-update-manager50 TARGET tst-update-manager
41 COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_LIST_DIR}/click.result ${CMAKE_CURRENT_BINARY_DIR}/click.result51 COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_LIST_DIR}/click.result ${CMAKE_CURRENT_BINARY_DIR}/click.result
4252
=== 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 14:58:55 +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"

Subscribers

People subscribed via source and target branches