Example #1
0
def _install_into_directory(os_services: OsServices,
                            src_file_path: pathlib.Path,
                            dst_file_name: str,
                            dst_container_path: pathlib.Path):
    target = dst_container_path / dst_file_name
    if target.exists():
        raise HardErrorException(
            failure_details.FailureDetailsRenderer(
                failure_details.FailureDetails.new_message(
                    text_docs.single_line(
                        str_constructor.FormatMap(
                            '{dst} already exists: {target}',
                            {
                                'dst': instruction_arguments.DESTINATION_PATH_ARGUMENT.name,
                                'target': target,
                            }))
                )
            )
        )
    src = str(src_file_path)
    dst = str(target)
    if src_file_path.is_dir():
        os_services.copy_tree__preserve_as_much_as_possible(src, dst)
    else:
        os_services.copy_file__preserve_as_much_as_possible(src, dst)
Example #2
0
    def render_sequence(self) -> Sequence[MajorBlock]:
        everything = rend_comb.ConcatenationR([
            self._failure_info.accept(_GetFailureInfoLocationRenderer()),
            failure_details.FailureDetailsRenderer(self._failure_info.failure_details),
        ])

        return everything.render_sequence()
Example #3
0
def _raise_he__single_line(
    format_str: str,
    format_map: Mapping[str, ToStringObject],
    ex: Exception,
):
    raise HardErrorException(
        failure_details.FailureDetailsRenderer(
            FailureDetails.new_message(
                text_docs.single_line(
                    str_constructor.FormatMap(format_str, format_map)), ex)))
Example #4
0
 def make(self, path: DescribedPath):
     self._assert_is_valid_path(path)
     try:
         self._maker(path)
     except OSError as ex:
         failure = failure_details.FailureDetails(
             path_err_msgs.line_header__primitive__path(
                 self._PATH_CREATION_FAILURE,
                 path),
             ex
         )
         raise HardErrorException(_fd_rendering.FailureDetailsRenderer(failure))
Example #5
0
 def __call__(self, *args, **kwargs):
     src_basename = self.src_path.name
     if self.dst_path.exists():
         if self.dst_path.is_dir():
             _install_into_directory(self.os_services,
                                     self.src_path,
                                     src_basename,
                                     self.dst_path)
         else:
             err_msg = '{} file already exists but is not a directory: {}'.format(
                 instruction_arguments.DESTINATION_PATH_ARGUMENT.name,
                 self.dst_path)
             raise HardErrorException(
                 failure_details.FailureDetailsRenderer(
                     failure_details.FailureDetails.new_constant_message(err_msg))
             )
     else:
         self.os_services.make_dir_if_not_exists(self.dst_path.parent)
         _install_into_directory(self.os_services,
                                 self.src_path,
                                 self.dst_path.name,
                                 self.dst_path.parent)