class Action(object):
def __init__(self, pakfire, pkg):
self.pakfire = pakfire
- self.pkg = pkg
+ self.pkg_solv = self.pkg = pkg
# Try to get the binary version of the package from the cache if
# any.
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)
self._extract(_("Updating"))
-class ActionRemove(ActionCleanup):
+class ActionRemove(Action):
type = "erase"
- def run(self):
- files = self.pkg.filelist
+ def __init__(self, *args, **kwargs):
+ Action.__init__(self, *args, **kwargs)
- if not files:
- return
+ # XXX This is ugly, but works for the moment.
+ self.pkg = self.local.index.db.get_package_from_solv(self.pkg_solv)
+ assert self.pkg
+
+ def run(self):
+ self.pkg.remove(_("Removing"), prefix=self.pakfire.path)
- self.remove_files(_("Removing: %s") % self.pkg.name, files)
+ # XXX Remove package from database
class ActionReinstall(Action):
sub_shell.add_argument("-a", "--arch",
help=_("Emulated architecture in the shell."))
+ sub_shell.add_argument("-m", "--mode", nargs="?", default="development",
+ help=_("Mode to run in. Is either 'release' or 'development' (default)."))
def parse_command_dist(self):
# Implement the "dist" command.
"arch" : self.args.arch,
}
- pakfire.shell(pkg, distro_config=distro_config, **self.pakfire_args)
+ pakfire.shell(pkg, builder_mode=self.args.mode,
+ distro_config=distro_config, **self.pakfire_args)
def handle_dist(self):
# Get the packages from the command line options
import datetime
import logging
+import os
import xml.sax.saxutils
import util
from pakfire.i18n import _
+from pakfire.util import make_progress
+
class Package(object):
def __init__(self, pakfire, repo=None):
self.pakfire = pakfire
def extract(self, path, prefix=None):
raise NotImplementedError, "%s" % repr(self)
+
+ def remove(self, message=None, prefix=None):
+ if prefix in ("/", None):
+ prefix = ""
+
+ # Make two filelists. One contains all binary files that need to be
+ # removed, the other one contains the configuration files which are
+ # kept. files and configfiles are disjunct.
+ files = []
+ configfiles = self.configfiles
+
+ for file in self.filelist:
+ if file in configfiles:
+ continue
+
+ assert file.startswith("/")
+ files.append(file)
+
+ # Load progressbar.
+ pb = None
+ if message:
+ message = "%-10s : %s" % (message, self.friendly_name)
+ pb = make_progress(message, len(files), eta=False)
+
+ # Sort files by the length of their name to remove all files in
+ # a directory first and then check, if there are any files left.
+ files.sort(cmp=lambda x,y: cmp(len(x), len(y)), reverse=True)
+
+ i = 0
+ for _file in files:
+ # Update progress.
+ if pb:
+ i += 1
+ pb.update(i)
+
+ logging.debug("Removing file: %s" % _file)
+
+ if prefix:
+ file = os.path.join(prefix, file[1:])
+ assert file.startswith("%s/" % prefix)
+ else:
+ file = _file
+
+ # If the file was removed by the user, we can skip it.
+ if not os.path.exists(file):
+ continue
+
+ # Handle regular files and symlinks.
+ if os.path.isfile(file) or os.path.islink(file):
+ try:
+ os.remove(file)
+ except OSError:
+ logging.error("Cannot remove file: %s. Remove manually." % _file)
+
+ # Handle directories.
+ # Skip removal if the directory is a mountpoint.
+ elif os.path.isdir(file) and not os.path.ismount(file):
+ # Try to remove the directory. If it is not empty, OSError is raised,
+ # but we are okay with that.
+ try:
+ os.rmdir(file)
+ except OSError:
+ pass
+
+ # Log all unhandled types.
+ else:
+ logging.warning("Cannot remove file: %s. Filetype is unhandled." % _file)
+
+ if pb:
+ pb.finish()
+
+ # XXX Rename config files
return self.__filelist
+ @property
+ def configfiles(self):
+ return [] # XXX to be done
+
@property
def payload_compression(self):
"""
finally:
c.close()
+ @property
+ def configfiles(self):
+ return [] # XXX to be done
+
def _does_provide_file(self, requires):
"""
A faster version to find a file in the database.
yield packages.DatabasePackage(self.pakfire, self.repo, self, row)
c.close()
+
+ def get_package_from_solv(self, solv_pkg):
+ c = self.cursor()
+ c.execute("SELECT * FROM packages WHERE uuid = ? LIMIT 1", (solv_pkg.uuid,))
+
+ try:
+ for row in c:
+ return packages.DatabasePackage(self.pakfire, self.repo, self, row)
+
+ finally:
+ c.close()
action.run()
except ActionError, e:
logging.error("Action finished with an error: %s - %s" % (action, e))
+
+ logging.info("")