summaryrefslogtreecommitdiff
path: root/app-portage/sisyphus/files/sisyphus-0.1709-r1.patch
blob: 206b3cc72949ed1b5cea22f0c486f5e9442c8986 (plain)
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
diff --git a/src/backend/libsisyphus.py b/src/backend/libsisyphus.py
index 8516a3d..120e268 100755
--- a/src/backend/libsisyphus.py
+++ b/src/backend/libsisyphus.py
@@ -1,16 +1,16 @@
 #!/usr/bin/python3
 
+import animation
+import atexit
 import csv
 import filecmp
 import os
 import shutil
 import sqlite3
-import sys
-import urllib3
 import subprocess
-import animation
+import sys
 import time
-import atexit
+import urllib3
 
 redcore_portage_tree_path = '/usr/portage'
 redcore_desktop_overlay_path = '/var/lib/layman/redcore-desktop'
@@ -19,13 +19,14 @@
 sisyphus_remote_csv_url = 'http://mirror.math.princeton.edu/pub/redcorelinux/csv/remote_preinst.csv'
 sisyphus_remote_csv_path_pre = '/var/lib/sisyphus/csv/remote_preinst.csv'
 sisyphus_remote_csv_path_post = '/var/lib/sisyphus/csv/remote_postinst.csv'
+sisyphus_removeable_csv_url = 'http://mirror.math.princeton.edu/pub/redcorelinux/csv/removeable_preinst.csv'
+sisyphus_removeable_csv_path_pre = '/var/lib/sisyphus/csv/removeable_preinst.csv'
+sisyphus_removeable_csv_path_post = '/var/lib/sisyphus/csv/removeable_postinst.csv'
 sisyphus_local_csv_path_pre = '/var/lib/sisyphus/csv/local_preinst.csv'
 sisyphus_local_csv_path_post = '/var/lib/sisyphus/csv/local_postinst.csv'
 sisyphus_spm_csv_path = '/var/lib/sisyphus/csv/spmsync.csv'
 sisyphus_database_path = '/var/lib/sisyphus/db/sisyphus.db'
 
-BLACKHOLE = open(os.devnull, 'w')
-
 def check_if_root():
     if not os.getuid() == 0:
         sys.exit("\nYou need root permissions to do this, exiting!\n")
@@ -47,36 +48,6 @@ def check_system_mode():
             print("\nThe system is not set to binmode or mixedmode, refusing to run!\n")
             sys.exit(1)
 
-def check_redcore_portage_tree():
-    os.chdir(redcore_portage_tree_path)
-    subprocess.call(['git', 'remote', 'update'], stdout=BLACKHOLE, stderr=subprocess.STDOUT)
-    redcore_portage_tree_local_hash = subprocess.check_output(['git', 'rev-parse', '@'])
-    redcore_portage_tree_remote_hash = subprocess.check_output(['git', 'rev-parse', '@{u}'])
-
-    if not redcore_portage_tree_local_hash == redcore_portage_tree_remote_hash:
-        print("\nPortage tree is out-of-date, run 'sisyphus update' first!\n")
-        sys.exit(1)
-
-def check_redcore_desktop_overlay():
-    os.chdir(redcore_desktop_overlay_path)
-    subprocess.check_call(['git', 'remote', 'update'], stdout=BLACKHOLE, stderr=subprocess.STDOUT)
-    redcore_desktop_overlay_local_hash = subprocess.check_output(['git', 'rev-parse', '@'])
-    redcore_desktop_overlay_remote_hash = subprocess.check_output(['git', 'rev-parse', '@{u}'])
-
-    if not redcore_desktop_overlay_local_hash == redcore_desktop_overlay_remote_hash:
-        print("\nOverlay is out-of-date, run 'sisyphus update' first!\n")
-        sys.exit(1)
-
-def check_redcore_portage_config():
-    os.chdir(redcore_portage_config_path)
-    subprocess.check_call(['git', 'remote', 'update'], stdout=BLACKHOLE, stderr=subprocess.STDOUT)
-    redcore_portage_config_local_hash = subprocess.check_output(['git', 'rev-parse', '@'])
-    redcore_portage_config_remote_hash = subprocess.check_output(['git', 'rev-parse', '@{u}'])
-
-    if not redcore_portage_config_local_hash == redcore_portage_config_remote_hash:
-        print("\nPortage config is out-of-date, run 'sisyphus update' first!\n")
-        sys.exit(1)
-
 def fetch_sisyphus_remote_packages_table_csv():
     http = urllib3.PoolManager()
     
@@ -88,35 +59,24 @@ def fetch_sisyphus_remote_packages_table_csv():
         with http.request('GET', sisyphus_remote_csv_url, preload_content=False) as tmp_buffer, open(sisyphus_remote_csv_path_post, 'wb') as output_file:
             shutil.copyfileobj(tmp_buffer, output_file)
 
-def check_sisyphus_remote_packages_table_csv():
-    if not filecmp.cmp(sisyphus_remote_csv_path_pre, sisyphus_remote_csv_path_post):
-        print("\nSisyphus database is out-of-date, run 'sisyphus update' first!\n")
-        os.remove(sisyphus_remote_csv_path_post)
-        sys.exit(1)
-    else:
-        os.remove(sisyphus_remote_csv_path_post)
-
-def check_sisyphus_remote_packages_table():
-    fetch_sisyphus_remote_packages_table_csv()
-    check_sisyphus_remote_packages_table_csv()
+def fetch_sisyphus_removeable_packages_table_csv():
+    http = urllib3.PoolManager()
 
-def check_sync():
-    check_if_root()
-    check_redcore_portage_tree()
-    check_redcore_desktop_overlay()
-    check_redcore_portage_config()
-    check_sisyphus_remote_packages_table()
+    if not os.path.isfile(sisyphus_removeable_csv_path_pre):
+        os.mknod(sisyphus_removeable_csv_path_pre)
+        with http.request('GET', sisyphus_removeable_csv_url, preload_content=False) as tmp_buffer, open(sisyphus_removeable_csv_path_post, 'wb') as output_file:
+            shutil.copyfileobj(tmp_buffer, output_file)
+    else:
+        with http.request('GET', sisyphus_removeable_csv_url, preload_content=False) as tmp_buffer, open(sisyphus_removeable_csv_path_post, 'wb') as output_file:
+            shutil.copyfileobj(tmp_buffer, output_file)
 
-@animation.wait('fetching remote ebuilds')
 def sync_redcore_portage_tree_and_desktop_overlay():
     subprocess.check_call(['emerge', '--sync', '--quiet'])
 
-@animation.wait('fetching remote configs')
 def sync_redcore_portage_config():
     os.chdir(redcore_portage_config_path)
     subprocess.call(['git', 'pull', '--quiet'])
 
-@animation.wait('fetching remote database')
 def sync_sisyphus_remote_packages_table_csv():
     if not filecmp.cmp(sisyphus_remote_csv_path_pre, sisyphus_remote_csv_path_post):
         sisyphusdb = sqlite3.connect(sisyphus_database_path)
@@ -128,16 +88,34 @@ def sync_sisyphus_remote_packages_table_csv():
         sisyphusdb.commit()
         sisyphusdb.close()
     shutil.move(sisyphus_remote_csv_path_post, sisyphus_remote_csv_path_pre)
+
+def sync_sisyphus_removeable_packages_table_csv():
+    if not filecmp.cmp(sisyphus_removeable_csv_path_pre, sisyphus_removeable_csv_path_post):
+        sisyphusdb = sqlite3.connect(sisyphus_database_path)
+        sisyphusdb.cursor().execute('''drop table if exists removeable_packages''')
+        sisyphusdb.cursor().execute('''create table removeable_packages (category TEXT,name TEXT,version TEXT,slot TEXT,description TEXT)''')
+        with open(sisyphus_removeable_csv_path_post) as sisyphus_removeable_csv:
+            for row in csv.reader(sisyphus_removeable_csv):
+                sisyphusdb.cursor().execute("insert into removeable_packages (category, name, version, slot, description) values (?, ?, ?, ?, ?);", row)
+        sisyphusdb.commit()
+        sisyphusdb.close()
+    shutil.move(sisyphus_removeable_csv_path_post, sisyphus_removeable_csv_path_pre)
         
 def sync_sisyphus_database_remote_packages_table():
     fetch_sisyphus_remote_packages_table_csv()
     sync_sisyphus_remote_packages_table_csv()
 
+def sync_sisyphus_database_removeable_packages_table():
+    fetch_sisyphus_removeable_packages_table_csv()
+    sync_sisyphus_removeable_packages_table_csv()
+
+@animation.wait('syncing remote databases')
 def redcore_sync():
     check_if_root()
     sync_redcore_portage_tree_and_desktop_overlay()
     sync_redcore_portage_config()
     sync_sisyphus_database_remote_packages_table()
+    sync_sisyphus_database_removeable_packages_table()
 
 def generate_sisyphus_local_packages_table_csv_pre():
     subprocess.check_call(['/usr/share/sisyphus/helpers/make_local_csv_pre']) # this is really hard to do in python, so we cheat with a bash helper script
@@ -171,13 +149,13 @@ def sync_sisyphus_spm_csv():
         sisyphusdb.close()
     os.remove(sisyphus_spm_csv_path)
 
-@animation.wait('syncing databases')
+@animation.wait('syncing local databases')
 def sisyphus_pkg_spmsync():
     generate_sisyphus_spm_csv()
     sync_sisyphus_spm_csv()
 
 def sisyphus_pkg_install(PKGLIST):
-    check_sync()
+    redcore_sync()
     generate_sisyphus_local_packages_table_csv_pre()
     portage_call = subprocess.Popen(['emerge', '-a'] + PKGLIST)
     atexit.register(kill_bg_portage, portage_call)
@@ -195,7 +173,7 @@ def sisyphus_pkg_auto_install(PKGLIST):
     sync_sisyphus_local_packages_table_csv()
 
 def sisyphus_pkg_uninstall(PKGLIST):
-    check_sync()
+    redcore_sync()
     generate_sisyphus_local_packages_table_csv_pre()
     portage_call = subprocess.Popen(['emerge', '--depclean', '-a'] + PKGLIST)
     atexit.register(kill_bg_portage, portage_call)
@@ -213,7 +191,7 @@ def sisyphus_pkg_auto_uninstall(PKGLIST):
     sync_sisyphus_local_packages_table_csv()
 
 def sisyphus_pkg_force_uninstall(PKGLIST):
-    check_sync()
+    redcore_sync()
     generate_sisyphus_local_packages_table_csv_pre()
     portage_call = subprocess.Popen(['emerge', '--unmerge', '-a'] + PKGLIST)
     atexit.register(kill_bg_portage, portage_call)
@@ -231,7 +209,7 @@ def sisyphus_pkg_auto_force_uninstall(PKGLIST):
     sync_sisyphus_local_packages_table_csv()
 
 def sisyphus_pkg_remove_orphans():
-    check_sync()
+    redcore_sync()
     generate_sisyphus_local_packages_table_csv_pre()
     portage_call = subprocess.Popen(['emerge', '--depclean', '-a'])
     atexit.register(kill_bg_portage, portage_call)
@@ -249,7 +227,7 @@ def sisyphus_pkg_auto_remove_orphans():
     sync_sisyphus_local_packages_table_csv()
 
 def sisyphus_pkg_system_upgrade():
-    check_sync()
+    redcore_sync()
     generate_sisyphus_local_packages_table_csv_pre()
     portage_call = subprocess.Popen(['emerge', '-uDaN', '--with-bdeps=y', '@world'])
     atexit.register(kill_bg_portage, portage_call)
diff --git a/src/frontend/gui/sisyphus-gui.py b/src/frontend/gui/sisyphus-gui.py
index 0391869..f910bb1 100755
--- a/src/frontend/gui/sisyphus-gui.py
+++ b/src/frontend/gui/sisyphus-gui.py
@@ -12,29 +12,32 @@ def __init__(self):
         self.show()
         
         self.SEARCHFIELDS = OrderedDict ([
-            ('Category', 'cat'),
-            ('Name', 'pn'),
-            ('Description', 'descr')
+            ('Search by category', 'cat'),
+            ('Search by description', 'descr'),
+            ('Search by name', 'pn')
             ])
         self.selectfield.addItems(self.SEARCHFIELDS.keys())
-        self.selectfield.setCurrentIndex(1)
+        self.selectfield.setCurrentIndex(2)
         self.selectfield.currentIndexChanged.connect(self.setSearchField)
-        
+        Sisyphus.SEARCHFIELD = self.SEARCHFIELDS['Search by name']
+             
         self.SEARCHFILTERS = OrderedDict ([
-            ('All', ''),
-            ('Available', 'AND iv IS NULL'),
-            ('Installed', 'AND iv IS NOT NULL'),
-            ('Upgradable', 'AND iv < av'),
-            ('Downgradable', 'AND iv > av')
+            ('All packages', ''),
+            ('Installed packages', 'AND iv IS NOT NULL'),
+            ('Installable packages', 'AND iv IS NULL'),
+            ('Removable packages', 'AND rmv = "yes"'),
+            ('Upgradable packages', 'AND iv <> av')
             ])
+        Sisyphus.SEARCHFILTER = self.SEARCHFILTERS['All packages']
+        
+        Sisyphus.SEARCHTERM = "'%%'"
+
         self.selectfilter.addItems(self.SEARCHFILTERS.keys())
         self.selectfilter.setCurrentIndex(0)
         self.selectfilter.currentIndexChanged.connect(self.setSearchFilter)
-                
-        Sisyphus.SEARCHTERM = "'%%'"
-        Sisyphus.SEARCHFIELD = self.SEARCHFIELDS['Name']
-        Sisyphus.SEARCHFILTER = self.SEARCHFILTERS['All']
-
+        
+        self.database.clicked.connect(self.rowClicked)
+        
         self.input.textEdited.connect(self.filterDatabase)
 
         self.updateThread = UpdateThread()
@@ -66,36 +69,52 @@ def __init__(self):
 
         self.abort.clicked.connect(self.sisyphusExit)
         
-    def setSearchField(self):
-        Sisyphus.SEARCHFIELD = self.SEARCHFIELDS[self.selectfield.currentText()]
-        self.loadDatabase(Sisyphus.SEARCHFIELD,Sisyphus.SEARCHTERM,Sisyphus.SEARCHFILTER)
-        
-    def setSearchFilter(self):
-        Sisyphus.SEARCHFILTER = self.SEARCHFILTERS[self.selectfilter.currentText()]
-        self.loadDatabase(Sisyphus.SEARCHFIELD,Sisyphus.SEARCHTERM,Sisyphus.SEARCHFILTER)
         
     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.PKGSELECTED = len(self.database.selectionModel().selectedRows())
+        self.showPackageCount()
+
+    def showPackageCount(self):
+        self.statusBar().showMessage("Found: %d, Selected: %d packages" %(Sisyphus.PKGCOUNT, Sisyphus.PKGSELECTED))
+
+    def setSearchField(self):
+        Sisyphus.SEARCHFIELD = self.SEARCHFIELDS[self.selectfield.currentText()]
+        self.loadDatabase()
+        
+    def setSearchFilter(self):
+        Sisyphus.SEARCHFILTER = self.SEARCHFILTERS[self.selectfilter.currentText()]
+        self.loadDatabase()
 
-    def loadDatabase(self,searchField,searchTerm,searchFilter):
-        with sqlite3.connect('/var/lib/sisyphus/db/sisyphus.db') as db:
+    def loadDatabase(self):
+        with sqlite3.connect(sisyphus_database_path) as db:
             cursor=db.cursor()
+            FILTEROUT = "AND cat NOT LIKE 'virtual'"
             cursor.execute('''SELECT
                             a.category AS cat,
                             a.name AS pn,
                             a.version AS av,
                             i.version AS iv,
-                            a.description AS descr
+                            a.description AS descr,
+                            CASE WHEN rm.name ISNULL THEN 'no' ELSE 'yes' END AS rmv
                             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
-                        ''' % (searchField, searchTerm, searchFilter))
+                            LEFT JOIN removeable_packages as rm
+                            ON i.category = rm.category
+                            AND i.name = rm.name
+                            AND i.slot = rm.slot
+                            WHERE %s LIKE %s %s %s
+                        ''' % (Sisyphus.SEARCHFIELD, Sisyphus.SEARCHTERM, Sisyphus.SEARCHFILTER, FILTEROUT))
             rows = cursor.fetchall()
+            Sisyphus.PKGCOUNT = len(rows)
+            Sisyphus.PKGSELECTED = 0
             model = QtGui.QStandardItemModel(len(rows), 5)
             model.setHorizontalHeaderLabels(['Category', 'Name', 'Available Version', 'Installed Version', 'Description'])
             for row in rows:
@@ -104,20 +123,21 @@ def loadDatabase(self,searchField,searchTerm,searchFilter):
                     item = QtGui.QStandardItem("%s"%(row[column]))
                     model.setItem(indx, column, item)
             self.database.setModel(model)
+            self.showPackageCount()
 
     def filterDatabase(self):
         search = self.input.text()
         Sisyphus.SEARCHTERM = "'%" + search + "%'"
-        self.loadDatabase(Sisyphus.SEARCHFIELD,Sisyphus.SEARCHTERM,Sisyphus.SEARCHFILTER)
+        self.loadDatabase()
 
     def updateSystem(self):
-        self.loadDatabase(Sisyphus.SEARCHFIELD,Sisyphus.SEARCHTERM,Sisyphus.SEARCHFILTER)
+        self.loadDatabase()
         self.updateThread.start()
 
     def packageInstall(self):
         indexes = self.database.selectionModel().selectedRows(1)
         if len(indexes) == 0:
-            self.input.setText("Please select at least one package!!!")
+            self.statusBar().showMessage("No package selected, please pick at least one!", 3000)
         else:
             Sisyphus.PKGLIST = []
             for index in sorted(indexes):
@@ -127,7 +147,7 @@ def packageInstall(self):
     def packageUninstall(self):
         indexes = self.database.selectionModel().selectedRows(1)
         if len(indexes) == 0:
-            self.input.setText("Please select at least one package!!!")
+            self.statusBar().showMessage("No package selected, please pick at least one!", 3000)
         else:
             Sisyphus.PKGLIST = []
             for index in sorted(indexes):
@@ -142,7 +162,7 @@ def orphansRemove(self):
 
     def jobDone(self):
         self.hideProgressBar()
-        self.loadDatabase(Sisyphus.SEARCHFIELD,Sisyphus.SEARCHTERM,Sisyphus.SEARCHFILTER)
+        self.loadDatabase()
 
     def showProgressBar(self):
         self.hideButtons()