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

Subscribers

People subscribed via source and target branches