def test_add_hash_explicit_write(): db = Db() random_key = helper.random_string(10) random_value = helper.random_string(12) # Test with explicit True value as 3rd param db.add_hash(random_key, random_value, True) assert db.check_hash(random_key) == True, 'Lookup for hash did not return True' # Instnatiate new db class to confirm random_key exists db2 = Db() assert db2.check_hash(random_key) == True
def test_add_hash_default_do_not_write(): db = Db() random_key = helper.random_string(10) random_value = helper.random_string(12) # Test with default False value as 3rd param db.add_hash(random_key, random_value) assert db.check_hash(random_key) == True, 'Lookup for hash did not return True' # Instnatiate new db class to confirm random_key does not exist db2 = Db() assert db2.check_hash(random_key) == False
def test_check_hash_does_not_exist(): db = Db() random_key = helper.random_string(10) assert db.check_hash( random_key ) == False, 'Lookup for hash that should not exist returned True'
def test_check_hash_exists(): db = Db() random_key = helper.random_string(10) random_value = helper.random_string(12) # Test with explicit False value as 3rd param db.add_hash(random_key, random_value, False) assert db.check_hash(random_key) == True, 'Lookup for hash did not return True'
def process_file(self, _file, destination, media, **kwargs): move = False if('move' in kwargs): move = kwargs['move'] allow_duplicate = False if('allowDuplicate' in kwargs): allow_duplicate = kwargs['allowDuplicate'] if(not media.is_valid()): print '%s is not a valid media file. Skipping...' % _file return metadata = media.get_metadata() directory_name = self.get_folder_path(metadata) dest_directory = os.path.join(destination, directory_name) file_name = self.get_file_name(media) dest_path = os.path.join(dest_directory, file_name) db = Db() checksum = db.checksum(_file) if(checksum is None): if(constants.debug is True): print 'Could not get checksum for %s. Skipping...' % _file return # If duplicates are not allowed and this hash exists in the db then we # return if(allow_duplicate is False and db.check_hash(checksum) is True): if(constants.debug is True): print '%s already exists at %s. Skipping...' % ( _file, db.get_hash(checksum) ) return self.create_directory(dest_directory) if(move is True): stat = os.stat(_file) shutil.move(_file, dest_path) os.utime(dest_path, (stat.st_atime, stat.st_mtime)) else: shutil.copy2(_file, dest_path) db.add_hash(checksum, dest_path) db.update_hash_db() return dest_path
def process_file(self, _file, destination, media, **kwargs): move = False if ('move' in kwargs): move = kwargs['move'] allow_duplicate = False if ('allowDuplicate' in kwargs): allow_duplicate = kwargs['allowDuplicate'] if (not media.is_valid()): print '%s is not a valid media file. Skipping...' % _file return metadata = media.get_metadata() directory_name = self.get_folder_path(metadata) dest_directory = os.path.join(destination, directory_name) file_name = self.get_file_name(media) dest_path = os.path.join(dest_directory, file_name) db = Db() checksum = db.checksum(_file) if (checksum is None): if (constants.debug is True): print 'Could not get checksum for %s. Skipping...' % _file return # If duplicates are not allowed and this hash exists in the db then we # return if (allow_duplicate is False and db.check_hash(checksum) is True): if (constants.debug is True): print '%s already exists at %s. Skipping...' % ( _file, db.get_hash(checksum)) return self.create_directory(dest_directory) if (move is True): stat = os.stat(_file) shutil.move(_file, dest_path) os.utime(dest_path, (stat.st_atime, stat.st_mtime)) else: shutil.copy2(_file, dest_path) db.add_hash(checksum, dest_path) db.update_hash_db() return dest_path
def test_check_hash_does_not_exist(): db = Db() random_key = helper.random_string(10) assert db.check_hash(random_key) == False, 'Lookup for hash that should not exist returned True'