many fixes

This commit is contained in:
guinux 2013-03-18 11:07:58 +01:00
parent 73e1e8d6c0
commit 8a5abb4b47
8 changed files with 200 additions and 88 deletions

View File

@ -5,6 +5,6 @@ STATUS=$2 # The new state of the interface
case "$STATUS" in case "$STATUS" in
'up') # $INTERFACE is up 'up') # $INTERFACE is up
/usr/bin/pamac-check-updates /usr/bin/pamac-refresh
;; ;;
esac esac

View File

@ -1,16 +0,0 @@
#! /usr/bin/python
# -*-coding:utf-8-*-
from pamac import common, transaction
if not common.pid_file_exists():
print('checking updates')
common.write_pid_file()
try:
transaction.Refresh()
transaction.StopDaemon()
except:
pass
finally:
common.rm_pid_file()
print('check updates done')

View File

@ -180,11 +180,11 @@ class PamacDBusService(dbus.service.Object):
pass pass
def CheckUpdates(self): def CheckUpdates(self):
updates = False updates = 0
for pkg in config.handle.get_localdb().pkgcache: for pkg in config.handle.get_localdb().pkgcache:
candidate = pyalpm.sync_newversion(pkg, config.handle.get_syncdbs()) candidate = pyalpm.sync_newversion(pkg, config.handle.get_syncdbs())
if candidate: if candidate:
updates = True updates += 1
self.EmitAvailableUpdates(updates) self.EmitAvailableUpdates(updates)
@dbus.service.method('org.manjaro.pamac', '', 's', async_callbacks=('success', 'nosuccess')) @dbus.service.method('org.manjaro.pamac', '', 's', async_callbacks=('success', 'nosuccess'))
@ -205,6 +205,8 @@ class PamacDBusService(dbus.service.Object):
self.CheckUpdates() self.CheckUpdates()
if self.error: if self.error:
self.EmitTransactionError(self.error) self.EmitTransactionError(self.error)
else:
self.EmitTransactionDone('')
self.task = Process(target=refresh) self.task = Process(target=refresh)
self.task.start() self.task.start()
success('') success('')

74
pamac-install Executable file
View File

@ -0,0 +1,74 @@
#! /usr/bin/python
# -*-coding:utf-8 -*-
from gi.repository import GObject
from sys import argv
import dbus
from pamac import common, transaction, main
def error(error):
transaction.StopDaemon()
common.rm_pid_file()
print('exiting')
loop.quit()
def reply(reply):
transaction.StopDaemon()
common.rm_pid_file()
print('exiting')
loop.quit()
def install(pkgnames):
transaction.to_add = []
transaction.to_remove = []
pkg_to_install = []
for pkgname in pkgnames:
if not pkgname in transaction.localpkgs.keys():
transaction.to_add.append(pkgname)
pkg_to_install.append(transaction.syncpkgs[pkgname])
main.check_conflicts(pkg_to_install)
if transaction.to_add:
if transaction.init_transaction(noconflicts = True, needed =True):
for pkgname in transaction.to_add:
transaction.Add(pkgname)
for pkgname in transaction.to_remove:
transaction.Remove(pkgname)
_error = transaction.Prepare()
if _error:
main.handle_error(_error)
error(_error)
else:
main.finalize()
loop.run()
else:
transaction.WarningDialog.format_secondary_text('Nothing to do')
response = transaction.WarningDialog.run()
if response:
transaction.WarningDialog.hide()
reply('')
bus = dbus.SystemBus()
bus.add_signal_receiver(reply, dbus_interface = "org.manjaro.pamac", signal_name = "EmitTransactionDone")
bus.add_signal_receiver(error, dbus_interface = "org.manjaro.pamac", signal_name = "EmitTransactionError")
loop = GObject.MainLoop()
transaction.update_db()
do_syncfirst, updates = transaction.get_updates()
if common.pid_file_exists():
transaction.ErrorDialog.format_secondary_text('Another instance of Pamac is running')
response = transaction.ErrorDialog.run()
if response:
transaction.ErrorDialog.hide()
transaction.StopDaemon()
elif updates:
transaction.ErrorDialog.format_secondary_text('Some updates are available.\nPlease update your system first')
response = transaction.ErrorDialog.run()
if response:
transaction.ErrorDialog.hide()
transaction.StopDaemon()
else:
common.write_pid_file()
pkgname_to_install = argv[1:]
install(pkgname_to_install)

30
pamac-refresh Executable file
View File

@ -0,0 +1,30 @@
#! /usr/bin/python
# -*-coding:utf-8-*-
from gi.repository import GObject
from pamac import common, transaction
import dbus
def reply(reply):
transaction.StopDaemon()
common.rm_pid_file()
print('check updates done')
loop.quit()
def error(error):
transaction.StopDaemon()
common.rm_pid_file()
print('check updates failed')
loop.quit()
bus = dbus.SystemBus()
bus.add_signal_receiver(reply, dbus_interface = "org.manjaro.pamac", signal_name = "EmitTransactionDone")
bus.add_signal_receiver(error, dbus_interface = "org.manjaro.pamac", signal_name = "EmitTransactionError")
loop = GObject.MainLoop()
if not common.pid_file_exists():
print('checking updates')
common.write_pid_file()
transaction.Refresh()
loop.run()

View File

@ -3,13 +3,20 @@
from gi.repository import Gtk, GObject from gi.repository import Gtk, GObject
from subprocess import call from subprocess import call
from pamac import transaction from pamac import common, transaction
import dbus import dbus
import threading import threading
GObject.threads_init() GObject.threads_init()
bus = dbus.SystemBus() bus = dbus.SystemBus()
icon = ''
info = ''
update_icon = '/usr/share/pamac/icons/scalable/status/update-normal.svg'
update_info = '{} Updates Available'
noupdate_icon = '/usr/share/pamac/icons/scalable/status/update-enhancement.svg'
noupdate_info = ' No Update Available'
class Tray: class Tray:
def __init__(self): def __init__(self):
self.statusIcon = Gtk.StatusIcon() self.statusIcon = Gtk.StatusIcon()
@ -27,6 +34,7 @@ class Tray:
self.menu.append(self.menuItem) self.menu.append(self.menuItem)
self.statusIcon.connect('popup-menu', self.popup_menu_cb, self.menu) self.statusIcon.connect('popup-menu', self.popup_menu_cb, self.menu)
self.statusIcon.connect('activate', self.activate_cb, self.menu)
def execute_update(self, widget, event, data = None): def execute_update(self, widget, event, data = None):
call(['/usr/bin/pamac-updater']) call(['/usr/bin/pamac-updater'])
@ -44,6 +52,9 @@ class Tray:
data.show_all() data.show_all()
data.popup(None, None, Gtk.StatusIcon.position_menu, self.statusIcon, 3, time) data.popup(None, None, Gtk.StatusIcon.position_menu, self.statusIcon, 3, time)
def activate_cb(self, widget, data = None):
call(['notify-send', '-i', icon, '-u', 'normal', 'Pamac', info])
def update_icon(self, icon, info): def update_icon(self, icon, info):
self.statusIcon.set_from_file(icon) self.statusIcon.set_from_file(icon)
self.statusIcon.set_tooltip_markup(info) self.statusIcon.set_tooltip_markup(info)
@ -72,18 +83,19 @@ class PeriodicTask(threading.Thread):
self._finished.wait(self._interval) self._finished.wait(self._interval)
def task(self): def task(self):
call(['/usr/bin/pamac-check-updates']) call(['/usr/bin/pamac-refresh'])
def set_icon(updates): def set_icon(updates):
print('set-icon') global icon
#transaction.get_handle() global info
#do_syncfirst, updates = transaction.get_updates()
if updates: if updates:
icon = '/usr/share/pamac/icons/24x24/status/update-normal.png' icon = update_icon
info = 'Updates available' info = update_info.format(updates)
if not common.pid_file_exists():
call(['notify-send', '-i', icon, '-u', 'normal', 'Pamac', info])
else: else:
icon = '/usr/share/pamac/icons/24x24/status/update-enhancement.png' icon = noupdate_icon
info = ' No update available' info = noupdate_info
print(info) print(info)
tray.update_icon(icon, info) tray.update_icon(icon, info)

View File

@ -186,8 +186,8 @@ class PacmanConfig(object):
pacman_conf = PacmanConfig(conf = "/etc/pacman.conf") pacman_conf = PacmanConfig(conf = "/etc/pacman.conf")
handle = pacman_conf.initialize_alpm() handle = pacman_conf.initialize_alpm()
holpkg = None holdpkg = []
syncfirst = None syncfirst = []
if 'HoldPkg' in pacman_conf.options: if 'HoldPkg' in pacman_conf.options:
holdpkg = pacman_conf.options['HoldPkg'] holdpkg = pacman_conf.options['HoldPkg']
if 'SyncFirst' in pacman_conf.options: if 'SyncFirst' in pacman_conf.options:

View File

@ -275,6 +275,8 @@ def handle_error(error):
global transaction_type global transaction_type
global transaction_dict global transaction_dict
ProgressWindow.hide() ProgressWindow.hide()
#while Gtk.events_pending():
# Gtk.main_iteration()
if error: if error:
if not 'DBus.Error.NoReply' in str(error): if not 'DBus.Error.NoReply' in str(error):
print('error:', error) print('error:', error)
@ -299,6 +301,8 @@ def handle_reply(reply):
global transaction_type global transaction_type
global transaction_dict global transaction_dict
ProgressWindow.hide() ProgressWindow.hide()
#while Gtk.events_pending():
# Gtk.main_iteration()
if reply: if reply:
transaction.InfoDialog.format_secondary_text(reply) transaction.InfoDialog.format_secondary_text(reply)
response = transaction.InfoDialog.run() response = transaction.InfoDialog.run()
@ -332,10 +336,12 @@ def do_refresh():
transaction.t_lock = True transaction.t_lock = True
progress_label.set_text('Refreshing...') progress_label.set_text('Refreshing...')
action_icon.set_from_file('/usr/share/pamac/icons/24x24/status/refresh-cache.png') action_icon.set_from_file('/usr/share/pamac/icons/24x24/status/refresh-cache.png')
progress_bar.set_text('')
progress_bar.set_fraction(0)
ProgressWindow.show_all() ProgressWindow.show_all()
while Gtk.events_pending(): while Gtk.events_pending():
Gtk.main_iteration() Gtk.main_iteration()
transaction.Refresh(reply_handler = handle_reply, error_handler = handle_error)#, timeout = 2000*1000) transaction.Refresh()#reply_handler = handle_reply, error_handler = handle_error, timeout = 2000*1000)
def have_updates(): def have_updates():
do_syncfirst, updates = transaction.get_updates() do_syncfirst, updates = transaction.get_updates()
@ -361,8 +367,8 @@ def do_sysupgrade():
if updates: if updates:
transaction.to_add = [] transaction.to_add = []
transaction.to_remove = [] transaction.to_remove = []
check_conflicts(updates)
if do_syncfirst: if do_syncfirst:
check_conflicts('normal', updates)
for pkg in updates: for pkg in updates:
transaction.to_add.append(pkg.name) transaction.to_add.append(pkg.name)
if transaction.init_transaction(recurse = True, needed = True): if transaction.init_transaction(recurse = True, needed = True):
@ -385,6 +391,7 @@ def do_sysupgrade():
if mode == 'manager': if mode == 'manager':
ConfDialog.show_all() ConfDialog.show_all()
else: else:
check_conflicts('updating', updates)
if transaction.init_transaction(noconflicts = True): if transaction.init_transaction(noconflicts = True):
error = transaction.Sysupgrade() error = transaction.Sysupgrade()
if error: if error:
@ -413,12 +420,13 @@ def finalize():
progress_label.set_text('Preparing...') progress_label.set_text('Preparing...')
action_icon.set_from_file('/usr/share/pamac/icons/24x24/status/setup.png') action_icon.set_from_file('/usr/share/pamac/icons/24x24/status/setup.png')
progress_bar.set_text('') progress_bar.set_text('')
progress_bar.set_fraction(0)
ProgressWindow.show_all() ProgressWindow.show_all()
while Gtk.events_pending(): while Gtk.events_pending():
Gtk.main_iteration() Gtk.main_iteration()
transaction.Commit()#reply_handler = handle_reply, error_handler = handle_error, timeout = 2000*1000) transaction.Commit()#reply_handler = handle_reply, error_handler = handle_error, timeout = 2000*1000)
def check_conflicts(pkg_list): def check_conflicts(mode, pkg_list):
depends = [pkg_list] depends = [pkg_list]
warning = '' warning = ''
error = '' error = ''
@ -495,6 +503,7 @@ def check_conflicts(pkg_list):
transaction.to_add.append(_pkg.name) transaction.to_add.append(_pkg.name)
else: else:
depends[i+1].append(provide) depends[i+1].append(provide)
if mode == 'updating':
for replace in pkg.replaces: for replace in pkg.replaces:
provide = pyalpm.find_satisfier(transaction.localpkgs.values(), replace) provide = pyalpm.find_satisfier(transaction.localpkgs.values(), replace)
if provide: if provide:
@ -502,17 +511,27 @@ def check_conflicts(pkg_list):
if not provide.name in transaction.to_remove: if not provide.name in transaction.to_remove:
transaction.to_remove.append(provide.name) transaction.to_remove.append(provide.name)
if warning: if warning:
warning = warning+'\n' warning += '\n'
warning = warning+provide.name+' will be replaced by '+pkg.name warning += provide.name+' will be replaced by '+pkg.name
for conflict in pkg.conflicts: for conflict in pkg.conflicts:
provide = pyalpm.find_satisfier(transaction.localpkgs.values(), conflict) provide = pyalpm.find_satisfier(transaction.localpkgs.values(), conflict)
if provide: if provide:
if provide.name != pkg.name: if provide.name != pkg.name:
if not provide.name in transaction.to_remove: required = pkg.compute_requiredby()
if required:
str_required = ''
for i in required:
if str_required:
str_required += ', '
str_required += i
if error:
error += '\n'
error += '{} conflicts with {} but cannot be removed because it is needed by {}'.format(provide.name, pkg.name, str_required)
elif not provide.name in transaction.to_remove:
transaction.to_remove.append(provide.name) transaction.to_remove.append(provide.name)
if warning: if warning:
warning = warning+'\n' warning += '\n'
warning = warning+pkg.name+' conflicts with '+provide.name warning += pkg.name+' conflicts with '+provide.name
provide = pyalpm.find_satisfier(depends[0], conflict) provide = pyalpm.find_satisfier(depends[0], conflict)
if provide: if provide:
if not common.format_pkg_name(conflict) == pkg.name: if not common.format_pkg_name(conflict) == pkg.name:
@ -521,19 +540,30 @@ def check_conflicts(pkg_list):
transaction.to_add.remove(common.format_pkg_name(conflict)) transaction.to_add.remove(common.format_pkg_name(conflict))
transaction.to_add.remove(pkg.name) transaction.to_add.remove(pkg.name)
if warning: if warning:
warning = warning+'\n' warning += '\n'
warning = warning+pkg.name+' conflicts with '+common.format_pkg_name(conflict)+'\nNone of them will be installed' warning += pkg.name+' conflicts with '+common.format_pkg_name(conflict)+'\nNone of them will be installed'
i += 1 i += 1
for pkg in transaction.localpkgs.values(): for pkg in transaction.localpkgs.values():
for conflict in pkg.conflicts: for conflict in pkg.conflicts:
provide = pyalpm.find_satisfier(depends[0], conflict) provide = pyalpm.find_satisfier(depends[0], conflict)
if provide: if provide:
if provide.name != pkg.name: if provide.name != pkg.name:
if not provide.name in transaction.to_remove: required = pkg.compute_requiredby()
if required:
str_required = ''
for i in required:
if str_required:
str_required += ', '
str_required += i
if error:
error += '\n'
error += '{} conflicts with {} but cannot be removed because it is needed by {}'.format(provide.name, pkg.name, str_required)
elif not provide.name in transaction.to_remove:
transaction.to_remove.append(pkg.name) transaction.to_remove.append(pkg.name)
if warning: if warning:
warning = warning+'\n' warning += '\n'
warning = warning+provide.name+' conflicts with '+pkg.name warning += provide.name+' conflicts with '+pkg.name
if mode == 'updating':
for pkg in transaction.syncpkgs.values(): for pkg in transaction.syncpkgs.values():
for replace in pkg.replaces: for replace in pkg.replaces:
provide = pyalpm.find_satisfier(transaction.localpkgs.values(), replace) provide = pyalpm.find_satisfier(transaction.localpkgs.values(), replace)
@ -545,36 +575,16 @@ def check_conflicts(pkg_list):
if not provide.name in transaction.to_remove: if not provide.name in transaction.to_remove:
transaction.to_remove.append(provide.name) transaction.to_remove.append(provide.name)
if warning: if warning:
warning = warning+'\n' warning += '\n'
warning = warning+provide.name+' will be replaced by '+pkg.name warning += provide.name+' will be replaced by '+pkg.name
if not pkg.name in transaction.to_add: if not pkg.name in transaction.to_add:
transaction.to_add.append(pkg.name) transaction.to_add.append(pkg.name)
print(transaction.to_add,transaction.to_remove) print('check result:', 'to add:', transaction.to_add, 'to remove:', transaction.to_remove)
if warning: if warning:
transaction.WarningDialog.format_secondary_text(warning) transaction.WarningDialog.format_secondary_text(warning)
response = transaction.WarningDialog.run() response = transaction.WarningDialog.run()
if response: if response:
transaction.WarningDialog.hide() transaction.WarningDialog.hide()
pkg_list = {}
for pkgname in transaction.to_remove:
pkg_list[pkgname] = transaction.localpkgs[pkgname]
for pkgname in transaction.to_add:
pkg = transaction.syncpkgs[pkgname]
for replace in pkg.replaces:
provide = pyalpm.find_satisfier(pkg_list.values(), replace)
if provide:
pkg_list.pop(provide.name)
for pkg in pkg_list.values():
required = pkg.compute_requiredby()
if required:
str_required = ''
for i in required:
if str_required:
str_required += ', '
str_required += i
if error:
error = error+'\n'
error += 'Cannot remove {} because it is needed by {}'.format(pkgname, str_required)
if error: if error:
handle_error(error) handle_error(error)
@ -638,7 +648,7 @@ class Handler:
for pkgname in transaction_dict.keys(): for pkgname in transaction_dict.keys():
transaction.to_add.append(pkgname) transaction.to_add.append(pkgname)
transaction.to_remove = [] transaction.to_remove = []
check_conflicts(transaction_dict.values()) check_conflicts('normal', transaction_dict.values())
if transaction.to_add: if transaction.to_add:
if transaction.init_transaction(noconflicts = True): if transaction.init_transaction(noconflicts = True):
for pkgname in transaction.to_add: for pkgname in transaction.to_add: