promising work
This commit is contained in:
parent
a9d1c0ed93
commit
faf63b6780
@ -131,10 +131,10 @@ Comment[zh_CN]=添加或删除系统中安装的软件
|
||||
Comment[zh_HK]=加入或移除系統上安裝的軟件
|
||||
Comment[zh_TW]=加入或移除系統上安裝的軟體
|
||||
Icon=system-software-install
|
||||
Exec=gksu pamac-manager
|
||||
Exec=pamac-manager
|
||||
Terminal=false
|
||||
Type=Application
|
||||
Categories=GNOME;GTK;System;
|
||||
NotShowIn=KDE;
|
||||
#NotShowIn=KDE;
|
||||
StartupNotify=true
|
||||
|
||||
|
@ -127,10 +127,10 @@ Comment[zh_CN]=更新本系统中安装的软件
|
||||
Comment[zh_HK]=更新系統中已安裝的軟件
|
||||
Comment[zh_TW]=更新系統中已安裝的軟體
|
||||
Icon=system-software-update
|
||||
Exec=gksu pamac-updater
|
||||
Exec=pamac-updater
|
||||
Terminal=false
|
||||
Type=Application
|
||||
Categories=GNOME;GTK;System;
|
||||
NotShowIn=KDE
|
||||
#NotShowIn=KDE
|
||||
StartupNotify=true
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
[D-BUS Service]
|
||||
Name=org.manjaro.pamac
|
||||
Exec=/usr/bin/start-pamac-daemon
|
||||
Exec=/usr/lib/python3.3/site-packages/pamac/pamac-daemon.py
|
||||
User=root
|
||||
SystemdService=pamac.service
|
||||
|
@ -4,4 +4,4 @@ Description=Pamac
|
||||
[Service]
|
||||
Type=dbus
|
||||
BusName=org.manjaro.pamac
|
||||
ExecStart=/usr/bin/start-pamac-daemon
|
||||
ExecStart=/usr/lib/python3.3/site-packages/pamac/pamac-daemon.py
|
||||
|
@ -1,3 +1,3 @@
|
||||
#! /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
2
pamac-updater
Normal file → Executable file
@ -1,3 +1,3 @@
|
||||
#! /bin/sh
|
||||
|
||||
exec /usr/lib/python3.3/site-packages/pamac/updater.py
|
||||
/usr/lib/python3.3/site-packages/pamac/updater.py
|
||||
|
@ -1,18 +1,6 @@
|
||||
#! /usr/bin/python
|
||||
# -*-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):
|
||||
KiB_size = size / 1024
|
||||
if KiB_size < 1000:
|
||||
|
119
pamac/manager.py
119
pamac/manager.py
@ -195,37 +195,66 @@ def set_desc(pkg, style):
|
||||
|
||||
def set_transaction_sum():
|
||||
transaction_sum.clear()
|
||||
if common.to_remove:
|
||||
transaction_sum.append(['To remove:', common.to_remove[0]])
|
||||
if transaction.to_remove:
|
||||
transaction_sum.append(['To remove:', transaction.to_remove[0]])
|
||||
i = 1
|
||||
while i < len(common.to_remove):
|
||||
transaction_sum.append([' ', common.to_remove[i]])
|
||||
while i < len(transaction.to_remove):
|
||||
transaction_sum.append([' ', transaction.to_remove[i]])
|
||||
i += 1
|
||||
bottom_label.set_markup('')
|
||||
if common.to_add:
|
||||
if transaction.to_add:
|
||||
installed = []
|
||||
for pkg_object in config.pacman_conf.initialize_alpm().get_localdb().pkgcache:
|
||||
installed.append(pkg_object.name)
|
||||
common.to_update = sorted(set(installed).intersection(common.to_add))
|
||||
to_remove_from_add = sorted(set(common.to_update).intersection(common.to_add))
|
||||
transaction.to_update = sorted(set(installed).intersection(transaction.to_add))
|
||||
to_remove_from_add = sorted(set(transaction.to_update).intersection(transaction.to_add))
|
||||
for name in to_remove_from_add:
|
||||
common.to_add.remove(name)
|
||||
if common.to_add:
|
||||
transaction_sum.append(['To install:', common.to_add[0]])
|
||||
transaction.to_add.remove(name)
|
||||
if transaction.to_add:
|
||||
transaction_sum.append(['To install:', transaction.to_add[0]])
|
||||
i = 1
|
||||
while i < len(common.to_add):
|
||||
transaction_sum.append([' ', common.to_add[i]])
|
||||
while i < len(transaction.to_add):
|
||||
transaction_sum.append([' ', transaction.to_add[i]])
|
||||
i += 1
|
||||
if common.to_update:
|
||||
transaction_sum.append(['To update:', common.to_update[0]])
|
||||
if transaction.to_update:
|
||||
transaction_sum.append(['To update:', transaction.to_update[0]])
|
||||
i = 1
|
||||
while i < len(common.to_update):
|
||||
transaction_sum.append([' ', common.to_update[i]])
|
||||
while i < len(transaction.to_update):
|
||||
transaction_sum.append([' ', transaction.to_update[i]])
|
||||
i += 1
|
||||
bottom_label.set_markup('')
|
||||
#bottom_label.set_markup('<b>Total Download size: </b>'+common.format_size(totaldlcb))
|
||||
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:
|
||||
def on_MainWindow_delete_event(self, *arg):
|
||||
if __name__ == "__main__":
|
||||
@ -240,9 +269,6 @@ class Handler:
|
||||
MainWindow.hide()
|
||||
|
||||
def on_ValidButton_clicked(self, *arg):
|
||||
global t
|
||||
global transaction_type
|
||||
global transaction_dict
|
||||
#if not geteuid() == 0:
|
||||
#transaction.ErrorDialog.format_secondary_text("You need to be root to run packages transactions")
|
||||
#response = transaction.ErrorDialog.run()
|
||||
@ -251,7 +277,7 @@ class Handler:
|
||||
#el
|
||||
if not transaction_dict:
|
||||
transaction.ErrorDialog.format_secondary_text("No package is selected")
|
||||
response = transaction.ErrorDialog.run()
|
||||
response = transaction.ErrorDialog.run()
|
||||
if response:
|
||||
transaction.ErrorDialog.hide()
|
||||
else:
|
||||
@ -286,12 +312,12 @@ class Handler:
|
||||
transaction.ErrorDialog.hide()
|
||||
transaction.Release()
|
||||
transaction.t_lock = False
|
||||
transaction.get_to_remove()
|
||||
transaction.get_to_add()
|
||||
transaction.check_conflicts()
|
||||
transaction.Release()
|
||||
set_transaction_sum()
|
||||
ConfDialog.show_all()
|
||||
transaction.get_to_remove()
|
||||
transaction.get_to_add()
|
||||
transaction.check_conflicts()
|
||||
transaction.Release()
|
||||
set_transaction_sum()
|
||||
ConfDialog.show_all()
|
||||
|
||||
def on_EraseButton_clicked(self, *arg):
|
||||
global transaction_type
|
||||
@ -310,31 +336,33 @@ class Handler:
|
||||
transaction.Release()
|
||||
|
||||
def on_TransValidButton_clicked(self, *arg):
|
||||
global transaction_type
|
||||
ConfDialog.hide()
|
||||
while Gtk.events_pending():
|
||||
Gtk.main_iteration()
|
||||
if transaction_type is "remove":
|
||||
error = transaction.Commit()
|
||||
if error:
|
||||
transaction.ErrorDialog.format_secondary_text(error)
|
||||
response = transaction.ErrorDialog.run()
|
||||
if response:
|
||||
transaction.ErrorDialog.hide()
|
||||
transaction.Release()
|
||||
common.to_add = []
|
||||
common.to_remove = []
|
||||
transaction.ProgressWindow.show_all()
|
||||
while Gtk.events_pending():
|
||||
Gtk.main_iteration()
|
||||
transaction.Commit(reply_handler = handle_reply, error_handler = handle_error, timeout = 2000*1000)
|
||||
if transaction_type is "install":
|
||||
if transaction.init_transaction(noconflicts = True, nodeps = True):
|
||||
for pkgname in common.to_add:
|
||||
for pkgname in transaction.to_add:
|
||||
transaction.Add(pkgname)
|
||||
for pkgname in common.to_remove:
|
||||
for pkgname in transaction.to_remove:
|
||||
transaction.Remove(pkgname)
|
||||
transaction.finalize()
|
||||
transaction_dict.clear()
|
||||
transaction_type = None
|
||||
set_packages_list()
|
||||
transaction.t_lock = False
|
||||
error = transaction.Prepare()
|
||||
if error:
|
||||
transaction.ErrorDialog.format_secondary_text(error)
|
||||
response = transaction.ErrorDialog.run()
|
||||
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):
|
||||
global list_dict
|
||||
@ -420,11 +448,6 @@ def main():
|
||||
MainWindow.show_all()
|
||||
|
||||
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()
|
||||
Gtk.main()
|
||||
|
||||
|
@ -4,135 +4,137 @@
|
||||
import dbus
|
||||
import dbus.service
|
||||
from dbus.mainloop.glib import DBusGMainLoop
|
||||
from gi.repository import GObject, Gtk
|
||||
from gi.repository import GObject
|
||||
|
||||
import pyalpm
|
||||
import traceback
|
||||
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):
|
||||
def __init__(self):
|
||||
bus=dbus.SystemBus()
|
||||
bus_name = dbus.service.BusName('org.manjaro.pamac', bus)
|
||||
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()
|
||||
proxy_dbus = connexion.get_object('org.freedesktop.DBus','/org/freedesktop/DBus/Bus', False)
|
||||
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), '')
|
||||
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')
|
||||
def Init(self, options, sender=None, connexion=None):
|
||||
global t
|
||||
global error
|
||||
if self.policykit_test(sender,connexion,'org.manjaro.pamac.init_release'):
|
||||
error = ''
|
||||
config.handle.dlcb = cb_dl
|
||||
config.handle.totaldlcb = totaldlcb
|
||||
config.handle.eventcb = cb_event
|
||||
config.handle.questioncb = cb_conv
|
||||
config.handle.progresscb = cb_progress
|
||||
config.handle.logcb = cb_log
|
||||
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
|
||||
try:
|
||||
t = config.handle.init_transaction(**options)
|
||||
print('Init:',t.flags)
|
||||
@ -167,6 +191,18 @@ class PamacDBusService(dbus.service.Object):
|
||||
else :
|
||||
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')
|
||||
def Remove(self, pkgname):
|
||||
global t
|
||||
@ -227,18 +263,20 @@ class PamacDBusService(dbus.service.Object):
|
||||
liste.append(pkg.name)
|
||||
return liste
|
||||
|
||||
@dbus.service.method('org.manjaro.pamac', '', 's',sender_keyword='sender', connection_keyword='connexion')
|
||||
def Commit(self, sender=None, connexion=None):
|
||||
@dbus.service.method('org.manjaro.pamac', '', 's', sender_keyword='sender', connection_keyword='connexion')#, async_callbacks=('success', 'nosuccess'))
|
||||
def Commit(self, sender=None, connexion=None):#success, nosuccess, sender=None, connexion=None):
|
||||
global t
|
||||
global error
|
||||
error = ''
|
||||
if self.policykit_test(sender,connexion,'org.manjaro.pamac.commit'):
|
||||
ProgressWindow.show_all()
|
||||
while Gtk.events_pending():
|
||||
Gtk.main_iteration()
|
||||
try:
|
||||
t.commit()
|
||||
#success('')
|
||||
except pyalpm.error:
|
||||
error = traceback.format_exc()
|
||||
error = traceback.format_exc()
|
||||
#nosuccess(error)
|
||||
except dbus.exceptions.DBusException:
|
||||
pass
|
||||
finally:
|
||||
return error
|
||||
else :
|
||||
@ -250,7 +288,6 @@ class PamacDBusService(dbus.service.Object):
|
||||
global error
|
||||
if self.policykit_test(sender,connexion,'org.manjaro.pamac.init_release'):
|
||||
error = ''
|
||||
ProgressWindow.hide()
|
||||
try:
|
||||
t.release()
|
||||
except pyalpm.error:
|
||||
@ -262,9 +299,9 @@ class PamacDBusService(dbus.service.Object):
|
||||
|
||||
@dbus.service.method('org.manjaro.pamac')
|
||||
def StopDaemon(self):
|
||||
loop.quit()
|
||||
|
||||
mainloop.quit()
|
||||
|
||||
DBusGMainLoop(set_as_default=True)
|
||||
myservice = PamacDBusService()
|
||||
loop.run()
|
||||
mainloop = GObject.MainLoop()
|
||||
mainloop.run()
|
||||
|
@ -1,20 +1,38 @@
|
||||
#! /usr/bin/python
|
||||
# -*-coding:utf-8-*-
|
||||
|
||||
from gi.repository import Gtk
|
||||
from gi.repository import Gtk, GObject
|
||||
|
||||
import pyalpm
|
||||
import traceback
|
||||
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
|
||||
do_syncfirst = False
|
||||
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')
|
||||
Sysupgrade = proxy.get_dbus_method('Sysupgrade','org.manjaro.pamac')
|
||||
Remove = proxy.get_dbus_method('Remove','org.manjaro.pamac')
|
||||
Add = proxy.get_dbus_method('Add','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')
|
||||
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):
|
||||
"Transaction initialization"
|
||||
global t_lock
|
||||
@ -31,16 +66,18 @@ def init_transaction(**options):
|
||||
t_lock = True
|
||||
return True
|
||||
else:
|
||||
common.ErrorDialog.format_secondary_text(error)
|
||||
response = common.ErrorDialog.run()
|
||||
ErrorDialog.format_secondary_text(error)
|
||||
response = ErrorDialog.run()
|
||||
if response:
|
||||
common.ErrorDialog.hide()
|
||||
ErrorDialog.hide()
|
||||
return False
|
||||
|
||||
def check_conflicts():
|
||||
global to_add
|
||||
global to_remove
|
||||
to_check = []
|
||||
warning = ''
|
||||
for pkgname in common.to_add:
|
||||
for pkgname in to_add:
|
||||
for repo in config.pacman_conf.initialize_alpm().get_syncdbs():
|
||||
pkg = repo.get_pkg(pkgname)
|
||||
if pkg:
|
||||
@ -51,8 +88,8 @@ def check_conflicts():
|
||||
for name in target.replaces:
|
||||
pkg = config.pacman_conf.initialize_alpm().get_localdb().get_pkg(name)
|
||||
if pkg:
|
||||
if not pkg.name in common.to_remove:
|
||||
common.to_remove.append(pkg.name)
|
||||
if not pkg.name in to_remove:
|
||||
to_remove.append(pkg.name)
|
||||
if warning:
|
||||
warning = warning+'\n'
|
||||
warning = warning+pkg.name+' will be replaced by '+target.name
|
||||
@ -60,66 +97,81 @@ def check_conflicts():
|
||||
for name in target.conflicts:
|
||||
pkg = config.pacman_conf.initialize_alpm().get_localdb().get_pkg(name)
|
||||
if pkg:
|
||||
if not pkg.name in common.to_remove:
|
||||
common.to_remove.append(pkg.name)
|
||||
if not pkg.name in to_remove:
|
||||
to_remove.append(pkg.name)
|
||||
for installed_pkg in config.pacman_conf.initialize_alpm().get_localdb().pkgcache:
|
||||
if installed_pkg.conflicts:
|
||||
for name in installed_pkg.conflicts:
|
||||
if name == target.name:
|
||||
if not name in common.to_remove:
|
||||
common.to_remove.append(installed_pkg.name)
|
||||
if not name in to_remove:
|
||||
to_remove.append(installed_pkg.name)
|
||||
if warning:
|
||||
common.WarningDialog.format_secondary_text(warning)
|
||||
response = common.WarningDialog.run()
|
||||
WarningDialog.format_secondary_text(warning)
|
||||
response = WarningDialog.run()
|
||||
if response:
|
||||
common.WarningDialog.hide()
|
||||
WarningDialog.hide()
|
||||
|
||||
def get_to_remove():
|
||||
common.to_remove = To_Remove()
|
||||
global to_remove
|
||||
to_remove = To_Remove()
|
||||
|
||||
def get_to_add():
|
||||
common.to_add = To_Add()
|
||||
global to_add
|
||||
to_add = To_Add()
|
||||
|
||||
def finalize():
|
||||
global t_lock
|
||||
while Gtk.events_pending():
|
||||
Gtk.main_iteration()
|
||||
error = Prepare()
|
||||
if error:
|
||||
common.ErrorDialog.format_secondary_text(error)
|
||||
response = common.ErrorDialog.run()
|
||||
ErrorDialog.format_secondary_text(error)
|
||||
response = ErrorDialog.run()
|
||||
if response:
|
||||
common.ErrorDialog.hide()
|
||||
error = Commit()
|
||||
if error:
|
||||
common.ErrorDialog.format_secondary_text(error)
|
||||
response = common.ErrorDialog.run()
|
||||
ErrorDialog.hide()
|
||||
Release()
|
||||
t_lock = False
|
||||
else:
|
||||
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:
|
||||
common.ErrorDialog.hide()
|
||||
ErrorDialog.hide()
|
||||
t_lock = False
|
||||
Release()
|
||||
common.to_add = []
|
||||
common.to_remove = []
|
||||
ProgressWindow.hide()
|
||||
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():
|
||||
"""Sync databases like pacman -Sy"""
|
||||
global t
|
||||
global t_lock
|
||||
for db in config.pacman_conf.initialize_alpm().get_syncdbs():
|
||||
if t_lock is False:
|
||||
t = init_transaction()
|
||||
try:
|
||||
db.update(force=False)
|
||||
t.release()
|
||||
t_lock = False
|
||||
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
|
||||
if t_lock is False:
|
||||
progress_label.set_text('Refreshing...')
|
||||
progress_bar.pulse()
|
||||
action_icon.set_from_file('/usr/share/pamac/icons/24x24/status/refresh-cache.png')
|
||||
ProgressWindow.show_all()
|
||||
t_lock = True
|
||||
Refresh(reply_handler = handle_reply, error_handler = handle_error, timeout = 2000*1000)
|
||||
|
||||
def get_updates():
|
||||
"""Return a list of package objects in local db which can be updated"""
|
||||
|
107
pamac/updater.py
107
pamac/updater.py
@ -6,7 +6,7 @@ from gi.repository import Gtk
|
||||
import pyalpm
|
||||
from os import geteuid
|
||||
|
||||
from pamac import config, transaction
|
||||
from pamac import config, common, transaction
|
||||
|
||||
interface = Gtk.Builder()
|
||||
interface.add_from_file('/usr/share/pamac/gui/updater.glade')
|
||||
@ -34,90 +34,81 @@ def have_updates():
|
||||
pkgname = pkg.name
|
||||
newversion = transaction.get_new_version_available(pkgname)
|
||||
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>")
|
||||
return True
|
||||
|
||||
def set_transaction_add():
|
||||
transaction_add.clear()
|
||||
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
|
||||
while i < len(transaction.to_remove):
|
||||
transaction_add.append([' ', transaction.to_remove[i].name])
|
||||
transaction_add.append([' ', transaction.to_remove[i]])
|
||||
i += 1
|
||||
bottom_label.set_markup('')
|
||||
if transaction.to_add:
|
||||
installed_name = []
|
||||
for pkg_object in config.handle.get_localdb().pkgcache:
|
||||
installed_name.append(pkg_object.name)
|
||||
to_add_name = []
|
||||
for pkg_object in 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))
|
||||
transaction.to_update = sorted(set(installed_name).intersection(transaction.to_add))
|
||||
to_remove_from_add_name = sorted(set(transaction.to_update).intersection(transaction.to_add))
|
||||
for name in to_remove_from_add_name:
|
||||
to_add_name.remove(name)
|
||||
if to_add_name:
|
||||
transaction_add.append(['To install:', to_add_name[0]])
|
||||
transaction.to_add.remove(name)
|
||||
if transaction.to_add:
|
||||
transaction_add.append(['To install:', transaction.to_add[0]])
|
||||
i = 1
|
||||
while i < len(to_add_name):
|
||||
transaction_add.append([' ', to_add_name[i]])
|
||||
while i < len(transaction.to_add):
|
||||
transaction_add.append([' ', transaction.to_add[i]])
|
||||
i += 1
|
||||
bottom_label.set_markup('')
|
||||
#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():
|
||||
"""Upgrade a system like pacman -Su"""
|
||||
if transaction.t_lock is False:
|
||||
if transaction.do_syncfirst is True:
|
||||
transaction.t = transaction.init_transaction(recurse = True)
|
||||
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:
|
||||
if transaction.init_transaction(recurse = True):
|
||||
for pkg in transaction.list_first:
|
||||
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_add = transaction.t.to_add
|
||||
set_transaction_add()
|
||||
if len(transaction_add) != 0:
|
||||
ConfDialog.show_all()
|
||||
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:
|
||||
def on_UpdateWindow_delete_event(self, *arg):
|
||||
@ -155,12 +146,6 @@ def main():
|
||||
UpdateWindow.show_all()
|
||||
|
||||
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.ProgressWindow.show_all()
|
||||
transaction.do_refresh()
|
||||
transaction.ProgressWindow.hide()
|
||||
transaction.do_refresh()
|
||||
main()
|
||||
Gtk.main()
|
||||
|
2
setup.py
2
setup.py
@ -3,7 +3,7 @@
|
||||
from distutils.core import setup
|
||||
|
||||
setup(name='Pamac',
|
||||
version='0.2',
|
||||
version='0.3',
|
||||
description='A gtk3 frontend for pyalpm',
|
||||
license='GPL',
|
||||
author='Guillaume Benoit',
|
||||
|
@ -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 &
|
||||
|
Loading…
Reference in New Issue
Block a user