pamac-classic/pamac-install.py

100 lines
2.9 KiB
Python
Raw Normal View History

2013-09-26 13:02:07 -03:00
#! /usr/bin/pkexec /usr/bin/python3
2013-03-31 14:31:33 -03:00
# -*- coding:utf-8 -*-
2013-03-18 07:07:58 -03:00
2013-09-26 13:02:07 -03:00
from gi.repository import Gtk
2013-03-18 07:07:58 -03:00
from sys import argv
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-03-18 07:07:58 -03:00
print('exiting')
loop.quit()
2013-09-26 13:02:07 -03:00
def on_ProgressCloseButton_clicked(*args):
transaction.ProgressWindow.hide()
transaction.progress_buffer.delete(transaction.progress_buffer.get_start_iter(),transaction.progress_buffer.get_end_iter())
common.rm_pid_file()
Gtk.main_quit()
2013-09-26 13:02:07 -03:00
def on_ProgressCancelButton_clicked(*args):
trans.interrupt()
2013-09-26 13:02:07 -03:00
def on_TransCancelButton_clicked(self, *arg):
transaction.ConfDialog.hide()
trans.release()
common.rm_pid_file()
Gtk.main_quit()
def on_TransValidButton_clicked(self, *arg):
transaction.ConfDialog.hide()
trans.finalize()
common.rm_pid_file()
Gtk.main_quit()
def get_pkgs(pkgstr_list):
get_error = ''
2013-09-26 13:02:07 -03:00
for pkgstr in pkgstr_list:
if '.pkg.tar.' in pkgstr:
full_path = abspath(pkgstr)
trans.to_load.append(full_path)
else:
2013-09-26 13:02:07 -03:00
pkg = trans.get_syncpkg(pkgstr)
if pkg:
trans.to_add.append(pkg)
else:
if get_error:
get_error += '\n'
get_error += _('{pkgname} is not a valid path or package name').format(pkgname = pkgstr)
if get_error:
2013-09-26 13:02:07 -03:00
trans.handle_error(get_error)
return False
2013-03-18 07:07:58 -03:00
else:
return True
2013-03-18 07:07:58 -03:00
2013-09-26 13:02:07 -03:00
signals = {'on_TransValidButton_clicked' : on_TransValidButton_clicked,
'on_TransCancelButton_clicked' : on_TransCancelButton_clicked,
'on_ChooseButton_clicked' : transaction.on_ChooseButton_clicked,
'on_progress_textview_size_allocate' : transaction.on_progress_textview_size_allocate,
'on_choose_renderertoggle_toggled' : transaction.on_choose_renderertoggle_toggled,
'on_ProgressCancelButton_clicked' : on_ProgressCancelButton_clicked,
'on_ProgressCloseButton_clicked' : on_ProgressCloseButton_clicked}
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-09-26 13:02:07 -03:00
trans = transaction.Transaction()
do_syncfirst, updates = trans.get_updates()
if updates:
2013-09-26 13:02:07 -03:00
transaction.ErrorDialog.format_secondary_text(_('Some updates are available.\nPlease update your system first'))
response = transaction.ErrorDialog.run()
2013-04-22 14:06:31 -03:00
if response:
2013-09-26 13:02:07 -03:00
transaction.ErrorDialog.hide()
else:
2013-09-26 13:02:07 -03:00
transaction.interface.connect_signals(signals)
args_str = argv[1:]
if get_pkgs(args_str):
if trans.to_add or trans.to_load:
if trans.check_extra_modules():
if trans.init(cascade = True):
for pkg in trans.to_add:
trans.add(pkg)
for path in trans.to_load:
trans.load(path)
if trans.prepare():
common.write_pid_file()
trans.set_transaction_sum(True)
transaction.ConfDialog.show()
Gtk.main()
2013-09-26 13:02:07 -03:00