pamac-classic/pamac-install.py

145 lines
4.2 KiB
Python
Raw Normal View History

2013-10-16 10:34:09 -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 Gtk
2013-03-18 07:07:58 -03:00
from sys import argv
2013-10-16 10:34:09 -03:00
import dbus
from os.path import abspath
2013-09-26 13:02:07 -03:00
from pamac import common, transaction
2013-03-18 07:07:58 -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
def exiting(msg):
2013-10-16 10:34:09 -03:00
transaction.StopDaemon()
print(msg)
2013-03-18 07:07:58 -03:00
print('exiting')
Gtk.main_quit()
2013-03-18 07:07:58 -03:00
2013-10-16 10:34:09 -03:00
def handle_error(error):
2013-09-26 13:02:07 -03:00
transaction.ProgressWindow.hide()
2013-10-16 10:34:09 -03:00
while Gtk.events_pending():
Gtk.main_iteration()
if error:
if not 'DBus.Error.NoReply' in str(error):
transaction.ErrorDialog.format_secondary_text(error)
response = transaction.ErrorDialog.run()
if response:
transaction.ErrorDialog.hide()
exiting(error)
2013-10-16 10:34:09 -03:00
def handle_reply(reply):
transaction.ProgressCloseButton.set_visible(True)
transaction.action_icon.set_from_icon_name('dialog-information', Gtk.IconSize.BUTTON)
transaction.progress_label.set_text(str(reply))
transaction.progress_bar.set_text('')
end_iter = transaction.progress_buffer.get_end_iter()
transaction.progress_buffer.insert(end_iter, str(reply))
def handle_updates(update_data):
syncfirst, updates = update_data
transaction.ProgressWindow.hide()
while Gtk.events_pending():
Gtk.main_iteration()
2013-11-17 11:05:58 -03:00
if transaction_done:
exiting('')
elif updates:
transaction.ErrorDialog.format_secondary_text(_('Some updates are available.\nPlease update your system first'))
response = transaction.ErrorDialog.run()
if response:
transaction.ErrorDialog.hide()
exiting('')
else:
common.write_pid_file()
transaction.interface.connect_signals(signals)
transaction.config_dbus_signals()
pkgs_to_install = argv[1:]
install(pkgs_to_install)
2013-10-16 10:34:09 -03:00
def on_TransValidButton_clicked(*args):
2013-09-26 13:02:07 -03:00
transaction.ConfDialog.hide()
2013-10-16 10:34:09 -03:00
while Gtk.events_pending():
Gtk.main_iteration()
transaction.finalize()
2013-09-26 13:02:07 -03:00
2013-10-16 10:34:09 -03:00
def on_TransCancelButton_clicked(*args):
2013-09-26 13:02:07 -03:00
transaction.ConfDialog.hide()
2013-10-16 10:34:09 -03:00
while Gtk.events_pending():
Gtk.main_iteration()
transaction.Release()
exiting('')
def on_ProgressCloseButton_clicked(*args):
2013-11-17 11:05:58 -03:00
global transaction_done
2013-10-16 10:34:09 -03:00
transaction.ProgressWindow.hide()
while Gtk.events_pending():
Gtk.main_iteration()
2013-11-17 11:05:58 -03:00
transaction_done = True
transaction.CheckUpdates()
2013-09-26 13:02:07 -03:00
2013-10-16 10:34:09 -03:00
def on_ProgressCancelButton_clicked(*args):
transaction.Interrupt()
transaction.ProgressWindow.hide()
while Gtk.events_pending():
Gtk.main_iteration()
exiting('')
def get_pkgs(pkgs):
error = ''
for name in pkgs:
if '.pkg.tar.' in name:
full_path = abspath(name)
transaction.to_load.add(full_path)
elif transaction.get_syncpkg(name):
transaction.to_add.add(name)
else:
2013-10-16 10:34:09 -03:00
if error:
error += '\n'
error += _('{pkgname} is not a valid path or package name').format(pkgname = name)
if error:
handle_error(error)
return False
2013-03-18 07:07:58 -03:00
else:
return True
2013-03-18 07:07:58 -03:00
2013-10-16 10:34:09 -03:00
def install(pkgs):
if get_pkgs(pkgs):
error = transaction.run()
while Gtk.events_pending():
Gtk.main_iteration()
2013-10-16 10:34:09 -03:00
if error:
handle_error(error)
signals = {'on_ChooseButton_clicked' : transaction.on_ChooseButton_clicked,
2013-09-26 13:02:07 -03:00
'on_progress_textview_size_allocate' : transaction.on_progress_textview_size_allocate,
'on_choose_renderertoggle_toggled' : transaction.on_choose_renderertoggle_toggled,
2013-10-16 10:34:09 -03:00
'on_TransValidButton_clicked' :on_TransValidButton_clicked,
'on_TransCancelButton_clicked' :on_TransCancelButton_clicked,
'on_ProgressCloseButton_clicked' : on_ProgressCloseButton_clicked,
'on_ProgressCancelButton_clicked' : on_ProgressCancelButton_clicked}
def config_dbus_signals():
bus = dbus.SystemBus()
bus.add_signal_receiver(handle_reply, dbus_interface = "org.manjaro.pamac", signal_name = "EmitTransactionDone")
bus.add_signal_receiver(handle_error, dbus_interface = "org.manjaro.pamac", signal_name = "EmitTransactionError")
bus.add_signal_receiver(handle_updates, dbus_interface = "org.manjaro.pamac", signal_name = "EmitAvailableUpdates")
2013-03-18 07:07:58 -03:00
if common.pid_file_exists():
2013-09-26 13:02:07 -03:00
transaction.ErrorDialog.format_secondary_text(_('Pamac is already running'))
response = transaction.ErrorDialog.run()
2013-03-18 07:07:58 -03:00
if response:
2013-09-26 13:02:07 -03:00
transaction.ErrorDialog.hide()
else:
2013-11-17 11:05:58 -03:00
transaction_done = False
2013-10-16 10:34:09 -03:00
transaction.get_handle()
transaction.update_dbs()
transaction.get_dbus_methods()
config_dbus_signals()
transaction.get_updates()
Gtk.main()