Beispiel #1
0
def _install_manpage(src_path, man_dir):
    """Install the given manual page for COT.

    Args:
      src_path (str): Path to manual page file.
      man_dir (str): Base directory where page should be installed.
    Returns:
      tuple: (page_previously_installed, page_updated)
    Raises:
      IOError: if installation fails under some circumstances
      OSError: if installation fails under other circumstances
    """
    # Which man section does this belong in?
    filename = os.path.basename(src_path)
    section = os.path.splitext(filename)[1][1:]
    dest = os.path.join(man_dir, "man{0}".format(section))
    Helper.mkdir(dest)

    previously_installed = False
    dest_path = os.path.join(dest, filename)
    if os.path.exists(dest_path):
        previously_installed = True
        if filecmp.cmp(src_path, dest_path):
            logger.verbose("File %s does not need to be updated", dest_path)
            return previously_installed, False

    Helper.copy_file(src_path, dest_path)
    return previously_installed, True
Beispiel #2
0
def _install_manpage(src_path, man_dir):
    """Install the given manual page for COT.

    Args:
      src_path (str): Path to manual page file.
      man_dir (str): Base directory where page should be installed.
    Returns:
      tuple: (page_previously_installed, page_updated)
    Raises:
      IOError: if installation fails under some circumstances
      OSError: if installation fails under other circumstances
    """
    # Which man section does this belong in?
    filename = os.path.basename(src_path)
    section = os.path.splitext(filename)[1][1:]
    dest = os.path.join(man_dir, "man{0}".format(section))
    Helper.mkdir(dest)

    previously_installed = False
    dest_path = os.path.join(dest, filename)
    if os.path.exists(dest_path):
        previously_installed = True
        if filecmp.cmp(src_path, dest_path):
            logger.verbose("File %s does not need to be updated", dest_path)
            return previously_installed, False

    Helper.copy_file(src_path, dest_path)
    return previously_installed, True
    def test_nondefault_permissions(self, mock_isdir, mock_exists,
                                    mock_makedirs, mock_check_call):
        """Non-default permissions should be applied whether sudo or not."""
        # Non-sudo case
        self.assertTrue(Helper.mkdir('/foo/bar', 511))  # 511 == 0o777
        mock_isdir.assert_called_with('/foo/bar')
        mock_exists.assert_called_with('/foo/bar')
        mock_makedirs.assert_called_with('/foo/bar', 511)
        mock_check_call.assert_not_called()

        # Sudo case
        mock_makedirs.reset_mock()
        mock_makedirs.side_effect = OSError
        self.assertTrue(Helper.mkdir('/foo/bar', 511))  # 511 == 0o777
        mock_makedirs.assert_called_with('/foo/bar', 511)
        mock_check_call.assert_called_with(
            ['sudo', 'mkdir', '-p', '--mode=777', '/foo/bar'])
 def test_permission_ok(self, mock_isdir, mock_exists,
                        mock_makedirs, mock_check_call):
     """Successfully create directory with user permissions."""
     self.assertTrue(Helper.mkdir('/foo/bar'))
     mock_isdir.assert_called_with('/foo/bar')
     mock_exists.assert_called_with('/foo/bar')
     mock_makedirs.assert_called_with('/foo/bar', 493)  # 493 == 0o755
     mock_check_call.assert_not_called()
Beispiel #5
0
    def test_nondefault_permissions(self, mock_isdir, mock_exists,
                                    mock_makedirs, mock_check_call):
        """Non-default permissions should be applied whether sudo or not."""
        # Non-sudo case
        self.assertTrue(Helper.mkdir('/foo/bar', 511))  # 511 == 0o777
        mock_isdir.assert_called_with('/foo/bar')
        mock_exists.assert_called_with('/foo/bar')
        mock_makedirs.assert_called_with('/foo/bar', 511)
        mock_check_call.assert_not_called()

        # Sudo case
        mock_makedirs.reset_mock()
        mock_makedirs.side_effect = OSError
        self.assertTrue(Helper.mkdir('/foo/bar', 511))  # 511 == 0o777
        mock_makedirs.assert_called_with('/foo/bar', 511)
        mock_check_call.assert_called_with(
            ['sudo', 'mkdir', '-p', '-m', '777', '/foo/bar'])
Beispiel #6
0
 def test_permission_ok(self, mock_isdir, mock_exists,
                        mock_makedirs, mock_check_call):
     """Successfully create directory with user permissions."""
     self.assertTrue(Helper.mkdir('/foo/bar'))
     mock_isdir.assert_called_with('/foo/bar')
     mock_exists.assert_called_with('/foo/bar')
     mock_makedirs.assert_called_with('/foo/bar', 493)  # 493 == 0o755
     mock_check_call.assert_not_called()
 def test_already_exists(self, mock_isdir, mock_exists,
                         mock_makedirs, mock_check_call):
     """Test case where the target directory already exists."""
     mock_isdir.return_value = True
     self.assertTrue(Helper.mkdir('/foo/bar'))
     mock_isdir.assert_called_with('/foo/bar')
     mock_exists.assert_not_called()
     mock_makedirs.assert_not_called()
     mock_check_call.assert_not_called()
Beispiel #8
0
 def test_already_exists(self, mock_isdir, mock_exists,
                         mock_makedirs, mock_check_call):
     """Test case where the target directory already exists."""
     mock_isdir.return_value = True
     self.assertTrue(Helper.mkdir('/foo/bar'))
     mock_isdir.assert_called_with('/foo/bar')
     mock_exists.assert_not_called()
     mock_makedirs.assert_not_called()
     mock_check_call.assert_not_called()
 def test_need_sudo(self, mock_isdir, mock_exists,
                    mock_makedirs, mock_check_call):
     """Directory creation needs sudo."""
     mock_makedirs.side_effect = OSError
     self.assertTrue(Helper.mkdir('/foo/bar'))
     mock_isdir.assert_called_with('/foo/bar')
     mock_exists.assert_called_with('/foo/bar')
     mock_makedirs.assert_called_with('/foo/bar', 493)  # 493 == 0o755
     mock_check_call.assert_called_with(
         ['sudo', 'mkdir', '-p', '--mode=755', '/foo/bar'])
Beispiel #10
0
 def test_need_sudo(self, mock_isdir, mock_exists,
                    mock_makedirs, mock_check_call):
     """Directory creation needs sudo."""
     mock_makedirs.side_effect = OSError
     self.assertTrue(Helper.mkdir('/foo/bar'))
     mock_isdir.assert_called_with('/foo/bar')
     mock_exists.assert_called_with('/foo/bar')
     mock_makedirs.assert_called_with('/foo/bar', 493)  # 493 == 0o755
     mock_check_call.assert_called_with(
         ['sudo', 'mkdir', '-p', '-m', '755', '/foo/bar'])