Ejemplo n.º 1
0
    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()
Ejemplo n.º 2
0
 def checksumIsEqual(self, f1, f2 ):
     
     chk = Checksum()
     
     if os.path.isfile( f1 ) and os.path.isfile( f2 ) :
         return (( os.path.getsize( f1 ) == os.path.getsize( f2 )) and
                 ( chk.sha256( f2 ) == chk.sha256( f2 )))
     else:
         return False
Ejemplo n.º 3
0
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 )
Ejemplo n.º 4
0
    
    if args.serverHost is None :
        serverHost = "http://localhost:8080/"
    else:
        serverHost = args.serverHost

        
    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 }