Ejemplo n.º 1
0
 def CheckObjects(self, path, root, objects, correct_objects):
     f= fsopendir(path)
     for type, object, attr in objects:
         try: i= f.getinfo(root+"/"+object)
         except:
             self.assertTrue(object not in correct_objects)
             continue
         if is_dir(i) and type==ObjectType.dir:
             self.assertTrue(object in correct_objects)
         elif is_file(i) and type==ObjectType.file:
             self.assertTrue(object in correct_objects)
         elif is_lnk(i) and type==ObjectType.link:
             self.assertTrue(object in correct_objects)
Ejemplo n.º 2
0
    def _synch_walk(self, src, dst, path, src_i, dst_i, depth= 0, cached_status= None, verbose=True):
        #Get list of files in dirs        
        src_files= src.listdir()
        dst_files= dst.listdir()
        
        #This operations are considered slow,
        #so we want to do them only once.
        src_info= [src.getinfo(i) for i in src_files]
        dst_info= [dst.getinfo(i) for i in dst_files]
        
        src_f= []
        src_d= []
        src_l=[]
        for id, i in enumerate(src_files):
            if is_file( src_info[id] ): src_f.append( (i,src_info[id]) )
            elif is_dir( src_info[id] ): src_d.append( (i,src_info[id]) )
            elif is_lnk( src_info[id] ): src_l.append( (i,src_info[id]) )
            else: pass #If file/dir is something we don't know we just pass.
            
        dst_f= []
        dst_d= []
        dst_l=[]
        for id, i in enumerate(dst_files):
            if is_file( dst_info[id] ): dst_f.append( (i,dst_info[id]) )
            elif is_dir( dst_info[id] ): dst_d.append( (i,dst_info[id]) )
            elif is_lnk( dst_info[id] ): dst_l.append( (i,dst_info[id]) )
            else: pass #If file/dir is something we don't know we just pass.

        #This operations are considered fast
        #Src
        copy_src_files = [(i,info) for i, info in src_f if i not in dst_files or (i, info) in dst_d]
        copy_src_dirs = [(i, info) for i, info in src_d if i not in dst_files or (i, info) in dst_f]
        make_src_links = [(i,info) for i, info in src_l if i not in dst_files]
        #Dst
        copy_dst_files = [(i,info) for i, info in dst_f if i not in src_files or (i, info) in src_d]
        copy_dst_dirs = [i for i, info in dst_d if i not in src_files or (i, info) in src_f]
        make_dst_links = [(i,info) for i, info in dst_l if i not in src_files]
        
        #Update files are in src and dst the same.
        #Files that are not in those files we are about to copy.
        update_files=[]
        for i1, sinfo in src_f:
            if (i1, sinfo) not in copy_src_files:
                for i2, dinfo in dst_f:
                    if i1==i2: update_files.append((i1, sinfo, dinfo))
        print update_files
        #Dirs that are not in those dirs we are about to copy.
        update_dirs=[]
        for i1, sinfo in src_d:
            if (i1, dinfo) not in copy_src_dirs: update_dirs.append((i1,sinfo,dinfo))
        update_links=[]
        for i1, sinfo in src_l:
            if (i1, sinfo) not in make_src_links:
                for i2, dinfo in dst_l:
                    if i1==i2: update_links.append((i1, sinfo, dinfo))
                
        #Select truncated based on if we have chached_status or not,
        #this way we don't have to pass another variable around.
        if cached_status: truncated= True
        else: truncated= False
        
        #Do all the hard work.
        #src->dst
        self._copy_files(src, dst, path, src_i, dst_i, copy_src_files, truncated, depth, cached_status, verbose)
        self._copy_dirs(src, dst, path, src_i, dst_i, copy_src_dirs, truncated, depth, cached_status, verbose)
        self._make_links(src, dst, path, src_i, dst_i, make_src_links, truncated, depth, cached_status, verbose)
        #dst->src
        self._copy_files(dst, src, path, dst_i, src_i, copy_dst_files, truncated, depth, cached_status, verbose)
        self._copy_dirs(dst, src, path, dst_i, src_i, copy_dst_dirs, truncated, depth, cached_status, verbose)
        self._make_links(dst, src, path, dst_i, src_i, make_dst_links, truncated, depth, cached_status, verbose)
        #dst<->src
        self._update_files(src, dst, path, src_i, dst_i, update_files, truncated, depth, cached_status, verbose)
        self._update_dirs(src, dst, path, src_i, dst_i, update_dirs, truncated, depth, cached_status, verbose)
        self._update_links(src, dst, path, src_i, dst_i, update_links, truncated, depth, cached_status, verbose)
        #We have to check if permissions have been changed on files links and dirs.
        self._update_permissions(src, dst, update_files+update_dirs+update_links, truncated, depth, cached_status, verbose)
        
        #Save file indexes to database from time to time.
        if datetime.now()-self.start_time>timedelta(seconds=100):
            print "Commit CommitCommitCommitCommitCommitCommitCommitCommitCommitCommitCommit"
            self.db.commit()
            self.start_time= datetime.now()