From 412d1f9a02e6cd6d73605c1f8321809a63f24c19 Mon Sep 17 00:00:00 2001 From: guinux Date: Thu, 25 Aug 2016 12:33:16 +0200 Subject: [PATCH] add clean cache feature in preferences (as paccache frontend) --- po/files_to_translate | 1 - po/pamac.pot | 41 +++++++----- resources/preferences_dialog.ui | 107 +++++++++++++++++++++++++++++++- src/daemon.vala | 50 +++++++++++++-- src/preferences_dialog.vala | 10 +++ src/transaction.vala | 9 +++ 6 files changed, 192 insertions(+), 26 deletions(-) diff --git a/po/files_to_translate b/po/files_to_translate index 3f63c8c..f552672 100644 --- a/po/files_to_translate +++ b/po/files_to_translate @@ -13,7 +13,6 @@ ../resources/progress_dialog.ui ../resources/history_dialog.ui ../resources/transaction_sum_dialog.ui -../resources/choose_dep_dialog.ui ../resources/manager_window.ui ../resources/updater_window.ui ../resources/preferences_dialog.ui diff --git a/po/pamac.pot b/po/pamac.pot index 3d02a4f..5aacc89 100644 --- a/po/pamac.pot +++ b/po/pamac.pot @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: Pamac\n" "Report-Msgid-Bugs-To: guillaume@manjaro.org\n" -"POT-Creation-Date: 2015-08-20 11:53+0200\n" +"POT-Creation-Date: 2016-04-24 08:44+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -25,6 +25,10 @@ msgstr "" msgid "Failed to initialize alpm library" msgstr "" +#: ../src/daemon.vala ../src/transaction.vala +msgid "Authentication failed" +msgstr "" + #: ../src/daemon.vala msgid "Failed to synchronize any databases" msgstr "" @@ -101,10 +105,6 @@ msgstr "" msgid "%s is invalid or corrupted" msgstr "" -#: ../src/daemon.vala ../src/transaction.vala -msgid "Authentication failed" -msgstr "" - #: ../src/daemon.vala #, c-format msgid "%s appears to be truncated: %jd/%jd bytes\n" @@ -325,7 +325,7 @@ msgstr "" msgid "Warning" msgstr "" -#: ../src/transaction.vala +#: ../src/transaction.vala ../resources/progress_dialog.ui msgid "_Close" msgstr "" @@ -518,8 +518,7 @@ msgstr "" msgid "Install Local Packages" msgstr "" -#: ../src/manager_window.vala ../resources/progress_dialog.ui -#: ../resources/transaction_sum_dialog.ui ../resources/choose_dep_dialog.ui +#: ../src/manager_window.vala ../resources/transaction_sum_dialog.ui #: ../resources/manager_window.ui ../resources/updater_window.ui #: ../resources/choose_ignorepkgs_dialog.ui msgid "_Cancel" @@ -553,7 +552,7 @@ msgstr "" msgid "Choose a Provider" msgstr "" -#: ../resources/choose_provider_dialog.ui ../resources/choose_dep_dialog.ui +#: ../resources/choose_provider_dialog.ui #: ../resources/choose_ignorepkgs_dialog.ui msgid "Choose" msgstr "" @@ -562,10 +561,6 @@ msgstr "" msgid "Progress" msgstr "" -#: ../resources/progress_dialog.ui -msgid "_Hide" -msgstr "" - #: ../resources/history_dialog.ui msgid "Pamac History" msgstr "" @@ -578,10 +573,6 @@ msgstr "" msgid "Commit" msgstr "" -#: ../resources/choose_dep_dialog.ui -msgid "Choose Optional Dependencies" -msgstr "" - #: ../resources/manager_window.ui ../resources/updater_window.ui msgid "Refresh databases" msgstr "" @@ -724,6 +715,22 @@ msgstr "" msgid "Do not ask for confirmation when building packages" msgstr "" +#: ../resources/preferences_dialog.ui +msgid "Number of each package to keep in the cache:" +msgstr "" + +#: ../resources/preferences_dialog.ui +msgid "Only remove uninstalled packages" +msgstr "" + +#: ../resources/preferences_dialog.ui +msgid "Clean cache" +msgstr "" + +#: ../resources/preferences_dialog.ui +msgid "Cache" +msgstr "" + #: ../resources/choose_ignorepkgs_dialog.ui msgid "Choose Ignored Upgrades" msgstr "" diff --git a/resources/preferences_dialog.ui b/resources/preferences_dialog.ui index 3a06601..50af84a 100644 --- a/resources/preferences_dialog.ui +++ b/resources/preferences_dialog.ui @@ -2,7 +2,13 @@ - + + 10 + 3 + 1 + 10 + + 1 1000 6 @@ -204,7 +210,7 @@ end False number - adjustment + refresh_period_adjustment True if-valid 6 @@ -657,6 +663,103 @@ All AUR users should be familiar with the build process. 2 + + + True + False + 6 + 6 + 6 + 6 + 6 + 6 + vertical + 6 + + + True + False + 12 + + + True + False + start + True + Number of each package to keep in the cache: + True + 300 + + + False + True + 0 + + + + + True + True + How often to check for updates, value in hours + end + False + number + cache_keep_nb_adjustment + True + if-valid + 3 + + + False + True + 1 + + + + + False + True + 0 + + + + + Only remove uninstalled packages + True + True + False + 22 + True + + + False + True + 1 + + + + + Clean cache + True + True + True + end + 12 + + + + False + True + 2 + + + + + cache + Cache + 3 + + True diff --git a/src/daemon.vala b/src/daemon.vala index e8c2492..55d70b8 100644 --- a/src/daemon.vala +++ b/src/daemon.vala @@ -281,12 +281,50 @@ namespace Pamac { generate_mirrors_list_finished (); } - public void start_generate_mirrors_list () { - try { - thread_pool.add (new AlpmAction (generate_mirrors_list)); - } catch (ThreadError e) { - stderr.printf ("Thread Error %s\n", e.message); - } + public void start_generate_mirrors_list (GLib.BusName sender) { + check_authorization.begin (sender, (obj, res) => { + bool authorized = check_authorization.end (res); + if (authorized) { + try { + thread_pool.add (new AlpmAction (generate_mirrors_list)); + } catch (ThreadError e) { + stderr.printf ("Thread Error %s\n", e.message); + } + } else { + current_error = ErrorInfos () { + message = _("Authentication failed") + }; + } + }); + } + + public void clean_cache (uint keep_nb, bool only_uninstalled, GLib.BusName sender) { + check_authorization.begin (sender, (obj, res) => { + bool authorized = check_authorization.end (res); + if (authorized) { + string[] commands = {"paccache", "-rq"}; + commands += "-k%u".printf (keep_nb); + if (only_uninstalled) { + commands += "-u"; + } + try { + var process = new Subprocess.newv ( + commands, + SubprocessFlags.STDOUT_PIPE | SubprocessFlags.STDERR_MERGE); + var dis = new DataInputStream (process.get_stdout_pipe ()); + string? line; + while ((line = dis.read_line ()) != null) { + print ("%s\n",line); + } + } catch (Error e) { + stderr.printf ("Error: %s\n", e.message); + } + } else { + current_error = ErrorInfos () { + message = _("Authentication failed") + }; + } + }); } public void start_write_mirrors_config (HashTable new_mirrors_conf, GLib.BusName sender) { diff --git a/src/preferences_dialog.vala b/src/preferences_dialog.vala index 1696a9d..156b6f7 100644 --- a/src/preferences_dialog.vala +++ b/src/preferences_dialog.vala @@ -56,6 +56,10 @@ namespace Pamac { Gtk.CheckButton check_aur_updates_checkbutton; [GtkChild] Gtk.CheckButton no_confirm_build_checkbutton; + [GtkChild] + Gtk.SpinButton cache_keep_nb_spin_button; + [GtkChild] + Gtk.CheckButton cache_only_uninstalled_checkbutton; Gtk.ListStore ignorepkgs_liststore; Transaction transaction; @@ -368,5 +372,11 @@ namespace Pamac { transaction.start_generate_mirrors_list (); generate_mirrors_list_button.get_style_context ().remove_class (Gtk.STYLE_CLASS_SUGGESTED_ACTION); } + + [GtkCallback] + void on_cache_clean_button_clicked () { + transaction.clean_cache ((uint) cache_keep_nb_spin_button.get_value_as_int (), + cache_only_uninstalled_checkbutton.active); + } } } diff --git a/src/transaction.vala b/src/transaction.vala index cca7c19..9a1f748 100644 --- a/src/transaction.vala +++ b/src/transaction.vala @@ -29,6 +29,7 @@ namespace Pamac { public abstract void start_write_alpm_config (HashTable new_alpm_conf) throws IOError; public abstract void start_write_mirrors_config (HashTable new_mirrors_conf) throws IOError; public abstract void start_generate_mirrors_list () throws IOError; + public abstract void clean_cache (uint keep_nb, bool only_uninstalled) throws IOError; public abstract void start_set_pkgreason (string pkgname, uint reason) throws IOError; public abstract AlpmPackage get_installed_pkg (string pkgname) throws IOError; public abstract void start_refresh (bool force) throws IOError; @@ -351,6 +352,14 @@ namespace Pamac { } } + public void clean_cache (uint keep_nb, bool only_uninstalled) { + try { + daemon.clean_cache (keep_nb, only_uninstalled); + } catch (IOError e) { + stderr.printf ("IOError: %s\n", e.message); + } + } + public void start_set_pkgreason (string pkgname, uint reason) { try { daemon.start_set_pkgreason (pkgname, reason);