summaryrefslogtreecommitdiff
path: root/portato
diff options
context:
space:
mode:
Diffstat (limited to 'portato')
-rw-r--r--portato/backend/flags.py67
-rw-r--r--portato/backend/package.py18
-rw-r--r--portato/backend/portage/system.py1
-rw-r--r--portato/gui/gtk/dialogs.py2
-rw-r--r--portato/gui/gtk/windows.py61
-rw-r--r--portato/gui/gui_helper.py4
-rw-r--r--portato/gui/templates/portato.glade2
7 files changed, 100 insertions, 55 deletions
diff --git a/portato/backend/flags.py b/portato/backend/flags.py
index f171356..b9fcae2 100644
--- a/portato/backend/flags.py
+++ b/portato/backend/flags.py
@@ -10,7 +10,7 @@
#
# Written by René 'Necoro' Neumann <necoro@necoro.net>
-from __future__ import absolute_import
+from __future__ import absolute_import, with_statement
import os
import os.path
@@ -250,12 +250,18 @@ def set_use_flag (pkg, flag):
if added: del newUseFlags[-1] # we currently added it as an extra option - delete it
added = True
jumpOut = False
- for t in [(file, line, invFlag, False),(file, line, flag, True)]:
+ for t in ((file, line, invFlag, False),(file, line, flag, True)):
if t in newUseFlags[cpv]:
newUseFlags[cpv].remove(t)
jumpOut = True
- break
- if not jumpOut: newUseFlags[cpv].append((file, line, invFlag, True))
+ # break # don't break as both cases can be valid (see below)
+ if not jumpOut:
+ newUseFlags[cpv].append((file, line, invFlag, True))
+
+ # we removed the inverted from package.use - but it is still enabled somewhere else
+ # so set it explicitly here
+ if invFlag in pkg.get_actual_use_flags():
+ newUseFlags[cpv].append((file, line, flag, False))
break
# we want to duplicate the flag --> ignore
@@ -306,17 +312,17 @@ def get_new_use_flags (cpv):
if is_package(cpv):
cpv = cpv.get_cpv()
- list2return = []
+ list2return = set()
try:
for file, line, flag, remove in newUseFlags[cpv]:
if remove:
- list2return.append(invert_use_flag(flag))
+ list2return.add("~"+invert_use_flag(flag))
else:
- list2return.append(flag)
+ list2return.add(flag)
except KeyError:
pass
- return list2return
+ return list(list2return)
def write_use_flags ():
"""This writes our changed useflags into the file."""
@@ -342,9 +348,11 @@ def write_use_flags ():
file_cache = {} # cache for having to read the file only once: name->[lines]
for cpv in newUseFlags:
flagsToAdd = [] # this is used for collecting the flags to be inserted in a _new_ line
+
+ newUseFlags[cpv].sort(key = lambda x: x[3]) # now the flags are sorted in a manner, that removal comes after appending
+
for file, line, flag, delete in newUseFlags[cpv]:
line = int(line) # it is saved as a string so far!
-
# add new line
if line == -1:
flagsToAdd.append(flag)
@@ -352,31 +360,30 @@ def write_use_flags ():
else:
if not file in file_cache:
# read file
- f = open(file, "r")
- lines = []
- i = 1
- while i < line: # stop at the given line
- lines.append(f.readline())
- i += 1
- l = f.readline().split(" ")
-
- # delete or insert
- if delete:
- remove(flag,l)
- else:
- insert(flag,l)
- lines.append(" ".join(l))
-
- # read the rest
- lines.extend(f.readlines())
-
- file_cache[file] = lines
- f.close()
+ with open(file, "r") as f:
+ lines = []
+ i = 1
+ while i < line: # stop at the given line
+ lines.append(f.readline())
+ i += 1
+ l = f.readline().split(" ")
+
+ # delete or insert
+ if delete:
+ remove(flag,l)
+ else:
+ insert(flag,l)
+ lines.append(" ".join(l))
+
+ # read the rest
+ lines.extend(f.readlines())
+
+ file_cache[file] = lines
else: # in cache
l = file_cache[file][line-1].split(" ")
if delete:
- remove(flag,l)
+ remove(flag, l)
else:
insert(flag,l)
file_cache[file][line-1] = " ".join(l)
diff --git a/portato/backend/package.py b/portato/backend/package.py
index 4f90765..16cee0e 100644
--- a/portato/backend/package.py
+++ b/portato/backend/package.py
@@ -12,6 +12,7 @@
from __future__ import absolute_import
+from ..helper import debug
from . import _Package, system, flags
class Package (_Package):
@@ -96,15 +97,22 @@ class Package (_Package):
@rtype: string[]"""
i_flags = self.get_global_settings("USE", installed = False).split()
+ m_flags = system.get_global_settings("USE").split()
for f in self.get_new_use_flags():
+ removed = False
+
+ if f[0] == "~":
+ f = f[1:]
+ removed = True
if f[0] == '-':
- if flags.invert_use_flag(f) in i_flags:
+ if flags.invert_use_flag(f) in i_flags and not (removed and flags.invert_use_flag(f) in m_flags):
i_flags.remove(flags.invert_use_flag(f))
-
+
elif f not in i_flags:
- i_flags.append(f)
-
+ if not (removed and flags.invert_use_flag(f) in m_flags):
+ i_flags.append(f)
+
return i_flags
def set_use_flag (self, flag):
@@ -130,7 +138,7 @@ class Package (_Package):
@returns: USE_EXPAND-value on success
@rtype: string or None"""
- if not suggest is None:
+ if suggest is not None:
if flag.startswith(suggest.lower()):
return suggest
diff --git a/portato/backend/portage/system.py b/portato/backend/portage/system.py
index 0997bed..a1ac90c 100644
--- a/portato/backend/portage/system.py
+++ b/portato/backend/portage/system.py
@@ -142,6 +142,7 @@ class PortageSystem (SystemInterface):
return list_of_packages
def get_global_settings (self, key):
+ self.settings.settings.reset()
return self.settings.settings[key]
def find_best (self, list, only_cpv = False):
diff --git a/portato/gui/gtk/dialogs.py b/portato/gui/gtk/dialogs.py
index 7a1f28d..c26835c 100644
--- a/portato/gui/gtk/dialogs.py
+++ b/portato/gui/gtk/dialogs.py
@@ -11,6 +11,7 @@
# Written by René 'Necoro' Neumann <necoro@necoro.net>
import gtk
+from ...helper import error
from gettext import lgettext as _
def queue_not_empty_dialog():
@@ -26,6 +27,7 @@ def io_ex_dialog (io_ex):
if io_ex.filename:
string = string+": "+io_ex.filename
+ error(string)
dialog = gtk.MessageDialog(None, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, string)
ret = dialog.run()
dialog.destroy()
diff --git a/portato/gui/gtk/windows.py b/portato/gui/gtk/windows.py
index 8b5c895..bf3c274 100644
--- a/portato/gui/gtk/windows.py
+++ b/portato/gui/gtk/windows.py
@@ -478,7 +478,7 @@ class PackageTable:
self.changelogView = self.tree.get_widget("changelogScroll").get_child()
self.filesView = self.tree.get_widget("filesScroll").get_child()
- def update (self, cp, queue = None, version = None, doEmerge = True, instantChange = False):
+ def update (self, cp, queue = None, version = None, doEmerge = True, instantChange = False, type = None):
"""Updates the table to show the contents for the package.
@param cp: the selected package
@@ -490,13 +490,16 @@ class PackageTable:
@param doEmerge: if False, the emerge buttons are disabled
@type doEmerge: boolean
@param instantChange: if True the changed keywords are updated instantly
- @type instantChange: boolean"""
+ @type instantChange: boolean
+ @param type: the type of the queue this package is in; if None there is no queue :)
+ @type type: string"""
self.cp = cp # category/package
self.version = version # version - if not None this is used
self.queue = queue
self.doEmerge = doEmerge
self.instantChange = instantChange
+ self.type = type
# packages and installed packages
if not self.doEmerge:
@@ -679,12 +682,13 @@ class PackageTable:
def _update_keywords (self, emerge, update = False):
if emerge:
+ type = "install" if not self.type else self.type
try:
try:
- self.queue.append(self.actual_package().get_cpv(), type = "install", update = update)
+ self.queue.append(self.actual_package().get_cpv(), type = type, update = update)
except PackageNotFoundException, e:
if unmask_dialog(e[0]) == gtk.RESPONSE_YES:
- self.queue.append(self.actual_package().get_cpv(), type = "install", unmask = True, update = update)
+ self.queue.append(self.actual_package().get_cpv(), type = type, unmask = True, update = update)
except BlockedException, e:
blocked_dialog(e[0], e[1])
else:
@@ -881,7 +885,7 @@ class PackageTable:
flag = store[path][2]
pkg = self.actual_package()
- if flag in pkg.get_global_settings("USE_EXPAND").split(): # ignore expanded flags
+ if pkg.use_expanded(flag): # ignore expanded flags
return False
store[path][0] = not store[path][0]
@@ -996,8 +1000,11 @@ class MainWindow (Window):
changelogScroll.add(HighlightView(lambda p: os.path.join(p.get_package_path(), "ChangeLog"), ["changelog"]))
def show_files (p):
- for f in p.get_files():
- yield " %s\n" % f
+ try:
+ for f in p.get_files():
+ yield " %s\n" % f
+ except IOError, e:
+ yield _("Error: %s") % e.strerror
filesScroll = self.tree.get_widget("filesScroll")
filesScroll.add(InstalledOnlyView(show_files))
@@ -1150,7 +1157,7 @@ class MainWindow (Window):
self.session = Session("gtk_session.cfg")
except (OSError, IOError), e:
io_ex_dialog(e)
- raise
+ return
def load_queue (merge, unmerge, oneshot):
def _load(q, **kwargs):
@@ -1291,7 +1298,7 @@ class MainWindow (Window):
self.fill_pkg_store(self.pkgList.get_model(), self.selCatName)
return True
- def cb_row_activated (self, view, path, *args):
+ def cb_queue_row_activated (self, view, path, *args):
"""Callback for an activated row in the emergeQueue. Opens a package window."""
store = self.queueTree
if len(path) > 1:
@@ -1300,7 +1307,15 @@ class MainWindow (Window):
package = store.get_value(iterator, store.get_cpv_column())
cat, name, vers, rev = system.split_cpv(package)
if rev != "r0": vers = vers+"-"+rev
- self.show_package(cat+"/"+name, queue = self.queue, version = vers, instantChange = True, doEmerge = False)
+
+ if store.is_in_emerge(iterator):
+ type = "install"
+ elif store.is_in_unmerge(iterator):
+ type = "uninstall"
+ elif store.is_in_update(iterator):
+ type = "update"
+
+ self.show_package(cat+"/"+name, queue = self.queue, version = vers, instantChange = True, doEmerge = False, type = type)
return True
def cb_queue_tooltip_queried (self, view, x, y, is_keyboard, tooltip):
@@ -1372,16 +1387,25 @@ class MainWindow (Window):
if len(flags.newUseFlags) > 0:
changed_flags_dialog(_("use flags"))
- flags.write_use_flags()
+ try:
+ flags.write_use_flags()
+ except IOError, e:
+ io_ex_dialog(e)
+ return True
if len(flags.new_masked)>0 or len(flags.new_unmasked)>0 or len(flags.newTesting)>0:
debug("new masked: %s",flags.new_masked)
debug("new unmasked: %s", flags.new_unmasked)
debug("new testing: %s", flags.newTesting)
changed_flags_dialog(_("masking keywords"))
- flags.write_masked()
- flags.write_testing()
- system.reload_settings()
+ try:
+ flags.write_masked()
+ flags.write_testing()
+ except IOError, e:
+ io_ex_dialog(e)
+ return True
+ else:
+ system.reload_settings()
model, iter = self.queueList.get_selection().get_selected()
@@ -1475,9 +1499,12 @@ class MainWindow (Window):
self.queue.sync()
def cb_save_flags_clicked (self, action):
- flags.write_use_flags()
- flags.write_testing()
- flags.write_masked()
+ try:
+ flags.write_use_flags()
+ flags.write_testing()
+ flags.write_masked()
+ except IOError, e:
+ io_ex_dialog(e)
@Window.watch_cursor
def cb_reload_clicked (self, action):
diff --git a/portato/gui/gui_helper.py b/portato/gui/gui_helper.py
index 5d171d6..9c16892 100644
--- a/portato/gui/gui_helper.py
+++ b/portato/gui/gui_helper.py
@@ -388,7 +388,7 @@ class EmergeQueue:
# recursive call
for d in deps:
try:
- self.update_tree(subIt, d, unmask)
+ self.update_tree(subIt, d, unmask, type = type)
except backend.BlockedException, e: # BlockedException occured -> delete current tree and re-raise exception
debug("Something blocked: %s", e[0])
self.remove_with_children(subIt)
@@ -431,7 +431,7 @@ class EmergeQueue:
if hasBeenInQueue: # package has been in queue before
self._queue_append(cpv, oneshot)
- self.update_tree(parentIt, cpv, unmask, oneshot = oneshot)
+ self.update_tree(parentIt, cpv, unmask, oneshot = oneshot, type = type)
else: # not update
if type == "install":
self._queue_append(cpv, oneshot)
diff --git a/portato/gui/templates/portato.glade b/portato/gui/templates/portato.glade
index d937b78..836261b 100644
--- a/portato/gui/templates/portato.glade
+++ b/portato/gui/templates/portato.glade
@@ -1040,7 +1040,7 @@
<property name="enable_search">False</property>
<signal name="button_press_event" handler="cb_right_click"/>
<signal name="query_tooltip" handler="cb_queue_tooltip_queried"/>
- <signal name="row_activated" handler="cb_row_activated"/>
+ <signal name="row_activated" handler="cb_queue_row_activated"/>
</widget>
</child>
</widget>