2013-04-07 09:16:23 -03:00
|
|
|
#! /usr/bin/python3
|
2013-03-31 14:31:33 -03:00
|
|
|
# -*- coding:utf-8 -*-
|
2013-03-18 07:07:58 -03:00
|
|
|
|
|
|
|
from gi.repository import GObject
|
|
|
|
from sys import argv
|
|
|
|
import dbus
|
2013-04-24 13:45:43 -03:00
|
|
|
from os.path import abspath
|
2013-03-18 07:07:58 -03:00
|
|
|
from pamac import common, transaction, main
|
|
|
|
|
2013-04-21 11:09:07 -03:00
|
|
|
# i18n
|
|
|
|
import gettext
|
|
|
|
import locale
|
|
|
|
locale.bindtextdomain('pamac', '/usr/share/locale')
|
|
|
|
gettext.bindtextdomain('pamac', '/usr/share/locale')
|
|
|
|
gettext.textdomain('pamac')
|
|
|
|
_ = gettext.gettext
|
2013-03-18 07:07:58 -03:00
|
|
|
|
2013-04-21 11:09:07 -03:00
|
|
|
def exiting(msg):
|
2013-03-18 07:07:58 -03:00
|
|
|
transaction.StopDaemon()
|
|
|
|
common.rm_pid_file()
|
|
|
|
print('exiting')
|
|
|
|
loop.quit()
|
|
|
|
|
2013-04-21 11:09:07 -03:00
|
|
|
bus = dbus.SystemBus()
|
|
|
|
bus.add_signal_receiver(exiting, dbus_interface = "org.manjaro.pamac", signal_name = "EmitTransactionDone")
|
|
|
|
bus.add_signal_receiver(exiting, dbus_interface = "org.manjaro.pamac", signal_name = "EmitTransactionError")
|
|
|
|
|
|
|
|
def new_on_TransCancelButton_clicked(self, *arg):
|
|
|
|
main.ProgressWindow.hide()
|
|
|
|
main.ConfDialog.hide()
|
|
|
|
transaction.Release()
|
|
|
|
exiting('')
|
|
|
|
|
|
|
|
def new_on_TransValidButton_clicked(self, *arg):
|
|
|
|
main.ConfDialog.hide()
|
|
|
|
main.finalize()
|
|
|
|
|
|
|
|
main.Handler.on_TransCancelButton_clicked = new_on_TransCancelButton_clicked
|
|
|
|
main.Handler.on_TransValidButton_clicked = new_on_TransValidButton_clicked
|
|
|
|
main.interface.connect_signals(main.Handler())
|
|
|
|
|
|
|
|
def get_pkgs(pkgs):
|
|
|
|
get_error = ''
|
|
|
|
for pkg in pkgs:
|
|
|
|
if '.pkg.tar.' in pkg:
|
2013-04-24 13:45:43 -03:00
|
|
|
full_path = abspath(pkg)
|
|
|
|
print('path',full_path)
|
|
|
|
transaction.to_load.add(full_path)
|
2013-04-21 11:09:07 -03:00
|
|
|
elif pkg in transaction.syncpkgs.keys():
|
|
|
|
transaction.to_add.add(pkg)
|
|
|
|
else:
|
|
|
|
if get_error:
|
|
|
|
get_error += '\n'
|
|
|
|
get_error += _('{pkgname} is not a valid path or package name').format(pkgname = pkg)
|
|
|
|
if get_error:
|
|
|
|
main.handle_error(get_error)
|
|
|
|
exiting(get_error)
|
|
|
|
return False
|
2013-03-18 07:07:58 -03:00
|
|
|
else:
|
2013-04-21 11:09:07 -03:00
|
|
|
return True
|
2013-03-18 07:07:58 -03:00
|
|
|
|
2013-04-21 11:09:07 -03:00
|
|
|
def install(pkgs):
|
|
|
|
if get_pkgs(pkgs):
|
|
|
|
main.check_conflicts()
|
|
|
|
if transaction.to_add | transaction.to_load:
|
|
|
|
if transaction.init_transaction(noconflicts = True):
|
|
|
|
for pkgname in transaction.to_add:
|
|
|
|
transaction.Add(pkgname)
|
|
|
|
for pkg_path in transaction.to_load:
|
|
|
|
transaction.Load(pkg_path)
|
|
|
|
for pkgname in transaction.to_remove:
|
|
|
|
transaction.Remove(pkgname)
|
|
|
|
_error = transaction.Prepare()
|
|
|
|
if _error:
|
|
|
|
main.handle_error(_error)
|
|
|
|
exiting(_error)
|
|
|
|
else:
|
|
|
|
main.set_transaction_sum()
|
2013-04-24 13:45:43 -03:00
|
|
|
if len(main.transaction_sum) != 0:
|
|
|
|
main.ConfDialog.show_all()
|
|
|
|
loop.run()
|
|
|
|
else:
|
|
|
|
main.WarningDialog.format_secondary_text(_('Nothing to do'))
|
|
|
|
response = main.WarningDialog.run()
|
|
|
|
if response:
|
|
|
|
main.WarningDialog.hide()
|
|
|
|
exiting('')
|
2013-04-21 11:09:07 -03:00
|
|
|
else:
|
|
|
|
main.WarningDialog.format_secondary_text(_('Nothing to do'))
|
|
|
|
response = main.WarningDialog.run()
|
|
|
|
if response:
|
|
|
|
main.WarningDialog.hide()
|
|
|
|
exiting('')
|
2013-03-18 07:07:58 -03:00
|
|
|
|
|
|
|
loop = GObject.MainLoop()
|
|
|
|
|
2013-03-26 10:26:16 -03:00
|
|
|
transaction.get_handle()
|
2013-03-18 07:07:58 -03:00
|
|
|
transaction.update_db()
|
|
|
|
do_syncfirst, updates = transaction.get_updates()
|
|
|
|
|
|
|
|
if common.pid_file_exists():
|
2013-04-21 11:09:07 -03:00
|
|
|
main.ErrorDialog.format_secondary_text(_('Pamac is already running'))
|
2013-04-10 11:20:54 -03:00
|
|
|
response = main.ErrorDialog.run()
|
2013-03-18 07:07:58 -03:00
|
|
|
if response:
|
2013-04-10 11:20:54 -03:00
|
|
|
main.ErrorDialog.hide()
|
2013-04-22 14:06:31 -03:00
|
|
|
elif updates:
|
|
|
|
main.ErrorDialog.format_secondary_text(_('Some updates are available.\nPlease update your system first'))
|
|
|
|
response = main.ErrorDialog.run()
|
|
|
|
if response:
|
|
|
|
main.ErrorDialog.hide()
|
|
|
|
transaction.StopDaemon()
|
2013-03-18 07:07:58 -03:00
|
|
|
else:
|
|
|
|
common.write_pid_file()
|
2013-04-21 11:09:07 -03:00
|
|
|
pkgs_to_install = argv[1:]
|
|
|
|
install(pkgs_to_install)
|