def test_ignore(self): ignore = DKIgnore() test = 'not_ignore' self.assertFalse(ignore.ignore(test)) test = '.DS_Store' self.assertTrue(ignore.ignore(test)) test = 'base/path/directory/.DS_Store' self.assertTrue(ignore.ignore(test))
def compare_sha(remote_sha, local_sha): same = dict() different = dict() only_local = dict() only_local_dir = dict() only_remote = dict() only_remote_dir = dict() # Look for differences from remote for remote_path in remote_sha: for remote_file in remote_sha[remote_path]: if remote_path in local_sha: local_files_found = filter( lambda local_file: local_file['filename'] == remote_file[ 'filename'], local_sha[remote_path]) else: if remote_path not in only_remote_dir: only_remote_dir[remote_path] = list() local_files_found = list() if len(local_files_found) != 0: if local_files_found[0]['sha'] == remote_file['sha']: # print '%s matches' % remote_file['filename'] if remote_path not in same: same[remote_path] = list() same[remote_path].append(remote_file) else: if remote_path not in different: different[remote_path] = list() # print '%s different' % remote_file['filename'] different[remote_path].append(remote_file) elif len(local_files_found) > 1: # print 'compare_sha: Unexpected return in remote_path' raise else: # print '%s not found for local' % remote_file['filename'] if remote_path not in only_remote: only_remote[remote_path] = list() only_remote[remote_path].append(remote_file) ignore = DKIgnore() for local_path, local_files in local_sha.iteritems(): if ignore.ignore(local_path): # Ignore some stuff. # print '%s ignoring' % local_path continue elif local_path in remote_sha: for local_file in local_files: if ignore.ignore(local_file['filename']): # print '%s ignoring' % local_file['filename'] continue elif ignore.ignore( os.path.join(local_path, local_file['filename'])): # print '%s ignoring' % os.path.join(local_path, local_file['filename']) continue remote_files_found = filter( lambda remote_file: remote_file['filename'] == local_file[ 'filename'], remote_sha[local_path]) if len(remote_files_found) > 1: # print 'compare_sha: Unexpected return in remote_path' raise elif len(remote_files_found) == 0: if local_path not in only_local: only_local[local_path] = list() # print '%s missing from remote' % local_file['filename'] only_local[local_path].append(local_file) else: if local_path not in only_local: # print '%s missing from remote' % local_path only_local_dir[local_path] = list() only_local[local_path] = list() for local_file in local_files: only_local[local_path].append(local_file) rv = dict() rv['same'] = same rv['different'] = different rv['only_local'] = only_local rv['only_local_dir'] = only_local_dir rv['only_remote'] = only_remote rv['only_remote_dir'] = only_remote_dir return rv
def compare_sha(remote_sha, local_sha): same = dict() different = dict() only_local = dict() only_remote = dict() # Look for differences from remote for remote_path in remote_sha: if remote_path in local_sha: for remote_file in remote_sha[remote_path]: local_files_found = filter(lambda local_file: local_file['filename'] == remote_file['filename'], local_sha[remote_path]) if len(local_files_found) != 0: if local_files_found[0]['sha'] == remote_file['sha']: # print '%s matches' % remote_file['filename'] if remote_path not in same: same[remote_path] = list() same[remote_path].append(remote_file) else: if remote_path not in different: different[remote_path] = list() # print '%s different' % remote_file['filename'] different[remote_path].append(remote_file) elif len(local_files_found) > 1: # print 'compare_sha: Unexpected return in remote_path' raise else: # print '%s not found for local' % remote_file['filename'] if remote_path not in only_remote: only_remote[remote_path] = list() only_remote[remote_path].append(remote_file) else: # print '%s missing from local' % remote_path if remote_path not in only_remote: only_remote[remote_path] = list() ignore = DKIgnore() for local_path, local_files in local_sha.iteritems(): if ignore.ignore(local_path): # Ignore some stuff. # print '%s ignoring' % local_path continue elif local_path in remote_sha: for local_file in local_files: if ignore.ignore(local_file['filename']): # print '%s ignoring' % local_file['filename'] continue elif ignore.ignore(os.path.join(local_path, local_file['filename'])): # print '%s ignoring' % os.path.join(local_path, local_file['filename']) continue remote_files_found = filter(lambda remote_file: remote_file['filename'] == local_file['filename'], remote_sha[local_path]) if len(remote_files_found) > 1: # print 'compare_sha: Unexpected return in remote_path' raise elif len(remote_files_found) == 0: if local_path not in only_local: only_local[local_path] = list() # print '%s missing from remote' % local_file['filename'] only_local[local_path].append(local_file) else: if local_path not in only_local: # print '%s missing from remote' % local_path only_local[local_path] = list() rv = dict() rv['same'] = same rv['different'] = different rv['only_local'] = only_local rv['only_remote'] = only_remote return rv