def add_right_dir(self, r): self.common_dirs_add = [] self.common_files_add = [] self.common_funny_add = [] #±£´æÓÒdir self.right = r org_rl = self.right_list self.right_list = _filter(os.listdir(self.right), self.hide + self.ignore) self.right_list.sort() #¸üÐÂleft onlyºÍright only a = dict(izip(imap(os.path.normcase, self.left_list), self.left_list)) b = dict(izip(imap(os.path.normcase, self.right_list), self.right_list)) self.common_add = map(a.__getitem__, ifilter(b.has_key, a)) print self.common_add self.common += self.common_add left_only_dict = dict( izip(imap(os.path.normcase, self.left_only), self.left_only)) self.left_only = map(left_only_dict.__getitem__, ifilterfalse(b.has_key, left_only_dict)) self.right_only += map(b.__getitem__, ifilterfalse(a.has_key, b)) for x in self.common_add: a_path = os.path.join(self.left, x) b_path = os.path.join(self.right, x) ok = 1 try: a_stat = os.stat(a_path) except os.error, why: # print 'Can\'t stat', a_path, ':', why[1] ok = 0 try: b_stat = os.stat(b_path) except os.error, why: # print 'Can\'t stat', b_path, ':', why[1] ok = 0
def report_changes(self): # Return differences between a and b # print 'diff', self.left, self.right changes = [] # file removed for f in self.left_only: changes.append( Change(os.path.join(self.left, f), None)) # file added for f in self.right_only: fpath = os.path.join(self.right, f) if os.path.isdir(fpath): for root, dirs, files in os.walk(fpath): if not files: changes.append( Change(None, root)) else: changes.extend([ Change(None, os.path.join(root, filename)) for filename in filecmp._filter( files, self.ignore + self.hide) ]) else: changes.append( Change(None, fpath)) # file modified for f in self.diff_files: changes.append( Change(os.path.join(self.left, f), os.path.join(self.right, f))) for f in self.funny_files: changes.append( Change(os.path.join(self.left, f), os.path.join(self.right, f))) return changes
def add_right_dir(self, r): self.common_dirs_add = [] self.common_files_add = [] self.common_funny_add = [] #±£´æÓÒdir self.right = r org_rl = self.right_list self.right_list = _filter(os.listdir(self.right), self.hide+self.ignore) self.right_list.sort() #¸üÐÂleft onlyºÍright only a = dict(izip(imap(os.path.normcase, self.left_list), self.left_list)) b = dict(izip(imap(os.path.normcase, self.right_list), self.right_list)) self.common_add = map(a.__getitem__, ifilter(b.has_key, a)) print self.common_add self.common += self.common_add left_only_dict = dict(izip(imap(os.path.normcase, self.left_only), self.left_only)) self.left_only = map(left_only_dict.__getitem__, ifilterfalse(b.has_key, left_only_dict)) self.right_only += map(b.__getitem__, ifilterfalse(a.has_key, b)) for x in self.common_add: a_path = os.path.join(self.left, x) b_path = os.path.join(self.right, x) ok = 1 try: a_stat = os.stat(a_path) except os.error, why: # print 'Can\'t stat', a_path, ':', why[1] ok = 0 try: b_stat = os.stat(b_path) except os.error, why: # print 'Can\'t stat', b_path, ':', why[1] ok = 0
def update_event(self, inp=-1): self.set_output_val(0, filecmp._filter(self.input(0), self.input(1)))