Exemplo n.º 1
0
 def __init__(self, uDefinitionName, oDefinitions):
     self.dDefinitionSettingsJSON = OrderedDict()
     self.aDefinitionsSettings = []
     self.oDefinitionVars = cDefinitionVars()
     self.oDefinitionVarsFromParent = cDefinitionVars()
     self.bImportActions = False
     self.bImportLanguages = False
     self.bImportPages = False
     self.bImportSettings = False
     self.bLoadedCached = False
     self.fRatio = 1.0
     self.fRationX = 1.0
     self.fRationY = 1.0
     self.iDefMaxX = 1
     self.iDefMaxY = 1
     self.iFontSize_Button = 200
     self.iFontSize_File = 200
     self.iFontSize_Text = 200
     self.iGapX = 0
     self.iGapY = 0
     self.oDefinitionPathes = Globals.dDefinitionPathes.get(
         uDefinitionName, cDefinitionPathes(uDefinitionName))
     self.oDefinitions = oDefinitions
     self.oET_Root = None
     self.oRepManEntry = None
     self.oTree = None
     self.sET_Data = ''
     self.uAlias = u''
     self.uDefaultFont = u''
     self.uDefDescription = u''
     self.uDefPublicTitle = u''
     self.uName = uDefinitionName
     self.uParentDefinitionName = u''
Exemplo n.º 2
0
 def __init__(self, *, uDefinitionName: str, oDefinitions: cDefinitions):
     self.dDefinitionSettingsJSON: OrderedDict = OrderedDict()
     self.aDefinitionsSettings: List[Dict] = []
     self.oDefinitionVars: cDefinitionVars = cDefinitionVars()
     self.oDefinitionVarsFromParent: cDefinitionVars = cDefinitionVars()
     self.bImportActions: bool = False
     self.bImportLanguages: bool = False
     self.bImportPages: bool = False
     self.bImportSettings: bool = False
     self.bLoadedCached: bool = False
     self.fRatio: float = 1.0
     self.fRationX: float = 1.0
     self.fRationY: float = 1.0
     self.iDefMaxX: int = 1
     self.iDefMaxY: int = 1
     self.uFontSize_Button: str = u'200'
     self.uFontSize_File: str = u'200'
     self.uFontSize_Text: str = u'200'
     self.iGapX: int = 0
     self.iGapY: int = 0
     self.oDefinitionPathes: cDefinitionPathes = Globals.dDefinitionPathes.get(
         uDefinitionName,
         cDefinitionPathes(uDefinitionName=uDefinitionName))
     self.oDefinitions = oDefinitions
     self.oET_Root: Optional[Element] = None
     self.oRepManEntry: Optional[cRepManagerEntry] = None
     self.sET_Data: str = ''
     self.uAlias: str = u''
     self.uDefaultFont: str = u''
     self.uDefDescription: str = u''
     self.uDefPublicTitle: str = u''
     self.uName: str = uDefinitionName
     self.uParentDefinitionName: str = u''
Exemplo n.º 3
0
def orca_et_loader(
        uFile: str,
        uParse: str,
        uEncoding: str = "xml",
        oReplacementVars: Optional[cDefinitionVars] = None) -> List[Element]:
    """Custom Loader for ElementTree Include to add definition path to includes
        and to make make bulk include using placeholder possible
    """

    aRet: List[Element] = []
    aFiles: List[cFileName] = []
    oFn: cFileName
    uRaw: str
    oFnLoad: cFileName
    oFnLoadFileRedirect: Union[cFileName, None]
    uBaseName: str
    oFn: cFileName
    oElement: Element
    uFnFileShort: str

    if oReplacementVars is None:
        oReplacementVars = cDefinitionVars()

    if "*" in uFile or "?" in uFile:
        oFn = cFileName("").ImportFullPath(uFnFullName=uFile)
        oDir: cPath = oFn.oPath
        aFolderFiles = oDir.GetFileList(bFullPath=True, bSubDirs=False)
        for uFolderFile in aFolderFiles:
            if MatchWildCard(uValue=uFolderFile,
                             uMatchWithWildCard=oFn.string):
                aFiles.append(
                    cFileName("").ImportFullPath(uFnFullName=uFolderFile))
    else:
        oFn = cFileName("").ImportFullPath(uFnFullName=uFile)
        if oFn.Exists():
            aFiles.append(cFileName("").ImportFullPath(uFnFullName=uFile))
        else:
            Logger.debug(u'XML: Skipping XML Include (File not found):' +
                         oFn.string)

    for oFnLoad in aFiles:
        oFnLoadFileRedirect = Globals.oTheScreen.oSkin.dSkinRedirects.get(
            oFnLoad.string)
        if oFnLoadFileRedirect is not None:
            oFnLoad = oFnLoadFileRedirect
        Logger.debug(u'XML: Loading XML Include:' + oFnLoad)
        #uRaw= ElementInclude.default_loader(uLoadFile, "text", encoding)
        uRaw = CachedFile(oFileName=oFnLoad)
        uRaw = ReplaceDefVars(uRaw, oReplacementVars)
        aRet.append(fromstring(uRaw))
        uFnFileShort = ShortenFileName(uFnFile=oFnLoad.string)
        if aRet[-1].get("linefilename", "") == "":
            aRet[-1].set("linefilename", uFnFileShort)
            for oElement in aRet[-1]:
                oElement.set("linefilename", uFnFileShort)

    return aRet
Exemplo n.º 4
0
 def GetUsedDefinitions(self):
     """ Gets a list of all used definitions """
     Logger.debug(u'Collecting used definitions...')
     fSplashScreenPercentageRange = 10.0
     Globals.oTheScreen.LogToSplashScreen("Collecting used definitions",
                                          fSplashScreenPercentageRange)
     self.__GetUsedDefinitions_Sub(Globals.uDefinitionName, True, True,
                                   True, True, Globals.oTheScreen.uDefName,
                                   Globals.uDefinitionName,
                                   cDefinitionVars(), u'')
     Globals.uDefinitionContext = ""  # to ensure, root definitioncontext is loaded
     RestoreDefinitionContext()
Exemplo n.º 5
0
def orca_et_loader(uFile,
                   parse,
                   encoding=None,
                   oReplacementVars=cDefinitionVars()):
    """Custom Loader for ElementTree Include to add definition path to includes
        and to make make bulk include using placeholder possible
    """
    if uFile.endswith('*'):
        uRet = []
        oFn = cFileName("").ImportFullPath(uFile)
        oDir = oFn.oPath
        uPattern = (oFn.string)[len(oDir.string):]
        uPattern = uPattern[1:-1]
        aFiles = oDir.GetFileList()
        for uFile in aFiles:
            if uFile.startswith(uPattern):
                oFnLoad = cFileName(oDir) + uFile
                oFnLoadFileRedirect = Globals.oTheScreen.oSkin.dSkinRedirects.get(
                    oFnLoad.string)
                if oFnLoadFileRedirect is not None:
                    oFnLoad = oFnLoadFileRedirect
                Logger.debug(u'XML: Bulk-Loading XML Include:' + oFnLoad)
                #uRaw= ElementInclude.default_loader(uLoadFile, "text", encoding)
                uRaw = CachedFile(oFnLoad)
                uRaw2 = ReplaceDefVars(uRaw, oReplacementVars)
                uRet.append(fromstring(uRaw2))
        if len(uRet) == 0:
            return None
        else:
            return uRet
    else:
        oFn = cFileName("").ImportFullPath(uFile)
        if oFn.Exists():
            Logger.debug(u'XML: Loading XML Include:' + oFn.string)
            #uRaw= ElementInclude.default_loader(uFile2, "text", encoding)
            uRaw = CachedFile(oFn)
            uRaw2 = ReplaceDefVars(uRaw, oReplacementVars)
            bRet = fromstring(uRaw2)
        else:
            Logger.debug(u'XML: Skipping XML Include (File not found):' +
                         oFn.string)
            bRet = None
        return bRet
Exemplo n.º 6
0
 def GetUsedDefinitions(self) -> None:
     """ Gets a list of all used definitions """
     Logger.debug(u'Collecting used definitions...')
     fSplashScreenPercentageRange: float = 10.0
     Globals.oTheScreen.LogToSplashScreen(
         uText="Collecting used definitions",
         uPercentage=str(fSplashScreenPercentageRange))
     self.__GetUsedDefinitions_Sub(
         uDefinitionName=Globals.uDefinitionName,
         bImportActions=True,
         bImportLanguages=True,
         bImportPages=True,
         bImportSettings=True,
         uParentDefinitionName=Globals.oTheScreen.uDefName,
         uParentDefinitionAlias=Globals.uDefinitionName,
         oDefinitionVarsFromParent=cDefinitionVars(),
         uAlias=u'')
     Globals.uDefinitionContext = ""  # to ensure, root definitioncontext is loaded
     RestoreDefinitionContext()
     return None
Exemplo n.º 7
0
    def __GetUsedDefinitions_Sub(self, uDefinitionName, bImportActions,
                                 bImportLanguages, bImportPages,
                                 bImportSettings, uParentDefinitionName,
                                 uParentDefinitionAlias,
                                 aDefinitionVarsFromParent, uAlias):

        aAdditionalDefVars = {}

        if not uAlias in self.dDefinitionList_Dict:
            oDefinitionPathes = cDefinitionPathes(uDefinitionName)
            SetVar(uVarName="DEFINITIONPATH[%s]" % (uDefinitionName),
                   oVarValue=oDefinitionPathes.oPathDefinition.string)
            SetVar(
                uVarName="DEFINITIONPATHSKINELEMENTS[%s]" % (uDefinitionName),
                oVarValue=oDefinitionPathes.oPathDefinitionSkinElements.string)
            Globals.dDefinitionPathes[uDefinitionName] = oDefinitionPathes
            SetDefinitionPathes(uDefinitionName)

            oFnDefinition = Globals.oDefinitionPathes.oFnDefinition
            Logger.debug(u'TheScreen: Load Definition XmlFile:' +
                         oFnDefinition)
            oDefinition = cDefinition(uDefinitionName, self)
            oDefinition.uParentDefinitionName = uParentDefinitionName
            oDefinition.bImportActions = bImportActions
            oDefinition.bImportLanguages = bImportLanguages
            oDefinition.bImportPages = bImportPages
            oDefinition.bImportSettings = bImportSettings
            oDefinition.oDefinitionVarsFromParent = aDefinitionVarsFromParent

            #we read the definitionvars first with raw funtions
            sET_Data = CachedFile(Globals.oDefinitionPathes.oFnDefinition)
            oET_Root = fromstring(sET_Data)
            oRef = oET_Root.find('def_parameter')
            # And merge / Replace the existing Vars
            oDefinition.oDefinitionVars.clear()
            oDefinition.oDefinitionVars.update(
                ToOrderedDic(
                    GetXMLTextValue(oRef, u'definitionvars', False, u'{}')))

            if len(aDefinitionVarsFromParent) > 0:
                for uVarName in oDefinition.oDefinitionVars:
                    if uVarName in oDefinition.oDefinitionVarsFromParent:
                        oDefinition.oDefinitionVars[
                            uVarName] = oDefinition.oDefinitionVarsFromParent[
                                uVarName]
                    else:
                        Logger.warning(
                            "Importing definition %s from %s: Definition varname not passed: '%s', using default %s"
                            %
                            (oDefinition.uName, uParentDefinitionName,
                             uVarName, oDefinition.oDefinitionVars[uVarName]))
                for uVarName in aDefinitionVarsFromParent:
                    if not uVarName in oDefinition.oDefinitionVars:
                        oDefinition.oDefinitionVars[
                            uVarName] = oDefinition.oDefinitionVarsFromParent[
                                uVarName]
                        aAdditionalDefVars[
                            uVarName] = oDefinition.oDefinitionVarsFromParent[
                                uVarName]

            for uKey in oDefinition.oDefinitionVars:
                uVar = oDefinition.oDefinitionVars[uKey]
                if "$cookie(" in uVar:
                    uValue = GetCookieValue(uVar)
                    oDefinition.oDefinitionVars[uKey] = uValue

            if uAlias == u'':
                # this works on all python versions
                for uKey in oDefinition.oDefinitionVars:
                    uAlias = oDefinition.oDefinitionVars[uKey]
                    break

            if uAlias == '':
                uAlias = uDefinitionName
                oDefinition.uDefPublicTitle = uDefinitionName
                #create a default alias def var
                uAliasDefVar = "definition_alias_" + uAlias
                if oDefinition.oDefinitionVars.get(uAliasDefVar) is None:
                    SetDefVar(uVarName=uAliasDefVar,
                              uVarValue=uAlias,
                              dArray=oDefinition.oDefinitionVars)
            else:
                oDefinition.uDefPublicTitle = "%s [%s]" % (uAlias,
                                                           uDefinitionName)

            oDefinition.uAlias = uAlias

            if not uAlias in self.dDefinitionList_Dict:
                # create defvars for import pages
                aTmpDefinitionVars = copy(oDefinition.oDefinitionVars)
                for uVar in aTmpDefinitionVars:
                    if not uVar.endswith("_IMPORTPAGES"):
                        if bImportPages:
                            SetDefVar(uVarName=uVar + "_IMPORTPAGES",
                                      uVarValue="1",
                                      dArray=oDefinition.oDefinitionVars)
                        else:
                            SetDefVar(uVarName=uVar + "_IMPORTPAGES",
                                      uVarValue="0",
                                      dArray=oDefinition.oDefinitionVars)

                #and now again with adjusted definitionvars
                oET_Root = Orca_FromString(sET_Data, oDefinition, "root")
                oDefinition.oET_Root = oET_Root
                oDefinition.sET_Data = sET_Data

                self.AddDefinition(oDefinition)

                oXMLIncludes = oET_Root.find('definitionimports')
                if oXMLIncludes is not None:
                    for oXMLInclude in oXMLIncludes.findall('definition'):
                        uDefinitionNameImp = GetXMLTextValue(
                            oXMLInclude, u'', True, '')
                        bImportActionsImp = GetXMLBoolAttribute(
                            oXMLInclude, u'importactions', False, False)
                        bImportLanguagesImp = GetXMLBoolAttribute(
                            oXMLInclude, u'importlanguages', False, False)
                        bImportPagesImp = GetXMLBoolAttribute(
                            oXMLInclude, u'importpages', False, False)
                        bImportSettingsImp = GetXMLBoolAttribute(
                            oXMLInclude, u'importsettings', False, False)
                        uAliasImp = GetXMLTextAttribute(
                            oXMLInclude, u'alias', False, '')
                        aDefinitionVarsImp = cDefinitionVars()
                        aDefinitionVarsImp.update(
                            ToDic(
                                GetXMLTextAttribute(oXMLInclude,
                                                    u'definitionvars', False,
                                                    {})))

                        # Pass Through of additional Definitionvars
                        for uVarName in aAdditionalDefVars:
                            if not uVarName in aDefinitionVarsImp:
                                aDefinitionVarsImp[
                                    uVarName] = aAdditionalDefVars[uVarName]

                        self.__GetUsedDefinitions_Sub(
                            uDefinitionNameImp, bImportActionsImp,
                            bImportLanguagesImp, bImportPagesImp,
                            bImportSettingsImp, oDefinition.uName,
                            oDefinition.uAlias, aDefinitionVarsImp, uAliasImp)
            else:
                Logger.debug(
                    u'GetUsedDefinitions: Skipping duplicate xml %s [%s]' %
                    (uAlias, uDefinitionName))
        else:
            Logger.debug(
                u'GetUsedDefinitions: Skipping duplicate xml %s [%s]' %
                (uAlias, uDefinitionName))
Exemplo n.º 8
0
def Orca_includesub(oElem: Union[Element, List[Element]],
                    pLoader: Callable,
                    uOrgDefinitionContext: str,
                    oDef: cDefinition,
                    uFileName: str = "Unknown Filename") -> Element:
    """ sub function for the include loader """
    global bBlockInclude

    aElemens: List[Element] = []
    oReplacementVars: cDefinitionVars = cDefinitionVars()
    oSaveReplacementVars: cDefinitionVars = cDefinitionVars()

    for e in oElem:
        aElemens.append(e)

    if oDef:
        oReplacementVars = oDef.oDefinitionVars

    i: int = 0

    for e in aElemens:
        if oDef:
            e.set('definitionalias', oDef.uAlias)

        if e.tag == 'startskip':
            if CheckCondition(oPar=e):
                bBlockInclude = True

        if e.tag == 'stopskip':
            bBlockInclude = False

        if e.tag == ElementInclude.XINCLUDE_INCLUDE:

            if CheckCondition(oPar=e) and not bBlockInclude:

                # process xinclude directive
                uHref: str = e.get("href")
                uHref = ReplaceVars(uHref)
                uParse: str = e.get("parse", None)
                if uParse is None:
                    uParse = "xml"

                if uParse == "xml":
                    uNewDefinitionContext = u''
                    if "DEFINITIONPATH[" in uHref:
                        uNewDefinitionContext, uHref = GetSetDefinitionName(
                            uText=uHref)

                    oTmpReplacementVars = e.get("definitionvars")
                    if oTmpReplacementVars is None:
                        oTmpReplacementVars = oReplacementVars

                    aIncludeReplacementVars = e.get("includedefinitionvars")
                    if aIncludeReplacementVars is None:
                        aIncludeReplacementVars = cDefinitionVars()
                    else:
                        aIncludeReplacementVars = ToDic(
                            aIncludeReplacementVars)

                    aIncludeReplacementVars = aIncludeReplacementVars.copy()

                    if oTmpReplacementVars is not None:
                        oTmpReplacementVars = oTmpReplacementVars.copy()
                        oSaveReplacementVars = oReplacementVars
                        oReplacementVars = oTmpReplacementVars
                        oReplacementVars.update(aIncludeReplacementVars)
                        if oDef:
                            oDef.oDefinitionVars = oTmpReplacementVars

                    aNodes: List[Element] = pLoader(uHref, uParse, None,
                                                    oReplacementVars)
                    oNodes: Element

                    # included element not found
                    if len(aNodes) == 0:
                        del oElem[i]
                        i -= 1
                    else:
                        uHref2 = uHref
                        if uNewDefinitionContext == u'':
                            oNodes = Orca_includesub(aNodes, pLoader,
                                                     uOrgDefinitionContext,
                                                     oDef, uHref2)
                        else:
                            oNodes = Orca_includesub(aNodes, pLoader,
                                                     uNewDefinitionContext,
                                                     oDef, uHref2)

                        if oTmpReplacementVars is not None:
                            oReplacementVars = oSaveReplacementVars
                            if oDef:
                                oDef.oDefinitionVars = oSaveReplacementVars

                        if uNewDefinitionContext != u'':
                            SetDefinitionContext(
                                uDefinitionName=uOrgDefinitionContext)

                        # we got a valid list of nodes
                        bFirst: bool = True
                        for oNode in oNodes:
                            oNode = copy(oNode)
                            if e.tail:
                                oNode.tail = (oNode.tail or "") + e.tail
                            if bFirst:
                                oElem[i] = oNode
                                bFirst = False
                            else:
                                oElem.insert(i, oNode)
                                i += 1
        else:
            Orca_includesub(e, pLoader, uOrgDefinitionContext, oDef, uFileName)
            # pass
        i += 1
    return oElem
Exemplo n.º 9
0
def Orca_includesub(elem,
                    loader,
                    uOrgDefinitionContext,
                    oDef,
                    uFileName="Unknown Filename"):
    """ sub function for the include loader """
    global bBlockInclude

    elemens = []
    oReplacementVars = cDefinitionVars()
    for e in elem:
        elemens.append(e)

    if oDef:
        oReplacementVars = oDef.oDefinitionVars

    i = 0
    for e in elemens:
        e.set('definitioncontext', uOrgDefinitionContext)
        if oDef:
            e.set('definitionalias', oDef.uAlias)
        e.set('linefilename', uFileName)

        if e.tag == 'startskip':
            if CheckCondition(e):
                bBlockInclude = True

        if e.tag == 'stopskip':
            bBlockInclude = False

        if e.tag == ElementInclude.XINCLUDE_INCLUDE:

            if CheckCondition(e) and not bBlockInclude:

                # process xinclude directive
                href = e.get("href")
                parse = e.get("parse", "xml")
                if parse == "xml":
                    uNewDefinitionContext = u''
                    if "DEFINITIONPATH[" in href:
                        uNewDefinitionContext, href = GetSetDefinitionName(
                            href)

                    oTmpReplacementVars = e.get("definitionvars")
                    if oTmpReplacementVars is None:
                        oTmpReplacementVars = oReplacementVars

                    aIncludeReplacementVars = e.get("includedefinitionvars")
                    if aIncludeReplacementVars is None:
                        aIncludeReplacementVars = cDefinitionVars()
                    else:
                        aIncludeReplacementVars = ToDic(
                            aIncludeReplacementVars)

                    #
                    aIncludeReplacementVars = aIncludeReplacementVars.copy()

                    if oTmpReplacementVars is not None:
                        oTmpReplacementVars = oTmpReplacementVars.copy()
                        #oTmpReplacementVars=ToDic(oTmpReplacementVars)
                        aSaveReplacementVars = oReplacementVars
                        oReplacementVars = oTmpReplacementVars
                        oReplacementVars.update(aIncludeReplacementVars)
                        if oDef:
                            oDef.oDefinitionVars = oTmpReplacementVars

                    oFnHRefRedirect = Globals.oTheScreen.oSkin.dSkinRedirects.get(
                        cFileName(u'').ImportFullPath(ReplaceVars(href)))
                    if oFnHRefRedirect is not None:
                        oFnHRef = oFnHRefRedirect.string
                    oFnHRef = cFileName(u'').ImportFullPath(ReplaceVars(href))
                    nodes = loader(oFnHRef.string, parse, None,
                                   oReplacementVars)

                    if nodes is not None:
                        if uNewDefinitionContext == u'':
                            nodes = Orca_includesub(nodes, loader,
                                                    uOrgDefinitionContext,
                                                    oDef, oFnHRef.string)
                        else:
                            nodes = Orca_includesub(nodes, loader,
                                                    uNewDefinitionContext,
                                                    oDef, oFnHRef.string)

                    if oTmpReplacementVars is not None:
                        oReplacementVars = aSaveReplacementVars
                        if oDef:
                            oDef.oDefinitionVars = aSaveReplacementVars

                    if uNewDefinitionContext != u'':
                        SetDefinitionContext(uOrgDefinitionContext)

                    if isinstance(nodes, list):
                        bFirst = True
                        for node in nodes:
                            node = copy(node)
                            if e.tail:
                                node.tail = (node.tail or "") + e.tail
                            if bFirst:
                                elem[i] = node
                                bFirst = False
                            else:
                                elem.insert(i, node)
                                i = i + 1
                    elif nodes is None:
                        del elem[i]
                        i = i - 1
                    else:
                        nodes = copy(nodes)
                        if e.tail:
                            nodes.tail = (nodes.tail or "") + e.tail
                        elem[i] = nodes
        else:
            Orca_includesub(e, loader, uOrgDefinitionContext, oDef, uFileName)
        i = i + 1
    return elem