def testAddFromWeb(self): f = randomutils.RandomFileHere( 1024 ) c =Checksum() checksum = c.blockComputeFile(f()) statInfo = FileStat(f()) payload = { "host" : socket.gethostname(), "path" : f(), "filename" : os.path.basename(f()), "size" : statInfo.size(), "ctime" : statInfo.ctime(), "atime" : statInfo.atime(), "mtime" : statInfo.mtime(), "isdir" : statInfo.isdir(), "checksum" : checksum } self._fc.addFileFromWeb( payload ) fRec = self._fc.getFileByPath( f()) self.assertIsNotNone( fRec ) self.assertEqual( os.path.getsize( f.name()), fRec[ 'size' ] ) self.assertTrue( self._fc.inFilesCollection( f())) self.assertTrue( self._fc.isSameFile( FileStat( f.name()), fRec )) self.assertEqual( 1, self._fc.count()) self.assertEqual(0, self._fc.duplicatesCount()) f.rm()
def compare( path1, path2 ): if path1 == path2 : print "Same file: %s" % path1 sys.exit(1) chk = Checksum() c1 = chk.blockComputeFile( path1 ) c2 = chk.blockComputeFile( path1 ) if c1 != c2 : print "%s is not a clone of %s" % ( path1, path2 ) sys.exit( 1 )
onefile=args.onefile if onefile: path = os.path.abspath( onefile ) statInfo = filestat.FileStat( path ) checksum = 0 cs = Checksum() if statInfo.isdir() : checksum = 0 else: checksum = cs.blockComputeFile( path ) payload = { "host" : socket.gethostname(), "path" : path, "filename" : os.path.basename( path ), "size" : statInfo.size(), "ctime" : statInfo.ctime(), "atime" : statInfo.atime(), "mtime" : statInfo.mtime(), "isdir" : statInfo.isdir(), "checksum" : checksum } headers = {'content-type': 'application/json'} requests.post( serverHost + "/add", data=json.dumps( payload ),