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
class Project(object): _singleton = None @staticmethod def get(): return Project._singleton 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 _initPath(self, path): self.path = path self.editorPath = path + '/' + _PROJECT_EDITOR_DIR self.editorLuaPath = self.editorPath + '/' + _PROJECT_LUA_DIR self.gamePath = path + '/' + _PROJECT_LUA_DIR def _affirmDirectories(self): _affirmPath(self.gamePath) def isLoaded(self): return self.path != None def init(self, path): signals.emitNow('project.init', self) # self.assetLibrary.load( _GII_ASSET_DIR, self.assetPath, self.path, self.envConfigPath ) def load(self, path): if not path: path = self.path if not self.path: return False if not os.path.exists(path + '/' + _PROJECT_INFO_FILE): return False self._initPath(path) self._affirmDirectories() self.info = jsonHelper.tryLoadJSON( self.getBasePath(_PROJECT_INFO_FILE)) if not os.path.exists(self.editorPath): os.makedirs(self.editorPath) self.config = jsonHelper.tryLoadJSON( self.getBasePath(_PROJECT_EDITOR_DIR + '/' + _PROJECT_CONFIG_FILE)) if not self.config: self.config = {} self.saveConfig() # self.cacheManager.load( _GII_ENV_CONFIG_DIR, self.envConfigPath ) # self.assetLibrary.load( _GII_ASSET_DIR, self.assetPath, self.path, self.envConfigPath ) self.loaded = True signals.emitNow('project.preload', self) signals.emitNow('project.load', self) return True def save(self): signals.emitNow('project.presave', self) if self.getBasePath(): jsonHelper.trySaveJSON(self.info, self.getBasePath(_PROJECT_INFO_FILE)) #save asset & cache self.assetLibrary.save() self.cacheManager.clearFreeCacheFiles() self.cacheManager.save() signals.emitNow('project.save', self) return True def saveConfig(self): if self.getBasePath(): jsonHelper.trySaveJSON( self.config, self.getBasePath(_PROJECT_EDITOR_DIR + '/' + _PROJECT_CONFIG_FILE)) def getPath(self, path=None): return self.getBasePath(path) def getBasePath(self, path=None): if path is None: return self.path return os.path.join(self.path, path) ##----------------------------------------------------------------## def getConfigDict(self): return self.config def getConfig(self, key, default=None): if self.config != None: return self.config.get(key, default) return default def setConfig(self, key, value): if self.config != None: self.config[key] = value ##----------------------------------------------------------------## def getEditorLuaPath(self): if self.editorLuaPath: if os.path.exists(self.editorLuaPath): return self.editorLuaPath return None def getEditorAssetsPath(self): return self.editorPath + '/' + _PROJECT_ASSETS_DIR ##----------------------------------------------------------------## def getAssetLibrary(self): return self.assetLibrary def loadAssetLibrary(self): #load cache & assetlib self.assetLibrary.loadAssetTable()
class Project(object): _singleton=None @staticmethod def get(): return Project._singleton 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 _initPath( self, path ): self.path = path self.editorPath = path + '/' + _PROJECT_EDITOR_DIR self.editorLuaPath = self.editorPath + '/' + _PROJECT_LUA_DIR self.gamePath = path + '/' + _PROJECT_LUA_DIR def _affirmDirectories( self ): _affirmPath( self.gamePath ) def isLoaded( self ): return self.path != None def init(self, path): signals.emitNow('project.init', self) # self.assetLibrary.load( _GII_ASSET_DIR, self.assetPath, self.path, self.envConfigPath ) def load(self, path): if not path: path = self.path if not self.path: return False if not os.path.exists( path + '/' + _PROJECT_INFO_FILE ): return False self._initPath( path ) self._affirmDirectories() self.info = jsonHelper.tryLoadJSON( self.getBasePath( _PROJECT_INFO_FILE ) ) if not os.path.exists( self.editorPath ): os.makedirs( self.editorPath ) self.config = jsonHelper.tryLoadJSON( self.getBasePath( _PROJECT_EDITOR_DIR + '/' + _PROJECT_CONFIG_FILE ) ) if not self.config: self.config = {} self.saveConfig() # self.cacheManager.load( _GII_ENV_CONFIG_DIR, self.envConfigPath ) # self.assetLibrary.load( _GII_ASSET_DIR, self.assetPath, self.path, self.envConfigPath ) self.loaded = True signals.emitNow( 'project.preload', self ) signals.emitNow( 'project.load', self ) return True def save(self): signals.emitNow('project.presave', self) if self.getBasePath(): jsonHelper.trySaveJSON( self.info, self.getBasePath( _PROJECT_INFO_FILE ) ) #save asset & cache self.assetLibrary.save() self.cacheManager.clearFreeCacheFiles() self.cacheManager.save() signals.emitNow( 'project.save', self ) return True def saveConfig( self ): if self.getBasePath(): jsonHelper.trySaveJSON( self.config, self.getBasePath( _PROJECT_EDITOR_DIR + '/' + _PROJECT_CONFIG_FILE )) def getPath( self, path = None ): return self.getBasePath( path ) def getBasePath( self, path = None ): if path is None: return self.path return os.path.join( self.path, path ) ##----------------------------------------------------------------## def getConfigDict( self ): return self.config def getConfig( self, key, default = None ): if self.config != None: return self.config.get( key, default ) return default def setConfig( self, key, value ): if self.config != None: self.config[ key ] = value ##----------------------------------------------------------------## def getEditorLuaPath( self ): if self.editorLuaPath: if os.path.exists( self.editorLuaPath ): return self.editorLuaPath return None def getEditorAssetsPath( self ): return self.editorPath + '/' + _PROJECT_ASSETS_DIR ##----------------------------------------------------------------## def getAssetLibrary( self ): return self.assetLibrary def loadAssetLibrary( self ): #load cache & assetlib self.assetLibrary.loadAssetTable()