Exemplo n.º 1
0
    def rollback(self, exc):
        """
        Handle the different types of execptions that may be raised during
        installation.

        Will always leave the system in a good state upon return.

        Args:
            exc: The exception that was raised.
        """
        USER.info('%s: Rolling Back Failed Build', self.recipe.name)
        cascade = False
        if isinstance(exc, AssertionError):
            logging.error('Error during verify() of %s', self.recipe.name)
            cascade = True
        if cascade or isinstance(exc, PakitLinkError):
            if not cascade:
                logging.error('Error during linking of %s', self.recipe.name)
            walk_and_unlink(self.recipe.install_dir, self.recipe.link_dir)
            cascade = True
        if cascade or (not isinstance(exc, PakitLinkError) and
                       not isinstance(exc, AssertionError)):
            if not cascade:
                logging.error('Error during build() of %s', self.recipe.name)
            try:
                Command('rm -rf ' + self.recipe.install_dir).wait()
            except PakitCmdError:  # pragma: no cover
                pass
Exemplo n.º 2
0
 def test_walk_and_unlink(self):
     walk_and_link(self.src, self.dst)
     walk_and_unlink(self.src, self.dst)
     for fname in self.dst_fnames:
         assert not os.path.exists(fname)
     assert not os.path.exists(self.subdir.replace(self.src, self.dst))
     for fname in self.fnames:
         assert os.path.exists(fname)
     assert os.path.exists(self.dst)
Exemplo n.º 3
0
    def test_walk_and_unlink_mkdirs(self):
        link_file = os.path.join(self.dst, "NotSymLink")
        with open(link_file, "w") as fout:
            fout.write("Hello")

        assert os.path.exists(link_file)
        walk_and_link(self.src, self.dst)
        walk_and_unlink(self.src, self.dst)
        assert os.path.exists(self.dst)
        assert os.path.exists(link_file)
Exemplo n.º 4
0
    def test_walk_and_unlink_mkdirs(self):
        link_file = os.path.join(self.dst, 'NotSymLink')
        with open(link_file, 'w') as fout:
            fout.write('Hello')

        assert os.path.exists(link_file)
        walk_and_link(self.src, self.dst)
        walk_and_unlink(self.src, self.dst)
        assert os.path.exists(self.dst)
        assert os.path.exists(link_file)
Exemplo n.º 5
0
 def save_old_install(self):
     """
     Before attempting an update of the program:
         - Unlink it.
         - Move the installation to a backup location.
         - Remove the pakit.conf.IDB entry.
     """
     USER.info('%s: Saving Old Install', self.recipe.name)
     walk_and_unlink(self.recipe.install_dir, self.recipe.link_dir)
     self.old_entry = pakit.conf.IDB.get(self.recipe.name)
     del pakit.conf.IDB[self.recipe.name]
     shutil.move(self.recipe.install_dir, self.back_dir)
Exemplo n.º 6
0
    def run(self):
        """
        Execute a set of operations to perform the Task.
        """
        if pakit.conf.IDB.get(self.recipe.name) is None:
            print(self.recipe.name + ': Not Installed')
            return

        walk_and_unlink(self.recipe.install_dir, self.recipe.link_dir)
        try:
            shutil.rmtree(self.recipe.install_dir)
        except OSError:  # pragma: no cover
            pass
        pakit.conf.IDB.remove(self.recipe.name)