From: Michael Tremer Date: Wed, 9 Mar 2011 19:38:04 +0000 (+0100) Subject: Add code to cleanup left-over files after a package update. X-Git-Tag: 0.9.3~78^2~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=911e0d8ce2dbdcff495008f4df26f7f2d28a25eb;p=pakfire.git Add code to cleanup left-over files after a package update. --- diff --git a/pakfire/depsolve.py b/pakfire/depsolve.py index 3bb998a6e..7b9550bc8 100644 --- a/pakfire/depsolve.py +++ b/pakfire/depsolve.py @@ -123,6 +123,10 @@ class DependencySet(object): for p in self.__packages: if pkg.name == p.name: transaction_mode = "update" + + # Set pointer to package that is updated. + pkg.old_package = p + break # Add package to transaction set diff --git a/pakfire/packages/base.py b/pakfire/packages/base.py index bd537a73d..81dd58013 100644 --- a/pakfire/packages/base.py +++ b/pakfire/packages/base.py @@ -17,6 +17,9 @@ class Package(object): self.pakfire = pakfire self._repo = repo + # Pointer to a package that is updated by this one. + self.old_package = None + def __repr__(self): return "<%s %s>" % (self.__class__.__name__, self.friendly_name) diff --git a/pakfire/transaction.py b/pakfire/transaction.py index 45634e999..1dcf48e3f 100644 --- a/pakfire/transaction.py +++ b/pakfire/transaction.py @@ -1,6 +1,7 @@ #!/usr/bin/python import logging +import progressbar import depsolve import packages @@ -43,6 +44,24 @@ class Action(object): """ return self.pakfire.repos.local + @staticmethod + def make_progress(self, message, maxval): + # Return nothing if stdout is not a terminal. + if not sys.stdout.isatty(): + return + + widgets = [ + " ", + message, + " ", + progressbar.Bar(left="[", right="]"), + " ", + progressbar.ETA(), + " ", + ] + + return progressbar.ProgressBar(widgets=widgets, maxval=maxval) + class ActionExtract(Action): def run(self): @@ -61,6 +80,59 @@ class ActionExtract(Action): extractor.cleanup() +class ActionCleanup(Action): + def gen_files(self): + """ + Return a list of all files that are not in the package anymore + and so to be removed. + """ + files = [] + + # Compare the filelist of the old and the new package and save the + # difference. + + for f in self.pkg.old_package.filelist: + if f in self.pkg.filelist: + continue + + # Save absolute path. + f = os.path.join(self.pakfire.path, f) + files.append(f) + + return files + + def run(self): + files = self.gen_files() + + if not files: + return + + pb = self.make_progress(_("Cleanup: %s") % pkg.name, len(files)) + i = 0 + + for f in self.files: + # Update progress if any. + i += 1 + if pb: + pb.update(i) + + # Skip non-existant files (mabye the user removed it already?) + if not os.path.exists(f): + continue + + logging.debug("Going to remove file: %s" % f) + + try: + os.unlink(f) + except: + logging.critical("Could not remove file: %s. Do it manually." % f) + + # XXX remove file from database + + if pb: + pb.finish() + + class ActionScript(Action): def run(self): pass # XXX TBD @@ -114,6 +186,7 @@ class TransactionSet(object): pkgs = [] for dl_list in self.download_lists: pkgs += dl_list + pkgs.sort() for pkg in pkgs: @@ -140,7 +213,10 @@ class TransactionSet(object): self.removes.append(pkg) def update(self, pkg, dep=False): - logging.info(" --> Marking package for update: %s" % pkg.friendly_name) + assert pkg.old_package + + logging.info(" --> Marking package for update: %s (was %s)" % \ + (pkg.friendly_name, pkg.old_package.friendly_version)) if dep: self.update_deps.append(pkg) @@ -201,7 +277,10 @@ class Transaction(object): action_extract = ActionExtract(self.pakfire, pkg) - self.add_action(action_extract) + action_cleanup = ActionCleanup(self.pakfire, pkg, deps=[action_extract]) + + for action in (action_extract, action_cleanup): + self.add_action(action) def _remove_pkg(self, pkg): # XXX TBD diff --git a/po/pakfire.pot b/po/pakfire.pot index cc0f7439a..363a0250f 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-03-06 12:48+0000\n" +"POT-Creation-Date: 2011-03-09 20:31+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -158,11 +158,11 @@ msgstr "" msgid "Package" msgstr "" -#: ../pakfire/depsolve.py:220 ../pakfire/packages/base.py:57 +#: ../pakfire/depsolve.py:220 ../pakfire/packages/base.py:72 msgid "Arch" msgstr "" -#: ../pakfire/depsolve.py:220 ../pakfire/packages/base.py:58 +#: ../pakfire/depsolve.py:220 ../pakfire/packages/base.py:73 msgid "Version" msgstr "" @@ -170,7 +170,7 @@ msgstr "" msgid "Repository" msgstr "" -#: ../pakfire/depsolve.py:220 ../pakfire/packages/base.py:60 +#: ../pakfire/depsolve.py:220 ../pakfire/packages/base.py:75 msgid "Size" msgstr "" @@ -224,59 +224,67 @@ msgstr "" msgid "Total download size: %s" msgstr "" -#: ../pakfire/__init__.py:202 ../pakfire/__init__.py:234 +#: ../pakfire/__init__.py:202 ../pakfire/__init__.py:233 msgid "Is this okay?" msgstr "" -#: ../pakfire/packages/base.py:56 +#: ../pakfire/packages/base.py:71 msgid "Name" msgstr "" -#: ../pakfire/packages/base.py:59 +#: ../pakfire/packages/base.py:74 msgid "Release" msgstr "" -#: ../pakfire/packages/base.py:61 +#: ../pakfire/packages/base.py:76 msgid "Repo" msgstr "" -#: ../pakfire/packages/base.py:62 +#: ../pakfire/packages/base.py:77 msgid "Summary" msgstr "" -#: ../pakfire/packages/base.py:63 +#: ../pakfire/packages/base.py:78 msgid "URL" msgstr "" -#: ../pakfire/packages/base.py:64 +#: ../pakfire/packages/base.py:79 msgid "License" msgstr "" -#: ../pakfire/packages/base.py:67 +#: ../pakfire/packages/base.py:82 msgid "Description" msgstr "" -#: ../pakfire/packages/base.py:73 +#: ../pakfire/packages/base.py:88 msgid "UUID" msgstr "" -#: ../pakfire/packages/base.py:74 +#: ../pakfire/packages/base.py:89 msgid "Build ID" msgstr "" -#: ../pakfire/packages/base.py:75 +#: ../pakfire/packages/base.py:90 msgid "Build date" msgstr "" -#: ../pakfire/packages/base.py:76 +#: ../pakfire/packages/base.py:91 msgid "Build host" msgstr "" -#: ../pakfire/packages/packager.py:77 +#: ../pakfire/packages/base.py:93 +msgid "Provides" +msgstr "" + +#: ../pakfire/packages/base.py:98 +msgid "Requires" +msgstr "" + +#: ../pakfire/packages/packager.py:82 msgid "Extracting" msgstr "" -#: ../pakfire/packages/packager.py:132 +#: ../pakfire/packages/packager.py:137 msgid "Extracting:" msgstr "" @@ -284,3 +292,8 @@ msgstr "" #, python-format msgid "%s: package database" msgstr "" + +#: ../pakfire/transaction.py:110 +#, python-format +msgid "Cleanup: %s" +msgstr ""