def setUp(self): super(SymlinkInfoTest, self).setUp() self.mock_host_controller = self.mox.CreateMock(RemoteHostController) self.symlink_path = "/path/to/symlink" self.symlink = SymlinkInfo(self.symlink_path, self.mock_host_controller)
def ensure_symlink_exists(self, symlink_path, real_path, with_sudo=False): path = PathInfo(symlink_path, self.host_controller) if path.exists() and not path.is_symlink(): self.feedback.abort( "Found existing path but path is not a symlink: %s" % symlink_path) elif not PathInfo(real_path, self.host_controller).exists(): self.feedback.abort( "Cannot create symlink to nonexistent path: %s" % real_path) else: symlink = SymlinkInfo(symlink_path, self.host_controller) if symlink.exists() and symlink.is_linked_to(real_path): self.feedback.comment("Found expected symlink: %s" % symlink) elif symlink.exists(): self.remove_symlink(symlink_path) self.create_symlink(symlink_path, real_path, with_sudo) else: self.create_symlink(symlink_path, real_path, with_sudo)
def create_symlink(self, symlink_path, real_path, with_sudo=False): self._run_command("ln -s %s %s" % (real_path, symlink_path), with_sudo) self.feedback.comment("Created symlink: %s" % SymlinkInfo(symlink_path, self.host_controller))