From: Michael Tremer Date: Sun, 1 May 2011 13:50:28 +0000 (+0000) Subject: Ask user to ack the transaction. X-Git-Tag: 0.9.3~38 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c0fd807caa0a1ecafa04f1c33d1403d086811c21;p=pakfire.git Ask user to ack the transaction. --- diff --git a/pakfire/base.py b/pakfire/base.py index b29d11c58..793ecf341 100644 --- a/pakfire/base.py +++ b/pakfire/base.py @@ -96,6 +96,11 @@ class Pakfire(object): if not t: return + # Ask if the user acknowledges the transaction. + if not t.cli_yesno(): + return + + # Run the transaction. t.run() def localinstall(self, files): @@ -134,7 +139,11 @@ class Pakfire(object): if not t: return - # Otherwise we run the transcation. + # Ask the user if this is okay. + if not t.cli_yesno(): + return + + # If okay, run the transcation. t.run() def update(self, pkgs): @@ -151,8 +160,11 @@ class Pakfire(object): if not t: return - t.dump() + # Ask the user if the transaction is okay. + if not t.cli_yesno(): + return + # Run the transaction. t.run() def remove(self, pkgs): @@ -167,8 +179,11 @@ class Pakfire(object): if not t: return - # Process the transaction if any. - t.dump() + # Ask the user if okay. + if not t.cli_yesno(): + return + + # Process the transaction. t.run() def info(self, patterns): diff --git a/pakfire/cli.py b/pakfire/cli.py index f195e6505..ad3224ffd 100644 --- a/pakfire/cli.py +++ b/pakfire/cli.py @@ -12,23 +12,6 @@ import pakfire.api as pakfire from constants import * from i18n import _ -def ask_user(question): - """ - Ask the user the question, he or she can answer with yes or no. - - This function returns True for "yes" and False for "no". - - If the software is running in a non-inteactive shell, no question - is asked at all and the answer is always "yes". - """ - if not util.cli_is_interactive(): - return True - - print _("%s [y/N]") % question, - ret = raw_input() - - return ret in ("y", "Y", "z", "Z", "j", "J") - class Cli(object): def __init__(self): self.parser = argparse.ArgumentParser( diff --git a/pakfire/repository/transaction.py b/pakfire/repository/transaction.py index c62e263d6..01600f17e 100644 --- a/pakfire/repository/transaction.py +++ b/pakfire/repository/transaction.py @@ -254,6 +254,11 @@ class Transaction(object): for line in s: logger.info(line) + def cli_yesno(self, logger=None): + self.dump(logger) + + return util.ask_user(_("Is this okay?")) + def run_action(self, action): try: action.run() diff --git a/pakfire/util.py b/pakfire/util.py index 575d5bbfa..d452f20d5 100644 --- a/pakfire/util.py +++ b/pakfire/util.py @@ -10,6 +10,7 @@ import time from errors import Error from packages.util import calc_hash1, format_size +from i18n import _ def cli_is_interactive(): """ @@ -20,6 +21,24 @@ def cli_is_interactive(): return False +def ask_user(question): + """ + Ask the user the question, he or she can answer with yes or no. + + This function returns True for "yes" and False for "no". + + If the software is running in a non-inteactive shell, no question + is asked at all and the answer is always "yes". + """ + if not cli_is_interactive(): + return True + + print _("%s [y/N]") % question, + ret = raw_input() + print # Just an empty line. + + return ret in ("y", "Y", "z", "Z", "j", "J") + def random_string(length=20): s = "" diff --git a/po/pakfire.pot b/po/pakfire.pot index 49b82e925..a72a72577 100644 --- a/po/pakfire.pot +++ b/po/pakfire.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2011-05-01 13:16+0000\n" +"POT-Creation-Date: 2011-05-01 13:43+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -17,6 +17,11 @@ msgstr "" "Content-Type: text/plain; charset=CHARSET\n" "Content-Transfer-Encoding: 8bit\n" +#: ../pakfire/util.py:36 +#, python-format +msgid "%s [y/N]" +msgstr "" + #: ../pakfire/packages/base.py:67 msgid "Name" msgstr "" @@ -121,7 +126,7 @@ msgstr "" msgid "Package" msgstr "" -#: ../pakfire/repository/transaction.py:226 ../pakfire/cli.py:240 +#: ../pakfire/repository/transaction.py:226 ../pakfire/cli.py:223 msgid "Repository" msgstr "" @@ -164,6 +169,10 @@ msgstr "" msgid "Total download size: %s" msgstr "" +#: ../pakfire/repository/transaction.py:260 +msgid "Is this okay?" +msgstr "" + #: ../pakfire/repository/index.py:335 #, python-format msgid "%s: package database" @@ -174,199 +183,194 @@ msgstr "" msgid "Extracting: %s (source)" msgstr "" -#: ../pakfire/cli.py:27 -#, python-format -msgid "%s [y/N]" -msgstr "" - -#: ../pakfire/cli.py:35 +#: ../pakfire/cli.py:18 msgid "Pakfire command line interface." msgstr "" -#: ../pakfire/cli.py:42 +#: ../pakfire/cli.py:25 msgid "The path where pakfire should operate in." msgstr "" -#: ../pakfire/cli.py:82 +#: ../pakfire/cli.py:65 msgid "Enable verbose output." msgstr "" -#: ../pakfire/cli.py:85 +#: ../pakfire/cli.py:68 msgid "Path to a configuration file to load." msgstr "" -#: ../pakfire/cli.py:88 +#: ../pakfire/cli.py:71 msgid "Disable a repository temporarily." msgstr "" -#: ../pakfire/cli.py:93 +#: ../pakfire/cli.py:76 msgid "Install one or more packages to the system." msgstr "" -#: ../pakfire/cli.py:95 +#: ../pakfire/cli.py:78 msgid "Give name of at least one package to install." msgstr "" -#: ../pakfire/cli.py:101 +#: ../pakfire/cli.py:84 msgid "Install one or more packages from the filesystem." msgstr "" -#: ../pakfire/cli.py:103 +#: ../pakfire/cli.py:86 msgid "Give filename of at least one package." msgstr "" -#: ../pakfire/cli.py:109 +#: ../pakfire/cli.py:92 msgid "Remove one or more packages from the system." msgstr "" -#: ../pakfire/cli.py:111 +#: ../pakfire/cli.py:94 msgid "Give name of at least one package to remove." msgstr "" -#: ../pakfire/cli.py:117 +#: ../pakfire/cli.py:100 msgid "Update the whole system or one specific package." msgstr "" -#: ../pakfire/cli.py:119 +#: ../pakfire/cli.py:102 msgid "Give a name of a package to update or leave emtpy for all." msgstr "" -#: ../pakfire/cli.py:125 +#: ../pakfire/cli.py:108 msgid "Print some information about the given package(s)." msgstr "" -#: ../pakfire/cli.py:127 +#: ../pakfire/cli.py:110 msgid "Give at least the name of one package." msgstr "" -#: ../pakfire/cli.py:133 +#: ../pakfire/cli.py:116 msgid "Search for a given pattern." msgstr "" -#: ../pakfire/cli.py:135 +#: ../pakfire/cli.py:118 msgid "A pattern to search for." msgstr "" -#: ../pakfire/cli.py:141 +#: ../pakfire/cli.py:124 msgid "Get a list of packages that provide a given file or feature." msgstr "" -#: ../pakfire/cli.py:143 ../pakfire/cli.py:151 +#: ../pakfire/cli.py:126 ../pakfire/cli.py:134 msgid "File or feature to search for." msgstr "" -#: ../pakfire/cli.py:149 +#: ../pakfire/cli.py:132 msgid "Get a list of packages that require a given file or feature." msgstr "" -#: ../pakfire/cli.py:157 +#: ../pakfire/cli.py:140 msgid "Get list of packages that belong to the given group." msgstr "" -#: ../pakfire/cli.py:159 +#: ../pakfire/cli.py:142 msgid "Group name to search for." msgstr "" -#: ../pakfire/cli.py:165 +#: ../pakfire/cli.py:148 msgid "Install all packages that belong to the given group." msgstr "" -#: ../pakfire/cli.py:167 +#: ../pakfire/cli.py:150 msgid "Group name." msgstr "" -#: ../pakfire/cli.py:173 +#: ../pakfire/cli.py:156 msgid "List all currently enabled repositories." msgstr "" -#: ../pakfire/cli.py:240 +#: ../pakfire/cli.py:223 msgid "Enabled" msgstr "" -#: ../pakfire/cli.py:240 +#: ../pakfire/cli.py:223 msgid "Priority" msgstr "" -#: ../pakfire/cli.py:255 +#: ../pakfire/cli.py:238 msgid "Pakfire builder command line interface." msgstr "" -#: ../pakfire/cli.py:297 +#: ../pakfire/cli.py:280 msgid "Update the package indexes." msgstr "" -#: ../pakfire/cli.py:303 +#: ../pakfire/cli.py:286 msgid "Build one or more packages." msgstr "" -#: ../pakfire/cli.py:305 +#: ../pakfire/cli.py:288 msgid "Give name of at least one package to build." msgstr "" -#: ../pakfire/cli.py:309 +#: ../pakfire/cli.py:292 msgid "Build the package for the given architecture." msgstr "" -#: ../pakfire/cli.py:311 ../pakfire/cli.py:333 +#: ../pakfire/cli.py:294 ../pakfire/cli.py:316 msgid "Path were the output files should be copied to." msgstr "" -#: ../pakfire/cli.py:316 +#: ../pakfire/cli.py:299 msgid "Go into a shell." msgstr "" -#: ../pakfire/cli.py:318 +#: ../pakfire/cli.py:301 msgid "Give name of a package." msgstr "" -#: ../pakfire/cli.py:322 +#: ../pakfire/cli.py:305 msgid "Emulated architecture in the shell." msgstr "" -#: ../pakfire/cli.py:327 +#: ../pakfire/cli.py:310 msgid "Generate a source package." msgstr "" -#: ../pakfire/cli.py:329 +#: ../pakfire/cli.py:312 msgid "Give name(s) of a package(s)." msgstr "" -#: ../pakfire/cli.py:398 +#: ../pakfire/cli.py:381 msgid "Pakfire repo command line interface." msgstr "" -#: ../pakfire/cli.py:417 +#: ../pakfire/cli.py:400 msgid "Repository management commands." msgstr "" -#: ../pakfire/cli.py:425 +#: ../pakfire/cli.py:408 msgid "Create a new repository index." msgstr "" -#: ../pakfire/cli.py:426 +#: ../pakfire/cli.py:409 msgid "Path to the packages." msgstr "" -#: ../pakfire/cli.py:427 +#: ../pakfire/cli.py:410 msgid "Path to input packages." msgstr "" -#: ../pakfire/cli.py:439 +#: ../pakfire/cli.py:422 msgid "Pakfire master command line interface." msgstr "" -#: ../pakfire/cli.py:461 +#: ../pakfire/cli.py:444 msgid "Update the sources." msgstr "" -#: ../pakfire/cli.py:471 +#: ../pakfire/cli.py:454 msgid "Pakfire slave command line interface." msgstr "" -#: ../pakfire/cli.py:495 +#: ../pakfire/cli.py:478 msgid "Request a build job from the server." msgstr "" -#: ../pakfire/cli.py:501 +#: ../pakfire/cli.py:484 msgid "Send a keepalive to the server." msgstr ""