示例#1
0
    def GetSummary(self):

        if self._never_faster_than == self._never_slower_than:

            timing_statement = 'Checking every ' + HydrusData.TimeDeltaToPrettyTimeDelta(
                self._never_faster_than) + '.'

        else:

            timing_statement = 'Trying to get ' + HydrusData.ToHumanInt(
                self._intended_files_per_check
            ) + ' files per check, never faster than ' + HydrusData.TimeDeltaToPrettyTimeDelta(
                self._never_faster_than
            ) + ' and never slower than ' + HydrusData.TimeDeltaToPrettyTimeDelta(
                self._never_slower_than) + '.'

        (death_files_found, death_time_delta) = self._death_file_velocity

        if death_files_found == 0:

            death_statement = 'Never stopping.'

        else:

            death_statement = 'Stopping if file velocity falls below ' + HydrusData.ToHumanInt(
                death_files_found
            ) + ' files per ' + HydrusData.TimeDeltaToPrettyTimeDelta(
                death_time_delta) + '.'

        return timing_statement + os.linesep * 2 + death_statement
 def _threadDoPOSTJob( self, request: HydrusServerRequest.HydrusRequest ):
     
     update_period = request.parsed_request_args[ 'update_period' ]
     
     if update_period < HydrusNetwork.MIN_UPDATE_PERIOD:
         
         raise HydrusExceptions.BadRequestException( 'The update period was too low. It needs to be at least {}.'.format( HydrusData.TimeDeltaToPrettyTimeDelta( HydrusNetwork.MIN_UPDATE_PERIOD ) ) )
         
     
     if update_period > HydrusNetwork.MAX_UPDATE_PERIOD:
         
         raise HydrusExceptions.BadRequestException( 'The update period was too high. It needs to be lower than {}.'.format( HydrusData.TimeDeltaToPrettyTimeDelta( HydrusNetwork.MAX_UPDATE_PERIOD ) ) )
         
     
     old_update_period = self._service.GetUpdatePeriod()
     
     if old_update_period != update_period:
         
         self._service.SetUpdatePeriod( update_period )
         
         HydrusData.Print(
             'Account {} changed the update period to from "{}" to "{}".'.format(
                 request.hydrus_account.GetAccountKey().hex(),
                 HydrusData.TimeDeltaToPrettyTimeDelta( old_update_period ),
                 HydrusData.TimeDeltaToPrettyTimeDelta( update_period )
             )
         )
         
     
     response_context = HydrusServerResources.ResponseContext( 200 )
     
     return response_context
示例#3
0
def CheckCanVacuum( db_path, stop_time = None ):
    
    db = sqlite3.connect( db_path, isolation_level = None, detect_types = sqlite3.PARSE_DECLTYPES )
    
    c = db.cursor()
    
    ( page_size, ) = c.execute( 'PRAGMA page_size;' ).fetchone()
    ( page_count, ) = c.execute( 'PRAGMA page_count;' ).fetchone()
    ( freelist_count, ) = c.execute( 'PRAGMA freelist_count;' ).fetchone()
    
    db_size = ( page_count - freelist_count ) * page_size
    
    if stop_time is not None:
        
        approx_vacuum_speed_mb_per_s = 1048576 * 1
        
        approx_vacuum_duration = db_size // approx_vacuum_speed_mb_per_s
        
        time_i_will_have_to_start = stop_time - approx_vacuum_duration
        
        if HydrusData.TimeHasPassed( time_i_will_have_to_start ):
            
            raise Exception( 'I believe you need about ' + HydrusData.TimeDeltaToPrettyTimeDelta( approx_vacuum_duration ) + ' to vacuum, but there is not enough time allotted.' )
            
        
    
    ( db_dir, db_filename ) = os.path.split( db_path )
    
    HydrusPaths.CheckHasSpaceForDBTransaction( db_dir, db_size )
示例#4
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.ToHumanBytes(max_allowed)

    elif bandwidth_type == HC.BANDWIDTH_TYPE_REQUESTS:

        s = HydrusData.ToHumanInt(max_allowed) + ' rqs'

    if time_delta is None:

        s += ' per month'

    else:

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

    return s
示例#5
0
def CheckCanVacuumCursor(db_path, c, stop_time=None):

    (page_size, ) = c.execute('PRAGMA page_size;').fetchone()
    (page_count, ) = c.execute('PRAGMA page_count;').fetchone()
    (freelist_count, ) = c.execute('PRAGMA freelist_count;').fetchone()

    db_size = (page_count - freelist_count) * page_size

    vacuum_estimate = int(db_size * 1.2)

    if stop_time is not None:

        approx_vacuum_speed_mb_per_s = 1048576 * 1

        approx_vacuum_duration = vacuum_estimate // approx_vacuum_speed_mb_per_s

        time_i_will_have_to_start = stop_time - approx_vacuum_duration

        if HydrusData.TimeHasPassed(time_i_will_have_to_start):

            raise Exception(
                'I believe you need about ' +
                HydrusData.TimeDeltaToPrettyTimeDelta(approx_vacuum_duration) +
                ' to vacuum, but there is not enough time allotted.')

    db_dir = os.path.dirname(db_path)

    HydrusPaths.CheckHasSpaceForDBTransaction(db_dir, vacuum_estimate)
示例#6
0
    def GetPrettyCurrentVelocity(self,
                                 file_seed_cache,
                                 last_check_time,
                                 no_prefix=False):

        if len(file_seed_cache) == 0:

            if last_check_time == 0:

                pretty_current_velocity = 'no files yet'

            else:

                pretty_current_velocity = 'no files, unable to determine velocity'

        else:

            if no_prefix:

                pretty_current_velocity = ''

            else:

                pretty_current_velocity = 'at last check, found '

            (current_files_found,
             current_time_delta) = self._GetCurrentFilesVelocity(
                 file_seed_cache, last_check_time)

            pretty_current_velocity += HydrusData.ToHumanInt(
                current_files_found
            ) + ' files in previous ' + HydrusData.TimeDeltaToPrettyTimeDelta(
                current_time_delta)

        return pretty_current_velocity
示例#7
0
    def GetBandwidthStringsAndGaugeTuples(self,
                                          bandwidth_tracker,
                                          threshold=600):

        with self._lock:

            rows = []

            rules_sorted = list(self._rules)

            def key(rule_tuple):

                (bandwidth_type, time_delta, max_allowed) = rule_tuple

                if time_delta is None:

                    return -1

                else:

                    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.TimeDeltaToPrettyTimeDelta(
                        time_delta)

                rows.append((s, (usage, max_allowed)))

            return rows
示例#8
0
    def _ConvertExportFolderToListCtrlTuples(
            self, export_folder: ClientExporting.ExportFolder):

        (name, path, export_type, delete_from_client_after_export,
         file_search_context, run_regularly, period, phrase, last_checked,
         paused, run_now) = export_folder.ToTuple()

        if export_type == HC.EXPORT_FOLDER_TYPE_REGULAR:

            pretty_export_type = 'regular'

        elif export_type == HC.EXPORT_FOLDER_TYPE_SYNCHRONISE:

            pretty_export_type = 'synchronise'

        if delete_from_client_after_export:

            pretty_export_type += ' and deleting from the client!'

        pretty_file_search_context = ', '.join(
            predicate.ToString(with_count=False)
            for predicate in file_search_context.GetPredicates())

        if run_regularly:

            pretty_period = HydrusData.TimeDeltaToPrettyTimeDelta(period)

        else:

            pretty_period = 'not running regularly'

        if run_now:

            pretty_period += ' (running after dialog ok)'

        if paused:

            pretty_paused = 'yes'

        else:

            pretty_paused = ''

        pretty_phrase = phrase

        last_error = export_folder.GetLastError()

        display_tuple = (name, path, pretty_export_type,
                         pretty_file_search_context, pretty_paused,
                         pretty_period, pretty_phrase, last_error)

        sort_tuple = (name, path, pretty_export_type,
                      pretty_file_search_context, paused, period, phrase,
                      last_error)

        return (display_tuple, sort_tuple)
示例#9
0
    def _RefreshLabel(self):

        value = self._value

        if value is None:

            text = 'monthly'

        else:

            text = HydrusData.TimeDeltaToPrettyTimeDelta(value)

        self.setText(text)
示例#10
0
    def _threadDoPOSTJob(self, request: HydrusServerRequest.HydrusRequest):

        nullification_period = request.parsed_request_args[
            'nullification_period']

        if nullification_period < HydrusNetwork.MIN_NULLIFICATION_PERIOD:

            raise HydrusExceptions.BadRequestException(
                'The anonymisation period was too low. It needs to be at least {}.'
                .format(
                    HydrusData.TimeDeltaToPrettyTimeDelta(
                        HydrusNetwork.MIN_NULLIFICATION_PERIOD)))

        if nullification_period > HydrusNetwork.MAX_NULLIFICATION_PERIOD:

            raise HydrusExceptions.BadRequestException(
                'The anonymisation period was too high. It needs to be lower than {}.'
                .format(
                    HydrusData.TimeDeltaToPrettyTimeDelta(
                        HydrusNetwork.MAX_NULLIFICATION_PERIOD)))

        old_nullification_period = self._service.GetNullificationPeriod()

        if old_nullification_period != nullification_period:

            self._service.SetNullificationPeriod(nullification_period)

            HydrusData.Print(
                'Account {} changed the anonymisation period to from "{}" to "{}".'
                .format(
                    request.hydrus_account.GetAccountKey().hex(),
                    HydrusData.TimeDeltaToPrettyTimeDelta(
                        old_nullification_period),
                    HydrusData.TimeDeltaToPrettyTimeDelta(
                        nullification_period)))

        response_context = HydrusServerResources.ResponseContext(200)

        return response_context
示例#11
0
    def GetDueString(self):

        due_delta = self._next_work_time - HydrusData.GetNowFloat()

        due_string = HydrusData.TimeDeltaToPrettyTimeDelta(due_delta)

        if due_delta < 0:

            due_string = 'was due {} ago'.format(due_string)

        else:

            due_string = 'due in {}'.format(due_string)

        return due_string
示例#12
0
 def _ConvertDataToListCtrlTuples( self, mapping ):
     
     ( description, internal_ip, internal_port, external_port, protocol, duration ) = mapping
     
     if duration == 0:
         
         pretty_duration = 'indefinite'
         
     else:
         
         pretty_duration = HydrusData.TimeDeltaToPrettyTimeDelta( duration )
         
     
     display_tuple = ( description, internal_ip, str( internal_port ), str( external_port ), protocol, pretty_duration )
     sort_tuple = mapping
     
     return ( display_tuple, sort_tuple )
示例#13
0
    def _UpdateAutoCreationHistoryText(self):

        (accounts_per_time_delta,
         time_delta) = self._auto_create_velocity_control.GetValue()

        text = ''

        if accounts_per_time_delta == 0:

            text = 'Auto-creation disabled. '

        num_created = self._auto_create_history.GetUsage(
            HC.BANDWIDTH_TYPE_DATA, time_delta)

        text += '{} auto-created in the past {}.'.format(
            HydrusData.ToHumanInt(num_created),
            HydrusData.TimeDeltaToPrettyTimeDelta(time_delta))

        self._auto_create_history_st.setText(text)
    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.ToHumanBytes(max_allowed)

        elif bandwidth_type == HC.BANDWIDTH_TYPE_REQUESTS:

            pretty_max_allowed = HydrusData.ToHumanInt(
                max_allowed) + ' requests'

        sort_time_delta = ClientGUIListCtrl.SafeNoneInt(time_delta)

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

        return (display_tuple, sort_tuple)
示例#15
0
def CheckCanVacuumData(db_path,
                       page_size,
                       page_count,
                       freelist_count,
                       stop_time=None):

    db_size = (page_count - freelist_count) * page_size

    if stop_time is not None:

        approx_vacuum_duration = GetApproxVacuumDuration(db_size)

        time_i_will_have_to_start = stop_time - approx_vacuum_duration

        if HydrusData.TimeHasPassed(time_i_will_have_to_start):

            raise Exception(
                'I believe you need about ' +
                HydrusData.TimeDeltaToPrettyTimeDelta(approx_vacuum_duration) +
                ' to vacuum, but there is not enough time allotted.')

    db_dir = os.path.dirname(db_path)

    HydrusDBBase.CheckHasSpaceForDBTransaction(db_dir, db_size)
示例#16
0
    def finish(self):

        HydrusRequest.finish(self)

        host = self.getHost()

        if self.hydrus_response_context is not None:

            status_text = str(self.hydrus_response_context.GetStatusCode())

        elif hasattr(self, 'code'):

            status_text = str(self.code)

        else:

            status_text = '200'

        message = str(host.port) + ' ' + str(self.method, 'utf-8') + ' ' + str(
            self.path, 'utf-8'
        ) + ' ' + status_text + ' in ' + HydrusData.TimeDeltaToPrettyTimeDelta(
            HydrusData.GetNowPrecise() - self.start_time)

        HydrusData.Print(message)
示例#17
0
    def AnalyzeDueTables(self,
                         maintenance_mode=HC.MAINTENANCE_FORCED,
                         stop_time=None,
                         force_reanalyze=False):

        names_to_analyze = self.GetTableNamesDueAnalysis(
            force_reanalyze=force_reanalyze)

        if len(names_to_analyze) > 0:

            job_key = ClientThreading.JobKey(maintenance_mode=maintenance_mode,
                                             cancellable=True)

            try:

                job_key.SetStatusTitle('database maintenance - analyzing')

                HG.client_controller.pub('modal_message', job_key)

                random.shuffle(names_to_analyze)

                for name in names_to_analyze:

                    HG.client_controller.frame_splash_status.SetText(
                        'analyzing ' + name)
                    job_key.SetVariable('popup_text_1', 'analyzing ' + name)

                    time.sleep(0.02)

                    started = HydrusData.GetNowPrecise()

                    self.AnalyzeTable(name)

                    time_took = HydrusData.GetNowPrecise() - started

                    if time_took > 1:

                        HydrusData.Print(
                            'Analyzed ' + name + ' in ' +
                            HydrusData.TimeDeltaToPrettyTimeDelta(time_took))

                    p1 = HG.client_controller.ShouldStopThisWork(
                        maintenance_mode, stop_time=stop_time)
                    p2 = job_key.IsCancelled()

                    if p1 or p2:

                        break

                self._Execute(
                    'ANALYZE sqlite_master;'
                )  # this reloads the current stats into the query planner

                job_key.SetVariable('popup_text_1', 'done!')

                HydrusData.Print(job_key.ToString())

            finally:

                job_key.Finish()

                job_key.Delete(10)
示例#18
0
    def GetPrettyMediaLine(self):

        return 'viewed ' + HydrusData.ToHumanInt(
            self.media_views
        ) + ' times in media viewer, totalling ' + HydrusData.TimeDeltaToPrettyTimeDelta(
            self.media_viewtime)
示例#19
0
    def GetPrettyCombinedLine(self):

        return 'viewed ' + HydrusData.ToHumanInt(
            self.media_views + self.preview_views
        ) + ' times, totalling ' + HydrusData.TimeDeltaToPrettyTimeDelta(
            self.media_viewtime + self.preview_viewtime)
示例#20
0
    def GetPrettyPreviewLine(self):

        return 'viewed ' + HydrusData.ToHumanInt(
            self.preview_views
        ) + ' times in preview window, totalling ' + HydrusData.TimeDeltaToPrettyTimeDelta(
            self.preview_viewtime)
示例#21
0
 def _ShowCogMenu( self ):
     
     menu = QW.QMenu()
     
     if self._network_job is not None and self._network_job.engine is not None:
         
         url = self._network_job.GetURL()
         
         ClientGUIMenus.AppendMenuLabel( menu, url, description = 'copy URL to the clipboard' )
         
         ClientGUIMenus.AppendSeparator( menu )
         
         network_contexts = self._network_job.GetNetworkContexts()
         
         if len( network_contexts ) > 0:
             
             bandwidth_manager = self._network_job.engine.bandwidth_manager
             
             submenu = QW.QMenu( menu )
             
             menu_network_contexts = []
             
             network_contexts_used = set()
             
             for network_context in network_contexts:
                 
                 uses_default = False
                 
                 if bandwidth_manager.UsesDefaultRules( network_context ):
                     
                     uses_default = True
                     
                     default_network_context = network_context.GetDefault()
                     
                     if default_network_context not in network_contexts_used:
                         
                         menu_network_contexts.append( ( False, default_network_context, network_context ) )
                         
                         network_contexts_used.add( default_network_context )
                         
                     
                 
                 if not network_context.IsEphemeral():
                     
                     menu_network_contexts.append( ( uses_default, network_context, network_context ) )
                     
                 
             
             for ( uses_default, network_context_to_edit, network_context_to_test ) in menu_network_contexts:
                 
                 network_context_text = network_context_to_edit.ToString()
                 
                 if uses_default:
                     
                     network_context_text = 'set rules for {}'.format( network_context_text )
                     
                 else:
                     
                     ( waiting_estimate, gumpf ) = bandwidth_manager.GetWaitingEstimateAndContext( [ network_context_to_test ] )
                     
                     if waiting_estimate > 0:
                         
                         network_context_text = '{} ({})'.format( network_context_text, HydrusData.TimeDeltaToPrettyTimeDelta( waiting_estimate ) )
                         
                     
                 
                 ClientGUIMenus.AppendMenuItem( submenu, network_context_text, 'edit the bandwidth rules for this network context', self._EditBandwidthRules, network_context_to_edit )
                 
             
             ClientGUIMenus.AppendMenu( menu, submenu, 'edit bandwidth rules' )
             
             ClientGUIMenus.AppendSeparator( menu )
             
         
         if self._network_job.CurrentlyWaitingOnConnectionError():
             
             ClientGUIMenus.AppendMenuItem( menu, 'reattempt connection now', 'Stop waiting on a connection error and reattempt the job now.', self._network_job.OverrideConnectionErrorWait )
             
         
         if not self._network_job.DomainOK():
             
             ClientGUIMenus.AppendMenuItem( menu, 'scrub domain errors', 'Clear recent domain errors and allow this job to go now.', self._network_job.ScrubDomainErrors )
             
         
         if self._network_job.CurrentlyWaitingOnServersideBandwidth():
             
             ClientGUIMenus.AppendMenuItem( menu, 'reattempt request now (server reports low bandwidth)', 'Stop waiting on a serverside bandwidth delay and reattempt the job now.', self._network_job.OverrideServersideBandwidthWait )
             
         
         if self._network_job.ObeysBandwidth():
             
             ClientGUIMenus.AppendMenuItem( menu, 'override bandwidth rules for this job', 'Tell the current job to ignore existing bandwidth rules and go ahead anyway.', self._network_job.OverrideBandwidth )
             
         
         if not self._network_job.TokensOK():
             
             ClientGUIMenus.AppendMenuItem( menu, 'override forced gallery wait times for this job', 'Force-allow this download to proceed, ignoring the normal gallery wait times.', self._network_job.OverrideToken )
             
         
         ClientGUIMenus.AppendSeparator( menu )
         
     
     ClientGUIMenus.AppendMenuCheckItem( menu, 'auto-override bandwidth rules for all jobs here after five seconds', 'Ignore existing bandwidth rules for all jobs under this control, instead waiting a flat five seconds.', self._auto_override_bandwidth_rules, self.FlipAutoOverrideBandwidth )
     
     CGC.core().PopupMenu( self._cog_button, menu )
示例#22
0
    def __repr__(self):

        return repr(self.__class__) + ': ' + repr(
            self._work_callable
        ) + ' next in ' + HydrusData.TimeDeltaToPrettyTimeDelta(
            self._next_work_time - HydrusData.GetNowFloat())
示例#23
0
    def ToString(self):

        if self._command_type == APPLICATION_COMMAND_TYPE_SIMPLE:

            action = self.GetSimpleAction()

            s = simple_enum_to_str_lookup[action]

            if action == SIMPLE_MEDIA_SEEK_DELTA:

                (direction, ms) = self.GetSimpleData()

                direction_s = 'back' if direction == -1 else 'forwards'

                ms_s = HydrusData.TimeDeltaToPrettyTimeDelta(ms / 1000)

                s = '{} ({} {})'.format(s, direction_s, ms_s)

            return s

        elif self._command_type == APPLICATION_COMMAND_TYPE_CONTENT:

            (service_key, content_type, action, value) = self._data

            components = []

            components.append(HC.content_update_string_lookup[action])
            components.append(HC.content_type_string_lookup[content_type])

            value_string = ''

            if content_type == HC.CONTENT_TYPE_RATINGS:

                if action in (HC.CONTENT_UPDATE_SET, HC.CONTENT_UPDATE_FLIP):

                    value_string = 'uncertain rating, "{}"'.format(value)

                    if HG.client_controller is not None and HG.client_controller.IsBooted(
                    ):

                        try:

                            service = HG.client_controller.services_manager.GetService(
                                service_key)

                            value_string = service.ConvertRatingToString(value)

                        except HydrusExceptions.DataMissing:

                            pass

                else:

                    value_string = ''  # only 1 up/down allowed atm

            elif content_type == HC.CONTENT_TYPE_FILES and action == HC.CONTENT_UPDATE_MOVE and value is not None:

                try:

                    from_name = HG.client_controller.services_manager.GetName(
                        value)

                    value_string = '(from {})'.format(from_name)

                except:

                    value_string = ''

            elif value is not None:

                value_string = '"{}"'.format(value)

            if len(value_string) > 0:

                components.append(value_string)

            if content_type == HC.CONTENT_TYPE_FILES:

                components.append('to')

            else:

                components.append('for')

            services_manager = HG.client_controller.services_manager

            if services_manager.ServiceExists(service_key):

                service = services_manager.GetService(service_key)

                components.append(service.GetName())

            else:

                components.append('unknown service!')

            return ' '.join(components)