big rewrite with a dbus service, not finished atm

This commit is contained in:
guinux
2013-01-06 19:10:13 +01:00
parent 9095ef993c
commit 5982973656
25 changed files with 682 additions and 406 deletions

0
pamac/__init__.py Normal file
View File

120
pamac/callbacks.py Executable file
View File

@@ -0,0 +1,120 @@
#! /usr/bin/python
# -*-coding:utf-8-*-
from gi.repository import Gtk
import pyalpm
from pamac import config
# Callbacks
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')
event_text = ' '
def cb_event(ID, event, tupel):
global event_text
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:
ErrorDialog.format_secondary_text("ERROR: "+line)
response = ErrorDialog.run()
if response:
ErrorDialog.hide()
#t.release()
elif level & pyalpm.LOG_WARNING:
WarningDialog.format_secondary_text("WARNING: "+line)
response = WarningDialog.run()
if response:
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 (to_remove or to_add):
for pkg in to_remove+to_add:
if pkg.name+'-'+pkg.version in _target:
size = pkg.size
if _transferred == size:
already_transferred += size
progress_label.set_text('Downloading '+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)

194
pamac/config.py Executable file
View File

@@ -0,0 +1,194 @@
#! /usr/bin/python
# -*-coding:utf-8 -*-
import io
import os
import glob
import sys
import argparse
import collections
import warnings
import pyalpm
class InvalidSyntax(Warning):
def __init__(self, filename, problem, arg):
self.filename = filename
self.problem = problem
self.arg = arg
def __str__(self):
return "unable to parse %s, %s: %r" % (self.filename, self.problem, self.arg)
# Options that may occur several times in a section. Their values should be
# accumulated in a list.
LIST_OPTIONS = (
'CacheDir',
'HoldPkg',
'SyncFirst',
'IgnoreGroup',
'IgnorePkg',
'NoExtract',
'NoUpgrade',
'Server'
)
SINGLE_OPTIONS = (
'RootDir',
'DBPath',
'GPGDir',
'LogFile',
'Architecture',
'XferCommand',
'CleanMethod',
'SigLevel'
)
BOOLEAN_OPTIONS = (
'UseSyslog',
'ShowSize',
'UseDelta',
'TotalDownload',
'CheckSpace',
'VerbosePkgLists',
'ILoveCandy'
)
def pacman_conf_enumerator(path):
filestack = []
current_section = None
filestack.append(open(path))
while len(filestack) > 0:
f = filestack[-1]
line = f.readline()
if len(line) == 0:
# end of file
filestack.pop()
continue
line = line.strip()
if len(line) == 0: continue
if line[0] == '#':
continue
if line[0] == '[' and line[-1] == ']':
current_section = line[1:-1]
continue
if current_section is None:
raise InvalidSyntax(f.name, 'statement outside of a section', line)
# read key, value
key, equal, value = [x.strip() for x in line.partition('=')]
# include files
if equal == '=' and key == 'Include':
filestack.extend(open(f) for f in glob.glob(value))
continue
if current_section != 'options':
# repos only have the Server option
if key == 'Server' and equal == '=':
yield (current_section, 'Server', value)
elif key == 'SigLevel' and equal == '=':
yield (current_section, 'SigLevel', value)
else:
raise InvalidSyntax(f.name, 'invalid key for repository configuration', line)
continue
if equal == '=':
if key in LIST_OPTIONS:
for val in value.split():
yield (current_section, key, val)
elif key in SINGLE_OPTIONS:
yield (current_section, key, value)
else:
warnings.warn(InvalidSyntax(f.name, 'unrecognized option', key))
else:
if key in BOOLEAN_OPTIONS:
yield (current_section, key, True)
else:
warnings.warn(InvalidSyntax(f.name, 'unrecognized option', key))
class PacmanConfig(object):
def __init__(self, conf = None, options = None):
self.options = {}
self.repos = collections.OrderedDict()
self.options["RootDir"] = "/"
self.options["DBPath"] = "/var/lib/pacman"
self.options["GPGDir"] = "/etc/pacman.d/gnupg/"
self.options["LogFile"] = "/var/log/pacman.log"
self.options["Architecture"] = os.uname()[-1]
if conf is not None:
self.load_from_file(conf)
if options is not None:
self.load_from_options(options)
def load_from_file(self, filename):
for section, key, value in pacman_conf_enumerator(filename):
if section == 'options':
if key == 'Architecture' and value == 'auto':
continue
if key in LIST_OPTIONS:
self.options.setdefault(key, []).append(value)
else:
self.options[key] = value
else:
servers = self.repos.setdefault(section, [])
if key == 'Server':
servers.append(value)
if "CacheDir" not in self.options:
self.options["CacheDir"]= ["/var/cache/pacman/pkg"]
def load_from_options(self, options):
global _logmask
if options.root is not None:
self.options["RootDir"] = options.root
if options.dbpath is not None:
self.options["DBPath"] = options.dbpath
if options.gpgdir is not None:
self.options["GPGDir"] = options.gpgdir
if options.arch is not None:
self.options["Architecture"] = options.arch
if options.logfile is not None:
self.options["LogFile"] = options.logfile
if options.cachedir is not None:
self.options["CacheDir"] = [option.cachedir]
if options.debug:
_logmask = 0xffff
def apply(self, h):
h.arch = self.options["Architecture"]
h.logfile = self.options["LogFile"]
h.gpgdir = self.options["GPGDir"]
h.cachedirs = self.options["CacheDir"]
if "IgnoreGroup" in self.options:
h.ignoregrps = self.options["IgnoreGroup"]
if "IgnorePkg" in self.options:
h.ignorepkgs = self.options["IgnorePkg"]
if "NoExtract" in self.options:
h.noextracts = self.options["NoExtract"]
if "NoUpgrade" in self.options:
h.noupgrades = self.options["NoUpgrade"]
# set sync databases
for repo, servers in self.repos.items():
db = h.register_syncdb(repo, 0)
db_servers = []
for rawurl in servers:
url = rawurl.replace("$repo", repo)
url = url.replace("$arch", self.options["Architecture"])
db_servers.append(url)
db.servers = db_servers
def initialize_alpm(self):
h = pyalpm.Handle(self.options["RootDir"], self.options["DBPath"])
self.apply(h)
return h
def __str__(self):
return("PacmanConfig(options=%s, repos=%s)" % (str(self.options), str(self.repos)))
pacman_conf = PacmanConfig(conf = "/etc/pacman.conf")
handle = pacman_conf.initialize_alpm()
holpkg = None
syncfirst = None
if 'HoldPkg' in pacman_conf.options:
holdpkg = pacman_conf.options['HoldPkg']
if 'SyncFirst' in pacman_conf.options:
syncfirst = pacman_conf.options['SyncFirst']

View File

@@ -10,11 +10,13 @@ from time import strftime, localtime
from os import geteuid
import traceback
from backend import transaction, config
from pamac import transaction, config, callbacks
interface = Gtk.Builder()
interface.add_from_file('/usr/share/pamac/pamac.glade')
interface.add_from_file('/usr/share/pamac/dialogs.glade')
interface.add_from_file('/usr/share/pamac/gui/manager.glade')
interface.add_from_file('/usr/share/pamac/gui/dialogs.glade')
MainWindow = interface.get_object("MainWindow")
packages_list = interface.get_object('packages_list')
groups_list = interface.get_object('groups_list')
@@ -64,6 +66,7 @@ def set_list_dict_search(*patterns):
pkg_object_dict[pkg_object.name] = pkg_object
pkg_installed_dict[pkg_object.name] = False
for pkg_object in config.handle.get_localdb().search(*patterns):
print(pkg_object)
if not pkg_object.name in pkg_name_list:
pkg_name_list.append(pkg_object.name)
pkg_installed_dict[pkg_object.name] = True
@@ -123,6 +126,7 @@ def refresh_packages_list():
packages_list.append([name, pkg_installed_dict[name], True])
else:
packages_list.append([name, pkg_installed_dict[name], True])
print(name,pkg_installed_dict[name])
def set_packages_list():
global list_dict
@@ -194,28 +198,25 @@ def set_desc(pkg, style):
def set_transaction_sum():
transaction_sum.clear()
if transaction.to_remove:
transaction_sum.append(['To remove:', transaction.to_remove[0].name])
transaction_sum.append(['To remove:', transaction.to_remove[0]])
i = 1
while i < len(transaction.to_remove):
transaction_sum.append([' ', transaction.to_remove[i].name])
transaction_sum.append([' ', transaction.to_remove[i]])
i += 1
bottom_label.set_markup('')
if transaction.to_add:
installed_name = []
installed = []
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))
for name in to_remove_from_add_name:
to_add_name.remove(name)
if to_add_name:
transaction_sum.append(['To install:', to_add_name[0]])
installed.append(pkg_object.name)
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:
transaction.to_add.remove(name)
if transaction.to_add:
transaction_sum.append(['To install:', transaction.to_add[0]])
i = 1
while i < len(to_add_name):
transaction_sum.append([' ', to_add_name[i]])
while i < len(transaction.to_add):
transaction_sum.append([' ', transaction.to_add[i]])
i += 1
if transaction.to_update:
transaction_sum.append(['To update:', transaction.to_update[0]])
@@ -225,25 +226,32 @@ def set_transaction_sum():
i += 1
bottom_label.set_markup('')
#bottom_label.set_markup('<b>Total Download size: </b>'+format_size(totaldlcb))
top_label.set_markup('<big><b>Transaction Summary</b></big>')
top_label.set_markup('<big><b>Transaction Summary</b></big>')
class Handler:
def on_MainWindow_delete_event(self, *arg):
Gtk.main_quit()
if __name__ == "__main__":
Gtk.main_quit()
else:
MainWindow.hide()
def on_QuitButton_clicked(self, *arg):
Gtk.main_quit()
if __name__ == "__main__":
Gtk.main_quit()
else:
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()
if response:
transaction.ErrorDialog.hide()
elif not transaction_dict:
#if not geteuid() == 0:
#transaction.ErrorDialog.format_secondary_text("You need to be root to run packages transactions")
#response = transaction.ErrorDialog.run()
#if response:
#transaction.ErrorDialog.hide()
#el
if not transaction_dict:
transaction.ErrorDialog.format_secondary_text("No package is selected")
response = transaction.ErrorDialog.run()
if response:
@@ -253,42 +261,37 @@ class Handler:
print('Transaction locked')
else:
if transaction_type is "remove":
transaction.t = transaction.init_transaction(config.handle, cascade = True)
for pkg in transaction_dict.values():
transaction.t.remove_pkg(pkg)
try:
transaction.t.prepare()
except pyalpm.error:
transaction.ErrorDialog.format_secondary_text(traceback.format_exc())
transaction.init_transaction(cascade = True)
for pkgname in transaction_dict.keys():
transaction.Remove(pkgname)
error = transaction.Prepare()
if error:
transaction.ErrorDialog.format_secondary_text(error)
response = transaction.ErrorDialog.run()
if response:
transaction.ErrorDialog.hide()
transaction.t.release()
transaction.Release()
transaction.t_lock = False
transaction.to_remove = transaction.t.to_remove
transaction.to_add = transaction.t.to_add
transaction.get_to_remove()
#transaction.get_to_add()
set_transaction_sum()
ConfDialog.show_all()
if transaction_type is "install":
transaction.t = transaction.init_transaction(config.handle, noconflicts = True)
for pkg in transaction_dict.values():
transaction.t.add_pkg(pkg)
try:
transaction.t.prepare()
except pyalpm.error:
transaction.ErrorDialog.format_secondary_text(traceback.format_exc())
transaction.init_transaction(noconflicts = True)
for pkgname in transaction_dict.keys():
transaction.Add(pkgname)
error = transaction.Prepare()
if error:
transaction.ErrorDialog.format_secondary_text(error)
response = transaction.ErrorDialog.run()
if response:
transaction.ErrorDialog.hide()
transaction.t.release()
transaction.Release()
transaction.t_lock = False
transaction.get_to_remove()
transaction.get_to_add()
transaction.check_conflicts()
transaction.to_add = transaction.t.to_add
transaction.to_remove = []
if transaction.conflict_to_remove:
for pkg in transaction.conflict_to_remove.values():
transaction.to_remove.append(pkg)
transaction.t.release()
transaction.Release()
set_transaction_sum()
ConfDialog.show_all()
@@ -306,37 +309,31 @@ class Handler:
def on_TransCancelButton_clicked(self, *arg):
ConfDialog.hide()
transaction.t_lock = False
try:
transaction.t.release()
except:
pass
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":
transaction.ProgressWindow.show_all()
try:
transaction.t.commit()
except pyalpm.error:
transaction.ErrorDialog.format_secondary_text(traceback.format_exc())
error = transaction.Commit()
if error:
transaction.ErrorDialog.format_secondary_text(error)
response = transaction.ErrorDialog.run()
if response:
transaction.ErrorDialog.hide()
transaction_dict.clear()
transaction_type = None
set_packages_list()
transaction.ProgressWindow.hide()
transaction.Release()
if transaction_type is "install":
transaction.t = transaction.init_transaction(config.handle, noconflicts = True, nodeps = True)
for pkg in transaction.to_add:
transaction.t.add_pkg(pkg)
for pkg in transaction.to_remove:
transaction.t.remove_pkg(pkg)
transaction.t_finalize(transaction.t)
transaction_dict.clear()
transaction_type = None
set_packages_list()
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)
transaction.finalize()
transaction_dict.clear()
transaction_type = None
set_packages_list()
transaction.t_lock = False
def on_search_button_clicked(self, widget):
@@ -418,15 +415,16 @@ class Handler:
packages_list[line][1] = not packages_list[line][1]
packages_list[line][2] = True
def main():
interface.connect_signals(Handler())
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/icons/hicolor/24x24/status/refresh-cache.png')
transaction.ProgressWindow.show_all()
transaction.action_icon.set_from_file('/usr/share/pamac/icons/24x24/status/refresh-cache.png')
transaction.do_refresh()
transaction.ProgressWindow.hide()
interface.connect_signals(Handler())
MainWindow = interface.get_object("MainWindow")
MainWindow.show_all()
main()
Gtk.main()

161
pamac/pamac-daemon.py Executable file
View File

@@ -0,0 +1,161 @@
#! /usr/bin/python
# -*-coding:utf-8-*-
import dbus
import dbus.service
from dbus.mainloop.glib import DBusGMainLoop
import os
from gi.repository import GObject, Gtk
import pyalpm
import traceback
from pamac import config, callbacks
LANG = os.environ['LANG']
t = None
error = ''
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')
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')
sender_pid = dbus_info.GetConnectionUnixProcessID(sender)
proxy_policykit = bus.get_object('org.freedesktop.PolicyKit1','/org/freedesktop/PolicyKit1/Authority',False)
policykit_authority = dbus.Interface(proxy_policykit,'org.freedesktop.PolicyKit1.Authority')
Subject = ('unix-process', {'pid': dbus.UInt32(sender_pid, variant_level=1),
'start-time': dbus.UInt64(0, variant_level=1)})
(is_authorized,is_challenge,details) = policykit_authority.CheckAuthorization(Subject, action, {'': ''}, dbus.UInt32(1), '')
return is_authorized
@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 = ''
try:
config.handle.dlcb = callbacks.cb_dl
config.handle.totaldlcb = callbacks.totaldlcb
config.handle.eventcb = callbacks.cb_event
config.handle.questioncb = callbacks.cb_conv
config.handle.progresscb = callbacks.cb_progress
config.handle.logcb = callbacks.cb_log
t = config.handle.init_transaction(**options)
print('Init:',t.flags)
except pyalpm.error:
error = traceback.format_exc()
finally:
return error
else :
return 'You are not authorized'
@dbus.service.method('org.manjaro.pamac', 's', 's', sender_keyword='sender', connection_keyword='connexion')
def Remove(self, pkgname, sender=None, connexion=None):
global t
global error
error = ''
try:
pkg = config.handle.get_localdb().get_pkg(pkgname)
if pkg is not None:
t.remove_pkg(pkg)
except pyalpm.error:
error = traceback.format_exc()
finally:
return error
@dbus.service.method('org.manjaro.pamac', 's', 's', sender_keyword='sender', connection_keyword='connexion')
def Add(self, pkgname, sender=None, connexion=None):
global t
global error
error = ''
try:
for repo in config.handle.get_syncdbs():
pkg = repo.get_pkg(pkgname)
if pkg:
t.add_pkg(pkg)
break
except pyalpm.error:
error = traceback.format_exc()
finally:
return error
@dbus.service.method('org.manjaro.pamac', '', 's', sender_keyword='sender', connection_keyword='connexion')
def Prepare(self, sender=None, connexion=None):
global t
global error
error = ''
try:
t.prepare()
except pyalpm.error:
error = traceback.format_exc()
finally:
print('to_add:',t.to_add)
print('to_remove:',t.to_remove)
return error
@dbus.service.method('org.manjaro.pamac', '', 'as', sender_keyword='sender', connection_keyword='connexion')
def To_Remove(self, sender=None, connexion=None):
global t
liste = []
for pkg in t.to_remove:
liste.append(pkg.name)
return liste
@dbus.service.method('org.manjaro.pamac', '', 'as', sender_keyword='sender', connection_keyword='connexion')
def To_Add(self, sender=None, connexion=None):
global t
liste = []
for pkg in t.to_add:
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):
global t
global error
if self.policykit_test(sender,connexion,'org.manjaro.pamac.commit'):
try:
callbacks.ProgressWindow.show_all()
while Gtk.events_pending():
Gtk.main_iteration()
t.commit()
except pyalpm.error:
error = traceback.format_exc()
finally:
return error
else :
return 'You are not authorized'
@dbus.service.method('org.manjaro.pamac', '', 's', sender_keyword='sender', connection_keyword='connexion')
def Release(self, sender=None, connexion=None):
global t
global error
if self.policykit_test(sender,connexion,'org.manjaro.pamac.init_release'):
error = ''
try:
callbacks.ProgressWindow.hide()
t.release()
except pyalpm.error:
error = traceback.format_exc()
finally:
return error
else :
return 'You are not authorized'
@dbus.service.method('org.manjaro.pamac',sender_keyword='sender', connection_keyword='connexion')
def StopDaemon(self,sender=None, connexion=None):
loop.quit()
DBusGMainLoop(set_as_default=True)
myservice = PamacDBusService()
loop = GObject.MainLoop()
loop.run()

178
pamac/transaction.py Executable file
View File

@@ -0,0 +1,178 @@
#! /usr/bin/python
# -*-coding:utf-8-*-
from gi.repository import Gtk
import pyalpm
import traceback
import dbus
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')
t = None
t_lock = False
conflict_to_remove = None
to_remove = None
to_add = None
to_update = None
do_syncfirst = False
list_first = []
proxy = dbus.SystemBus().get_object('org.manjaro.pamac','/org/manjaro/pamac')
Init = proxy.get_dbus_method('Init','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')
To_Remove = proxy.get_dbus_method('To_Remove','org.manjaro.pamac')
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 init_transaction(**options):
"Transaction initialization"
global t_lock
global proxy
error = Init(options)
print(error)
if not error:
t_lock = True
return True
else:
ErrorDialog.format_secondary_text(error)
response = ErrorDialog.run()
if response:
ErrorDialog.hide()
return False
def check_conflicts():
global conflict_to_remove
global to_add
global to_remove
conflict_to_remove = {}
to_check = []
warning = ''
for pkgname in to_add:
for repo in config.handle.get_syncdbs():
pkg = repo.get_pkg(pkgname)
if pkg:
to_check.append(pkg)
break
for target in to_check:
if target.replaces:
for name in target.replaces:
pkg = config.handle.get_localdb().get_pkg(name)
if pkg:
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
if target.conflicts:
for name in target.conflicts:
pkg = config.handle.get_localdb().get_pkg(name)
if pkg:
if not pkg.name in to_remove:
to_remove.append(pkg.name)
for installed_pkg in config.handle.get_localdb().pkgcache:
if installed_pkg.conflicts:
for name in installed_pkg.conflicts:
if name == target.name:
if not name in to_remove:
to_remove.append(installed_pkg.name)
if warning:
WarningDialog.format_secondary_text(warning)
response = WarningDialog.run()
if response:
WarningDialog.hide()
def get_to_remove():
global to_remove
to_remove = To_Remove()
def get_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:
ErrorDialog.format_secondary_text(error)
response = ErrorDialog.run()
if response:
transaction.ErrorDialog.hide()
error = Commit()
if error:
ErrorDialog.format_secondary_text(error)
response = ErrorDialog.run()
if response:
transaction.ErrorDialog.hide()
t_lock = False
Release()
def do_refresh():
"""Sync databases like pacman -Sy"""
global t
global t_lock
for db in config.handle.get_syncdbs():
if t_lock is False:
t = init_transaction()
try:
db.update(force=False)
t.release()
t_lock = False
except pyalpm.error:
ErrorDialog.format_secondary_text(traceback.format_exc())
response = ErrorDialog.run()
if response:
ErrorDialog.hide()
t_lock = False
break
t_lock = False
progress_label.set_text('')
progress_bar.set_text('')
def get_updates():
"""Return a list of package objects in local db which can be updated"""
global do_syncfirst
global list_first
if config.syncfirst:
for name in config.syncfirst:
pkg = config.handle.get_localdb().get_pkg(name)
candidate = pyalpm.sync_newversion(pkg, config.handle.get_syncdbs())
if candidate:
list_first.append(candidate)
if list_first:
do_syncfirst = True
return list_first
result = []
installed_pkglist = config.handle.get_localdb().pkgcache
for pkg in installed_pkglist:
candidate = pyalpm.sync_newversion(pkg, config.handle.get_syncdbs())
if candidate:
result.append(candidate)
return result
def get_new_version_available(pkgname):
for repo in config.handle.get_syncdbs():
pkg = repo.get_pkg(pkgname)
if pkg is not None:
return pkg.version
break
def format_size(size):
KiB_size = size / 1024
if KiB_size < 1000:
size_string = '%.1f KiB' % (KiB_size)
return size_string
else:
size_string = '%.2f MiB' % (KiB_size / 1024)
return size_string

55
pamac/tray.py Executable file
View File

@@ -0,0 +1,55 @@
#! /usr/bin/python
# -*-coding:utf-8-*-
from gi.repository import Gtk
from pamac import transaction, updater, manager
class Tray:
def __init__(self, icon, info):
self.icon = icon
self.info = info
self.statusIcon = Gtk.StatusIcon()
self.statusIcon.set_from_file(icon)
self.statusIcon.set_visible(True)
self.statusIcon.set_tooltip_markup(info)
self.menu = Gtk.Menu()
self.menuItem = Gtk.ImageMenuItem('Check for updates')
self.menuItem.connect('activate', self.execute_update, self.statusIcon)
self.menu.append(self.menuItem)
self.menuItem = Gtk.ImageMenuItem('Run pamac')
self.menuItem.connect('activate', self.execute_manager, self.statusIcon)
self.menu.append(self.menuItem)
self.menuItem = Gtk.ImageMenuItem(Gtk.STOCK_QUIT)
self.menuItem.connect('activate', self.quit_tray, self.statusIcon)
self.menu.append(self.menuItem)
self.statusIcon.connect('popup-menu', self.popup_menu_cb, self.menu)
self.statusIcon.set_visible(1)
def execute_update(self, widget, event, data = None):
updater.main()
def execute_manager(self, widget, event, data = None):
manager.main()
def quit_tray(self, widget, data = None):
Gtk.main_quit()
def popup_menu_cb(self, widget, button, time, data = None):
if button == 3:
if data:
data.show_all()
data.popup(None, None, Gtk.StatusIcon.position_menu, self.statusIcon, 3, time)
if __name__ == "__main__":
updates = transaction.get_updates()
if updates:
icon = '/usr/share/pamac/icons/24x24/status/update-normal.png'
info = str(len(updates))+' update(s) available'
else:
icon = '/usr/share/pamac/icons/24x24/status/update-enhancement.png'
info = ' No update available'
tray = Tray(icon, info)
Gtk.main()

166
pamac/updater.py Executable file
View File

@@ -0,0 +1,166 @@
#! /usr/bin/python
# -*-coding:utf-8 -*-
from gi.repository import Gtk
import pyalpm
from os import geteuid
from pamac import config, transaction
interface = Gtk.Builder()
interface.add_from_file('/usr/share/pamac/gui/updater.glade')
interface.add_from_file('/usr/share/pamac/gui/dialogs.glade')
UpdateWindow = interface.get_object("UpdateWindow")
ConfDialog = interface.get_object('ConfDialog')
transaction_add = interface.get_object('transaction_add')
top_label = interface.get_object('top_label')
bottom_label = interface.get_object('bottom_label')
update_listore = interface.get_object('update_list')
update_label = interface.get_object('update_label')
def have_updates():
available_updates = transaction.get_updates()
update_listore.clear()
update_label.set_justify(Gtk.Justification.CENTER)
if not available_updates:
update_listore.append(["", ""])
update_label.set_markup("<big><b>No update available</b></big>")
return False
else:
for pkg in available_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_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])
i = 1
while i < len(transaction.to_remove):
transaction_add.append([' ', transaction.to_remove[i].name])
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))
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]])
i = 1
while i < len(to_add_name):
transaction_add.append([' ', to_add_name[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>')
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:
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)
class Handler:
def on_UpdateWindow_delete_event(self, *arg):
if __name__ == "__main__":
Gtk.main_quit()
else:
UpdateWindow.hide()
def on_QuitButton_clicked(self, *arg):
if __name__ == "__main__":
Gtk.main_quit()
else:
UpdateWindow.hide()
def on_ApplyButton_clicked(self, *arg):
do_sysupgrade()
have_updates()
def on_RefreshButton_clicked(self, *arg):
transaction.do_refresh()
have_updates()
def on_TransCancelButton_clicked(self, *arg):
ConfDialog.hide()
transaction.t_lock = False
transaction.t.release()
def on_TransValidButton_clicked(self, *arg):
ConfDialog.hide()
transaction.t_finalize(t)
def main():
have_updates()
interface.connect_signals(Handler())
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()
main()
Gtk.main()