Пример #1
0
def ConvertBandwidthRuleToString(rule):

    (bandwidth_type, time_delta, max_allowed) = rule

    if max_allowed == 0:

        return 'No requests currently permitted.'

    if bandwidth_type == HC.BANDWIDTH_TYPE_DATA:

        s = HydrusData.ConvertIntToBytes(max_allowed)

    elif bandwidth_type == HC.BANDWIDTH_TYPE_REQUESTS:

        s = HydrusData.ToHumanInt(max_allowed)

    if time_delta is None:

        s += ' per month'

    else:

        s += ' per ' + HydrusData.TimeDeltaToPrettyTimeDelta(time_delta)

    return s
Пример #2
0
    def _DisplayService(self):

        service_type = self._service.GetServiceType()

        self._DisplayAccountInfo()

        if service_type in HC.REPOSITORIES + HC.LOCAL_SERVICES + [HC.IPFS]:

            service_info = self._controller.Read('service_info',
                                                 self._service_key)

            if service_type in (HC.LOCAL_RATING_LIKE,
                                HC.LOCAL_RATING_NUMERICAL):

                num_ratings = service_info[HC.SERVICE_INFO_NUM_FILES]

                self._ratings_text.SetLabelText(
                    HydrusData.ConvertIntToPrettyString(num_ratings) +
                    ' files rated')

            elif service_type == HC.LOCAL_BOORU:

                num_shares = service_info[HC.SERVICE_INFO_NUM_SHARES]

                self._num_shares.SetLabelText(
                    HydrusData.ConvertIntToPrettyString(num_shares) +
                    ' shares currently active')

        if service_type == HC.LOCAL_BOORU:

            booru_shares = self._controller.Read('local_booru_shares')

            self._booru_shares.DeleteAllItems()

            for (share_key, info) in booru_shares.items():

                name = info['name']
                text = info['text']
                timeout = info['timeout']
                hashes = info['hashes']

                self._booru_shares.Append(
                    (name, text,
                     HydrusData.ConvertTimestampToPrettyExpires(timeout),
                     len(hashes)),
                    (name, text, timeout, (len(hashes), hashes, share_key)))

        if service_type == HC.IPFS:

            ipfs_shares = self._controller.Read('service_directories',
                                                self._service_key)

            self._ipfs_shares.DeleteAllItems()

            for (multihash, num_files, total_size, note) in ipfs_shares:

                self._ipfs_shares.Append(
                    (multihash, HydrusData.ConvertIntToPrettyString(num_files),
                     HydrusData.ConvertIntToBytes(total_size), note),
                    (multihash, num_files, total_size, note))
Пример #3
0
 def GetCurrentMonthSummary( self ):
     
     with self._lock:
         
         num_bytes = self._GetUsage( HC.BANDWIDTH_TYPE_DATA, None, True )
         num_requests = self._GetUsage( HC.BANDWIDTH_TYPE_REQUESTS, None, True )
         
         return 'used ' + HydrusData.ConvertIntToBytes( num_bytes ) + ' in ' + HydrusData.ConvertIntToPrettyString( num_requests ) + ' requests this month'
Пример #4
0
def GetPayloadDescriptionAndString(payload_obj):

    payload_string = GetPayloadString(payload_obj)

    payload_description = GetPayloadTypeString(
        payload_obj) + ' - ' + HydrusData.ConvertIntToBytes(
            len(payload_string))

    return (payload_description, payload_string)
Пример #5
0
def HasSpaceForDBTransaction( db_dir, num_bytes ):
    
    temp_dir = tempfile.gettempdir()
    
    temp_disk_free_space = GetFreeSpace( temp_dir )
    
    a = GetDevice( temp_dir )
    b = GetDevice( db_dir )
    
    if GetDevice( temp_dir ) == GetDevice( db_dir ):
        
        space_needed = int( num_bytes * 2.2 )
        
        if temp_disk_free_space < space_needed:
            
            return ( False, 'I believe you need about ' + HydrusData.ConvertIntToBytes( space_needed ) + ' on your db\'s partition, which I think also holds your temporary path, but you only seem to have ' + HydrusData.ConvertIntToBytes( temp_disk_free_space ) + '.' )
            
        
    else:
        
        space_needed = int( num_bytes * 1.1 )
        
        if temp_disk_free_space < space_needed:
            
            return ( False, 'I believe you need about ' + HydrusData.ConvertIntToBytes( space_needed ) + ' on your temporary path\'s partition, which I think is ' + temp_dir + ', but you only seem to have ' + HydrusData.ConvertIntToBytes( temp_disk_free_space ) + '.' )
            
        
        db_disk_free_space = GetFreeSpace( db_dir )
        
        if db_disk_free_space < space_needed:
            
            return ( False, 'I believe you need about ' + HydrusData.ConvertIntToBytes( space_needed ) + ' on your db\'s partition, but you only seem to have ' + HydrusData.ConvertIntToBytes( db_disk_free_space ) + '.' )
            
        
    
    return ( True, 'You seem to have enough space!' )
Пример #6
0
 def _GetDisplayTuple( self, rule ):
     
     ( bandwidth_type, time_delta, max_allowed ) = rule
     
     pretty_bandwidth_type = HC.bandwidth_type_string_lookup[ bandwidth_type ]
     
     pretty_time_delta = HydrusData.ConvertTimeDeltaToPrettyString( time_delta )
     
     if bandwidth_type == HC.BANDWIDTH_TYPE_DATA:
         
         pretty_max_allowed = HydrusData.ConvertIntToBytes( max_allowed )
         
     elif bandwidth_type == HC.BANDWIDTH_TYPE_REQUESTS:
         
         pretty_max_allowed = HydrusData.ConvertIntToPrettyString( max_allowed )
         
     
     return ( pretty_bandwidth_type, pretty_time_delta, pretty_max_allowed )
Пример #7
0
 def _ConvertRuleToListctrlTuples( self, rule ):
     
     ( bandwidth_type, time_delta, max_allowed ) = rule
     
     pretty_time_delta = HydrusData.TimeDeltaToPrettyTimeDelta( time_delta )
     
     if bandwidth_type == HC.BANDWIDTH_TYPE_DATA:
         
         pretty_max_allowed = HydrusData.ConvertIntToBytes( max_allowed )
         
     elif bandwidth_type == HC.BANDWIDTH_TYPE_REQUESTS:
         
         pretty_max_allowed = HydrusData.ToHumanInt( max_allowed ) + ' requests'
         
     
     sort_tuple = ( max_allowed, time_delta )
     display_tuple = ( pretty_max_allowed, pretty_time_delta )
     
     return ( display_tuple, sort_tuple )
Пример #8
0
def StreamResponseToFile(job_key, response, f):

    if 'content-length' in response.headers:

        gauge_range = int(response.headers['content-length'])

    else:

        gauge_range = None

    gauge_value = 0

    try:

        for chunk in response.iter_content(chunk_size=65536):

            (i_paused, should_quit) = job_key.WaitIfNeeded()

            if should_quit:

                raise HydrusExceptions.CancelledException()

            f.write(chunk)

            gauge_value += len(chunk)

            if gauge_range is None:

                text = 'downloading - ' + HydrusData.ConvertIntToBytes(
                    gauge_value)

            else:

                text = 'downloading - ' + HydrusData.ConvertValueRangeToBytes(
                    gauge_value, gauge_range)

            job_key.SetVariable('popup_download',
                                (text, gauge_value, gauge_range))

    finally:

        job_key.DeleteVariable('popup_download')
Пример #9
0
        def THREADUpdateTagInfo(self):

            service_info = HydrusGlobals.client_controller.Read(
                'service_info', self._service.GetServiceKey())

            num_files = service_info[HC.SERVICE_INFO_NUM_FILES]
            total_size = service_info[HC.SERVICE_INFO_TOTAL_SIZE]

            text = HydrusData.ConvertIntToPrettyString(
                num_files
            ) + ' files, totalling ' + HydrusData.ConvertIntToBytes(total_size)

            if self._service.GetServiceType() in (HC.COMBINED_LOCAL_FILE,
                                                  HC.FILE_REPOSITORY):

                num_deleted_files = service_info[
                    HC.SERVICE_INFO_NUM_DELETED_FILES]

                text += ' - ' + HydrusData.ConvertIntToPrettyString(
                    num_deleted_files) + ' deleted files'

            wx.CallAfter(self._UpdateFromThread, text)
Пример #10
0
    def __init__(self,
                 parent,
                 payload_obj,
                 title=None,
                 description=None,
                 payload_description=None):

        ClientGUIScrolledPanels.ReviewPanel.__init__(self, parent)

        self._payload_obj = payload_obj

        self._filepicker = wx.FilePickerCtrl(self,
                                             style=wx.FLP_SAVE
                                             | wx.FLP_USE_TEXTCTRL,
                                             wildcard='PNG (*.png)|*.png')

        flp_width = ClientGUICommon.ConvertTextToPixelWidth(
            self._filepicker, 64)

        self._filepicker.SetMinSize((flp_width, -1))

        self._title = wx.TextCtrl(self)

        self._payload_description = wx.TextCtrl(self)

        self._text = wx.TextCtrl(self)

        self._width = wx.SpinCtrl(self, min=100, max=4096)

        self._export = ClientGUICommon.BetterButton(self, 'export',
                                                    self.Export)

        #

        if payload_description is None:

            (payload_description, payload_string
             ) = ClientSerialisable.GetPayloadDescriptionAndString(
                 self._payload_obj)

        else:

            payload_string = ClientSerialisable.GetPayloadString(
                self._payload_obj)

            payload_description += ' - ' + HydrusData.ConvertIntToBytes(
                len(payload_string))

        self._payload_description.SetValue(payload_description)

        self._payload_description.Disable()

        self._width.SetValue(512)

        last_png_export_dir = HG.client_controller.new_options.GetNoneableString(
            'last_png_export_dir')

        if title is not None:

            name = title

        elif isinstance(self._payload_obj,
                        HydrusSerialisable.SerialisableBaseNamed):

            name = self._payload_obj.GetName()

        else:

            name = payload_description

        self._title.SetValue(name)

        if description is not None:

            self._text.SetValue(description)

        if last_png_export_dir is not None:

            filename = name + '.png'

            filename = HydrusPaths.SanitizeFilename(filename)

            path = os.path.join(last_png_export_dir, filename)

            self._filepicker.SetPath(path)

        self._Update()

        #

        rows = []

        rows.append(('export path: ', self._filepicker))
        rows.append(('title: ', self._title))
        rows.append(('payload description: ', self._payload_description))
        rows.append(('your description (optional): ', self._text))
        rows.append(('png width: ', self._width))
        rows.append(('', self._export))

        gridbox = ClientGUICommon.WrapInGrid(self, rows)

        self.SetSizer(gridbox)

        self._filepicker.Bind(wx.EVT_FILEPICKER_CHANGED, self.EventChanged)
        self._title.Bind(wx.EVT_TEXT, self.EventChanged)
Пример #11
0
    def _ReadResponse(self, response, stream_dest, max_allowed=None):

        with self._lock:

            if self._content_type is not None and self._content_type in HC.mime_enum_lookup:

                mime = HC.mime_enum_lookup[self._content_type]

            else:

                mime = None

            if 'content-length' in response.headers:

                self._num_bytes_to_read = int(
                    response.headers['content-length'])

                if max_allowed is not None and self._num_bytes_to_read > max_allowed:

                    raise HydrusExceptions.NetworkException(
                        'The url was apparently ' +
                        HydrusData.ConvertIntToBytes(self._num_bytes_to_read) +
                        ' but the max network size for this type of job is ' +
                        HydrusData.ConvertIntToBytes(max_allowed) + '!')

                if self._file_import_options is not None:

                    certain = True

                    self._file_import_options.CheckNetworkDownload(
                        mime, self._num_bytes_to_read, certain)

            else:

                self._num_bytes_to_read = None

        for chunk in response.iter_content(chunk_size=65536):

            if self._IsCancelled():

                return

            stream_dest.write(chunk)

            chunk_length = len(chunk)

            with self._lock:

                self._num_bytes_read += chunk_length

                if max_allowed is not None and self._num_bytes_read > max_allowed:

                    raise HydrusExceptions.NetworkException(
                        'The url exceeded the max network size for this type of job, which is '
                        + HydrusData.ConvertIntToBytes(max_allowed) + '!')

                if self._file_import_options is not None:

                    certain = False

                    self._file_import_options.CheckNetworkDownload(
                        mime, self._num_bytes_to_read, certain)

            self._ReportDataUsed(chunk_length)
            self._WaitOnOngoingBandwidth()

            if HG.view_shutdown:

                raise HydrusExceptions.ShutdownException()

        if self._num_bytes_to_read is not None and self._num_bytes_read < self._num_bytes_to_read * 0.8:

            raise HydrusExceptions.ShouldReattemptNetworkException(
                'Was expecting ' +
                HydrusData.ConvertIntToBytes(self._num_bytes_to_read) +
                ' but only got ' +
                HydrusData.ConvertIntToBytes(self._num_bytes_read) + '.')
Пример #12
0
    def _Update(self):

        if self._network_job is None or self._network_job.NoEngineYet():

            self._left_text.SetLabelText('')
            self._right_text.SetLabelText('')
            self._gauge.SetRange(1)
            self._gauge.SetValue(0)

            can_cancel = False

        else:

            if self._network_job.IsDone():

                can_cancel = False

            else:

                can_cancel = True

            (status_text, current_speed, bytes_read,
             bytes_to_read) = self._network_job.GetStatus()

            self._left_text.SetLabelText(status_text)

            if not self._download_started and current_speed > 0:

                self._download_started = True

            if self._download_started and not self._network_job.HasError():

                speed_text = ''

                if bytes_read is not None:

                    if bytes_to_read is not None and bytes_read != bytes_to_read:

                        speed_text += HydrusData.ConvertValueRangeToBytes(
                            bytes_read, bytes_to_read)

                    else:

                        speed_text += HydrusData.ConvertIntToBytes(bytes_read)

                if current_speed != bytes_to_read:  # if it is a real quick download, just say its size

                    speed_text += ' ' + HydrusData.ConvertIntToBytes(
                        current_speed) + '/s'

                self._right_text.SetLabelText(speed_text)

            else:

                self._right_text.SetLabelText('')

            self._gauge.SetRange(bytes_to_read)
            self._gauge.SetValue(bytes_read)

        if can_cancel:

            if not self._cancel_button.IsEnabled():

                self._cancel_button.Enable()

        else:

            if self._cancel_button.IsEnabled():

                self._cancel_button.Disable()