]> git.ipfire.org Git - pakfire.git/commitdiff
Move Actions to a seperate file.
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 21 Jul 2011 14:27:50 +0000 (16:27 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 21 Jul 2011 14:27:50 +0000 (16:27 +0200)
pakfire/actions.py [new file with mode: 0644]
pakfire/errors.py
pakfire/packages/file.py
pakfire/repository/actions.py [deleted file]
pakfire/transaction.py
pakfire/util.py
po/POTFILES.in
po/pakfire.pot

diff --git a/pakfire/actions.py b/pakfire/actions.py
new file mode 100644 (file)
index 0000000..ac1cbc3
--- /dev/null
@@ -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
index e49de316460dc82106c70eef87ff0ee955a10db1..1a8409fc203f26603b7fa15851840550d9de5b83 100644 (file)
@@ -2,6 +2,9 @@
 
 class Error(Exception):
        pass
+       
+class ActionError(Error):
+       pass
 
 class BuildAbortedException(Error):
        pass
index f692c3a2ca53b2fbd6ebb6c4ce91589f06f18799..8c89a4890539730d53b78dfa1e7d1df373a9d54f 100644 (file)
@@ -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 (file)
index e69de29..0000000
index 79f767e9915a33d30ba395b63a85c19bab39887b..944e6e1313ae1fc639790dabdc83b303b3a14d7d 100644 (file)
@@ -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 = [
index 2c263a8ff07ae10c2d4c0b421508a0c3272f24ab..8dcdacd14274f72f72b35becc5335dbd891c828d 100644 (file)
@@ -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
 
index 24106b414d5b96424108f5f234481ac60c2e6499..828fd69641781f2458535557af00768cd9631366 100644 (file)
@@ -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
index 6c597ecb13f9e094b25a32c9a9114c282c3c293c..bea417d2e3230665a4bdf86aa58c5196be716575 100644 (file)
@@ -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 <EMAIL@ADDRESS>\n"
 "Language-Team: LANGUAGE <LL@li.org>\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 ""