def __init__(self, name:str, dirPath:str): self.__testData = jk_json.loadFromFile(dirPath + "/testData.jsonc") self.__expectedOutput = jk_json.loadFromFile(dirPath + "/expectedOutput.jsonc") self.__scmgr = jk_jsoncfghelper2.loadFromXMLFile(dirPath + "/definition.xml") self.__checker = self.__scmgr.get("main") assert self.__checker is not None self.__name = name
def tryLoad(dirPath: str, log: jk_logging.AbstractLogger = None): pypinexInfoFilePath = os.path.join(dirPath, "pypinex_info.json") if not os.path.isfile(pypinexInfoFilePath): return None moduleName = os.path.basename(dirPath) try: jData = jk_json.loadFromFile(pypinexInfoFilePath) except Exception as ee: if log: log.error(ee) return None # check format try: if not jData["magic"]["magic"] == "pypinex-info": raise Exception() if jData["magic"]["version"] != 1: raise Exception() except Exception as ee: if log: log.error("Not a valid PyPine extension file!") return None # create instance of PyPineXModuleInfo return PyPineXModuleInfo(dirPath, jData)
def getSMWVersion(self) -> typing.Union[jk_version.Version, None]: p = os.path.join(self.__wikiInstDirPath, "extensions", "SemanticMediaWiki", "extension.json") if os.path.isfile(p): j = jk_json.loadFromFile(p) return jk_version.Version(j["version"]) return None
def getObjectE(self, clazz: type, identifier: str): assert clazz is not None cr = self.__classRecords[clazz.__name__] filePath = os.path.join(cr.dirPath, identifier + ".json") obj = self.__objCache[clazz.__name__].get(identifier) if obj is not None: t = int(os.path.getmtime(filePath)) if (obj is None) or (obj._x_timeStamp != t): if not os.path.exists(filePath): raise Exception("Object of type " + repr(clazz) + " identified by " + repr(identifier) + " does not exists!") jData = jk_json.loadFromFile(filePath) obj = cr.clazz() obj.deserialize(cr.ctx, jData) obj._x_identifier = identifier obj._x_persisteer = self obj._x_isModified = False obj._x_timeStamp = t return obj
def loadFromFile(filePath: str): assert isinstance(filePath, str) jData = jk_json.loadFromFile(filePath) ret = UploadedBackupInfoFile() ret._loadFromJSON(jData) return ret
def loadFromFile(filePath: str): assert isinstance(filePath, str) jData = jk_json.loadFromFile(filePath) ret = ServerBackupUploadInfo() ret._loadFromJSON(jData) return ret
def loadFromFile(filePath: str): assert isinstance(filePath, str) jData = jk_json.loadFromFile(filePath) ret = ThaniyaClientCfg() ret._loadFromJSON(jData) return ret
def loadFromFile(filePath: str): assert isinstance(filePath, str) jData = jk_json.loadFromFile(filePath) ret = ExampleCfg() ret._loadFromJSON(jData) return ret
def loadFromDir(extensionDirPath:str): extFilePath = os.path.join(extensionDirPath, "extension.json") if not os.path.isfile(extFilePath): raise Exception("Not an extension directory: " + extensionDirPath) jExtCfg = jk_json.loadFromFile(extFilePath) if ("name" not in jExtCfg) or (jExtCfg.get("manifest_version") is None) or (jExtCfg.get("manifest_version") < 1): raise Exception("Not an extension: " + extensionDirPath) return MediaWikiExtensionInfo(extensionDirPath, jExtCfg)
def loadFromDir(skinDirPath: str): cfgFilePath = os.path.join(skinDirPath, "skin.json") if not os.path.isfile(cfgFilePath): raise Exception("Not a skin directory: " + skinDirPath) jSkinCfg = jk_json.loadFromFile(cfgFilePath) if (not jSkinCfg.get("name")) or (jSkinCfg.get("type") != "skin") or ( jSkinCfg.get("manifest_version") != 1): raise Exception("Not a skin: " + skinDirPath) return MediaWikiSkinInfo(skinDirPath, jSkinCfg)
def getObject(self, clazz: type, identifier: str): assert clazz is not None obj = self.__objCache[clazz.__name__].get(identifier) if obj is None: cr = self.__classRecords[clazz.__name__] filePath = os.path.join(cr.dirPath, identifier + ".json") if not os.path.exists(filePath): return None jData = jk_json.loadFromFile(filePath) obj = cr.clazz() obj.deserialize(cr.ctx, jData) obj._x_identifier = identifier obj._x_persisteer = self obj._x_isModified = False obj._x_timeStamp = int(os.path.getmtime(filePath)) return obj
def loadFromFile(filePath: str): assert isinstance(filePath, str) jData = jk_json.loadFromFile(filePath) return ThaniyaBackupStats.loadFromJSON(jData)
#!/usr/bin/env python3 import jk_json FILE_NAME = "test-relaxed.json" jData = jk_json.loadFromFile(FILE_NAME) print("=" * 160) jk_json.prettyPrint(jData) print("=" * 160) text = jk_json.prettyPrintToStr(jData) jData2 = jk_json.loads(text) print("Parsing again succeeded.")
try: while True: cmdName, cmdArgs = parsedArgs.parseNextCommand() if cmdName is None: bSuccess = True break if cmdName == "stdin": line = sys.stdin.readline() jsonData = json.loads(line) continue if cmdName == "load": jsonData = jk_json.loadFromFile(cmdArgs[0]) continue if cmdName == "save": if jsonData is None: raise Exception("No data loaded!") jk_json.saveToFile(jsonData, cmdArgs[0]) continue if cmdName == "savePretty": if jsonData is None: raise Exception("No data loaded!") jk_json.saveToFilePretty(jsonData, cmdArgs[0]) continue if cmdName == "prettyPrint":
if len(parsedArgs.programArgs) == 0: ap.showHelp() sys.exit(1) bVerbose = parsedArgs.optionData["bVerbose"] if bVerbose: log.notice("Verbose output mode: enabled") # load configuration: merge it with specified arguments ctx = jk_mediawiki.MWManagementCtx() if bVerbose: log.notice("Loading: " + ctx.cfgFilePath) if os.path.isfile(ctx.cfgFilePath): cfg = jk_json.loadFromFile(ctx.cfgFilePath) else: raise Exception( "No configuration file: '~/.config/wikilocalctrl.json'") if bVerbose: log.notice("Verifying configuration ...") for key in ["wwwWikiRootDir", "httpBinDir"]: if (key in parsedArgs.optionData) and (parsedArgs.optionData[key] is not None): cfg[key] = parsedArgs.optionData[key] for key in ["wwwWikiRootDir", "httpBinDir"]: if not os.path.isdir(cfg[key]): raise Exception(key + ": Directory does not exist: " + repr(cfg[key])) localMediaWikisMgr = jk_mediawiki.LocalMediaWikisMgr(
if parsedArgs.optionData["color"]: log = jk_logging.ConsoleLogger.create( logMsgFormatter=jk_logging.COLOR_LOG_MESSAGE_FORMATTER, printToStdErr=True) else: log = jk_logging.ConsoleLogger.create(printToStdErr=True) bSuccess = True if parsedArgs.optionData["stdin"]: line = sys.stdin.readline() jsonData = json.loads(line) else: for filePath in parsedArgs.programArgs: jsonData = jk_json.loadFromFile(filePath) extractionPath = parsedArgs.optionData.get("extractionPath") if extractionPath: assert isinstance(extractionPath, jk_flexdata.FlexDataSelector) _, result = extractionPath.getOne(jk_flexdata.FlexObject(jsonData)) jsonData = result if isinstance(jsonData, jk_flexdata.FlexObject): jsonData = jsonData._toDict() if isinstance(jsonData, str): retLine = "-" * 160 ret2 = jsonData.encode("utf-8").decode('unicode_escape') print("\n".join([retLine, ret2, retLine])) else: jk_json.prettyPrint(jsonData)
import os import jk_json import jk_pwdinput import jk_json from jk_mediawikiapi import * if os.path.isfile("constants.local.json"): cfg = jk_json.loadFromFile("constants.local.json") elif os.path.isfile("constants.local.jsonc"): cfg = jk_json.loadFromFile("constants.local.jsonc") else: raise Exception( "Configuration file required: 'constants.local.json' or 'constants.local.jsonc'" ) URL = cfg["url"] WIKI_USER_NAME = cfg["user"] if ("pwd" in cfg) and cfg["pwd"]: WIKI_PASSWORD = cfg["pwd"] else: WIKI_PASSWORD = jk_pwdinput.readpwd("Password for wiki user " + repr(WIKI_USER_NAME) + ": ") OTHER_USER = cfg["someOtherUser"] if "someOtherUserPwd" in cfg: OTHER_USER_PASSWORD = cfg["someOtherUserPwd"] else: OTHER_USER_PASSWORD = jk_pwdinput.readpwd("Password for wiki user " +
def loadSystemConfiguration(self) -> dict: if os.path.isfile(self.systemCfgFilePath): return jk_json.loadFromFile(self.systemCfgFilePath) else: return None