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
1=== modified file 'debian/control'
2--- debian/control 2015-02-17 12:55:11 +0000
3+++ debian/control 2015-04-30 14:58:55 +0000
4@@ -40,6 +40,7 @@
5 pep8,
6 python3-pep8,
7 pyflakes,
8+ ubuntu-sdk-libs,
9 Standards-Version: 3.9.6
10 Homepage: https://launchpad.net/ubuntu-system-settings
11 # If you aren't a member of ~system-settings-touch but need to upload packaging
12
13=== modified file 'plugins/system-update/network/network.cpp'
14--- plugins/system-update/network/network.cpp 2014-09-18 13:50:15 +0000
15+++ plugins/system-update/network/network.cpp 2015-04-30 14:58:55 +0000
16@@ -17,6 +17,7 @@
17 */
18
19 #include "network.h"
20+#include <sstream>
21 #include <QJsonDocument>
22 #include <QJsonObject>
23 #include <QJsonArray>
24@@ -25,9 +26,13 @@
25 #include <QUrl>
26 #include <QProcessEnvironment>
27
28-#define URL_APPS "https://myapps.developer.ubuntu.com/dev/api/click-metadata/"
29-
30-#define APPS_DATA "APPS_DATA"
31+namespace {
32+ const QString URL_APPS = "https://search.apps.ubuntu.com/api/v1/click-metadata";
33+ const QString APPS_DATA = "APPS_DATA";
34+ constexpr static const char* FRAMEWORKS_FOLDER {"/usr/share/click/frameworks/"};
35+ constexpr static const char* FRAMEWORKS_PATTERN {"*.framework"};
36+ constexpr static const int FRAMEWORKS_EXTENSION_LENGTH = 10; // strlen(".framework")
37+}
38
39 namespace UpdatePlugin {
40
41@@ -39,10 +44,55 @@
42 this, SLOT(onReply(QNetworkReply*)));
43 }
44
45+std::string Network::getArchitecture()
46+{
47+ static const std::string deb_arch {architectureFromDpkg()};
48+ return deb_arch;
49+}
50+
51+std::vector<std::string> Network::getAvailableFrameworks()
52+{
53+ std::vector<std::string> result;
54+ for (auto f: listFolder(FRAMEWORKS_FOLDER, FRAMEWORKS_PATTERN)) {
55+ result.push_back(f.substr(0, f.size()-FRAMEWORKS_EXTENSION_LENGTH));
56+ }
57+ return result;
58+}
59+
60+std::string Network::architectureFromDpkg()
61+{
62+ QString program("dpkg");
63+ QStringList arguments;
64+ arguments << "--print-architecture";
65+ QProcess archDetector;
66+ archDetector.start(program, arguments);
67+ if(!archDetector.waitForFinished()) {
68+ qWarning() << "Architecture detection failed.";
69+ }
70+ auto output = archDetector.readAllStandardOutput();
71+ auto ostr = QString::fromUtf8(output);
72+
73+ return ostr.trimmed().toStdString();
74+}
75+
76+std::vector<std::string> Network::listFolder(const std::string& folder, const std::string& pattern)
77+{
78+ std::vector<std::string> result;
79+
80+ QDir dir(QString::fromStdString(folder), QString::fromStdString(pattern),
81+ QDir::Unsorted, QDir::Readable | QDir::Files);
82+ QStringList entries = dir.entryList();
83+ for (int i = 0; i < entries.size(); ++i) {
84+ QString filename = entries.at(i);
85+ result.push_back(filename.toStdString());
86+ }
87+
88+ return result;
89+}
90+
91 void Network::checkForNewVersions(QHash<QString, Update*> &apps)
92 {
93 m_apps = apps;
94-
95 QJsonObject serializer;
96 QJsonArray array;
97 foreach(QString id, m_apps.keys()) {
98@@ -50,13 +100,18 @@
99 }
100
101 serializer.insert("name", array);
102+ std::stringstream frameworks;
103+ for (auto f: getAvailableFrameworks()) {
104+ frameworks << "," << f;
105+ }
106 QJsonDocument doc(serializer);
107-
108 QByteArray content = doc.toJson();
109
110 QString urlApps = getUrlApps();
111 QNetworkRequest request;
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()));
115 request.setUrl(QUrl(urlApps));
116 RequestObject* reqObject = new RequestObject(QString(APPS_DATA));
117 request.setOriginatingObject(reqObject);
118
119=== modified file 'plugins/system-update/network/network.h'
120--- plugins/system-update/network/network.h 2014-10-07 17:50:03 +0000
121+++ plugins/system-update/network/network.h 2015-04-30 14:58:55 +0000
122@@ -51,6 +51,8 @@
123 void checkForNewVersions(QHash<QString, Update*> &apps);
124 void getClickToken(Update *app, const QString &url,
125 const QString &authHeader);
126+ virtual std::vector<std::string> getAvailableFrameworks();
127+ virtual std::string getArchitecture();
128
129 Q_SIGNALS:
130 void updatesFound();
131@@ -68,6 +70,11 @@
132 QHash<QString, Update*> m_apps;
133
134 QString getUrlApps();
135+
136+protected:
137+ virtual std::string architectureFromDpkg();
138+ virtual std::vector<std::string> listFolder(const std::string &folder, const std::string &pattern);
139+
140 };
141
142 }
143
144=== modified file 'tests/plugins/system-update/CMakeLists.txt'
145--- tests/plugins/system-update/CMakeLists.txt 2014-10-23 13:27:05 +0000
146+++ tests/plugins/system-update/CMakeLists.txt 2015-04-30 14:58:55 +0000
147@@ -25,6 +25,12 @@
148 ../../../plugins/system-update/update.cpp
149 )
150
151+add_executable(tst-network
152+ tst_network.cpp
153+ ../../../plugins/system-update/update.cpp
154+ ../../../plugins/system-update/network/network.cpp
155+)
156+
157 # set the path to the library folder
158 include_directories(/usr/include/apt-pkg/)
159
160@@ -36,6 +42,10 @@
161 target_link_libraries(tst-update apt-pkg update-plugin)
162 add_test(NAME tst-update COMMAND ${XVFB_CMD} ${CMAKE_CURRENT_BINARY_DIR}/tst-update)
163
164+qt5_use_modules(tst-network Qml Quick Core DBus Xml Network Test)
165+target_link_libraries(tst-network apt-pkg update-plugin)
166+add_test(NAME tst-network COMMAND ${XVFB_CMD} ${CMAKE_CURRENT_BINARY_DIR}/tst-network)
167+
168 add_custom_command(
169 TARGET tst-update-manager
170 COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_LIST_DIR}/click.result ${CMAKE_CURRENT_BINARY_DIR}/click.result
171
172=== added file 'tests/plugins/system-update/tst_network.cpp'
173--- tests/plugins/system-update/tst_network.cpp 1970-01-01 00:00:00 +0000
174+++ tests/plugins/system-update/tst_network.cpp 2015-04-30 14:58:55 +0000
175@@ -0,0 +1,58 @@
176+/*
177+ * This file is part of system-settings
178+ *
179+ * Copyright (C) 2015 Canonical Ltd.
180+ *
181+ * This program is free software: you can redistribute it and/or modify it
182+ * under the terms of the GNU General Public License version 3, as published
183+ * by the Free Software Foundation.
184+ *
185+ * This program is distributed in the hope that it will be useful, but
186+ * WITHOUT ANY WARRANTY; without even the implied warranties of
187+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
188+ * PURPOSE. See the GNU General Public License for more details.
189+ *
190+ * You should have received a copy of the GNU General Public License along
191+ * with this program. If not, see <http://www.gnu.org/licenses/>.
192+ */
193+
194+#include <QDebug>
195+#include <QtQml>
196+#include <QtQml/QQmlContext>
197+#include <QObject>
198+#include <QTest>
199+#include <QString>
200+#include "network/network.h"
201+#include "update.h"
202+
203+using namespace UpdatePlugin;
204+
205+class NetworkTest: public QObject
206+{
207+ Q_OBJECT
208+
209+public:
210+ NetworkTest() {};
211+
212+private Q_SLOTS:
213+ void testArch();
214+ void testFrameworks();
215+
216+};
217+
218+void NetworkTest::testFrameworks()
219+{
220+ Network net;
221+ auto frameworks = net.getAvailableFrameworks();
222+ QCOMPARE(frameworks.empty(), false);
223+}
224+
225+void NetworkTest::testArch()
226+{
227+ Network net;
228+ auto arch = net.getArchitecture();
229+ QCOMPARE(arch.empty(), false);
230+}
231+
232+QTEST_MAIN(NetworkTest)
233+#include "tst_network.moc"

Subscribers

People subscribed via source and target branches