Пример #1
0
def move_with_path_safety_checks(full_source_path: T.Path,
                                 full_dest_path: T.Path) -> None:
    """
    Method that creates a hardlink at destination, with the latest
    mtime, and the hardlink from source, with checks that the source and
    destination are well-behaved

    @param full_source_path full path to the source file
    @param full_dest_path location full path to the destination

    """

    if not full_source_path.exists():
        raise exception.NoSourceFound(
            f"Source file {full_source_path} does not exist")
    if not full_dest_path.parent.exists():
        raise exception.NoParentForDestination(
            f"Source path exists {full_source_path} but destination parent {full_dest_path.parent} does not exist"
        )
    if full_dest_path.exists():
        raise exception.DestinationAlreadyExists(
            f"Destination {full_dest_path} already has an existing file")

    full_source_path.replace(full_dest_path)
    log.debug(f"{full_source_path} moved to {full_dest_path} ")
    file.touch(full_dest_path)
    log.info(f"File has been restored at {full_dest_path}")
Пример #2
0
 def test_1_touch(self):
     f.touch('test_touch')
     exists = os.path.exists('test_touch')
     assert exists == True
     os.remove('test_touch')
Пример #3
0
 def touch(self, file_):
     ''' touch a file, like the unix command touch
         arguments: file_ -- the file/path to file to be changed
     '''
     assert file_, "no file variable passed, or value is None"
     _file.touch(file_)