From: Michael Tremer Date: Thu, 21 Jul 2011 14:27:50 +0000 (+0200) Subject: Move Actions to a seperate file. X-Git-Tag: 0.9.4~13 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=1e80d5d7e8afc36cfee75ff9db9980d7a584f2e5;p=pakfire.git Move Actions to a seperate file. --- diff --git a/pakfire/actions.py b/pakfire/actions.py new file mode 100644 index 000000000..ac1cbc3ed --- /dev/null +++ b/pakfire/actions.py @@ -0,0 +1,131 @@ +#!/usr/bin/python + +import logging + +import packages + +from constants import * +from i18n import _ + +class Action(object): + def __init__(self, pakfire, pkg): + self.pakfire = pakfire + self.pkg = pkg + + # Try to get the binary version of the package from the cache if + # any. + binary_package = self.pkg.get_from_cache() + if binary_package: + self.pkg = binary_package + + def __cmp__(self, other): + # XXX ugly + return cmp(self.__repr__(), other.__repr__()) + + def __repr__(self): + return "<%s %s>" % (self.__class__.__name__, self.pkg.friendly_name) + + @property + def needs_download(self): + return self.type in ("install", "reinstall", "upgrade", "downgrade",) \ + and not isinstance(self.pkg, packages.BinaryPackage) + + def download(self, text): + if not self.needs_download: + return + + self.pkg = self.pkg.download(text) + + def run(self): + raise NotImplementedError + + @property + def local(self): + """ + Reference to local repository. + """ + return self.pakfire.repos.local + + def _extract(self, message, prefix=None): + # Add package to the database. + self.local.add_package(self.pkg) + + if prefix is None: + prefix = self.pakfire.path + + self.pkg.extract(message, prefix=prefix) + + +class ActionCleanup(Action): + type = "ignore" + + def run(self): + print "XXX Cleanup: %s" % self.pkg + + +class ActionScript(Action): + def run(self): + pass + + +class ActionScriptPreIn(ActionScript): + pass + + +class ActionScriptPostIn(ActionScript): + pass + + +class ActionScriptPreUn(ActionScript): + pass + + +class ActionScriptPostUn(ActionScript): + pass + + +class ActionInstall(Action): + type = "install" + + def run(self): + self._extract(_("Installing")) + + +class ActionUpdate(Action): + type = "upgrade" + + def run(self): + self._extract(_("Updating")) + + +class ActionRemove(ActionCleanup): + type = "erase" + + def run(self): + files = self.pkg.filelist + + if not files: + return + + self.remove_files(_("Removing: %s") % self.pkg.name, files) + + +class ActionReinstall(Action): + type = "reinstall" + + def run(self): + self._extract(_("Installing")) + + +class ActionDowngrade(Action): + type = "downgrade" + + def run(self): + self._extract(_("Downgrading")) + + +class ActionChange(Action): + type = "change" + + def run(self): + print "XXX Change: %s" % self.pkg diff --git a/pakfire/errors.py b/pakfire/errors.py index e49de3164..1a8409fc2 100644 --- a/pakfire/errors.py +++ b/pakfire/errors.py @@ -2,6 +2,9 @@ class Error(Exception): pass + +class ActionError(Error): + pass class BuildAbortedException(Error): pass diff --git a/pakfire/packages/file.py b/pakfire/packages/file.py index f692c3a2c..8c89a4890 100644 --- a/pakfire/packages/file.py +++ b/pakfire/packages/file.py @@ -169,7 +169,8 @@ class FilePackage(Package): # Load progressbar. pb = None if message: - pb = util.make_progress("%-40s" % message, len(members)) + message = "%-10s : %s" % (message, self.friendly_name) + pb = util.make_progress(message, len(members), eta=False) i = 0 for member in members: diff --git a/pakfire/repository/actions.py b/pakfire/repository/actions.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/pakfire/transaction.py b/pakfire/transaction.py index 79f767e99..944e6e131 100644 --- a/pakfire/transaction.py +++ b/pakfire/transaction.py @@ -10,140 +10,13 @@ import packages import satsolver import util +from constants import * from i18n import _ PKG_DUMP_FORMAT = " %-21s %-8s %-21s %-19s %5s " -class ActionError(Exception): - pass - - -class Action(object): - def __init__(self, pakfire, pkg): - self.pakfire = pakfire - self.pkg = pkg - - # Try to get the binary version of the package from the cache if - # any. - binary_package = self.pkg.get_from_cache() - if binary_package: - self.pkg = binary_package - - def __cmp__(self, other): - # XXX ugly - return cmp(self.__repr__(), other.__repr__()) - - def __repr__(self): - return "<%s %s>" % (self.__class__.__name__, self.pkg.friendly_name) - - @property - def needs_download(self): - return self.type in ("install", "reinstall", "upgrade", "downgrade",) \ - and not isinstance(self.pkg, packages.BinaryPackage) - - def download(self, text): - if not self.needs_download: - return - - self.pkg = self.pkg.download(text) - - def run(self): - raise NotImplementedError - - @property - def local(self): - """ - Reference to local repository (database). - """ - return self.pakfire.repos.local - - -class ActionCleanup(Action): - type = "ignore" - - def run(self): - print "XXX Cleanup: %s" % self.pkg - - -class ActionScript(Action): - def run(self): - pass # XXX TBD - - -class ActionScriptPreIn(ActionScript): - pass - - -class ActionScriptPostIn(ActionScript): - pass - - -class ActionScriptPreUn(ActionScript): - pass - - -class ActionScriptPostUn(ActionScript): - pass - - -class ActionInstall(Action): - type = "install" - - def extract(self, message, prefix=None): - logging.debug("Extracting package %s" % self.pkg.friendly_name) - - # Create package in the database - self.local.add_package(self.pkg) - - if prefix is None: - prefix = self.pakfire.path - - self.pkg.extract(message, prefix=prefix) - - def run(self): - msg = _("Extracting: %s") - - if self.type == "install": - msg = _("Installing: %s") - elif self.type == "reinstall": - msg = _("Reinstalling: %s") - elif self.type == "upgrade": - msg = _("Updating: %s") - elif self.type == "downgrade": - msg = _("Downgrading: %s") - - self.extract(msg % self.pkg.name) - - -class ActionUpdate(ActionInstall): - type = "upgrade" - -class ActionRemove(ActionCleanup): - type = "erase" - - def run(self): - files = self.pkg.filelist - - if not files: - return - - self.remove_files(_("Removing: %s") % self.pkg.name, files) - - -class ActionReinstall(ActionInstall): - type = "reinstall" - - -class ActionDowngrade(ActionInstall): - type = "downgrade" - - -class ActionChange(Action): - type = "change" - - def run(self): - print "XXX Change: %s" % self.pkg - +# Import all actions directly. +from actions import * class Transaction(object): action_classes = [ diff --git a/pakfire/util.py b/pakfire/util.py index 2c263a8ff..8dcdacd14 100644 --- a/pakfire/util.py +++ b/pakfire/util.py @@ -50,7 +50,20 @@ def random_string(length=20): return s -def make_progress(message, maxval): + +class Bar(progressbar.Bar): + def update(self, pbar, width): + percent = pbar.percentage() + if pbar.finished: + return " " * width + + cwidth = width - len(self.left) - len(self.right) + marked_width = int(percent * cwidth / 100) + m = self._format_marker(pbar) + bar = (self.left + (m*marked_width).ljust(cwidth) + self.right) + return bar + +def make_progress(message, maxval, eta=True): # Return nothing if stdout is not a terminal. if not sys.stdout.isatty(): return @@ -59,12 +72,13 @@ def make_progress(message, maxval): " ", "%-40s" % message, " ", - progressbar.Bar(left="[", right="]"), - " ", - progressbar.ETA(), + Bar(left="[", right="]"), " ", ] + if eta: + widgets += [progressbar.ETA(), " ",] + if not maxval: maxval = 1 diff --git a/po/POTFILES.in b/po/POTFILES.in index 24106b414..828fd6964 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -1,3 +1,4 @@ +pakfire/actions.py pakfire/api.py pakfire/base.py pakfire/builder.py @@ -24,7 +25,6 @@ pakfire/packages/solv.py pakfire/packages/source.py pakfire/packages/util.py pakfire/packages/virtual.py -pakfire/repository/actions.py pakfire/repository/base.py pakfire/repository/cache.py pakfire/repository/database.py diff --git a/po/pakfire.pot b/po/pakfire.pot index 6c597ecb1..bea417d2e 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-07-21 15:40+0200\n" +"POT-Creation-Date: 2011-07-21 16:26+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -17,6 +17,23 @@ msgstr "" "Content-Type: text/plain; charset=CHARSET\n" "Content-Transfer-Encoding: 8bit\n" +#: ../pakfire/actions.py:91 ../pakfire/actions.py:117 +msgid "Installing" +msgstr "" + +#: ../pakfire/actions.py:98 +msgid "Updating" +msgstr "" + +#: ../pakfire/actions.py:110 +#, python-format +msgid "Removing: %s" +msgstr "" + +#: ../pakfire/actions.py:124 +msgid "Downgrading" +msgstr "" + #: ../pakfire/builder.py:246 #, python-format msgid "Extracting: %s (source)" @@ -130,7 +147,7 @@ msgstr "" msgid "Cleanup all temporary files." msgstr "" -#: ../pakfire/cli.py:234 ../pakfire/transaction.py:281 +#: ../pakfire/cli.py:234 ../pakfire/transaction.py:155 msgid "Repository" msgstr "" @@ -238,11 +255,11 @@ msgstr "" msgid "Name" msgstr "" -#: ../pakfire/packages/base.py:70 ../pakfire/transaction.py:280 +#: ../pakfire/packages/base.py:70 ../pakfire/transaction.py:154 msgid "Arch" msgstr "" -#: ../pakfire/packages/base.py:71 ../pakfire/transaction.py:280 +#: ../pakfire/packages/base.py:71 ../pakfire/transaction.py:154 msgid "Version" msgstr "" @@ -250,7 +267,7 @@ msgstr "" msgid "Release" msgstr "" -#: ../pakfire/packages/base.py:73 ../pakfire/transaction.py:281 +#: ../pakfire/packages/base.py:73 ../pakfire/transaction.py:155 msgid "Size" msgstr "" @@ -318,83 +335,53 @@ msgstr "" msgid "Loading installed packages" msgstr "" -#: ../pakfire/transaction.py:104 -#, python-format -msgid "Extracting: %s" -msgstr "" - -#: ../pakfire/transaction.py:107 -#, python-format -msgid "Installing: %s" -msgstr "" - -#: ../pakfire/transaction.py:109 -#, python-format -msgid "Reinstalling: %s" -msgstr "" - -#: ../pakfire/transaction.py:111 -#, python-format -msgid "Updating: %s" -msgstr "" - -#: ../pakfire/transaction.py:113 -#, python-format -msgid "Downgrading: %s" -msgstr "" - -#: ../pakfire/transaction.py:130 -#, python-format -msgid "Removing: %s" -msgstr "" - -#: ../pakfire/transaction.py:216 +#: ../pakfire/transaction.py:89 msgid "Downloading packages:" msgstr "" -#: ../pakfire/transaction.py:243 +#: ../pakfire/transaction.py:116 #, python-format msgid "%s | %-5sB %s " msgstr "" -#: ../pakfire/transaction.py:280 +#: ../pakfire/transaction.py:154 msgid "Package" msgstr "" -#: ../pakfire/transaction.py:285 +#: ../pakfire/transaction.py:159 msgid "Installing:" msgstr "" -#: ../pakfire/transaction.py:286 +#: ../pakfire/transaction.py:160 msgid "Reinstalling:" msgstr "" -#: ../pakfire/transaction.py:287 +#: ../pakfire/transaction.py:161 msgid "Updating:" msgstr "" -#: ../pakfire/transaction.py:288 +#: ../pakfire/transaction.py:162 msgid "Downgrading:" msgstr "" -#: ../pakfire/transaction.py:289 +#: ../pakfire/transaction.py:163 msgid "Removing:" msgstr "" -#: ../pakfire/transaction.py:295 +#: ../pakfire/transaction.py:169 msgid "Transaction Summary" msgstr "" -#: ../pakfire/transaction.py:302 +#: ../pakfire/transaction.py:176 msgid "package" msgstr "" -#: ../pakfire/transaction.py:308 +#: ../pakfire/transaction.py:182 #, python-format msgid "Total download size: %s" msgstr "" -#: ../pakfire/transaction.py:317 +#: ../pakfire/transaction.py:191 msgid "Is this okay?" msgstr ""