예제 #1
0
파일: media2.py 프로젝트: bhdn/mediasys
 def _exec_remove(self):
     for (mediainfo, pkgset, comment, touches) in self._remove_operations[:]:
         for pkg in pkgset.packages():
             srcpath = self.distro.package_path(mediainfo, pkg)
             srcdir = os.path.dirname(srcpath)
             filename = os.path.basename(srcpath)
             dstpath = os.path.join(self.storedir, filename)
             # TODO allow ignoring this kind of error
             if not os.path.exists(srcpath):
                 raise TransactionError("cannot find file: %s" %
                         (srcpath))
             if util.same_partition(self.storedir, srcdir):
                 logger.debug("renaming %s to %s", srcpath, dstpath)
                 try:
                     os.rename(srcpath, dstpath)
                 except EnvironmentError, e:
                     raise TransactionError("failed to move file from "
                             "%s to %s: %s" % (srcpath, dstpath, e))
             else:
                 cpcmd = self.config.get_copy_command()
                 cpcmd.append(srcpath)
                 cpcmd.append(dstpath)
                 logger.debug("running %s", cpcmd)
                 try:
                     cmd.run(cpcmd)
                 except cmd.CommandError, e:
                     raise TransactionError("failed to copy file from "
                         "%s to %s: %s" % (srcpath, dstpath, e))
                 logger.debug("unlinking %s", srcpath)
                 try:
                     os.unlink(srcpath)
                 except EnvironmentError, e:
                     raise TransactionError("failed to unlink %s: %s" %
                             (srcpath, e))
예제 #2
0
파일: media2.py 프로젝트: bhdn/mediasys
 def _exec_install(self):
     params = []
     for (media, pkgset, comment, touches) in self._install_operations[:]:
         for pkg in pkgset.packages():
             srcdir = os.path.dirname(pkg.path)
             if not os.path.exists(pkg.path):
                 raise TransactionError("cannot find %s" % (pkg.path))
             if not os.access(srcdir, os.W_OK):
                 raise TransactionError("no write permission for %s" %
                         (pkg.path))
             dstpath = self.distro.package_path(media, pkg)
             dstdir = os.path.dirname(os.path.abspath(dstpath))
             if not os.access(dstdir, os.W_OK):
                 raise TransactionError("no write permission for the "
                         "destination directory: %s" % (dstdir))
     paths = set()
     for (media, pkgset, comment, touches) in self._install_operations[:]:
         for pkg in pkgset.packages():
             if pkg.path in paths:
                 # prevent collision between operations that may involve
                 # the same file (the default install action vs. the
                 # debug package filter)
                 continue
             else:
                 paths.add(pkg.path)
             dstpath = self.distro.package_path(media, pkg)
             dstdir = os.path.dirname(os.path.abspath(dstpath))
             srcdir = os.path.dirname(os.path.abspath(pkg.path))
             if not os.path.exists(pkg.path):
                 raise TransactionError("cannot find file: %s" %
                         (pkg.path))
             if util.same_partition(srcdir, dstdir):
                 logger.debug("renaming %s to %s", pkg.path, dstpath)
                 try:
                     os.rename(pkg.path, dstpath)
                 except EnvironmentError, e:
                     raise TransactionError("failed to move file from "
                             "%s to %s: %s" % (pkg.path, dstpath, e))
             else:
                 cpcmd = self.config.get_copy_command()
                 cpcmd.append(pkg.path)
                 cpcmd.append(dstpath)
                 logger.debug("running command %s", cpcmd)
                 try:
                     cmd.run(cpcmd)
                 except cmd.CommandError, e:
                     raise TransactionError("failed to copy file from "
                         "%s to %s: %s" % (pkg.path, dstpath, e))
             try:
                 args = self.config.get_chmod_command()
                 args.append(self.config.package_copy_mode)
                 args.append(dstpath)
                 cmd.run(args)
             except cmd.CommandError, e:
                 raise TransactionError("failed to set permissions "
                         "for %s: %s" % (dstpath, e))