Esempio n. 1
0
 def _import_and_find_dupes( self ):
     
     phash = os.urandom( 8 )
     
     # fake-import the files with the phash
     
     ( size, mime, width, height, duration, num_frames, has_audio, num_words ) = ( 65535, HC.IMAGE_JPEG, 640, 480, None, None, False, None )
     
     file_import_options = HG.client_controller.new_options.GetDefaultFileImportOptions( 'loud' )
     
     for hash in self._all_hashes:
         
         fake_file_import_job = ClientImportFiles.FileImportJob( 'fake path', file_import_options )
         
         fake_file_import_job._pre_import_file_status = ClientImportFiles.FileImportStatus( CC.STATUS_UNKNOWN, hash )
         fake_file_import_job._file_info = ( size, mime, width, height, duration, num_frames, has_audio, num_words )
         fake_file_import_job._extra_hashes = ( b'abcd', b'abcd', b'abcd' )
         fake_file_import_job._phashes = [ phash ]
         fake_file_import_job._file_import_options = FileImportOptions.FileImportOptions()
         
         self._write( 'import_file', fake_file_import_job )
         
     
     # run search maintenance
     
     self._write( 'maintain_similar_files_tree' )
     
     self._write( 'maintain_similar_files_search_for_potential_duplicates', 0 )
Esempio n. 2
0
    def _do_fake_imports(self):

        self._md5_to_sha256 = {}
        self._sha256_to_md5 = {}
        self._sha256_to_sha1 = {}

        self._my_files_sha256 = set()

        self._hashes_to_current_tags = {}
        self._hashes_to_pending_tags = {}
        self._hashes_to_deleted_tags = {}

        (size, mime, width, height, duration, num_frames, has_audio,
         num_words) = (65535, HC.IMAGE_JPEG, 640, 480, None, None, False, None)

        file_import_options = HG.client_controller.new_options.GetDefaultFileImportOptions(
            'loud')

        for i in range(100):

            hash = HydrusData.GenerateKey()
            md5 = os.urandom(16)
            sha1 = os.urandom(20)
            sha512 = os.urandom(64)

            self._md5_to_sha256[md5] = hash
            self._sha256_to_md5[hash] = md5
            self._sha256_to_sha1[hash] = sha1

            self._hashes_to_current_tags[hash] = set(
                random.sample(current_tag_pool, 3))
            self._hashes_to_pending_tags[hash] = set(
                random.sample(pending_tag_pool, 3))
            self._hashes_to_deleted_tags[hash] = set(
                random.sample(deleted_tag_pool, 3))

            if i < 50:

                fake_file_import_job = ClientImportFiles.FileImportJob(
                    'fake path', file_import_options)

                fake_file_import_job._pre_import_file_status = ClientImportFiles.FileImportStatus(
                    CC.STATUS_UNKNOWN, hash)
                fake_file_import_job._file_info = (size, mime, width, height,
                                                   duration, num_frames,
                                                   has_audio, num_words)
                fake_file_import_job._extra_hashes = (md5, sha1, sha512)
                fake_file_import_job._perceptual_hashes = [os.urandom(8)]
                fake_file_import_job._file_import_options = FileImportOptions.FileImportOptions(
                )

                self.WriteSynchronous('import_file', fake_file_import_job)

                self._my_files_sha256.add(hash)
Esempio n. 3
0
    def WriteSynchronous(self, name, *args, **kwargs):

        self._write_call_args[name].append((args, kwargs))

        if name == 'import_file':

            (file_import_job, ) = args

            if file_import_job.GetHash().hex(
            ) == 'a593942cb7ea9ffcd8ccf2f0fa23c338e23bfecd9a3e508dfc0bcf07501ead08':  # 'blarg' in sha256 hex

                raise Exception('File failed to import for some reason!')

            else:

                h = file_import_job.GetHash()

                if h is None:

                    h = os.urandom(32)

                return ClientImportFiles.FileImportStatus(
                    CC.STATUS_SUCCESSFUL_AND_NEW, h, note='test note')
    def GetHashIdStatus(self,
                        hash_id,
                        prefix='') -> ClientImportFiles.FileImportStatus:

        if prefix != '':

            prefix += ': '

        hash = self.modules_hashes_local_cache.GetHash(hash_id)

        (is_deleted, timestamp,
         file_deletion_reason) = self.modules_files_storage.GetDeletionStatus(
             self.modules_services.combined_local_file_service_id, hash_id)

        if is_deleted:

            if timestamp is None:

                note = 'Deleted from the client before delete times were tracked ({}).'.format(
                    file_deletion_reason)

            else:

                note = 'Deleted from the client {} ({}), which was {} before this check.'.format(
                    HydrusData.ConvertTimestampToPrettyTime(timestamp),
                    file_deletion_reason,
                    HydrusData.BaseTimestampToPrettyTimeDelta(timestamp))

            return ClientImportFiles.FileImportStatus(CC.STATUS_DELETED,
                                                      hash,
                                                      note=prefix + note)

        result = self.modules_files_storage.GetCurrentTimestamp(
            self.modules_services.trash_service_id, hash_id)

        if result is not None:

            timestamp = result

            note = 'Currently in trash ({}). Sent there at {}, which was {} before this check.'.format(
                file_deletion_reason,
                HydrusData.ConvertTimestampToPrettyTime(timestamp),
                HydrusData.BaseTimestampToPrettyTimeDelta(
                    timestamp, just_now_threshold=0))

            return ClientImportFiles.FileImportStatus(CC.STATUS_DELETED,
                                                      hash,
                                                      note=prefix + note)

        result = self.modules_files_storage.GetCurrentTimestamp(
            self.modules_services.combined_local_file_service_id, hash_id)

        if result is not None:

            timestamp = result

            mime = self.modules_files_metadata_basic.GetMime(hash_id)

            note = 'Imported at {}, which was {} before this check.'.format(
                HydrusData.ConvertTimestampToPrettyTime(timestamp),
                HydrusData.BaseTimestampToPrettyTimeDelta(
                    timestamp, just_now_threshold=0))

            return ClientImportFiles.FileImportStatus(
                CC.STATUS_SUCCESSFUL_BUT_REDUNDANT,
                hash,
                mime=mime,
                note=prefix + note)

        return ClientImportFiles.FileImportStatus(CC.STATUS_UNKNOWN, hash)