pamac-classic/pamac-install.py

171 lines
5.5 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
2013-11-26 05:24:54 -03:00
# pamac - A Python implementation of alpm
2014-02-01 11:39:58 -03:00
# Copyright (C) 2013-2014 Guillaume Benoit <guillaume@manjaro.org>
2013-11-26 05:24:54 -03:00
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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
2014-02-01 11:39:58 -03:00
from pamac import common, config, transaction, aur
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
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:
2014-02-01 11:39:58 -03:00
transaction.action_handler(_('Preparing')+'...')
transaction.icon_handler('/usr/share/pamac/icons/24x24/status/package-setup.png')
while Gtk.events_pending():
Gtk.main_iteration()
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:
2014-02-01 11:39:58 -03:00
aur_pkg = None
if config.enable_aur:
aur_pkg = aur.info(name)
if aur_pkg:
transaction.to_build.append(aur_pkg)
if not aur_pkg:
if error:
error += '\n'
error += _('{pkgname} is not a valid path or package name').format(pkgname = name)
2013-10-16 10:34:09 -03:00
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,
2014-02-01 11:39:58 -03:00
'on_PreferencesCloseButton_clicked' : transaction.on_PreferencesCloseButton_clicked,
'on_PreferencesWindow_delete_event' : transaction.on_PreferencesWindow_delete_event,
'on_PreferencesValidButton_clicked' : transaction.on_PreferencesValidButton_clicked,
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.get_dbus_methods()
config_dbus_signals()
transaction.get_updates()
Gtk.main()