1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
|
#!/usr/bin/python3
import sys
import subprocess
import sqlite3
import io
import atexit
from collections import OrderedDict
from PyQt5 import QtCore, QtGui, QtWidgets, uic
from libsisyphus import *
from sisyphusconfig import SisyphusConfig
class Sisyphus(QtWidgets.QMainWindow):
def __init__(self):
super(Sisyphus, self).__init__()
uic.loadUi('ui/sisyphus-gui.ui', self)
self.centerOnScreen()
self.show()
self.filterApplications = OrderedDict([
('Search by Name', 'pn'),
('Search by Category', 'cat'),
('Search by Description', 'descr')
])
self.applicationFilter.addItems(self.filterApplications.keys())
self.applicationFilter.setCurrentText('Search by Name')
self.applicationFilter.currentIndexChanged.connect(self.setApplicationFilter)
Sisyphus.applicationView = self.filterApplications['Search by Name']
self.filterDatabases = OrderedDict([
('All Packages', 'all'),
('Installed Packages', 'instaled'),
('Installable Packages', 'installable'),
('Safely Removable Packages', 'removable'),
('Upgradable/Rebuilt Packages', 'upgradable')
])
self.databaseFilter.addItems(self.filterDatabases.keys())
self.databaseFilter.setCurrentText('All Packages')
self.databaseFilter.currentIndexChanged.connect(self.setDatabaseFilter)
Sisyphus.databaseView = self.filterDatabases['All Packages']
Sisyphus.searchTerm = "'%%'"
self.databaseTable.clicked.connect(self.rowClicked)
self.inputBox.textEdited.connect(self.searchDatabase)
self.settingsButton.clicked.connect(self.sisyphusSettings)
self.updateWorker = UpdateWorker()
self.updateThread = QtCore.QThread()
self.updateWorker.moveToThread(self.updateThread)
self.updateWorker.started.connect(self.showProgressBar)
self.updateWorker.finished.connect(self.updateThread.quit)
self.updateThread.started.connect(self.updateWorker.startUpdate)
self.updateThread.finished.connect(self.jobDone)
self.installButton.clicked.connect(self.packageInstall)
self.installWorker = InstallWorker()
self.installThread = QtCore.QThread()
self.installWorker.moveToThread(self.installThread)
self.installWorker.started.connect(self.showProgressBar)
self.installWorker.strReady.connect(self.updateStatusBar)
self.installWorker.finished.connect(self.installThread.quit)
self.installThread.started.connect(self.installWorker.startInstall)
self.installThread.finished.connect(self.jobDone)
self.uninstallButton.clicked.connect(self.packageUninstall)
self.uninstallWorker = UninstallWorker()
self.uninstallThread = QtCore.QThread()
self.uninstallWorker.moveToThread(self.uninstallThread)
self.uninstallWorker.started.connect(self.showProgressBar)
self.uninstallWorker.strReady.connect(self.updateStatusBar)
self.uninstallWorker.finished.connect(self.uninstallThread.quit)
self.uninstallThread.started.connect(
self.uninstallWorker.startUninstall)
self.uninstallThread.finished.connect(self.jobDone)
self.upgradeButton.clicked.connect(self.systemUpgrade)
self.upgradeWorker = UpgradeWorker()
self.upgradeThread = QtCore.QThread()
self.upgradeWorker.moveToThread(self.upgradeThread)
self.upgradeWorker.started.connect(self.showProgressBar)
self.upgradeWorker.strReady.connect(self.updateStatusBar)
self.upgradeWorker.finished.connect(self.upgradeThread.quit)
self.upgradeThread.started.connect(self.upgradeWorker.startUpgrade)
self.upgradeThread.finished.connect(self.jobDone)
self.orphansButton.clicked.connect(self.orphansRemove)
self.orphansWorker = OrphansWorker()
self.orphansThread = QtCore.QThread()
self.orphansWorker.moveToThread(self.orphansThread)
self.orphansWorker.started.connect(self.showProgressBar)
self.orphansWorker.strReady.connect(self.updateStatusBar)
self.orphansWorker.finished.connect(self.orphansThread.quit)
self.orphansThread.started.connect(self.orphansWorker.cleanOrphans)
self.orphansThread.finished.connect(self.jobDone)
self.updateSystem()
self.progressBar.hide()
self.exitButton.clicked.connect(self.sisyphusExit)
def centerOnScreen(self):
resolution = QtWidgets.QDesktopWidget().screenGeometry()
self.move((resolution.width() / 2) - (self.frameSize().width() / 2),
(resolution.height() / 2) - (self.frameSize().height() / 2))
def rowClicked(self):
Sisyphus.pkgSelect = len(
self.databaseTable.selectionModel().selectedRows())
self.showPackageCount()
def showPackageCount(self):
self.statusBar().showMessage("Found: %d, Selected: %d packages" %
(Sisyphus.pkgCount, Sisyphus.pkgSelect))
def setApplicationFilter(self):
Sisyphus.applicationView = self.filterApplications[self.applicationFilter.currentText(
)]
self.loadDatabase()
def setDatabaseFilter(self):
Sisyphus.databaseView = self.filterDatabases[self.databaseFilter.currentText(
)]
Sisyphus.SELECT = self.databaseFilter.currentText()
self.loadDatabase()
def loadDatabase(self):
noVirtual = "AND cat NOT LIKE 'virtual'"
self.SELECTS = OrderedDict([
('all', '''SELECT
i.category AS cat,
i.name as pn,
IFNULL(a.version, 'None') AS av,
i.version AS iv,
i.description AS descr
FROM local_packages AS i LEFT OUTER JOIN remote_packages as a
ON i.category = a.category
AND i.name = a.name
AND i.slot = a.slot
WHERE %s LIKE %s %s
UNION
SELECT
a.category AS cat,
a.name as pn,
a.version AS av,
IFNULL(i.version, 'None') AS iv,
a.description AS descr
FROM remote_packages AS a LEFT OUTER JOIN local_packages AS i
ON a.category = i.category
AND a.name = i.name
AND a.slot = i.slot
WHERE %s LIKE %s %s
''' % (Sisyphus.applicationView, Sisyphus.searchTerm, noVirtual, Sisyphus.applicationView, Sisyphus.searchTerm, noVirtual)),
('instaled', '''SELECT
i.category AS cat,
i.name AS pn,
a.version AS av,
i.version AS iv,
i.description AS descr
FROM local_packages AS i
LEFT JOIN remote_packages AS a
ON i.category = a.category
AND i.name = a.name
AND i.slot = a.slot
WHERE %s LIKE %s %s
''' % (Sisyphus.applicationView, Sisyphus.searchTerm, noVirtual)),
('installable', '''SELECT
a.category AS cat,
a.name AS pn,
a.version AS av,
i.version AS iv,
a.description AS descr
FROM remote_packages AS a
LEFT JOIN local_packages AS i
ON a.category = i.category
AND a.name = i.name
AND a.slot = i.slot
WHERE %s LIKE %s %s
AND iv IS NULL
''' % (Sisyphus.applicationView, Sisyphus.searchTerm, noVirtual)),
('removable', '''SELECT
i.category AS cat,
i.name AS pn,
a.version AS av,
i.version AS iv,
i.description AS descr
FROM local_packages AS i
LEFT JOIN remote_packages AS a
ON i.category = a.category
AND i.name = a.name
AND i.slot = a.slot
INNER JOIN removable_packages as rm
ON i.category = rm.category
AND i.name = rm.name
AND i.slot = rm.slot
WHERE %s LIKE %s %s
''' % (Sisyphus.applicationView, Sisyphus.searchTerm, noVirtual)),
('upgradable', '''SELECT
i.category AS cat,
i.name AS pn,
CASE WHEN a.version = i.version THEN 'Rebuilt' ELSE a.version END AS av,
i.version AS iv,
i.description AS descr
FROM local_packages AS i
INNER JOIN remote_packages AS a
ON i.category = a.category
AND i.name = a.name
AND i.slot = a.slot
WHERE %s LIKE %s %s
AND a.timestamp > i.timestamp
''' % (Sisyphus.applicationView, Sisyphus.searchTerm, noVirtual)),
])
with sqlite3.connect(sisyphus_database_path) as db:
cursor = db.cursor()
cursor.execute('%s' % (self.SELECTS[Sisyphus.databaseView]))
rows = cursor.fetchall()
Sisyphus.pkgCount = len(rows)
Sisyphus.pkgSelect = 0
model = QtGui.QStandardItemModel(len(rows), 5)
model.setHorizontalHeaderLabels(
['Category', 'Name', 'Available Version', 'Installed Version', 'Description'])
for row in rows:
indx = rows.index(row)
for column in range(0, 5):
item = QtGui.QStandardItem("%s" % (row[column]))
model.setItem(indx, column, item)
self.databaseTable.setModel(model)
self.showPackageCount()
def searchDatabase(self):
search = self.inputBox.text()
Sisyphus.searchTerm = "'%" + search + "%'"
self.loadDatabase()
def updateSystem(self):
self.loadDatabase()
self.statusBar().showMessage("I am syncing myself, hope to finish soon ...")
self.updateThread.start()
def packageInstall(self):
indexes = self.databaseTable.selectionModel().selectedRows(1)
if len(indexes) == 0:
self.statusBar().showMessage("No package selected, please pick at least one!")
else:
Sisyphus.pkgList = []
for index in sorted(indexes):
Sisyphus.pkgList.append(index.data())
self.statusBar().showMessage("I am installing requested package(s), please wait ...")
self.installThread.start()
def packageUninstall(self):
indexes = self.databaseTable.selectionModel().selectedRows(1)
if len(indexes) == 0:
self.statusBar().showMessage("No package selected, please pick at least one!")
else:
Sisyphus.pkgList = []
for index in sorted(indexes):
Sisyphus.pkgList.append(index.data())
self.statusBar().showMessage("I am removing requested package(s), please wait ...")
self.uninstallThread.start()
def systemUpgrade(self):
self.statusBar().showMessage("I am upgrading the system, please be patient ...")
self.upgradeThread.start()
def orphansRemove(self):
self.statusBar().showMessage("I am busy with some cleaning, please don't rush me ...")
self.orphansThread.start()
def jobDone(self):
self.hideProgressBar()
self.loadDatabase()
def showProgressBar(self):
self.hideButtons()
self.progressBar.setRange(0, 0)
self.progressBar.show()
def hideProgressBar(self):
self.progressBar.setRange(0, 1)
self.progressBar.setValue(1)
self.progressBar.hide()
self.showButtons()
def hideButtons(self):
self.installButton.hide()
self.uninstallButton.hide()
self.orphansButton.hide()
self.upgradeButton.hide()
self.exitButton.hide()
def showButtons(self):
self.installButton.show()
self.uninstallButton.show()
self.orphansButton.show()
self.upgradeButton.show()
self.exitButton.show()
def updateStatusBar(self, workerMessage):
self.statusBar().showMessage(workerMessage)
def sisyphusSettings(self):
self.window = SisyphusConfig()
self.window.show()
def sisyphusExit(self):
self.close()
class UpdateWorker(QtCore.QObject):
started = QtCore.pyqtSignal()
finished = QtCore.pyqtSignal()
@QtCore.pyqtSlot()
def startUpdate(self):
self.started.emit()
sisyphus_pkg_system_update()
self.finished.emit()
class InstallWorker(QtCore.QObject):
started = QtCore.pyqtSignal()
finished = QtCore.pyqtSignal()
strReady = QtCore.pyqtSignal(str)
@QtCore.pyqtSlot()
def startInstall(self):
self.started.emit()
pkgList = Sisyphus.pkgList
redcore_sync()
generate_sisyphus_local_packages_table_csv_pre()
portage_call = subprocess.Popen(
['emerge', '-q'] + pkgList, stdout=subprocess.PIPE)
atexit.register(kill_bg_portage, portage_call)
for portage_output in io.TextIOWrapper(portage_call.stdout, encoding="utf-8"):
self.strReady.emit(portage_output.rstrip())
generate_sisyphus_local_packages_table_csv_post()
sync_sisyphus_local_packages_table_csv()
self.finished.emit()
class UninstallWorker(QtCore.QObject):
started = QtCore.pyqtSignal()
finished = QtCore.pyqtSignal()
strReady = QtCore.pyqtSignal(str)
@QtCore.pyqtSlot()
def startUninstall(self):
self.started.emit()
pkgList = Sisyphus.pkgList
redcore_sync()
generate_sisyphus_local_packages_table_csv_pre()
portage_call = subprocess.Popen(
['emerge', '--depclean', '-q'] + pkgList, stdout=subprocess.PIPE)
atexit.register(kill_bg_portage, portage_call)
for portage_output in io.TextIOWrapper(portage_call.stdout, encoding="utf-8"):
self.strReady.emit(portage_output.rstrip())
generate_sisyphus_local_packages_table_csv_post()
sync_sisyphus_local_packages_table_csv()
self.finished.emit()
class UpgradeWorker(QtCore.QObject):
started = QtCore.pyqtSignal()
finished = QtCore.pyqtSignal()
strReady = QtCore.pyqtSignal(str)
@QtCore.pyqtSlot()
def startUpgrade(self):
self.started.emit()
redcore_sync()
generate_sisyphus_local_packages_table_csv_pre()
portage_call = subprocess.Popen(
['emerge', '-uDNq', '--backtrack=100', '--with-bdeps=y', '@world'], stdout=subprocess.PIPE)
atexit.register(kill_bg_portage, portage_call)
for portage_output in io.TextIOWrapper(portage_call.stdout, encoding="utf-8"):
self.strReady.emit(portage_output.rstrip())
generate_sisyphus_local_packages_table_csv_post()
sync_sisyphus_local_packages_table_csv()
self.finished.emit()
class OrphansWorker(QtCore.QObject):
started = QtCore.pyqtSignal()
finished = QtCore.pyqtSignal()
strReady = QtCore.pyqtSignal(str)
@QtCore.pyqtSlot()
def cleanOrphans(self):
self.started.emit()
redcore_sync()
generate_sisyphus_local_packages_table_csv_pre()
portage_call = subprocess.Popen(
['emerge', '--depclean', '-q'], stdout=subprocess.PIPE)
atexit.register(kill_bg_portage, portage_call)
for portage_output in io.TextIOWrapper(portage_call.stdout, encoding="utf-8"):
self.strReady.emit(portage_output.rstrip())
generate_sisyphus_local_packages_table_csv_post()
sync_sisyphus_local_packages_table_csv()
self.finished.emit()
if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv)
window = Sisyphus()
sys.exit(app.exec_())
|