pamac-classic/pamac-install.py

117 lines
3.2 KiB
Python
Raw Normal View History

#! /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
from os.path import abspath
2013-03-18 07:07:58 -03:00
from pamac import common, transaction, main
# 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
def exiting(msg):
2013-03-18 07:07:58 -03:00
transaction.StopDaemon()
common.rm_pid_file()
print('exiting')
loop.quit()
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:
full_path = abspath(pkg)
print('path',full_path)
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
2013-03-18 07:07:58 -03:00
else:
return True
2013-03-18 07:07:58 -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()
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('')
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():
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()
pkgs_to_install = argv[1:]
main.mode = 'manager'
install(pkgs_to_install)