def updateSource(source=None): """ 更新源 Args: source(str): 源 Returns: `None` """ global configData if source == None: if configData == None: loadConfig() source = configData['source'] sourceFile = pathmanager.getConfigPath(SOURCE_FILE_NAME) mkConfigDir() packages = {"version": "v0.0.1", "name": "espm packages", "packages": []} if configData == None: loadConfig() logging.info("update source form %s", source) packages['packages'] = pm.getPackages(source) with open(sourceFile, 'w') as f: f.write(json.dumps(packages, indent=4))
def getSource(): """ 获取默认源 Returns: str: 默认源 """ global configData sourceFile = pathmanager.getConfigPath(SOURCE_FILE_NAME) mkConfigDir() if not os.path.isfile(sourceFile): updateSource() return sourceFile
def loadConfig(): """ 加载配置 Returns: `None` """ global configData configFile = pathmanager.getConfigPath(CONFIG_FILE_NAME) mkConfigDir() if not os.path.isfile(configFile): with open(configFile, 'w', encoding='utf-8') as f: f.write(DEFAULT_CONFIG) with open(configFile, 'r', encoding='utf-8') as f: configData = json.loads(f.read())
def updateConfig(key, value): """ 更新配置项 Args: key(str): key value(Any): value Returns: `None` """ global configData if configData == None: loadConfig() configData[key] = value configFile = pathmanager.getConfigPath(CONFIG_FILE_NAME) with open(configFile, 'w', encoding='utf-8') as f: f.write(json.dumps(configData, indent=4))