Merge lp:~zeller-benjamin/qtcreator-plugin-ubuntu/upgradenotifier into lp:qtcreator-plugin-ubuntu

Proposed by Benjamin Zeller
Status: Merged
Approved by: Zoltan Balogh
Approved revision: 329
Merged at revision: 330
Proposed branch: lp:~zeller-benjamin/qtcreator-plugin-ubuntu/upgradenotifier
Merge into: lp:qtcreator-plugin-ubuntu
Diff against target: 533 lines (+413/-4)
9 files modified
share/qtcreator/ubuntu/scripts/qtc_chroot_get_upgrades.py (+84/-0)
src/ubuntu/targetupgrademanager.cpp (+131/-0)
src/ubuntu/targetupgrademanager.h (+85/-0)
src/ubuntu/targetupgrademanagerdialog.ui (+80/-0)
src/ubuntu/ubuntu.pro (+6/-3)
src/ubuntu/ubuntuconstants.h (+7/-1)
src/ubuntu/ubuntuplugin.cpp (+5/-0)
src/ubuntu/ubuntusettingsclickwidget.cpp (+8/-0)
src/ubuntu/ubuntusettingsclickwidget.ui (+7/-0)
To merge this branch: bzr merge lp:~zeller-benjamin/qtcreator-plugin-ubuntu/upgradenotifier
Reviewer Review Type Date Requested Status
Zoltan Balogh Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+246409@code.launchpad.net

Commit message

Automatically check if upgrades for chroots are available when QtCreator is started

Description of the change

Automatically check if upgrades for chroots are available when QtCreator is started

To post a comment you must log in.
Revision history for this message
Zoltan Balogh (bzoltan) wrote :

OK

review: Approve
Revision history for this message
Zoltan Balogh (bzoltan) wrote :

Inline comments

review: Needs Fixing
Revision history for this message
Zoltan Balogh (bzoltan) :
328. By Benjamin Zeller

- Add setting to disable the automatic check
- Fix comments from bzoltan

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
329. By Benjamin Zeller

Merge

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Zoltan Balogh (bzoltan) wrote :

OK

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'share/qtcreator/ubuntu/scripts/qtc_chroot_get_upgrades.py'
2--- share/qtcreator/ubuntu/scripts/qtc_chroot_get_upgrades.py 1970-01-01 00:00:00 +0000
3+++ share/qtcreator/ubuntu/scripts/qtc_chroot_get_upgrades.py 2015-01-23 10:28:15 +0000
4@@ -0,0 +1,84 @@
5+#!/usr/bin/env python3
6+# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
7+#
8+# QTC chroot update check
9+# Copyright (C) 2015 Canonical
10+#
11+# This program is free software: you can redistribute it and/or modify
12+# it under the terms of the GNU General Public License as published by
13+# the Free Software Foundation, either version 3 of the License, or
14+# (at your option) any later version.
15+#
16+# This program is distributed in the hope that it will be useful,
17+# but WITHOUT ANY WARRANTY; without even the implied warranty of
18+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+# GNU General Public License for more details.
20+#
21+# You should have received a copy of the GNU General Public License
22+# along with this program. If not, see <http://www.gnu.org/licenses/>.
23+#
24+# Author: Benjamin Zeller <benjamin.zeller@canonical.com>
25+
26+import signal
27+import subprocess
28+import sys
29+import os
30+import uuid
31+import shutil
32+
33+def splitIgnoreEmptyParts(s, delim=None):
34+ return [x for x in s.split(delim) if x]
35+
36+if (len(sys.argv) < 3):
37+ print("Useage: qtc_chroot_get_upgrades <framework> <architecture>")
38+ sys.exit(-1)
39+
40+click = shutil.which("click")
41+session_id = ""
42+chroot_name_prefix = os.getenv('CLICK_CHROOT_SUFFIX', "click")
43+
44+architecture = sys.argv[1]
45+framework = sys.argv[2]
46+subproc = None
47+
48+if (len(session_id) == 0):
49+ session_id = str(uuid.uuid4())
50+ pre_spawned_session = False
51+else:
52+ pre_spawned_session = True
53+
54+def endSession():
55+ subprocess.call([click, "chroot","-a",architecture,"-f",framework,"-n",chroot_name_prefix,"end-session",session_id],stdout=subprocess.DEVNULL)
56+
57+def exit_gracefully(arg1,arg2):
58+ if(subproc is not None):
59+ subproc.kill()
60+ endSession()
61+ sys.exit(-1)
62+
63+signal.signal(signal.SIGTERM, exit_gracefully)
64+signal.signal(signal.SIGINT , exit_gracefully)
65+signal.signal(signal.SIGHUP , exit_gracefully)
66+
67+if ( not pre_spawned_session ):
68+ success = subprocess.call([click, "chroot","-a",architecture,"-f",framework,"-n",chroot_name_prefix,"begin-session",session_id],stdout=subprocess.DEVNULL)
69+
70+subproc = subprocess.Popen([click, "chroot","-a",architecture,"-f",framework,"-n",chroot_name_prefix,"maint","-n",session_id
71+ ,"env","LC_ALL=C","apt-get","update"],stdout=subprocess.DEVNULL,stderr=subprocess.DEVNULL)
72+subproc.wait()
73+subproc = subprocess.Popen([click, "chroot","-a",architecture,"-f",framework,"-n",chroot_name_prefix,"maint","-n",session_id
74+ ,"env","LC_ALL=C","apt","list","--upgradable"],stdout=subprocess.PIPE,stderr=subprocess.DEVNULL, universal_newlines=True)
75+stdout, stderr = subproc.communicate()
76+endSession()
77+
78+packages = splitIgnoreEmptyParts(stdout,"\n")
79+if(len(packages) == 0):
80+ sys.exit(0)
81+
82+packages.pop(0)
83+sys.exit(len(packages))
84+
85+
86+
87+
88+
89
90=== added file 'src/ubuntu/targetupgrademanager.cpp'
91--- src/ubuntu/targetupgrademanager.cpp 1970-01-01 00:00:00 +0000
92+++ src/ubuntu/targetupgrademanager.cpp 2015-01-23 10:28:15 +0000
93@@ -0,0 +1,131 @@
94+/*
95+ * Copyright 2015 Canonical Ltd.
96+ *
97+ * This program is free software; you can redistribute it and/or modify
98+ * it under the terms of the GNU Lesser General Public License as published by
99+ * the Free Software Foundation; version 2.1.
100+ *
101+ * This program is distributed in the hope that it will be useful,
102+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
103+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
104+ * GNU Lesser General Public License for more details.
105+ *
106+ * You should have received a copy of the GNU Lesser General Public License
107+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
108+ *
109+ * Author: Benjamin Zeller <benjamin.zeller@canonical.com>
110+ */
111+
112+#include "targetupgrademanager.h"
113+
114+#include "ubuntuconstants.h"
115+#include "ubuntuclickdialog.h"
116+#include "ui_targetupgrademanagerdialog.h"
117+
118+#include <coreplugin/coreplugin.h>
119+#include <utils/qtcassert.h>
120+
121+#include <QProcess>
122+#include <QString>
123+#include <QPointer>
124+#include <QSettings>
125+
126+
127+namespace Ubuntu {
128+namespace Internal {
129+
130+TargetUpgradeManager::TargetUpgradeManager(QObject *parent) :
131+ QObject(parent), m_state(Idle)
132+{
133+}
134+
135+void TargetUpgradeManager::checkForUpgrades()
136+{
137+ QSettings settings (QLatin1String(Constants::SETTINGS_COMPANY),QLatin1String(Constants::SETTINGS_PRODUCT));
138+ settings.beginGroup(QLatin1String(Constants::SETTINGS_GROUP_CLICK));
139+ bool set = settings.value(QLatin1String(Constants::SETTINGS_KEY_AUTO_CHECK_CHROOT_UPDATES),true).toBool();
140+ settings.endGroup();
141+
142+ if(set && m_state == Idle) {
143+ m_state = CollectPendingUpdates;
144+ m_outdatedChroots.clear();
145+ foreach(const UbuntuClickTool::Target &chroot, UbuntuClickTool::listAvailableTargets()) {
146+ QPointer<QProcess> proc(new QProcess(this));
147+ connect(proc.data(),SIGNAL(finished(int)),this,SLOT(processFinished()));
148+
149+ proc->start(QString::fromLatin1(Constants::CHROOT_UPDATE_LIST_SCRIPT)
150+ .arg(Constants::UBUNTU_RESOURCE_PATH)
151+ .arg(chroot.architecture)
152+ .arg(chroot.framework));
153+
154+ Task t;
155+ t.proc = proc;
156+ t.target = chroot;
157+ m_running.insert(reinterpret_cast<qintptr>(proc.data()),t);
158+ }
159+ }
160+}
161+
162+void TargetUpgradeManager::processFinished()
163+{
164+ qintptr id = reinterpret_cast<qintptr>(sender());
165+ QTC_ASSERT(m_running.contains(id),return);
166+
167+ switch(m_state) {
168+ case CollectPendingUpdates:{
169+ Task task = m_running.take(id);
170+ task.proc->deleteLater();
171+
172+ if(task.proc->exitStatus() == QProcess::NormalExit && task.proc->exitCode() > 0)
173+ m_outdatedChroots.append(task.target);
174+
175+ if(m_running.isEmpty()) {
176+ m_state = Idle;
177+
178+ if(m_outdatedChroots.isEmpty())
179+ break;
180+
181+ TargetUpgradeManagerDialog::selectAndUpgradeTargets(m_outdatedChroots,Core::ICore::mainWindow());
182+ m_outdatedChroots.clear();
183+ }
184+
185+ break;
186+ }
187+ default:
188+ break;
189+ }
190+}
191+
192+TargetUpgradeManagerDialog::TargetUpgradeManagerDialog(QWidget *parent) : QDialog(parent)
193+{
194+ m_ui = new Ubuntu::Internal::Ui::TargetUpgradeManagerDialog;
195+ m_ui->setupUi(this);
196+}
197+
198+TargetUpgradeManagerDialog::~TargetUpgradeManagerDialog()
199+{
200+ delete m_ui;
201+}
202+
203+void TargetUpgradeManagerDialog::selectAndUpgradeTargets(QList<UbuntuClickTool::Target> targets,QWidget *parent)
204+{
205+
206+ TargetUpgradeManagerDialog dlg(parent);
207+ for(int i = 0; i < targets.size(); i++) {
208+ QTreeWidgetItem *item = new QTreeWidgetItem;
209+ item->setCheckState(0,Qt::Unchecked);
210+ item->setText(0,targets.at(i).framework+QStringLiteral("-")+targets.at(i).architecture);
211+ dlg.m_ui->treeWidget->addTopLevelItem(item);
212+ }
213+
214+ if( dlg.exec() == QDialog::Accepted ) {
215+ for(int i = 0; i < targets.size(); i++) {
216+ if(dlg.m_ui->treeWidget->topLevelItem(i)->checkState(0) == Qt::Checked) {
217+ UbuntuClickDialog::maintainClickModal(targets.at(i),UbuntuClickTool::Upgrade);
218+ }
219+ }
220+ }
221+}
222+
223+} // namespace Internal
224+} // namespace Ubuntu
225
226=== added file 'src/ubuntu/targetupgrademanager.h'
227--- src/ubuntu/targetupgrademanager.h 1970-01-01 00:00:00 +0000
228+++ src/ubuntu/targetupgrademanager.h 2015-01-23 10:28:15 +0000
229@@ -0,0 +1,85 @@
230+/*
231+ * Copyright 2015 Canonical Ltd.
232+ *
233+ * This program is free software; you can redistribute it and/or modify
234+ * it under the terms of the GNU Lesser General Public License as published by
235+ * the Free Software Foundation; version 2.1.
236+ *
237+ * This program is distributed in the hope that it will be useful,
238+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
239+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
240+ * GNU Lesser General Public License for more details.
241+ *
242+ * You should have received a copy of the GNU Lesser General Public License
243+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
244+ *
245+ * Author: Benjamin Zeller <benjamin.zeller@canonical.com>
246+ */
247+
248+#ifndef UBUNTU_INTERNAL_TARGETUPGRADEMANAGER_H
249+#define UBUNTU_INTERNAL_TARGETUPGRADEMANAGER_H
250+
251+#include <QObject>
252+#include <QMap>
253+#include <QPointer>
254+#include <QDialog>
255+
256+#include "ubuntuclicktool.h"
257+
258+class QProcess;
259+
260+namespace Ubuntu {
261+namespace Internal {
262+
263+namespace Ui {
264+ class TargetUpgradeManagerDialog;
265+}
266+
267+class TargetUpgradeManager : public QObject
268+{
269+ Q_OBJECT
270+
271+ enum State {
272+ Idle,
273+ CollectPendingUpdates
274+ };
275+
276+ struct Task {
277+ UbuntuClickTool::Target target;
278+ QPointer<QProcess> proc;
279+ };
280+
281+public:
282+ explicit TargetUpgradeManager(QObject *parent = 0);
283+
284+public slots:
285+ void checkForUpgrades ();
286+
287+private slots:
288+ void processFinished ();
289+
290+private:
291+ QMap<qintptr,Task> m_running;
292+ QList<UbuntuClickTool::Target> m_outdatedChroots;
293+ State m_state;
294+
295+};
296+
297+class TargetUpgradeManagerDialog : public QDialog
298+{
299+ Q_OBJECT
300+
301+public:
302+ TargetUpgradeManagerDialog(QWidget *parent = 0);
303+ ~TargetUpgradeManagerDialog();
304+
305+ static void selectAndUpgradeTargets (QList<UbuntuClickTool::Target> targets,QWidget *parent);
306+
307+private:
308+ Ui::TargetUpgradeManagerDialog *m_ui;
309+};
310+
311+} // namespace Internal
312+} // namespace Ubuntu
313+
314+#endif // UBUNTU_INTERNAL_TARGETUPGRADEMANAGER_H
315
316=== added file 'src/ubuntu/targetupgrademanagerdialog.ui'
317--- src/ubuntu/targetupgrademanagerdialog.ui 1970-01-01 00:00:00 +0000
318+++ src/ubuntu/targetupgrademanagerdialog.ui 2015-01-23 10:28:15 +0000
319@@ -0,0 +1,80 @@
320+<?xml version="1.0" encoding="UTF-8"?>
321+<ui version="4.0">
322+ <class>Ubuntu::Internal::TargetUpgradeManagerDialog</class>
323+ <widget class="QDialog" name="Ubuntu::Internal::TargetUpgradeManagerDialog">
324+ <property name="geometry">
325+ <rect>
326+ <x>0</x>
327+ <y>0</y>
328+ <width>653</width>
329+ <height>479</height>
330+ </rect>
331+ </property>
332+ <property name="windowTitle">
333+ <string>Dialog</string>
334+ </property>
335+ <layout class="QVBoxLayout" name="verticalLayout">
336+ <item>
337+ <widget class="QLabel" name="label">
338+ <property name="text">
339+ <string>Updates are available for your Kits. Please select those which should be updated.</string>
340+ </property>
341+ <property name="wordWrap">
342+ <bool>true</bool>
343+ </property>
344+ </widget>
345+ </item>
346+ <item>
347+ <widget class="QTreeWidget" name="treeWidget">
348+ <column>
349+ <property name="text">
350+ <string/>
351+ </property>
352+ </column>
353+ </widget>
354+ </item>
355+ <item>
356+ <widget class="QDialogButtonBox" name="buttonBox">
357+ <property name="standardButtons">
358+ <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
359+ </property>
360+ </widget>
361+ </item>
362+ </layout>
363+ </widget>
364+ <resources/>
365+ <connections>
366+ <connection>
367+ <sender>buttonBox</sender>
368+ <signal>accepted()</signal>
369+ <receiver>Ubuntu::Internal::TargetUpgradeManagerDialog</receiver>
370+ <slot>accept()</slot>
371+ <hints>
372+ <hint type="sourcelabel">
373+ <x>440</x>
374+ <y>448</y>
375+ </hint>
376+ <hint type="destinationlabel">
377+ <x>649</x>
378+ <y>41</y>
379+ </hint>
380+ </hints>
381+ </connection>
382+ <connection>
383+ <sender>buttonBox</sender>
384+ <signal>rejected()</signal>
385+ <receiver>Ubuntu::Internal::TargetUpgradeManagerDialog</receiver>
386+ <slot>reject()</slot>
387+ <hints>
388+ <hint type="sourcelabel">
389+ <x>358</x>
390+ <y>457</y>
391+ </hint>
392+ <hint type="destinationlabel">
393+ <x>648</x>
394+ <y>79</y>
395+ </hint>
396+ </hints>
397+ </connection>
398+ </connections>
399+</ui>
400
401=== modified file 'src/ubuntu/ubuntu.pro'
402--- src/ubuntu/ubuntu.pro 2015-01-16 13:03:01 +0000
403+++ src/ubuntu/ubuntu.pro 2015-01-23 10:28:15 +0000
404@@ -26,7 +26,8 @@
405 ubuntupackagestepconfigwidget.ui \
406 ubuntumanifesteditor.ui \
407 ubuntuapparmoreditor.ui \
408- ubunturemoterunconfigurationwidget.ui
409+ ubunturemoterunconfigurationwidget.ui \
410+ targetupgrademanagerdialog.ui
411
412 RESOURCES += \
413 resources.qrc
414@@ -134,7 +135,8 @@
415 ubuntutestcontrol.cpp \
416 ubuntupackageoutputparser.cpp \
417 ubuntuprojecthelper.cpp \
418- wizards/ubuntuprojectmigrationwizard.cpp
419+ wizards/ubuntuprojectmigrationwizard.cpp \
420+ targetupgrademanager.cpp
421
422 HEADERS += \
423 ubuntuplugin.h \
424@@ -219,7 +221,8 @@
425 ubuntupackageoutputparser.h \
426 ubuntuprojecthelper.h \
427 ubuntuscopefinalizer.h \
428- wizards/ubuntuprojectmigrationwizard.h
429+ wizards/ubuntuprojectmigrationwizard.h \
430+ targetupgrademanager.h
431
432 INCLUDEPATH+=$$OUT_PWD
433
434
435=== modified file 'src/ubuntu/ubuntuconstants.h'
436--- src/ubuntu/ubuntuconstants.h 2015-01-07 10:50:28 +0000
437+++ src/ubuntu/ubuntuconstants.h 2015-01-23 10:28:15 +0000
438@@ -427,7 +427,8 @@
439
440 const char SETTINGS_COMPANY[] = "Canonical";
441 const char SETTINGS_PRODUCT[] = "UbuntuSDK";
442-const char SETTINGS_GROUP_MODE[] = "Mode";
443+const char SETTINGS_GROUP_MODE[] = "Mode";
444+const char SETTINGS_GROUP_CLICK[] = "Click";
445 const char SETTINGS_GROUP_DEVICE_CONNECTIVITY[] = "DeviceConnectivity";
446 const char SETTINGS_GROUP_DEVICES[] = "Devices";
447
448@@ -441,6 +442,7 @@
449 const char SETTINGS_KEY_QML[] = "QML";
450 const char SETTINGS_KEY_SSH[] = "SSH";
451 const char SETTINGS_KEY_AUTOTOGGLE[] = "Auto_Toggle";
452+const char SETTINGS_KEY_AUTO_CHECK_CHROOT_UPDATES[] = "Auto_Check_Chroot_Updates";
453
454 //const char SETTINGS_GROUP_CLICK[] = "Click";
455 //const char SETTINGS_KEY_CLICK_REVIEWERSTOOLS[] = "ReviewersToolsEnabled";
456@@ -583,6 +585,10 @@
457 //Actions
458 const char UBUNTU_MIGRATE_QMAKE_PROJECT[] = "UbuntuProjectManager.MigrateQMakeProject";
459
460+//TargetUpgradeManager
461+const char CHROOT_UPDATE_LIST_SCRIPT[] = "%1/ubuntu/scripts/qtc_chroot_get_upgrades.py %2 %3";
462+
463+
464 } // namespace Ubuntu
465 } // namespace Constants
466
467
468=== modified file 'src/ubuntu/ubuntuplugin.cpp'
469--- src/ubuntu/ubuntuplugin.cpp 2014-12-12 13:42:11 +0000
470+++ src/ubuntu/ubuntuplugin.cpp 2015-01-23 10:28:15 +0000
471@@ -43,6 +43,7 @@
472 #include "ubuntupackageoutputparser.h"
473 #include "ubuntuprojecthelper.h"
474 #include "ubuntuscopefinalizer.h"
475+#include "targetupgrademanager.h"
476
477 #include "wizards/ubuntuprojectapplicationwizard.h"
478 #include "wizards/ubuntufirstrunwizard.h"
479@@ -305,6 +306,10 @@
480 ,this,SLOT(onKitsLoaded()));
481
482 showFirstStartWizard();
483+
484+ TargetUpgradeManager *mgr = new TargetUpgradeManager();
485+ addAutoReleasedObject(mgr);
486+ mgr->checkForUpgrades();
487 }
488
489 void UbuntuPlugin::showFirstStartWizard()
490
491=== modified file 'src/ubuntu/ubuntusettingsclickwidget.cpp'
492--- src/ubuntu/ubuntusettingsclickwidget.cpp 2014-09-30 15:44:15 +0000
493+++ src/ubuntu/ubuntusettingsclickwidget.cpp 2015-01-23 10:28:15 +0000
494@@ -40,6 +40,9 @@
495 ui->setupUi(this);
496
497 m_settings = new QSettings(QLatin1String(Constants::SETTINGS_COMPANY),QLatin1String(Constants::SETTINGS_PRODUCT));
498+ m_settings->beginGroup(QLatin1String(Constants::SETTINGS_GROUP_CLICK));
499+ ui->enableUpdateCheckerCheckBox->setChecked(m_settings->value(QLatin1String(Constants::SETTINGS_KEY_AUTO_CHECK_CHROOT_UPDATES),true).toBool());
500+ m_settings->endGroup();
501
502 m_deleteMapper = new QSignalMapper(this);
503 connect(m_deleteMapper, SIGNAL(mapped(int)),this, SLOT(on_deleteClickChroot(int)));
504@@ -55,6 +58,11 @@
505 }
506
507 void UbuntuSettingsClickWidget::apply() {
508+
509+ m_settings->beginGroup(QLatin1String(Constants::SETTINGS_GROUP_CLICK));
510+ m_settings->setValue(QLatin1String(Constants::SETTINGS_KEY_AUTO_CHECK_CHROOT_UPDATES),ui->enableUpdateCheckerCheckBox->checkState() == Qt::Checked);
511+ m_settings->endGroup();
512+
513 m_settings->sync();
514 }
515
516
517=== modified file 'src/ubuntu/ubuntusettingsclickwidget.ui'
518--- src/ubuntu/ubuntusettingsclickwidget.ui 2014-09-30 15:44:15 +0000
519+++ src/ubuntu/ubuntusettingsclickwidget.ui 2015-01-23 10:28:15 +0000
520@@ -21,6 +21,13 @@
521 </property>
522 <layout class="QVBoxLayout" name="verticalLayout">
523 <item>
524+ <widget class="QCheckBox" name="enableUpdateCheckerCheckBox">
525+ <property name="text">
526+ <string>Automatically check for updates</string>
527+ </property>
528+ </widget>
529+ </item>
530+ <item>
531 <widget class="QTreeWidget" name="treeWidgetClickTargets">
532 <property name="editTriggers">
533 <set>QAbstractItemView::NoEditTriggers</set>

Subscribers

People subscribed via source and target branches