pamac-classic/pamac-install.py
2013-05-19 15:17:08 +02:00

113 lines
3.2 KiB
Python
Executable File

#! /usr/bin/python3
# -*- coding:utf-8 -*-
from gi.repository import GObject
from sys import argv
import dbus
from os.path import abspath
from pamac import common
# i18n
import gettext
import locale
locale.bindtextdomain('pamac', '/usr/share/locale')
gettext.bindtextdomain('pamac', '/usr/share/locale')
gettext.textdomain('pamac')
_ = gettext.gettext
def exiting(msg):
transaction.StopDaemon()
print('exiting')
loop.quit()
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:
full_path = abspath(pkg)
transaction.to_load.add(full_path)
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
else:
return True
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()
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('')
else:
main.WarningDialog.format_secondary_text(_('Nothing to do'))
response = main.WarningDialog.run()
if response:
main.WarningDialog.hide()
exiting('')
if common.pid_file_exists():
from pamac.main import ErrorDialog
ErrorDialog.format_secondary_text(_('Pamac is already running'))
response = ErrorDialog.run()
if response:
ErrorDialog.hide()
else:
from pamac import transaction, main
transaction.get_handle()
transaction.update_db()
do_syncfirst, updates = transaction.get_updates()
if 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()
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)