promising work

This commit is contained in:
guinux 2013-01-20 17:38:33 +01:00
parent a9d1c0ed93
commit faf63b6780
14 changed files with 397 additions and 312 deletions

View File

@ -131,10 +131,10 @@ Comment[zh_CN]=添加或删除系统中安装的软件
Comment[zh_HK]=加入或移除系統上安裝的軟件 Comment[zh_HK]=加入或移除系統上安裝的軟件
Comment[zh_TW]=加入或移除系統上安裝的軟體 Comment[zh_TW]=加入或移除系統上安裝的軟體
Icon=system-software-install Icon=system-software-install
Exec=gksu pamac-manager Exec=pamac-manager
Terminal=false Terminal=false
Type=Application Type=Application
Categories=GNOME;GTK;System; Categories=GNOME;GTK;System;
NotShowIn=KDE; #NotShowIn=KDE;
StartupNotify=true StartupNotify=true

View File

@ -127,10 +127,10 @@ Comment[zh_CN]=更新本系统中安装的软件
Comment[zh_HK]=更新系統中已安裝的軟件 Comment[zh_HK]=更新系統中已安裝的軟件
Comment[zh_TW]=更新系統中已安裝的軟體 Comment[zh_TW]=更新系統中已安裝的軟體
Icon=system-software-update Icon=system-software-update
Exec=gksu pamac-updater Exec=pamac-updater
Terminal=false Terminal=false
Type=Application Type=Application
Categories=GNOME;GTK;System; Categories=GNOME;GTK;System;
NotShowIn=KDE #NotShowIn=KDE
StartupNotify=true StartupNotify=true

View File

@ -1,5 +1,5 @@
[D-BUS Service] [D-BUS Service]
Name=org.manjaro.pamac Name=org.manjaro.pamac
Exec=/usr/bin/start-pamac-daemon Exec=/usr/lib/python3.3/site-packages/pamac/pamac-daemon.py
User=root User=root
SystemdService=pamac.service SystemdService=pamac.service

View File

@ -4,4 +4,4 @@ Description=Pamac
[Service] [Service]
Type=dbus Type=dbus
BusName=org.manjaro.pamac BusName=org.manjaro.pamac
ExecStart=/usr/bin/start-pamac-daemon ExecStart=/usr/lib/python3.3/site-packages/pamac/pamac-daemon.py

View File

@ -1,3 +1,3 @@
#! /bin/sh #! /bin/sh
exec /usr/lib/python3.3/site-packages/pamac/manager.py /usr/lib/python3.3/site-packages/pamac/manager.py

2
pamac-updater Normal file → Executable file
View File

@ -1,3 +1,3 @@
#! /bin/sh #! /bin/sh
exec /usr/lib/python3.3/site-packages/pamac/updater.py /usr/lib/python3.3/site-packages/pamac/updater.py

View File

@ -1,18 +1,6 @@
#! /usr/bin/python #! /usr/bin/python
# -*-coding:utf-8-*- # -*-coding:utf-8-*-
from gi.repository import Gtk
interface = Gtk.Builder()
interface.add_from_file('/usr/share/pamac/gui/dialogs.glade')
ErrorDialog = interface.get_object('ErrorDialog')
WarningDialog = interface.get_object('WarningDialog')
to_remove = []
to_add = []
to_update = []
def format_size(size): def format_size(size):
KiB_size = size / 1024 KiB_size = size / 1024
if KiB_size < 1000: if KiB_size < 1000:

View File

@ -195,37 +195,66 @@ def set_desc(pkg, style):
def set_transaction_sum(): def set_transaction_sum():
transaction_sum.clear() transaction_sum.clear()
if common.to_remove: if transaction.to_remove:
transaction_sum.append(['To remove:', common.to_remove[0]]) transaction_sum.append(['To remove:', transaction.to_remove[0]])
i = 1 i = 1
while i < len(common.to_remove): while i < len(transaction.to_remove):
transaction_sum.append([' ', common.to_remove[i]]) transaction_sum.append([' ', transaction.to_remove[i]])
i += 1 i += 1
bottom_label.set_markup('') bottom_label.set_markup('')
if common.to_add: if transaction.to_add:
installed = [] installed = []
for pkg_object in config.pacman_conf.initialize_alpm().get_localdb().pkgcache: for pkg_object in config.pacman_conf.initialize_alpm().get_localdb().pkgcache:
installed.append(pkg_object.name) installed.append(pkg_object.name)
common.to_update = sorted(set(installed).intersection(common.to_add)) transaction.to_update = sorted(set(installed).intersection(transaction.to_add))
to_remove_from_add = sorted(set(common.to_update).intersection(common.to_add)) to_remove_from_add = sorted(set(transaction.to_update).intersection(transaction.to_add))
for name in to_remove_from_add: for name in to_remove_from_add:
common.to_add.remove(name) transaction.to_add.remove(name)
if common.to_add: if transaction.to_add:
transaction_sum.append(['To install:', common.to_add[0]]) transaction_sum.append(['To install:', transaction.to_add[0]])
i = 1 i = 1
while i < len(common.to_add): while i < len(transaction.to_add):
transaction_sum.append([' ', common.to_add[i]]) transaction_sum.append([' ', transaction.to_add[i]])
i += 1 i += 1
if common.to_update: if transaction.to_update:
transaction_sum.append(['To update:', common.to_update[0]]) transaction_sum.append(['To update:', transaction.to_update[0]])
i = 1 i = 1
while i < len(common.to_update): while i < len(transaction.to_update):
transaction_sum.append([' ', common.to_update[i]]) transaction_sum.append([' ', transaction.to_update[i]])
i += 1 i += 1
bottom_label.set_markup('') bottom_label.set_markup('')
#bottom_label.set_markup('<b>Total Download size: </b>'+common.format_size(totaldlcb)) #bottom_label.set_markup('<b>Total Download size: </b>'+common.format_size(totaldlcb))
top_label.set_markup('<big><b>Transaction Summary</b></big>') top_label.set_markup('<big><b>Transaction Summary</b></big>')
def handle_error(error):
global transaction_type
global transaction_dict
if not 'DBus.Error.NoReply' in str(error):
transaction.ErrorDialog.format_secondary_text('Commit Error:\n'+str(error))
response = transaction.ErrorDialog.run()
if response:
transaction.ErrorDialog.hide()
transaction.t_lock = False
transaction.Release()
transaction.ProgressWindow.hide()
transaction.to_add = []
transaction.to_remove = []
transaction_dict.clear()
transaction_type = None
set_packages_list()
def handle_reply(reply):
global transaction_type
global transaction_dict
transaction.t_lock = False
transaction.Release()
transaction.ProgressWindow.hide()
transaction.to_add = []
transaction.to_remove = []
transaction_dict.clear()
transaction_type = None
set_packages_list()
class Handler: class Handler:
def on_MainWindow_delete_event(self, *arg): def on_MainWindow_delete_event(self, *arg):
if __name__ == "__main__": if __name__ == "__main__":
@ -240,9 +269,6 @@ class Handler:
MainWindow.hide() MainWindow.hide()
def on_ValidButton_clicked(self, *arg): def on_ValidButton_clicked(self, *arg):
global t
global transaction_type
global transaction_dict
#if not geteuid() == 0: #if not geteuid() == 0:
#transaction.ErrorDialog.format_secondary_text("You need to be root to run packages transactions") #transaction.ErrorDialog.format_secondary_text("You need to be root to run packages transactions")
#response = transaction.ErrorDialog.run() #response = transaction.ErrorDialog.run()
@ -251,7 +277,7 @@ class Handler:
#el #el
if not transaction_dict: if not transaction_dict:
transaction.ErrorDialog.format_secondary_text("No package is selected") transaction.ErrorDialog.format_secondary_text("No package is selected")
response = transaction.ErrorDialog.run() response = transaction.ErrorDialog.run()
if response: if response:
transaction.ErrorDialog.hide() transaction.ErrorDialog.hide()
else: else:
@ -286,12 +312,12 @@ class Handler:
transaction.ErrorDialog.hide() transaction.ErrorDialog.hide()
transaction.Release() transaction.Release()
transaction.t_lock = False transaction.t_lock = False
transaction.get_to_remove() transaction.get_to_remove()
transaction.get_to_add() transaction.get_to_add()
transaction.check_conflicts() transaction.check_conflicts()
transaction.Release() transaction.Release()
set_transaction_sum() set_transaction_sum()
ConfDialog.show_all() ConfDialog.show_all()
def on_EraseButton_clicked(self, *arg): def on_EraseButton_clicked(self, *arg):
global transaction_type global transaction_type
@ -310,31 +336,33 @@ class Handler:
transaction.Release() transaction.Release()
def on_TransValidButton_clicked(self, *arg): def on_TransValidButton_clicked(self, *arg):
global transaction_type
ConfDialog.hide() ConfDialog.hide()
while Gtk.events_pending(): while Gtk.events_pending():
Gtk.main_iteration() Gtk.main_iteration()
if transaction_type is "remove": if transaction_type is "remove":
error = transaction.Commit() transaction.ProgressWindow.show_all()
if error: while Gtk.events_pending():
transaction.ErrorDialog.format_secondary_text(error) Gtk.main_iteration()
response = transaction.ErrorDialog.run() transaction.Commit(reply_handler = handle_reply, error_handler = handle_error, timeout = 2000*1000)
if response:
transaction.ErrorDialog.hide()
transaction.Release()
common.to_add = []
common.to_remove = []
if transaction_type is "install": if transaction_type is "install":
if transaction.init_transaction(noconflicts = True, nodeps = True): if transaction.init_transaction(noconflicts = True, nodeps = True):
for pkgname in common.to_add: for pkgname in transaction.to_add:
transaction.Add(pkgname) transaction.Add(pkgname)
for pkgname in common.to_remove: for pkgname in transaction.to_remove:
transaction.Remove(pkgname) transaction.Remove(pkgname)
transaction.finalize() error = transaction.Prepare()
transaction_dict.clear() if error:
transaction_type = None transaction.ErrorDialog.format_secondary_text(error)
set_packages_list() response = transaction.ErrorDialog.run()
transaction.t_lock = False if response:
transaction.ErrorDialog.hide()
transaction.Release()
transaction.t_lock = False
else:
transaction.ProgressWindow.show_all()
while Gtk.events_pending():
Gtk.main_iteration()
transaction.Commit(reply_handler = handle_reply, error_handler = handle_error, timeout = 2000*1000)
def on_search_button_clicked(self, widget): def on_search_button_clicked(self, widget):
global list_dict global list_dict
@ -420,11 +448,6 @@ def main():
MainWindow.show_all() MainWindow.show_all()
if __name__ == "__main__": if __name__ == "__main__":
if geteuid() == 0:
transaction.progress_label.set_text('Refreshing...')
transaction.progress_bar.pulse()
transaction.action_icon.set_from_file('/usr/share/pamac/icons/24x24/status/refresh-cache.png')
transaction.do_refresh()
main() main()
Gtk.main() Gtk.main()

View File

@ -4,135 +4,137 @@
import dbus import dbus
import dbus.service import dbus.service
from dbus.mainloop.glib import DBusGMainLoop from dbus.mainloop.glib import DBusGMainLoop
from gi.repository import GObject, Gtk from gi.repository import GObject
import pyalpm import pyalpm
import traceback import traceback
from pamac import config, common from pamac import config, common
loop = GObject.MainLoop()
t = None
error = ''
interface = Gtk.Builder()
interface.add_from_file('/usr/share/pamac/gui/dialogs.glade')
ProgressWindow = interface.get_object('ProgressWindow')
progress_bar = interface.get_object('progressbar2')
progress_label = interface.get_object('progresslabel2')
action_icon = interface.get_object('action_icon')
def cb_event(ID, event, tupel):
while Gtk.events_pending():
Gtk.main_iteration()
if ID is 1:
progress_label.set_text('Checking dependencies')
action_icon.set_from_file('/usr/share/pamac/icons/24x24/status/package-search.png')
elif ID is 3:
progress_label.set_text('Checking file conflicts')
action_icon.set_from_file('/usr/share/pamac/icons/24x24/status/package-search.png')
elif ID is 5:
progress_label.set_text('Resolving dependencies')
action_icon.set_from_file('/usr/share/pamac/icons/24x24/status/setup.png')
elif ID is 7:
progress_label.set_text('Checking inter conflicts')
action_icon.set_from_file('/usr/share/pamac/icons/24x24/status/package-search.png')
elif ID is 9:
progress_label.set_text('Installing packages')
action_icon.set_from_file('/usr/share/pamac/icons/24x24/status/package-add.png')
elif ID is 11:
progress_label.set_text('Removing packages')
action_icon.set_from_file('/usr/share/pamac/icons/24x24/status/package-delete.png')
elif ID is 13:
progress_label.set_text('Upgrading packages')
action_icon.set_from_file('/usr/share/pamac/icons/24x24/status/package-update.png')
elif ID is 15:
progress_label.set_text('Checking integrity')
action_icon.set_from_file('/usr/share/pamac/icons/24x24/status/package-search.png')
elif ID is 17:
progress_label.set_text('Checking signatures')
action_icon.set_from_file('/usr/share/pamac/icons/24x24/status/package-search.png')
print('Checking signatures')
elif ID is 27:
print('Downloading a file')
else :
progress_label.set_text('')
progress_bar.set_fraction(0.0)
progress_bar.set_text('')
print(ID,event)
def cb_conv(*args):
print("conversation", args)
_logmask = pyalpm.LOG_ERROR | pyalpm.LOG_WARNING
def cb_log(level, line):
#global t
if not (level & _logmask):
return
if level & pyalpm.LOG_ERROR:
common.ErrorDialog.format_secondary_text("ERROR: "+line)
response = common.ErrorDialog.run()
if response:
common.ErrorDialog.hide()
#t.release()
elif level & pyalpm.LOG_WARNING:
common.WarningDialog.format_secondary_text("WARNING: "+line)
response = common.WarningDialog.run()
if response:
common.WarningDialog.hide()
elif level & pyalpm.LOG_DEBUG:
line = "DEBUG: " + line
print(line)
elif level & pyalpm.LOG_FUNCTION:
line = "FUNC: " + line
print(line)
total_size = 0
def totaldlcb(_total_size):
global total_size
total_size = _total_size
already_transferred = 0
def cb_dl(_target, _transferred, total):
global already_transferred
while Gtk.events_pending():
Gtk.main_iteration()
if total_size > 0:
fraction = (_transferred+already_transferred)/total_size
size = 0
if (t.to_remove or t.to_add):
for pkg in t.to_remove+t.to_add:
if pkg.name+'-'+pkg.version in _target:
size = pkg.size
if _transferred == size:
already_transferred += size
progress_label.set_text('Downloading '+common.format_size(total_size))
progress_bar.set_text(_target)
progress_bar.set_fraction(fraction)
action_icon.set_from_file('/usr/share/pamac/icons/24x24/status/package-download.png')
else:
progress_label.set_text('Refreshing...')
progress_bar.set_text(_target)
progress_bar.pulse()
action_icon.set_from_file('/usr/share/pamac/icons/24x24/status/refresh-cache.png')
def cb_progress(_target, _percent, n, i):
while Gtk.events_pending():
Gtk.main_iteration()
target = _target+' ('+str(i)+'/'+str(n)+')'
progress_bar.set_fraction(_percent/100)
progress_bar.set_text(target)
class PamacDBusService(dbus.service.Object): class PamacDBusService(dbus.service.Object):
def __init__(self): def __init__(self):
bus=dbus.SystemBus() bus=dbus.SystemBus()
bus_name = dbus.service.BusName('org.manjaro.pamac', bus) bus_name = dbus.service.BusName('org.manjaro.pamac', bus)
dbus.service.Object.__init__(self, bus_name, '/org/manjaro/pamac') dbus.service.Object.__init__(self, bus_name, '/org/manjaro/pamac')
self.t = None
self.error = ''
self.warning = ''
self.action = ''
self.icon = ''
self.target = ''
self.percent = 0
self.total_size = 0
self.already_transferred = 0
def policykit_test(self,sender,connexion,action): @dbus.service.signal('org.manjaro.pamac')
def EmitAction(self, action):
pass
@dbus.service.signal('org.manjaro.pamac')
def EmitIcon(self, icon):
pass
@dbus.service.signal('org.manjaro.pamac')
def EmitTarget(self, target):
pass
@dbus.service.signal('org.manjaro.pamac')
def EmitPercent(self, percent):
pass
def cb_event(self, ID, event, tupel):
if ID is 1:
self.action = 'Checking dependencies'
self.icon = '/usr/share/pamac/icons/24x24/status/package-search.png'
elif ID is 3:
self.action = 'Checking file conflicts'
self.icon = '/usr/share/pamac/icons/24x24/status/package-search.png'
elif ID is 5:
self.action = 'Resolving dependencies'
self.icon = '/usr/share/pamac/icons/24x24/status/setup.png'
elif ID is 7:
self.action = 'Checking inter conflicts'
self.icon = '/usr/share/pamac/icons/24x24/status/package-search.png'
elif ID is 9:
self.action = 'Installing packages'
self.icon = '/usr/share/pamac/icons/24x24/status/package-add.png'
elif ID is 11:
self.action = 'Removing packages'
self.icon = '/usr/share/pamac/icons/24x24/status/package-delete.png'
elif ID is 13:
self.action = 'Upgrading packages'
self.icon = '/usr/share/pamac/icons/24x24/status/package-update.png'
elif ID is 15:
self.action = 'Checking integrity'
self.icon = '/usr/share/pamac/icons/24x24/status/package-search.png'
self.already_transferred = 0
elif ID is 17:
self.action = 'Checking signatures'
self.icon = '/usr/share/pamac/icons/24x24/status/package-search.png'
print('Checking signatures')
elif ID is 27:
print('Downloading a file')
else :
self.action = ''
self.EmitTarget('')
self.EmitPercent(str(0))
self.EmitAction(self.action)
self.EmitIcon(self.icon)
print(ID,event)
def cb_conv(self, *args):
print("conversation", args)
def cb_log(self, level, line):
#global t
_logmask = pyalpm.LOG_ERROR | pyalpm.LOG_WARNING
if not (level & _logmask):
return
if level & pyalpm.LOG_ERROR:
self.error = "ERROR: "+line
#t.release()
elif level & pyalpm.LOG_WARNING:
self.warning = "WARNING: "+line
elif level & pyalpm.LOG_DEBUG:
line = "DEBUG: " + line
print(line)
elif level & pyalpm.LOG_FUNCTION:
line = "FUNC: " + line
print(line)
def totaldlcb(self, _total_size):
self.total_size = _total_size
def cb_dl(self, _target, _transferred, total):
if self.total_size > 0:
fraction = (_transferred+self.already_transferred)/self.total_size
size = 0
if (t.to_remove or t.to_add):
for pkg in t.to_remove+t.to_add:
if pkg.name+'-'+pkg.version in _target:
size = pkg.size
if _transferred == size:
self.already_transferred += size
self.action = 'Downloading '+common.format_size(self.total_size)
self.target = _target
self.percent = fraction
self.icon = '/usr/share/pamac/icons/24x24/status/package-download.png'
else:
self.action = 'Refreshing...'
self.target = _target
self.percent = 0
self.icon = '/usr/share/pamac/icons/24x24/status/refresh-cache.png'
self.EmitAction(self.action)
self.EmitIcon(self.icon)
self.EmitTarget(self.target)
self.EmitPercent(str(self.percent))
def cb_progress(self, _target, _percent, n, i):
self.target = _target+' ('+str(i)+'/'+str(n)+')'
self.percent = _percent/100
self.EmitTarget(self.target)
self.EmitPercent(str(self.percent))
def policykit_test(self, sender,connexion, action):
bus = dbus.SystemBus() bus = dbus.SystemBus()
proxy_dbus = connexion.get_object('org.freedesktop.DBus','/org/freedesktop/DBus/Bus', False) proxy_dbus = connexion.get_object('org.freedesktop.DBus','/org/freedesktop/DBus/Bus', False)
dbus_info = dbus.Interface(proxy_dbus,'org.freedesktop.DBus') dbus_info = dbus.Interface(proxy_dbus,'org.freedesktop.DBus')
@ -145,18 +147,40 @@ class PamacDBusService(dbus.service.Object):
(is_authorized,is_challenge,details) = policykit_authority.CheckAuthorization(Subject, action, {'': ''}, dbus.UInt32(1), '') (is_authorized,is_challenge,details) = policykit_authority.CheckAuthorization(Subject, action, {'': ''}, dbus.UInt32(1), '')
return is_authorized return is_authorized
@dbus.service.method('org.manjaro.pamac', '', 's')
def Refresh(self):
global t
global error
error = ''
config.handle.dlcb = self.cb_dl
config.handle.totaldlcb = self.totaldlcb
config.handle.eventcb = self.cb_event
config.handle.questioncb = self.cb_conv
config.handle.progresscb = self.cb_progress
config.handle.logcb = self.cb_log
for db in config.handle.get_syncdbs():
try:
t = config.handle.init_transaction()
db.update(force=True)
print('refresh')
t.release()
except pyalpm.error:
error = traceback.format_exc()
break
return error
@dbus.service.method('org.manjaro.pamac', 'a{sb}', 's', sender_keyword='sender', connection_keyword='connexion') @dbus.service.method('org.manjaro.pamac', 'a{sb}', 's', sender_keyword='sender', connection_keyword='connexion')
def Init(self, options, sender=None, connexion=None): def Init(self, options, sender=None, connexion=None):
global t global t
global error global error
if self.policykit_test(sender,connexion,'org.manjaro.pamac.init_release'): if self.policykit_test(sender,connexion,'org.manjaro.pamac.init_release'):
error = '' error = ''
config.handle.dlcb = cb_dl config.handle.dlcb = self.cb_dl
config.handle.totaldlcb = totaldlcb config.handle.totaldlcb = self.totaldlcb
config.handle.eventcb = cb_event config.handle.eventcb = self.cb_event
config.handle.questioncb = cb_conv config.handle.questioncb = self.cb_conv
config.handle.progresscb = cb_progress config.handle.progresscb = self.cb_progress
config.handle.logcb = cb_log config.handle.logcb = self.cb_log
try: try:
t = config.handle.init_transaction(**options) t = config.handle.init_transaction(**options)
print('Init:',t.flags) print('Init:',t.flags)
@ -167,6 +191,18 @@ class PamacDBusService(dbus.service.Object):
else : else :
return 'You are not authorized' return 'You are not authorized'
@dbus.service.method('org.manjaro.pamac', '', 's')
def Sysupgrade(self):
global t
global error
error = ''
try:
t.sysupgrade(downgrade=False)
except pyalpm.error:
error = traceback.format_exc()
finally:
return error
@dbus.service.method('org.manjaro.pamac', 's', 's') @dbus.service.method('org.manjaro.pamac', 's', 's')
def Remove(self, pkgname): def Remove(self, pkgname):
global t global t
@ -227,18 +263,20 @@ class PamacDBusService(dbus.service.Object):
liste.append(pkg.name) liste.append(pkg.name)
return liste return liste
@dbus.service.method('org.manjaro.pamac', '', 's',sender_keyword='sender', connection_keyword='connexion') @dbus.service.method('org.manjaro.pamac', '', 's', sender_keyword='sender', connection_keyword='connexion')#, async_callbacks=('success', 'nosuccess'))
def Commit(self, sender=None, connexion=None): def Commit(self, sender=None, connexion=None):#success, nosuccess, sender=None, connexion=None):
global t global t
global error global error
error = ''
if self.policykit_test(sender,connexion,'org.manjaro.pamac.commit'): if self.policykit_test(sender,connexion,'org.manjaro.pamac.commit'):
ProgressWindow.show_all()
while Gtk.events_pending():
Gtk.main_iteration()
try: try:
t.commit() t.commit()
#success('')
except pyalpm.error: except pyalpm.error:
error = traceback.format_exc() error = traceback.format_exc()
#nosuccess(error)
except dbus.exceptions.DBusException:
pass
finally: finally:
return error return error
else : else :
@ -250,7 +288,6 @@ class PamacDBusService(dbus.service.Object):
global error global error
if self.policykit_test(sender,connexion,'org.manjaro.pamac.init_release'): if self.policykit_test(sender,connexion,'org.manjaro.pamac.init_release'):
error = '' error = ''
ProgressWindow.hide()
try: try:
t.release() t.release()
except pyalpm.error: except pyalpm.error:
@ -262,9 +299,9 @@ class PamacDBusService(dbus.service.Object):
@dbus.service.method('org.manjaro.pamac') @dbus.service.method('org.manjaro.pamac')
def StopDaemon(self): def StopDaemon(self):
loop.quit() mainloop.quit()
DBusGMainLoop(set_as_default=True) DBusGMainLoop(set_as_default=True)
myservice = PamacDBusService() myservice = PamacDBusService()
loop.run() mainloop = GObject.MainLoop()
mainloop.run()

View File

@ -1,20 +1,38 @@
#! /usr/bin/python #! /usr/bin/python
# -*-coding:utf-8-*- # -*-coding:utf-8-*-
from gi.repository import Gtk from gi.repository import Gtk, GObject
import pyalpm import pyalpm
import traceback import traceback
import dbus import dbus
from dbus.mainloop.glib import DBusGMainLoop
from pamac import config, common from pamac import config
interface = Gtk.Builder()
interface.add_from_file('/usr/share/pamac/gui/dialogs.glade')
ErrorDialog = interface.get_object('ErrorDialog')
WarningDialog = interface.get_object('WarningDialog')
ProgressWindow = interface.get_object('ProgressWindow')
progress_bar = interface.get_object('progressbar2')
progress_label = interface.get_object('progresslabel2')
action_icon = interface.get_object('action_icon')
t_lock = False t_lock = False
do_syncfirst = False do_syncfirst = False
list_first = [] list_first = []
to_remove = []
to_add = []
to_update = []
proxy = dbus.SystemBus().get_object('org.manjaro.pamac','/org/manjaro/pamac') DBusGMainLoop(set_as_default=True)
bus = dbus.SystemBus()
proxy = bus.get_object('org.manjaro.pamac','/org/manjaro/pamac', introspect=False)
Refresh = proxy.get_dbus_method('Refresh','org.manjaro.pamac')
Init = proxy.get_dbus_method('Init','org.manjaro.pamac') Init = proxy.get_dbus_method('Init','org.manjaro.pamac')
Sysupgrade = proxy.get_dbus_method('Sysupgrade','org.manjaro.pamac')
Remove = proxy.get_dbus_method('Remove','org.manjaro.pamac') Remove = proxy.get_dbus_method('Remove','org.manjaro.pamac')
Add = proxy.get_dbus_method('Add','org.manjaro.pamac') Add = proxy.get_dbus_method('Add','org.manjaro.pamac')
Prepare = proxy.get_dbus_method('Prepare','org.manjaro.pamac') Prepare = proxy.get_dbus_method('Prepare','org.manjaro.pamac')
@ -23,6 +41,23 @@ To_Add = proxy.get_dbus_method('To_Add','org.manjaro.pamac')
Commit = proxy.get_dbus_method('Commit','org.manjaro.pamac') Commit = proxy.get_dbus_method('Commit','org.manjaro.pamac')
Release = proxy.get_dbus_method('Release','org.manjaro.pamac') Release = proxy.get_dbus_method('Release','org.manjaro.pamac')
def action_signal_handler(action):
progress_label.set_text(action)
def icon_signal_handler(icon):
action_icon.set_from_file(icon)
def target_signal_handler(target):
progress_bar.set_text(target)
def percent_signal_handler(percent):
progress_bar.set_fraction(float(percent))
bus.add_signal_receiver(action_signal_handler, dbus_interface = "org.manjaro.pamac", signal_name = "EmitAction")
bus.add_signal_receiver(icon_signal_handler, dbus_interface = "org.manjaro.pamac", signal_name = "EmitIcon")
bus.add_signal_receiver(target_signal_handler, dbus_interface = "org.manjaro.pamac", signal_name = "EmitTarget")
bus.add_signal_receiver(percent_signal_handler, dbus_interface = "org.manjaro.pamac", signal_name = "EmitPercent")
def init_transaction(**options): def init_transaction(**options):
"Transaction initialization" "Transaction initialization"
global t_lock global t_lock
@ -31,16 +66,18 @@ def init_transaction(**options):
t_lock = True t_lock = True
return True return True
else: else:
common.ErrorDialog.format_secondary_text(error) ErrorDialog.format_secondary_text(error)
response = common.ErrorDialog.run() response = ErrorDialog.run()
if response: if response:
common.ErrorDialog.hide() ErrorDialog.hide()
return False return False
def check_conflicts(): def check_conflicts():
global to_add
global to_remove
to_check = [] to_check = []
warning = '' warning = ''
for pkgname in common.to_add: for pkgname in to_add:
for repo in config.pacman_conf.initialize_alpm().get_syncdbs(): for repo in config.pacman_conf.initialize_alpm().get_syncdbs():
pkg = repo.get_pkg(pkgname) pkg = repo.get_pkg(pkgname)
if pkg: if pkg:
@ -51,8 +88,8 @@ def check_conflicts():
for name in target.replaces: for name in target.replaces:
pkg = config.pacman_conf.initialize_alpm().get_localdb().get_pkg(name) pkg = config.pacman_conf.initialize_alpm().get_localdb().get_pkg(name)
if pkg: if pkg:
if not pkg.name in common.to_remove: if not pkg.name in to_remove:
common.to_remove.append(pkg.name) to_remove.append(pkg.name)
if warning: if warning:
warning = warning+'\n' warning = warning+'\n'
warning = warning+pkg.name+' will be replaced by '+target.name warning = warning+pkg.name+' will be replaced by '+target.name
@ -60,66 +97,81 @@ def check_conflicts():
for name in target.conflicts: for name in target.conflicts:
pkg = config.pacman_conf.initialize_alpm().get_localdb().get_pkg(name) pkg = config.pacman_conf.initialize_alpm().get_localdb().get_pkg(name)
if pkg: if pkg:
if not pkg.name in common.to_remove: if not pkg.name in to_remove:
common.to_remove.append(pkg.name) to_remove.append(pkg.name)
for installed_pkg in config.pacman_conf.initialize_alpm().get_localdb().pkgcache: for installed_pkg in config.pacman_conf.initialize_alpm().get_localdb().pkgcache:
if installed_pkg.conflicts: if installed_pkg.conflicts:
for name in installed_pkg.conflicts: for name in installed_pkg.conflicts:
if name == target.name: if name == target.name:
if not name in common.to_remove: if not name in to_remove:
common.to_remove.append(installed_pkg.name) to_remove.append(installed_pkg.name)
if warning: if warning:
common.WarningDialog.format_secondary_text(warning) WarningDialog.format_secondary_text(warning)
response = common.WarningDialog.run() response = WarningDialog.run()
if response: if response:
common.WarningDialog.hide() WarningDialog.hide()
def get_to_remove(): def get_to_remove():
common.to_remove = To_Remove() global to_remove
to_remove = To_Remove()
def get_to_add(): def get_to_add():
common.to_add = To_Add() global to_add
to_add = To_Add()
def finalize(): def finalize():
global t_lock global t_lock
while Gtk.events_pending():
Gtk.main_iteration()
error = Prepare() error = Prepare()
if error: if error:
common.ErrorDialog.format_secondary_text(error) ErrorDialog.format_secondary_text(error)
response = common.ErrorDialog.run() response = ErrorDialog.run()
if response: if response:
common.ErrorDialog.hide() ErrorDialog.hide()
error = Commit() Release()
if error: t_lock = False
common.ErrorDialog.format_secondary_text(error) else:
response = common.ErrorDialog.run() ProgressWindow.show_all()
while Gtk.events_pending():
Gtk.main_iteration()
Commit(reply_handler = handle_reply, error_handler = handle_error, timeout = 2000*1000)
def handle_error(error):
global t_lock
global to_add
global to_remove
if not 'DBus.Error.NoReply' in str(error):
ErrorDialog.format_secondary_text('Commit Error:\n'+str(error))
response = ErrorDialog.run()
if response: if response:
common.ErrorDialog.hide() ErrorDialog.hide()
t_lock = False t_lock = False
Release() Release()
common.to_add = [] ProgressWindow.hide()
common.to_remove = [] to_add = []
to_remove = []
def handle_reply(reply):
global t_lock
global to_add
global to_remove
print('reply',reply)
t_lock = False
Release()
ProgressWindow.hide()
to_add = []
to_remove = []
def do_refresh(): def do_refresh():
"""Sync databases like pacman -Sy""" """Sync databases like pacman -Sy"""
global t global t
global t_lock global t_lock
for db in config.pacman_conf.initialize_alpm().get_syncdbs(): if t_lock is False:
if t_lock is False: progress_label.set_text('Refreshing...')
t = init_transaction() progress_bar.pulse()
try: action_icon.set_from_file('/usr/share/pamac/icons/24x24/status/refresh-cache.png')
db.update(force=False) ProgressWindow.show_all()
t.release() t_lock = True
t_lock = False Refresh(reply_handler = handle_reply, error_handler = handle_error, timeout = 2000*1000)
except pyalpm.error:
common.ErrorDialog.format_secondary_text(traceback.format_exc())
response = common.ErrorDialog.run()
if response:
common.ErrorDialog.hide()
t_lock = False
break
t_lock = False
def get_updates(): def get_updates():
"""Return a list of package objects in local db which can be updated""" """Return a list of package objects in local db which can be updated"""

View File

@ -6,7 +6,7 @@ from gi.repository import Gtk
import pyalpm import pyalpm
from os import geteuid from os import geteuid
from pamac import config, transaction from pamac import config, common, transaction
interface = Gtk.Builder() interface = Gtk.Builder()
interface.add_from_file('/usr/share/pamac/gui/updater.glade') interface.add_from_file('/usr/share/pamac/gui/updater.glade')
@ -34,90 +34,81 @@ def have_updates():
pkgname = pkg.name pkgname = pkg.name
newversion = transaction.get_new_version_available(pkgname) newversion = transaction.get_new_version_available(pkgname)
pkgname = pkg.name+" "+newversion pkgname = pkg.name+" "+newversion
update_listore.append([pkgname, transaction.format_size(pkg.size)]) update_listore.append([pkgname, common.format_size(pkg.size)])
update_label.set_markup("<big><b>Available updates</b></big>") update_label.set_markup("<big><b>Available updates</b></big>")
return True return True
def set_transaction_add(): def set_transaction_add():
transaction_add.clear() transaction_add.clear()
if transaction.to_remove: if transaction.to_remove:
transaction_add.append(['To remove:', transaction.to_remove[0].name]) transaction_add.append(['To remove:', transaction.to_remove[0]])
i = 1 i = 1
while i < len(transaction.to_remove): while i < len(transaction.to_remove):
transaction_add.append([' ', transaction.to_remove[i].name]) transaction_add.append([' ', transaction.to_remove[i]])
i += 1 i += 1
bottom_label.set_markup('') bottom_label.set_markup('')
if transaction.to_add: if transaction.to_add:
installed_name = [] installed_name = []
for pkg_object in config.handle.get_localdb().pkgcache: for pkg_object in config.handle.get_localdb().pkgcache:
installed_name.append(pkg_object.name) installed_name.append(pkg_object.name)
to_add_name = [] transaction.to_update = sorted(set(installed_name).intersection(transaction.to_add))
for pkg_object in transaction.to_add: to_remove_from_add_name = sorted(set(transaction.to_update).intersection(transaction.to_add))
to_add_name.append(pkg_object.name)
transaction.to_update = sorted(set(installed_name).intersection(to_add_name))
to_remove_from_add_name = sorted(set(transaction.to_update).intersection(to_add_name))
for name in to_remove_from_add_name: for name in to_remove_from_add_name:
to_add_name.remove(name) transaction.to_add.remove(name)
if to_add_name: if transaction.to_add:
transaction_add.append(['To install:', to_add_name[0]]) transaction_add.append(['To install:', transaction.to_add[0]])
i = 1 i = 1
while i < len(to_add_name): while i < len(transaction.to_add):
transaction_add.append([' ', to_add_name[i]]) transaction_add.append([' ', transaction.to_add[i]])
i += 1 i += 1
bottom_label.set_markup('') bottom_label.set_markup('')
#bottom_label.set_markup('<b>Total Download size: </b>'+format_size(totaldlcb)) #bottom_label.set_markup('<b>Total Download size: </b>'+format_size(totaldlcb))
top_label.set_markup('<big><b>Additionnal Transaction(s)</b></big>') top_label.set_markup('<big><b>Additionnal Transaction(s)</b></big>')
def do_sysupgrade(): def do_sysupgrade():
"""Upgrade a system like pacman -Su""" """Upgrade a system like pacman -Su"""
if transaction.t_lock is False: if transaction.t_lock is False:
if transaction.do_syncfirst is True: if transaction.do_syncfirst is True:
transaction.t = transaction.init_transaction(recurse = True) if transaction.init_transaction(recurse = True):
for pkg in transaction.list_first: for pkg in transaction.list_first:
transaction.t.add_pkg(pkg)
transaction.to_remove = transaction.t.to_remove
transaction.to_add = transaction.t.to_add
set_transaction_add()
if len(transaction_add) != 0:
ConfDialog.show_all()
else:
transaction.t_finalize(transaction.t)
transaction.do_syncfirst = False
transaction.list_first = []
else:
try:
transaction.t = transaction.init_transaction()
transaction.t.sysupgrade(downgrade=False)
except pyalpm.error:
ErrorDialog.format_secondary_text(traceback.format_exc())
response = ErrorDialog.run()
if response:
ErrorDialog.hide()
transaction.t.release()
transaction.t_lock = False
transaction.check_conflicts()
transaction.to_add = transaction.t.to_add
transaction.to_remove = []
for pkg in transaction.conflict_to_remove.values():
transaction.to_remove.append(pkg)
if len(transaction.to_add) + len(transaction.to_remove) == 0:
transaction.t.release()
transaction.t_lock = False
print("Nothing to update")
else:
transaction.t.release()
transaction.t = transaction.init_transaction(noconflicts = True, nodeps = True)
for pkg in transaction.to_add:
transaction.t.add_pkg(pkg) transaction.t.add_pkg(pkg)
for pkg in transaction.conflict_to_remove.values():
transaction.t.remove_pkg(pkg)
transaction.to_remove = transaction.t.to_remove transaction.to_remove = transaction.t.to_remove
transaction.to_add = transaction.t.to_add transaction.to_add = transaction.t.to_add
set_transaction_add() set_transaction_add()
if len(transaction_add) != 0: if len(transaction_add) != 0:
ConfDialog.show_all() ConfDialog.show_all()
else: else:
transaction.t_finalize(transaction.t) transaction.t_finalize()
transaction.do_syncfirst = False
transaction.list_first = []
else:
if transaction.init_transaction():
error = transaction.Sysupgrade()
if error:
transaction.ErrorDialog.format_secondary_text(error)
response = transaction.ErrorDialog.run()
if response:
transaction.ErrorDialog.hide()
transaction.Release()
transaction.t_lock = False
transaction.get_to_remove()
transaction.get_to_add()
transaction.check_conflicts()
transaction.Release()
if len(transaction.to_add) + len(transaction.to_remove) == 0:
transaction.t_lock = False
print("Nothing to update")
else:
if transaction.init_transaction(noconflicts = True, nodeps = True):
for pkgname in transaction.to_add:
transaction.Add(pkgname)
for pkgname in transaction.to_remove:
transaction.Remove(pkgname)
set_transaction_add()
if len(transaction_add) != 0:
ConfDialog.show_all()
else:
transaction.t_finalize()
class Handler: class Handler:
def on_UpdateWindow_delete_event(self, *arg): def on_UpdateWindow_delete_event(self, *arg):
@ -155,12 +146,6 @@ def main():
UpdateWindow.show_all() UpdateWindow.show_all()
if __name__ == "__main__": if __name__ == "__main__":
if geteuid() == 0: transaction.do_refresh()
transaction.progress_label.set_text('Refreshing...')
transaction.progress_bar.pulse()
transaction.action_icon.set_from_file('/usr/share/pamac/icons/24x24/status/refresh-cache.png')
transaction.ProgressWindow.show_all()
transaction.do_refresh()
transaction.ProgressWindow.hide()
main() main()
Gtk.main() Gtk.main()

View File

@ -3,7 +3,7 @@
from distutils.core import setup from distutils.core import setup
setup(name='Pamac', setup(name='Pamac',
version='0.2', version='0.3',
description='A gtk3 frontend for pyalpm', description='A gtk3 frontend for pyalpm',
license='GPL', license='GPL',
author='Guillaume Benoit', author='Guillaume Benoit',

View File

@ -1,3 +1,3 @@
#! /bin/bash #! /bin/sh
DISPLAY=:0.0 /usr/lib/python3.3/site-packages/pamac/pamac-daemon.py /usr/lib/python3.3/site-packages/pamac/pamac-daemon.py &

2
tray Normal file → Executable file
View File

@ -1,3 +1,3 @@
#! /bin/sh #! /bin/sh
exec /usr/lib/python3.3/site-packages/pamac/tray.py /usr/lib/python3.3/site-packages/pamac/tray.py