From 09ff0c9ca12a98ff9c68320071577aa42d301b80 Mon Sep 17 00:00:00 2001 From: guinux Date: Wed, 29 Jan 2014 15:44:19 +0100 Subject: [PATCH] introducing settings support --- data/etc/pamac.conf | 11 + data/polkit/org.manjaro.pamac.policy | 8 + gui/dialogs.ui | 675 +++++++++++++++++---------- gui/manager.ui | 263 ++++++----- gui/updater.ui | 167 ++++--- pamac-daemon.py | 86 +++- pamac-manager.py | 22 +- pamac-tray.py | 15 +- pamac-updater.py | 18 +- pamac/config.py | 80 +++- pamac/transaction.py | 31 +- 11 files changed, 903 insertions(+), 473 deletions(-) create mode 100644 data/etc/pamac.conf diff --git a/data/etc/pamac.conf b/data/etc/pamac.conf new file mode 100644 index 0000000..6269906 --- /dev/null +++ b/data/etc/pamac.conf @@ -0,0 +1,11 @@ +### Pamac configuration file + +## How often to check for updates, value in hours: +RefreshPeriod = 4 + +## Allow Pamac to search and install packages from AUR: +#EnableAUR + +## When removing a package, also remove those dependencies +## that are not required by other packages (recurse option): +RemoveUnrequiredDeps diff --git a/data/polkit/org.manjaro.pamac.policy b/data/polkit/org.manjaro.pamac.policy index e753b1d..65c0a53 100644 --- a/data/polkit/org.manjaro.pamac.policy +++ b/data/polkit/org.manjaro.pamac.policy @@ -14,4 +14,12 @@ auth_admin_keep + + Authentication is required + + no + no + auth_admin_keep + + diff --git a/gui/dialogs.ui b/gui/dialogs.ui index 6c53771..9d58603 100644 --- a/gui/dialogs.ui +++ b/gui/dialogs.ui @@ -1,257 +1,7 @@ - + - - - False - Choose - True - center-on-parent - system-software-install - dialog - False - - - False - vertical - - - False - end - - - gtk-ok - True - True - True - True - - - - False - True - 0 - - - - - False - True - end - 0 - - - - - True - False - - - False - True - 1 - - - - - True - True - in - 300 - 250 - - - True - True - choose_list - False - False - False - False - - - none - - - - - autosize - - - - - - 0 - - - - - - 1 - - - - - - - - - True - True - 2 - - - - - - ChooseButton - - - - False - 5 - Summary - True - center-on-parent - system-software-install - dialog - False - - - True - False - vertical - 5 - - - True - False - - - False - True - 0 - - - - - True - False - True - True - in - 330 - 250 - - - True - True - True - True - transaction_sum - False - False - False - False - - - none - - - - - autosize - - - 0 - 600 - - - 0 - - - - - - - autosize - - - - 1 - - - - - - - - - True - True - 1 - - - - - True - False - - - False - True - 2 - - - - - True - False - 7 - True - end - - - gtk-cancel - True - True - True - True - False - True - - - - False - True - 0 - - - - - gtk-ok - True - True - False - True - - - - False - True - 1 - - - - - False - True - 3 - - - - - + False False @@ -319,7 +69,6 @@ system-software-install dialog False - False True @@ -519,6 +268,176 @@ + + 10000 + 1 + 10 + + + False + 5 + Pamac Preferences + center + 300 + 250 + + + True + False + vertical + 5 + + + True + True + + + True + False + vertical + 5 + + + Enable AUR support + True + True + False + Allow Pamac to search and install packages from AUR. + False + 0 + True + + + False + True + 0 + + + + + Remove unrequired dependencies + True + True + False + When removing a package, also remove those dependencies that are not required by other packages. + False + 0 + True + + + False + True + 1 + + + + + True + False + 5 + + + True + False + 3 + How often to check for updates, value in hours: + + + False + True + 0 + + + + + True + True + How often to check for updates, value in hours. + 3 + False + number + adjustment1 + True + if-valid + + + False + True + 1 + + + + + False + True + 2 + + + + + + + True + False + Options + + + False + + + + + True + True + 0 + + + + + True + False + 5 + end + + + gtk-ok + True + True + True + True + + + + False + True + 0 + + + + + gtk-close + True + True + True + True + + + + False + True + 1 + + + + + False + True + 1 + + + + + @@ -527,6 +446,111 @@ + + False + Choose + True + center-on-parent + system-software-install + dialog + False + + + False + vertical + + + False + end + + + gtk-ok + True + True + True + True + + + + False + True + 0 + + + + + False + True + end + 0 + + + + + True + False + + + False + True + 1 + + + + + True + True + in + 300 + 250 + + + True + True + choose_list + False + False + False + False + + + none + + + + + autosize + + + + + + 0 + + + + + + 1 + + + + + + + + + True + True + 2 + + + + + + ChooseButton + + @@ -535,4 +559,149 @@ + + False + 5 + Summary + True + center-on-parent + system-software-install + dialog + False + + + True + False + vertical + 5 + + + True + False + + + False + True + 0 + + + + + True + False + True + True + in + 330 + 250 + + + True + True + True + True + transaction_sum + False + False + False + False + + + none + + + + + autosize + + + 0 + 600 + + + 0 + + + + + + + autosize + + + + 1 + + + + + + + + + True + True + 1 + + + + + True + False + + + False + True + 2 + + + + + True + False + 7 + True + end + + + gtk-cancel + True + True + True + True + False + True + + + + False + True + 0 + + + + + gtk-ok + True + True + False + True + + + + False + True + 1 + + + + + False + True + 3 + + + + + diff --git a/gui/manager.ui b/gui/manager.ui index f9cbb39..307d5cd 100644 --- a/gui/manager.ui +++ b/gui/manager.ui @@ -1,7 +1,7 @@ - + - + False 5 @@ -36,6 +36,116 @@ + + True + False + gtk-cancel + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + True + False + 16 + emblem-package + + + True + False + + + gtk-refresh + True + False + True + True + + + + + + True + False + + + + + Install local packages + True + False + local_icon + False + + + + + + True + False + + + + + gtk-preferences + True + False> + True + + + + + + True + False + + + + + gtk-about + True + False + True + True + + + + + + True + False + gtk-execute + + + + application/x-xz-compressed-tar + + False 5 @@ -105,39 +215,43 @@ package_open_button - - True - False - gtk-cancel - - + - + - + + + + + + + - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + True + False + gtk-ok + False 2 @@ -838,103 +952,4 @@ - - True - False - 16 - emblem-package - - - True - False - - - gtk-refresh - True - False - True - True - - - - - - True - False - - - - - Install local packages - True - False - local_icon - False - - - - - - True - False - - - - - gtk-about - True - False - True - True - - - - - - True - False - gtk-execute - - - - application/x-xz-compressed-tar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - True - False - gtk-ok - diff --git a/gui/updater.ui b/gui/updater.ui index 170f5b8..59e2bc5 100644 --- a/gui/updater.ui +++ b/gui/updater.ui @@ -1,7 +1,7 @@ - + - + @@ -23,15 +23,117 @@ 5 Update Manager center + 500 system-software-update + True False True True vertical 8 + + + True + False + + + True + False + 5 + start + + + gtk-preferences + True + True + True + True + + + + False + True + 0 + + + + + False + True + 0 + + + + + True + True + True + 5 + end + + + gtk-refresh + True + True + True + True + + + + False + True + 0 + + + + + gtk-apply + True + True + True + True + + + + False + True + 1 + + + + + gtk-close + True + True + True + True + + + + False + True + 2 + + + + + False + True + end + 1 + + + + + False + True + end + 0 + + True @@ -65,66 +167,7 @@ False True - 0 - - - - - True - True - 5 - end - - - gtk-refresh - True - True - True - True - - - - False - True - 0 - - - - - gtk-apply - True - True - True - True - - - - False - True - 1 - - - - - gtk-close - True - True - True - True - - - - False - True - 2 - - - - - False - True - end - 0 + 1 diff --git a/pamac-daemon.py b/pamac-daemon.py index d00fb4d..8afb274 100755 --- a/pamac-daemon.py +++ b/pamac-daemon.py @@ -152,6 +152,10 @@ class PamacDBusService(dbus.service.Object): def EmitTransactionError(self, message): pass + @dbus.service.signal('org.manjaro.pamac') + def EmitReloadConfig(self, message): + pass + def cb_event(self, event, tupel): action = self.previous_action action_long = self.previous_action_long @@ -392,9 +396,10 @@ class PamacDBusService(dbus.service.Object): def cb_progress(self, event, target, _percent, n, i): if event in ('ALPM_PROGRESS_ADD_START', 'ALPM_PROGRESS_UPGRADE_START', 'ALPM_PROGRESS_DOWNGRADE_START', 'ALPM_PROGRESS_REINSTALL_START', 'ALPM_PROGRESS_REMOVE_START'): percent = round(((i-1)/n)+(_percent/(100*n)), 2) - self.EmitTransactionStart('') else: percent = round(_percent/100, 2) + if percent == 0: + self.EmitTransactionStart('') if target != self.previous_target: self.previous_target = target if percent != self.previous_percent: @@ -453,24 +458,25 @@ class PamacDBusService(dbus.service.Object): syncfirst = True updates.append((candidate.name, candidate.version, candidate.db.name, '', candidate.download_size)) if not updates: - if not self.aur_updates_checked: - self.get_local_packages() - self.local_packages -= _ignorepkgs - for pkg in self.localdb.pkgcache: - if not pkg.name in _ignorepkgs: - candidate = pyalpm.sync_newversion(pkg, self.syncdbs) - if candidate: - updates.append((candidate.name, candidate.version, candidate.db.name, '', candidate.download_size)) - self.local_packages.discard(pkg.name) - if not self.aur_updates_checked: - if self.local_packages: - self.aur_updates_pkgs = aur.multiinfo(self.local_packages) - self.aur_updates_checked = True - for aur_pkg in self.aur_updates_pkgs: - if self.localdb.get_pkg(aur_pkg.name): - comp = pyalpm.vercmp(aur_pkg.version, self.localdb.get_pkg(aur_pkg.name).version) - if comp == 1: - updates.append((aur_pkg.name, aur_pkg.version, aur_pkg.db.name, aur_pkg.tarpath, aur_pkg.download_size)) + if config.enable_aur: + if not self.aur_updates_checked: + self.get_local_packages() + self.local_packages -= _ignorepkgs + for pkg in self.localdb.pkgcache: + if not pkg.name in _ignorepkgs: + candidate = pyalpm.sync_newversion(pkg, self.syncdbs) + if candidate: + updates.append((candidate.name, candidate.version, candidate.db.name, '', candidate.download_size)) + self.local_packages.discard(pkg.name) + if not self.aur_updates_checked: + if self.local_packages: + self.aur_updates_pkgs = aur.multiinfo(self.local_packages) + self.aur_updates_checked = True + for aur_pkg in self.aur_updates_pkgs: + if self.localdb.get_pkg(aur_pkg.name): + comp = pyalpm.vercmp(aur_pkg.version, self.localdb.get_pkg(aur_pkg.name).version) + if comp == 1: + updates.append((aur_pkg.name, aur_pkg.version, aur_pkg.db.name, aur_pkg.tarpath, aur_pkg.download_size)) self.EmitAvailableUpdates((syncfirst, updates)) @dbus.service.method('org.manjaro.pamac', 'b', '') @@ -481,7 +487,6 @@ class PamacDBusService(dbus.service.Object): error = '' for db in self.syncdbs: try: - print(db.name) self.t = self.handle.init_transaction() db.update(force = bool(force_update)) self.t.release() @@ -763,6 +768,47 @@ class PamacDBusService(dbus.service.Object): common.rm_pid_file() mainloop.quit() + @dbus.service.method('org.manjaro.pamac', 'a(ss)', '', sender_keyword='sender', connection_keyword='connexion') + def WriteConfig(self, array, sender=None, connexion=None): + try: + authorized = self.policykit_test(sender,connexion,'org.manjaro.pamac.write_config') + except dbus.exceptions.DBusException as e: + self.EmitLogError(_('Authentication failed')) + else: + if authorized: + with open('/etc/pamac.conf', 'r') as conffile: + data = conffile.readlines() + i = 0 + while i < len(data): + line = data[i].strip() + if len(line) == 0: + i += 1 + continue + if line[0] == '#': + line = line.lstrip('#') + if line == '\n': + i += 1 + continue + old_key, equal, old_value = [x.strip() for x in line.partition('=')] + for tupel in array: + new_key = tupel[0] + new_value = tupel[1] + if old_key == new_key: + # i is equal to the line number where we find the key in the file + if new_key in config.SINGLE_OPTIONS: + data[i] = '{} = {}\n'.format(new_key, new_value) + elif new_key in config.BOOLEAN_OPTIONS: + if new_value == 'False': + data[i] = '#{}\n'.format(new_key) + else: + data[i] = '{}\n'.format(new_key) + i += 1 + with open('/etc/pamac.conf', 'w') as conffile: + conffile.writelines(data) + self.EmitReloadConfig('') + else: + self.EmitLogError(_('Authentication failed')) + GObject.threads_init() DBusGMainLoop(set_as_default = True) myservice = PamacDBusService() diff --git a/pamac-manager.py b/pamac-manager.py index 291425f..5906db8 100755 --- a/pamac-manager.py +++ b/pamac-manager.py @@ -77,6 +77,7 @@ PackagesChooserDialog = interface.get_object('PackagesChooserDialog') files_buffer = files_textview.get_buffer() AboutDialog.set_version(version) +search_aur_button.set_visible(config.enable_aur) search_dict = {} groups_dict = {} @@ -470,6 +471,13 @@ def handle_updates(updates): if error: handle_error(error) +def reload_config(msg): + config.pamac_conf.reload() + if config.enable_aur == False: + search_aur_button.set_active(False) + search_aur_button.set_visible(config.enable_aur) + transaction.get_updates() + def on_ManagerWindow_delete_event(*args): transaction.StopDaemon() common.rm_pid_file() @@ -748,7 +756,7 @@ def on_manager_valid_button_clicked(*args): ManagerWindow.get_window().set_cursor(Gdk.Cursor(Gdk.CursorType.WATCH)) while Gtk.events_pending(): Gtk.main_iteration() - error = transaction.run() + error = transaction.run(recurse = config.recurse) ManagerWindow.get_window().set_cursor(None) if error: handle_error(error) @@ -776,6 +784,12 @@ def on_local_item_activate(*args): while Gtk.events_pending(): Gtk.main_iteration() +def on_preferences_item_activate(*args): + transaction.EnableAURButton.set_active(config.enable_aur) + transaction.RemoveUnrequiredDepsButton.set_active(config.recurse) + transaction.RefreshPeriodSpinButton.set_value(config.refresh_period) + transaction.PreferencesWindow.show() + def on_about_item_activate(*args): response = AboutDialog.run() if response: @@ -856,6 +870,8 @@ signals = {'on_ManagerWindow_delete_event' : on_ManagerWindow_delete_event, 'on_TransValidButton_clicked' : on_TransValidButton_clicked, 'on_TransCancelButton_clicked' : on_TransCancelButton_clicked, 'on_ChooseButton_clicked' : transaction.on_ChooseButton_clicked, + 'on_PreferencesCloseButton_clicked' : transaction.on_PreferencesCloseButton_clicked, + 'on_PreferencesValidButton_clicked' : transaction.on_PreferencesValidButton_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, @@ -874,6 +890,7 @@ signals = {'on_ManagerWindow_delete_event' : on_ManagerWindow_delete_event, 'on_manager_cancel_button_clicked' : on_manager_cancel_button_clicked, 'on_refresh_item_activate' : on_refresh_item_activate, 'on_local_item_activate' : on_local_item_activate, + 'on_preferences_item_activate' : on_preferences_item_activate, 'on_about_item_activate' : on_about_item_activate, 'on_package_open_button_clicked' : on_package_open_button_clicked, 'on_package_cancel_button_clicked' : on_package_cancel_button_clicked, @@ -889,6 +906,7 @@ def config_dbus_signals(): 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") + bus.add_signal_receiver(reload_config, dbus_interface = "org.manjaro.pamac", signal_name = "EmitReloadConfig") if common.pid_file_exists(): transaction.ErrorDialog.format_secondary_text(_('Pamac is already running')) @@ -908,7 +926,7 @@ else: size_column.set_cell_data_func(size_renderertext, size_column_display_func) transaction.get_handle() update_lists() - ManagerWindow.show_all() + ManagerWindow.show() ManagerWindow.get_window().set_cursor(Gdk.Cursor(Gdk.CursorType.WATCH)) transaction.refresh() while Gtk.events_pending(): diff --git a/pamac-tray.py b/pamac-tray.py index e8f0b4f..977a795 100755 --- a/pamac-tray.py +++ b/pamac-tray.py @@ -25,7 +25,7 @@ from dbus.mainloop.glib import DBusGMainLoop from threading import Thread from time import sleep -from pamac import common +from pamac import common, config # i18n import gettext @@ -130,12 +130,23 @@ def set_icon(update_data): print(info) tray.update_icon(icon, info) +def launch_refresh_timeout(): + # GObject timeout is in milliseconds + global refresh_timeout_id + refresh_timeout_id = GObject.timeout_add(config.refresh_period*3600*1000, refresh) + +def relaunch_refresh_timeout(msg): + config.pamac_conf.reload() + GObject.source_remove(refresh_timeout_id) + launch_refresh_timeout() + DBusGMainLoop(set_as_default = True) bus = dbus.SystemBus() bus.add_signal_receiver(set_icon, dbus_interface = "org.manjaro.pamac", signal_name = "EmitAvailableUpdates") +bus.add_signal_receiver(reload_config, dbus_interface = "org.manjaro.pamac", signal_name = "EmitReloadConfig") tray = Tray() Notify.init(_('Update Manager')) refresh() -GObject.timeout_add(3*3600*1000, refresh) +launch_refresh_timeout() GObject.idle_add(check_pacman_running) Gtk.main() diff --git a/pamac-updater.py b/pamac-updater.py index 5b018d3..19c1c4e 100755 --- a/pamac-updater.py +++ b/pamac-updater.py @@ -22,7 +22,7 @@ from gi.repository import Gtk, Gdk import pyalpm import dbus -from pamac import config, common, transaction, aur +from pamac import config, common, transaction # i18n import gettext @@ -119,6 +119,10 @@ def handle_updates(updates): transaction.available_updates = updates have_updates() +def reload_config(msg): + config.pamac_conf.reload() + transaction.get_updates() + def on_UpdaterWindow_delete_event(*args): transaction.StopDaemon() common.rm_pid_file() @@ -162,6 +166,12 @@ def on_ProgressCancelButton_clicked(*args): while Gtk.events_pending(): Gtk.main_iteration() +def on_UpdaterPreferencesButton_clicked(*args): + transaction.EnableAURButton.set_active(config.enable_aur) + transaction.RemoveUnrequiredDepsButton.set_active(config.recurse) + transaction.RefreshPeriodSpinButton.set_value(config.refresh_period) + transaction.PreferencesWindow.show() + def on_Updater_ApplyButton_clicked(*args): UpdaterWindow.get_window().set_cursor(Gdk.Cursor(Gdk.CursorType.WATCH)) while Gtk.events_pending(): @@ -184,11 +194,14 @@ def on_Updater_CloseButton_clicked(*args): signals = {'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_PreferencesCloseButton_clicked' : transaction.on_PreferencesCloseButton_clicked, + 'on_PreferencesValidButton_clicked' : transaction.on_PreferencesValidButton_clicked, 'on_TransValidButton_clicked' :on_TransValidButton_clicked, 'on_TransCancelButton_clicked' :on_TransCancelButton_clicked, 'on_ProgressCloseButton_clicked' : on_ProgressCloseButton_clicked, 'on_ProgressCancelButton_clicked' : on_ProgressCancelButton_clicked, 'on_UpdaterWindow_delete_event' : on_UpdaterWindow_delete_event, + 'on_UpdaterPreferencesButton_clicked': on_UpdaterPreferencesButton_clicked, 'on_Updater_ApplyButton_clicked' : on_Updater_ApplyButton_clicked, 'on_Updater_RefreshButton_clicked' : on_Updater_RefreshButton_clicked, 'on_Updater_CloseButton_clicked' : on_Updater_CloseButton_clicked} @@ -198,6 +211,7 @@ def config_dbus_signals(): 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") + bus.add_signal_receiver(reload_config, dbus_interface = "org.manjaro.pamac", signal_name = "EmitReloadConfig") if common.pid_file_exists(): transaction.ErrorDialog.format_secondary_text(_('Pamac is already running')) @@ -210,7 +224,7 @@ else: transaction.get_dbus_methods() transaction.config_dbus_signals() config_dbus_signals() - UpdaterWindow.show_all() + UpdaterWindow.show() UpdaterWindow.get_window().set_cursor(Gdk.Cursor(Gdk.CursorType.WATCH)) while Gtk.events_pending(): Gtk.main_iteration() diff --git a/pamac/config.py b/pamac/config.py index b0bdf09..f29e678 100644 --- a/pamac/config.py +++ b/pamac/config.py @@ -60,7 +60,8 @@ SINGLE_OPTIONS = ( 'CleanMethod', 'SigLevel', 'LocalFileSigLevel', - 'RemoteFileSigLevel' + 'RemoteFileSigLevel', + 'RefreshPeriod' ) BOOLEAN_OPTIONS = ( @@ -69,7 +70,9 @@ BOOLEAN_OPTIONS = ( 'CheckSpace', 'VerbosePkgLists', 'ILoveCandy', - 'Color' + 'Color', + 'EnableAUR', + 'RemoveUnrequiredDeps' ) def define_siglevel(default_level, conf_string): @@ -186,7 +189,7 @@ def pacman_conf_enumerator(path): else: warnings.warn(InvalidSyntax(f.name, 'unrecognized option', key)) -class PacmanConfig: +class PacmanConfig(): def __init__(self, conf = None, options = None): self.options = {} self.repos = collections.OrderedDict() @@ -292,8 +295,79 @@ class PacmanConfig: def __str__(self): return("PacmanConfig(options={}, repos={})".format(self.options, self.repos)) +def pamac_conf_enumerator(path): + filestack = [] + current_section = None + filestack.append(open(path)) + while len(filestack) > 0: + f = filestack[-1] + line = f.readline() + if len(line) == 0: + # end of file + filestack.pop() + continue + + line = line.strip() + if len(line) == 0: + continue + if line[0] == '#': + continue + # read key, value + key, equal, value = [x.strip() for x in line.partition('=')] + + if equal == '=': + if key in LIST_OPTIONS: + for val in value.split(): + yield (current_section, key, val) + elif key in SINGLE_OPTIONS: + if key == 'RefreshPeriod': + yield (current_section, key, int(value)) + else: + yield (current_section, key, value) + else: + warnings.warn(InvalidSyntax(f.name, 'unrecognized option', key)) + else: + if key in BOOLEAN_OPTIONS: + yield (current_section, key, True) + else: + warnings.warn(InvalidSyntax(f.name, 'unrecognized option', key)) + +class PamacConfig(): + def __init__(self, conf = None): + self.options = {} + self.options["RefreshPeriod"] = 3600*3 + self.options["EnableAUR"] = False + self.options["RemoveUnrequiredDeps"] = False + if conf: + self.load_from_file(conf) + + def load_from_file(self, filename): + for section, key, value in pamac_conf_enumerator(filename): + if key in LIST_OPTIONS: + self.options.setdefault(key, []).append(value) + else: + self.options[key] = value + self.set_global_variables() + + def set_global_variables(self): + global refresh_period + global enable_aur + global recurse + refresh_period = self.options['RefreshPeriod'] + enable_aur = self.options['EnableAUR'] + recurse = self.options['RemoveUnrequiredDeps'] + + def reload(self): + self.options["EnableAUR"] = False + self.options["RemoveUnrequiredDeps"] = False + self.load_from_file("/etc/pamac.conf") + + def __str__(self): + return("PamacConfig(options={})".format(self.options)) + pacman_conf = PacmanConfig(conf = "/etc/pacman.conf") handle = pacman_conf.initialize_alpm +pamac_conf = PamacConfig(conf = "/etc/pamac.conf") holdpkg = [] syncfirst = [] if 'HoldPkg' in pacman_conf.options: diff --git a/pamac/transaction.py b/pamac/transaction.py index 41d0f1b..e0ee0c6 100644 --- a/pamac/transaction.py +++ b/pamac/transaction.py @@ -67,7 +67,7 @@ interface.add_from_file('/usr/share/pamac/gui/dialogs.ui') ErrorDialog = interface.get_object('ErrorDialog') WarningDialog = interface.get_object('WarningDialog') #InfoDialog = interface.get_object('InfoDialog') -#QuestionDialog = interface.get_object('QuestionDialog') +QuestionDialog = interface.get_object('QuestionDialog') ConfDialog = interface.get_object('ConfDialog') transaction_sum = interface.get_object('transaction_sum') sum_top_label = interface.get_object('sum_top_label') @@ -84,6 +84,10 @@ ProgressCancelButton = interface.get_object('ProgressCancelButton') ProgressCloseButton = interface.get_object('ProgressCloseButton') progress_expander = interface.get_object('progress_expander') progress_textview = interface.get_object('progress_textview') +PreferencesWindow = interface.get_object('PreferencesWindow') +EnableAURButton = interface.get_object('EnableAURButton') +RemoveUnrequiredDepsButton = interface.get_object('RemoveUnrequiredDepsButton') +RefreshPeriodSpinButton = interface.get_object('RefreshPeriodSpinButton') progress_buffer = progress_textview.get_buffer() @@ -107,6 +111,7 @@ def get_dbus_methods(): global Release global StopDaemon global SetPkgReason + global WriteConfig SetPkgReason = proxy.get_dbus_method('SetPkgReason','org.manjaro.pamac') Refresh = proxy.get_dbus_method('Refresh','org.manjaro.pamac') CheckUpdates = proxy.get_dbus_method('CheckUpdates','org.manjaro.pamac') @@ -122,6 +127,7 @@ def get_dbus_methods(): Interrupt = proxy.get_dbus_method('Interrupt','org.manjaro.pamac') Release = proxy.get_dbus_method('Release','org.manjaro.pamac') StopDaemon = proxy.get_dbus_method('StopDaemon','org.manjaro.pamac') + WriteConfig = proxy.get_dbus_method('WriteConfig','org.manjaro.pamac') def config_dbus_signals(): bus.add_signal_receiver(action_handler, dbus_interface = "org.manjaro.pamac", signal_name = "EmitAction") @@ -200,7 +206,7 @@ def choose_provides(data): def on_choose_renderertoggle_toggled(widget, line): choose_list[line][0] = not choose_list[line][0] -def on_ChooseButton_clicked(*arg): +def on_ChooseButton_clicked(*args): ChooseDialog.hide() while Gtk.events_pending(): Gtk.main_iteration() @@ -208,11 +214,26 @@ def on_ChooseButton_clicked(*arg): if row[0] is True: to_add.add(row[1].split(':')[0]) # split done in case of optdep choice -def on_progress_textview_size_allocate(*arg): +def on_progress_textview_size_allocate(*args): #auto-scrolling method adj = progress_textview.get_vadjustment() adj.set_value(adj.get_upper() - adj.get_page_size()) +def on_PreferencesValidButton_clicked(*args): + data = [] + if EnableAURButton.get_active() != config.enable_aur: + data.append(('EnableAUR', str(EnableAURButton.get_active()))) + if RemoveUnrequiredDepsButton.get_active() != config.recurse: + data.append(('RemoveUnrequiredDeps', str(RemoveUnrequiredDepsButton.get_active()))) + if RefreshPeriodSpinButton.get_value() != config.refresh_period: + data.append(('RefreshPeriod', str(RefreshPeriodSpinButton.get_value_as_int()))) + if data: + WriteConfig(data) + PreferencesWindow.hide() + +def on_PreferencesCloseButton_clicked(*args): + PreferencesWindow.hide() + def get_handle(): global handle global syncdbs @@ -380,7 +401,7 @@ def check_to_build(): print('builddeps:',build_depends) return error -def run(): +def run(cascade = True, recurse = False): if to_add or to_remove or to_load or to_build: global progress_buffer action_handler(_('Preparing')+'...') @@ -404,7 +425,7 @@ def run(): if to_add or to_remove or to_load: while Gtk.events_pending(): Gtk.main_iteration() - trans_flags = {'cascade' : True} + trans_flags = {'cascade': cascade, 'recurse': recurse} error += init_transaction(**trans_flags) if not error: for name in to_add: