Exemple #1
0
def MirrorTree(source, dest):

    pauser = HydrusData.BigJobPauser()

    if not os.path.exists(dest):

        os.makedirs(dest)

    num_errors = 0

    for (root, dirnames, filenames) in os.walk(source):

        dest_root = root.replace(source, dest)

        surplus_dest_paths = {
            os.path.join(dest_root, dest_filename)
            for dest_filename in os.listdir(dest_root)
        }

        for dirname in dirnames:

            pauser.Pause()

            source_path = os.path.join(root, dirname)
            dest_path = os.path.join(dest_root, dirname)

            surplus_dest_paths.discard(dest_path)

            if not os.path.exists(dest_path):

                os.makedirs(dest_path)

            shutil.copystat(source_path, dest_path)

        for filename in filenames:

            if num_errors > 5:

                raise Exception('Too many errors, directory copy abandoned.')

            pauser.Pause()

            source_path = os.path.join(root, filename)

            dest_path = os.path.join(dest_root, filename)

            surplus_dest_paths.discard(dest_path)

            ok = MirrorFile(source_path, dest_path)

            if not ok:

                num_errors += 1

        for dest_path in surplus_dest_paths:

            pauser.Pause()

            DeletePath(dest_path)
Exemple #2
0
def MirrorTree( source, dest ):
    
    pauser = HydrusData.BigJobPauser()
    
    if not os.path.exists( dest ):
        
        os.makedirs( dest )
        
    
    for ( root, dirnames, filenames ) in os.walk( source ):
        
        dest_root = root.replace( source, dest )
        
        surplus_dest_paths = { os.path.join( dest_root, dest_filename ) for dest_filename in os.listdir( dest_root ) }
        
        for dirname in dirnames:
            
            pauser.Pause()
            
            source_path = os.path.join( root, dirname )
            dest_path = os.path.join( dest_root, dirname )
            
            surplus_dest_paths.discard( dest_path )
            
            if not os.path.exists( dest_path ):
                
                os.makedirs( dest_path )
                
            
            shutil.copystat( source_path, dest_path )
            
        
        for filename in filenames:
            
            pauser.Pause()
            
            source_path = os.path.join( root, filename )
            
            dest_path = os.path.join( dest_root, filename )
            
            surplus_dest_paths.discard( dest_path )
            
            if not PathsHaveSameSizeAndDate( source_path, dest_path ):
                
                shutil.copy2( source_path, dest_path )
                
            
        
        for dest_path in surplus_dest_paths:
            
            pauser.Pause()
            
            DeletePath( dest_path )
Exemple #3
0
def MergeTree(source, dest):

    pauser = HydrusData.BigJobPauser()

    if not os.path.exists(dest):

        shutil.move(source, dest)

    else:

        MakeSureDirectoryExists(dest)

        num_errors = 0

        for (root, dirnames, filenames) in os.walk(source):

            dest_root = root.replace(source, dest)

            for dirname in dirnames:

                pauser.Pause()

                source_path = os.path.join(root, dirname)
                dest_path = os.path.join(dest_root, dirname)

                MakeSureDirectoryExists(dest_path)

                shutil.copystat(source_path, dest_path)

            for filename in filenames:

                if num_errors > 5:

                    raise Exception(
                        'Too many errors, directory move abandoned.')

                pauser.Pause()

                source_path = os.path.join(root, filename)
                dest_path = os.path.join(dest_root, filename)

                ok = MergeFile(source_path, dest_path)

                if not ok:

                    num_errors += 1

        if num_errors == 0:

            DeletePath(source)
Exemple #4
0
def CopyAndMergeTree(source, dest):

    pauser = HydrusData.BigJobPauser()

    if not os.path.exists(dest):

        os.makedirs(dest)

    num_errors = 0

    for (root, dirnames, filenames) in os.walk(source):

        dest_root = root.replace(source, dest)

        for dirname in dirnames:

            pauser.Pause()

            source_path = os.path.join(root, dirname)
            dest_path = os.path.join(dest_root, dirname)

            if not os.path.exists(dest_path):

                os.makedirs(dest_path)

            shutil.copystat(source_path, dest_path)

        for filename in filenames:

            if num_errors > 5:

                raise Exception('Too many errors, directory copy abandoned.')

            pauser.Pause()

            source_path = os.path.join(root, filename)
            dest_path = os.path.join(dest_root, filename)

            ok = MirrorFile(source_path, dest_path)

            if not ok:

                num_errors += 1
Exemple #5
0
def CopyAndMergeTree( source, dest ):
    
    pauser = HydrusData.BigJobPauser()
    
    if not os.path.exists( dest ):
        
        os.makedirs( dest )
        
    
    for ( root, dirnames, filenames ) in os.walk( source ):
        
        dest_root = root.replace( source, dest )
        
        for dirname in dirnames:
            
            pauser.Pause()
            
            source_path = os.path.join( root, dirname )
            dest_path = os.path.join( dest_root, dirname )
            
            if not os.path.exists( dest_path ):
                
                os.makedirs( dest_path )
                
            
            shutil.copystat( source_path, dest_path )
            
        
        for filename in filenames:
            
            pauser.Pause()
            
            source_path = os.path.join( root, filename )
            dest_path = os.path.join( dest_root, filename )
            
            if not PathsHaveSameSizeAndDate( source, dest ):
                
                shutil.copy2( source_path, dest_path )
Exemple #6
0
def MirrorTree( source, dest, text_update_hook = None, is_cancelled_hook = None ):
    
    pauser = HydrusData.BigJobPauser()
    
    MakeSureDirectoryExists( dest )
    
    num_errors = 0
    
    for ( root, dirnames, filenames ) in os.walk( source ):
        
        if is_cancelled_hook is not None and is_cancelled_hook():
            
            return
            
        
        if text_update_hook is not None:
            
            text_update_hook( 'Copying ' + root + '.' )
            
        
        dest_root = root.replace( source, dest )
        
        surplus_dest_paths = { os.path.join( dest_root, dest_filename ) for dest_filename in os.listdir( dest_root ) }
        
        for dirname in dirnames:
            
            pauser.Pause()
            
            source_path = os.path.join( root, dirname )
            dest_path = os.path.join( dest_root, dirname )
            
            surplus_dest_paths.discard( dest_path )
            
            MakeSureDirectoryExists( dest_path )
            
            shutil.copystat( source_path, dest_path )
            
        
        for filename in filenames:
            
            if num_errors > 5:
                
                raise Exception( 'Too many errors, directory copy abandoned.' )
                
            
            pauser.Pause()
            
            source_path = os.path.join( root, filename )
            
            dest_path = os.path.join( dest_root, filename )
            
            surplus_dest_paths.discard( dest_path )
            
            ok = MirrorFile( source_path, dest_path )
            
            if not ok:
                
                num_errors += 1
                
            
        
        for dest_path in surplus_dest_paths:
            
            pauser.Pause()
            
            DeletePath( dest_path )
Exemple #7
0
def MergeTree( source, dest, text_update_hook = None ):
    
    pauser = HydrusData.BigJobPauser()
    
    if not os.path.exists( dest ):
        
        try:
            
            shutil.move( source, dest )
            
        except OSError:
            
            # if there were read only files in source and this was partition to partition, the copy2 goes ok but the subsequent source unlink fails
            # so, if it seems this has happened, let's just try a walking mergetree, which should be able to deal with these readonlies on a file-by-file basis
            if os.path.exists( dest ):
                
                MergeTree( source, dest, text_update_hook = text_update_hook )
                
            
        
    else:
        
        if len( os.listdir( dest ) ) == 0:
            
            for filename in os.listdir( source ):
                
                source_path = os.path.join( source, filename )
                dest_path = os.path.join( dest, filename )
                
                if not os.path.isdir( source_path ):
                    
                    MakeFileWritable( source_path )
                    
                
                shutil.move( source_path, dest_path )
                
            
        else:
            
            num_errors = 0
            
            for ( root, dirnames, filenames ) in os.walk( source ):
                
                if text_update_hook is not None:
                    
                    text_update_hook( 'Copying ' + root + '.' )
                    
                
                dest_root = root.replace( source, dest )
                
                for dirname in dirnames:
                    
                    pauser.Pause()
                    
                    source_path = os.path.join( root, dirname )
                    dest_path = os.path.join( dest_root, dirname )
                    
                    MakeSureDirectoryExists( dest_path )
                    
                    shutil.copystat( source_path, dest_path )
                    
                
                for filename in filenames:
                    
                    if num_errors > 5:
                        
                        raise Exception( 'Too many errors, directory move abandoned.' )
                        
                    
                    pauser.Pause()
                    
                    source_path = os.path.join( root, filename )
                    dest_path = os.path.join( dest_root, filename )
                    
                    ok = MergeFile( source_path, dest_path )
                    
                    if not ok:
                        
                        num_errors += 1
                        
                    
                
            
            if num_errors == 0:
                
                DeletePath( source )