#!/usr/bin/python 'remote diff' import sys, os, hashlib DEBUGGING = False def rdiff(source, dest): sourcefiles, destfiles = listfiles(source), listfiles(dest) #print sourcefiles, destfiles reference = dict(destfiles).keys() for item in sourcefiles: if not item in destfiles: if item[0] in reference: print 'differs: %s' % item[0] else: print 'not in %s: %s' % (dest, item[0]) reference = dict(sourcefiles).keys() for item in destfiles: if item[0] not in reference: print 'not in %s: %s' % (source, item[0]) def listfiles(location): if ':' in location: host, directory = location.split(':') remote = os.popen('ssh %s bin/listfiles %s' % (host, directory)) listing = remote.read() debug('listing: %s' % repr(listing)) listing = eval(listing) else: os.chdir(location) listing = [] os.path.walk('.', listdir, listing) return sorted(listing) def listdir(listing, dirname, fnames): if '.bzr' in fnames: fnames.remove('.bzr') for fname in fnames: listing.append([os.path.join(dirname, fname)]) listing[-1].append(sha1sum(listing[-1][0])) if False: # skip stat for now listing[-1].append(os.lstat(listing[-1][0])) def sha1sum(filename): if os.path.isfile(filename): with open(filename) as input: sha1sum = hashlib.sha1(input.read()) return sha1sum.digest().encode('hex') else: return '0' def debug(message): if DEBUGGING: print >>sys.stderr, message if __name__ == '__main__': command = os.path.splitext(os.path.basename(sys.argv[0]))[0] if command in globals() and callable(eval(command)): print eval(command)(*sys.argv[1:]) or '' else: print >>sys.stderr, 'No such function %s' % command