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-05-19 09:17:08 -04:00
|
|
|
from pamac import common
|
2013-03-18 07:07:58 -03:00
|
|
|
|
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()
|
|
|
|
print('exiting')
|
|
|
|
loop.quit()
|
|
|
|
|
2013-04-21 11:09:07 -03:00
|
|
|
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()
|
|
|
|
|
|
|
|
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)
|
|
|
|
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
|
|
|
|
|
|
|
if common.pid_file_exists():
|
2013-05-19 09:17:08 -04:00
|
|
|
from pamac.main import ErrorDialog
|
|
|
|
ErrorDialog.format_secondary_text(_('Pamac is already running'))
|
|
|
|
response = ErrorDialog.run()
|
2013-03-18 07:07:58 -03:00
|
|
|
if response:
|
2013-05-19 09:17:08 -04:00
|
|
|
ErrorDialog.hide()
|
2013-05-18 05:24:20 -04:00
|
|
|
else:
|
2013-05-19 09:17:08 -04:00
|
|
|
from pamac import transaction, main
|
2013-05-18 05:24:20 -04:00
|
|
|
transaction.get_handle()
|
|
|
|
transaction.update_db()
|
|
|
|
do_syncfirst, updates = transaction.get_updates()
|
|
|
|
if updates:
|
2013-04-22 14:06:31 -03:00
|
|
|
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-05-18 05:24:20 -04:00
|
|
|
else:
|
|
|
|
loop = GObject.MainLoop()
|
|
|
|
main.config_signals()
|
|
|
|
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")
|
|
|
|
main.Handler.on_TransCancelButton_clicked = new_on_TransCancelButton_clicked
|
|
|
|
main.Handler.on_TransValidButton_clicked = new_on_TransValidButton_clicked
|
|
|
|
main.interface.connect_signals(main.Handler())
|
|
|
|
pkgs_to_install = argv[1:]
|
|
|
|
install(pkgs_to_install)
|