def _run_daily(self, list_of_mirrors=None, cache_size=20): """Pings the provided mirrors and handles post-ping operations. This function pings the provided operations and handles the following post-ping operations: Saves to cache: the cache will be used on daily scans. Adds to blacklist: mirrors that will be added to blacklist will not be pinged on daily scans. Switches to fastest mirror: sets the fastest mirror as the default upstream mirror. :param list_of_mirrors: the mirrors that should be pinged. (list) :param cache_size: the size of the mirrors to be saved in cache. (int) :returns sorted_mirrors: the result of the ping operation. (dict) """ if not list_of_mirrors: list_of_mirrors = self._list_of_mirrors pinger = FastestMirrors() pinger.sort_mirrors_by_ping_avg(mirrors=list_of_mirrors) sorted_mirrors = pinger.sorted_mirrors cache = CacheManager(fastest_mirrors=pinger, cache_size=cache_size) cache.set_cached_mirrors_from_list() cache.save() self._parser.switch_to_fastest_mirror( mirror=next(iter(cache.cache_mirrors.keys()))) return sorted_mirrors
def daily_scan(self, cache_size=20, max_mirror_ping_avg=1.0): """Pings the cache file and handles post-ping operations. This function loads the cached mirrors from the cache file and do the following operations: Calls run_daily() function to ping and handle post-ping operations. Saves all the mirrors to file. In case there is no cache file or the cache file contains less mirrors than the half of the provided cache size, it calls a full run again. :param parser: the parser that will be used. (Parser-like class) :param cache_size: the size of the mirrors to be saved in cache. (int) """ logger.debug('daily scan') if not path.exists(CACHED_MIRRORS_FILE_NAME) or self._file_len( CACHED_MIRRORS_FILE_NAME) < int(cache_size) / 2: logger.debug( 'There was not a cached mirrors file, or number of cached mirrors' ' entries was less than half of the given cache_size') self.full_scan() else: cache = CacheManager(fastest_mirrors=FastestMirrors(), cache_size=cache_size) cache.load(max_mirror_ping_time=max_mirror_ping_avg) self._run_daily(cache.cache_mirrors.keys(), cache_size=cache_size)
def __init__(self): from db import ConnectionManager self.connection_manager = ConnectionManager(XConfig.get('db')) self.cache_manager = CacheManager(XConfig.get('cache')) self.entity_list = {} self.use_cache = False self.use_preload = True self.use_validator = False self.bad_entitys = []
def __init__(self): assert not Project._singleton Project._singleton = self self.path = None self.cacheManager = CacheManager() self.assetLibrary = AssetLibrary() self.info = {'name': 'Name', 'author': 'author', 'version': '1.0.0'} self.config = {}
def __init__(self): assert not Project._singleton Project._singleton = self self.cacheManager = CacheManager() self.assetLibrary = AssetLibrary() self.path = None self.editorPath = None self.editorLuaPath = None self.gamePath = None self.info = None self.config = None
def __init__(self, port, pluginUUID, registerEvent, info, loop, process_manager, os_manager, cache_manager=CacheManager()): self.port = port self.pluginUUID = pluginUUID self.registerEvent = registerEvent self.info = info self.loop = loop self.process_manager = process_manager self.cache_manager = cache_manager self.os_manager = os_manager
# -*- coding : utf-8 -*- import sys from subprocess import CalledProcessError from cache import CacheManager from processor import SSHAuthFileProcessor from handler import SSHAuthEventHandler from watcher import SSHAuthWatcher from env import AUTH_LOG_FILE_PATH if __name__ == "__main__": try: cache = CacheManager() processor = SSHAuthFileProcessor(AUTH_LOG_FILE_PATH, cache=cache) handler = SSHAuthEventHandler(processor) SSHAuthWatcher(AUTH_LOG_FILE_PATH, handler).run() except CalledProcessError: print('Cannot fetch the last line') sys.exit(1)
class CacheHandler: cache = CacheManager()