def _copy_files(self, src, dst, path, src_i, dst_i, files, truncated= False, depth= 0, cached_status= None,verbose=True): if verbose and files: print "\t"*depth+"Copy files" status= cached_status for file, info in files: if verbose: print "\t"*depth+"Object: "+file if not cached_status or cached_status==PathStatus.ignore or not self.cache_file_status: status= self.config.GetPathStatus(path+[file]) if status==PathStatus.include: src_index= None dst_index= None src_mtime= info["modified_time"] src_filesize= info["size"] try: copyfile(src, file, dst, file) #Change mod of newly created file #to mod of a source file dst.chmod(file, get_fmod(info)) except: continue if src_filesize>=0: print "Sync synch synch..............................." src_index= src_i.GetPathPart([src_i.name,file], True) dst_index= dst_i.GetPathPart([dst_i.name,file], True) src_index.CreationTime= self.dt2ut(src_mtime) dst_index.CreationTime= self.dt2ut(dst.getinfo(file)["modified_time"]) if status==PathStatus.stop: if verbose: print "\t"*depth+"Removing file" src.remove(file)
def _make_links(self, src, dst, path, src_i, dst_i, links, truncated= False,depth= 0, cached_status= None,verbose=True): if verbose and links: print "\t"*depth+"Make links" status= cached_status for link, info in links: if verbose: print "\t"*depth+"Object: "+link if not cached_status or not self.cache_file_status: (truncated, status)= self.config.GetPathStatus(path+[link], True) if truncated: cached_status= status if status==PathStatus.include: lnk= src.readlink(link) if verbose: print "\t"*depth+"Creating link to"+lnk dst.symlink(lnk, link) #Change mod of newly created link #to mod of a source link dst.chmod(link, get_fmod(info)) elif status==PathStatus.stop: if verbose: print "\t"*depth+"Removing link" src.remove(link)
def _copy_dirs(self, src, dst, path, src_i, dst_i, dirs, truncated= False, depth= 0, cached_status= None,verbose=True): if verbose and dirs: print "\t"*depth+"Copy dirs" status= cached_status for file, sinfo, dinfo in dirs: if verbose: print "\t"*depth+"Object: "+file l_cached_status= None if not cached_status: (truncated, status)= self.config.GetPathStatus(path+[file], True) if truncated: l_cached_status= status if status==PathStatus.include or (status==PathStatus.ignore and self.config.PathExists(path+[file])): if verbose: print "\t"*depth+"dir_enter->" new_src= src.makeopendir(file) new_dst= dst.makeopendir(file) #Change mod of newly created file #to mod of a source file dst.chmod(file, get_fmod(sinfo)) self._synch_walk(new_src, new_dst, path[:]+[file], src_i.GetPathPart([src_i.name,file], True), dst_i.GetPathPart([dst_i.name,file], True), depth+1, l_cached_status) if verbose: print "\t"*depth+"<-dir_leave" elif status==PathStatus.stop: if verbose: print "\t"*depth+"Removing dir" src.removedir(file, force=True) else: pass
#to mod of a source link dst.chmod(link, get_fmod(info)) elif status==PathStatus.stop: if verbose: print "\t"*depth+"Removing link" src.remove(link) def _update_permissions(self, src, dst, files, truncated= False,depth= 0, cached_status= None,verbose=True):): if verbose and links: print "\t"*depth+"Update permissions" #Here we can't act based on modification time, #so we have to decide based on options. for file, sinfo, dinfo in files: if verbose: print "\t"*depth+"Object: "+file #We update in case if st_modes are different #this should be sufficient detection. if get_fmod(sinfo["st_mode"])!=get_fmod(dinfo["st_mode"]): dst.chmod(file, get_fmod(sinfo)) #src.chmod(file, dmod) def _update_links(self, src, dst, path, src_i, dst_i, links, truncated= False,depth= 0, cached_status= None,verbose=True): if verbose and links: print "\t"*depth+"Update links" status= cached_status for file, sinfo, dinfo in links: if verbose: print "\t"*depth+"Object: "+file if not cached_status or not self.cache_file_status: (truncated, status)= self.config.GetPathStatus(path+[file], True) if truncated: cached_status= status if status==PathStatus.include: #Links point to same location, do nothing. slnk= src.readlink(file)