Пример #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.ConvertIntToPrettyString( max_allowed )
        
    
    if time_delta is None:
        
        s += ' per month'
        
    else:
        
        s += ' per ' + HydrusData.ConvertTimeDeltaToPrettyString( time_delta )
        
    
    return s
Пример #2
0
    def finish(self):

        Request.finish(self)

        host = self.getHost()

        if self.hydrus_response_context is not None:

            status_text = HydrusData.ToUnicode(
                self.hydrus_response_context.GetStatusCode())

        elif hasattr(self, 'code'):

            status_text = str(self.code)

        else:

            status_text = '200'

        message = str(host.port) + ' ' + HydrusData.ToUnicode(
            self.method
        ) + ' ' + HydrusData.ToUnicode(
            self.path
        ) + ' ' + status_text + ' in ' + HydrusData.ConvertTimeDeltaToPrettyString(
            time.clock() - self.start_time)

        HydrusData.Print(message)
Пример #3
0
    def _RefreshLabel(self):

        value = self._value

        if value is None:

            text = 'monthly'

        else:

            text = HydrusData.ConvertTimeDeltaToPrettyString(value)

        self.SetLabelText(text)
Пример #4
0
 def GetBandwidthStringsAndGaugeTuples( self, bandwidth_tracker, threshold = 600 ):
     
     with self._lock:
         
         rows = []
         
         rules_sorted = list( self._rules )
         
         def key( ( bandwidth_type, time_delta, max_allowed ) ):
             
             return time_delta
             
         
         rules_sorted.sort( key = key )
         
         for ( bandwidth_type, time_delta, max_allowed ) in rules_sorted:
             
             time_is_less_than_threshold = time_delta is not None and time_delta <= threshold
             
             if time_is_less_than_threshold or max_allowed == 0:
                 
                 continue
                 
             
             usage = bandwidth_tracker.GetUsage( bandwidth_type, time_delta )
             
             s = 'used '
             
             if bandwidth_type == HC.BANDWIDTH_TYPE_DATA:
                 
                 s += HydrusData.ConvertValueRangeToBytes( usage, max_allowed )
                 
             elif bandwidth_type == HC.BANDWIDTH_TYPE_REQUESTS:
                 
                 s += HydrusData.ConvertValueRangeToPrettyString( usage, max_allowed ) + ' requests'
                 
             
             if time_delta is None:
                 
                 s += ' this month'
                 
             else:
                 
                 s += ' in the past ' + HydrusData.ConvertTimeDeltaToPrettyString( time_delta )
                 
             
             rows.append( ( s, ( usage, max_allowed ) ) )
             
         
         return rows
Пример #5
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 )
Пример #6
0
    def _ConvertRuleToListctrlTuples(self, rule):

        (bandwidth_type, time_delta, max_allowed) = rule

        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) + ' requests'

        sort_tuple = (max_allowed, time_delta)
        display_tuple = (pretty_max_allowed, pretty_time_delta)

        return (display_tuple, sort_tuple)
Пример #7
0
    def __repr__(self):

        return repr(self.__class__) + ': ' + repr(
            self._work_callable
        ) + ' next in ' + HydrusData.ConvertTimeDeltaToPrettyString(
            self._next_work_time - HydrusData.GetNowFloat())