Exemple #1
0
def TimestampToPrettyTimeDelta(timestamp,
                               just_now_string='just now',
                               just_now_threshold=3,
                               history_suffix=' ago',
                               show_seconds=True,
                               no_prefix=False):

    if HG.client_controller.new_options.GetBoolean('always_show_iso_time'):

        return HydrusData.ConvertTimestampToPrettyTime(timestamp)

    else:

        return HydrusData.BaseTimestampToPrettyTimeDelta(
            timestamp,
            just_now_string=just_now_string,
            just_now_threshold=just_now_threshold,
            history_suffix=history_suffix,
            show_seconds=show_seconds,
            no_prefix=no_prefix)
    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)