Ejemplo n.º 1
0
    def ParseFile(self,oFileName:cFileName,iStartLine:int=0) -> List[cWikiPage]:
        """ parses a single file """

        uContent:str
        aContent:List[str]
        uParts:List[str]
        uLine:str
        bFound:bool
        i:int=0

        if oFileName.string.endswith("__init__.py"):
            return self.oPages

        if iStartLine==0:
            Logger.debug("Reading File:"+oFileName.string)
        try:
            if oFileName.Exists():
                uContent=LoadFile(oFileName=oFileName)
                aContent=uContent.split("\n")
                bFound = False
                for  i,uLine in enumerate(aContent):
                    if i>iStartLine:
                        uLine=uLine.strip()
                        if uLine.startswith(u'WikiDoc:Doc'):
                            bFound = True
                        elif uLine.startswith(u'WikiDoc:End'):
                            self.oPages.append(self)
                            break
                        elif uLine.startswith("WikiDoc:Context:"):
                            uParts=uLine.split(":")
                            self.uContext=uParts[-1]
                        elif uLine.startswith("WikiDoc:Page:"):
                            uParts=uLine.split(":")
                            self.uPage=uParts[-1]
                            Logger.debug("Parsed Wikipage:"+self.uPage)
                        elif uLine.startswith("WikiDoc:TOCTitle:"):
                            uParts=uLine.split(":")
                            self.uTOCTitle=uParts[-1]
                        elif "'''" in uLine:
                            pass
                        elif '"""' in uLine:
                            pass
                        else:
                            if bFound:
                                self.uContent.append(uLine)
            else:
                LogError(uMsg=u'cWikiDoc:Cant find file:'+oFileName.string)

            if len(self.oPages)>0:
                oPage:cWikiPage = cWikiPage()
                oPages=oPage.ParseFile(oFileName,i)
                if len(oPages)>0:
                    self.oPages.extend(oPages)
            else:
                if iStartLine==0:
                    Logger.warning("No Wikidoc entry in file:"+oFileName.string)
            return self.oPages
        except Exception as e:
            LogError(uMsg=u'WikiDoc:Unexpected error reading file:',oException=e)
            return []
Ejemplo n.º 2
0
 def ParseFromSourceFile(self):
     """ Parses an xml file into object vars """
     uContent = LoadFile(self.oFnEntry)
     lPos = uContent.find('<root>')
     lPos2 = uContent.find('</root>')
     if lPos == -1 or lPos2 == -1:
         return False
     uContent = uContent[lPos:lPos2 + 7]
     return self.ParseFromXML(uContent)
Ejemplo n.º 3
0
def GetJsonFromSettingFileName(uSettingFileName: str) -> str:
    oFnSetting: cFileName = cFileName(
        Globals.oPathAppReal +
        "ORCA/settings/settingstrings") + uSettingFileName
    if not oFnSetting.Exists():
        oFnSetting: cFileName = cFileName(
            Globals.oPathApp +
            "ORCA/settings/settingstrings") + uSettingFileName

    return ReplaceVars(LoadFile(oFileName=oFnSetting))
Ejemplo n.º 4
0
    def ParseFromSourceFile(self) -> bool:
        """ Parses an xml file into object vars """
        uContent:str=LoadFile(oFileName=self.oFnEntry)
        #iPos=uContent.find('<root>')
        #iPos2=uContent.find('</root>')
        iPos=uContent.find('<repositorymanager>')
        iPos2=uContent.find('</repositorymanager>')
        if iPos==-1 or iPos2==-1:
            return False
        #uContent=uContent[iPos:iPos2+7]
        uContent="<root>"+uContent[iPos:iPos2+21]+"</root>"

        return self.ParseFromXML(vContent=uContent)
Ejemplo n.º 5
0
def CachedFile(*, oFileName: cFileName) -> str:
    """
    Returns the content of a file as string, using a cache if already loaded
    """

    uFileContent: str = Cache.get(category=uCacheName, key=oFileName.string)
    if uFileContent is None:
        uFileContent = LoadFile(oFileName=oFileName)
        Cache.append(category=uCacheName,
                     key=oFileName.string,
                     obj=uFileContent,
                     timeout=120)

    return uFileContent
Ejemplo n.º 6
0
def CachedFile(oFileName):
    """
    Returns the content of a file as string, using a cache if already loaded

    :rtype: string
    :param cFileName oFileName:
    :return: The content of a file
    """

    uFileContent = Cache.get(category = uCacheName, key = oFileName.string)
    if uFileContent is None:
        uFileContent = LoadFile(oFileName)
        Cache.append(category = uCacheName, key = oFileName.string, obj = uFileContent, timeout = 120)

    return uFileContent
Ejemplo n.º 7
0
def Var_LoadFile(uVarName: str, uFileName: str) -> str:
    """
    Loads the content a file into a var
    The changed variable value will be return and stored in the user vars (Triggers raised if set)

    :param str uVarName: The variable name for the action, from where the value is pulled
    :param str uFileName: The filename for the content to load
    :return: The changed variable value
    """

    try:
        oFileName: cFileName = cFileName('').ImportFullPath(
            uFnFullName=uFileName)
        uValue: str = LoadFile(oFileName=oFileName)
        SetVar(uVarName=uVarName, oVarValue=uValue)
        return uValue
    except Exception as e:
        LogError(uMsg=u'Var_LoadFile: Error Loading File Content (%s:%s)' %
                 (uVarName, uFileName),
                 oException=e)
        return u''
Ejemplo n.º 8
0
 def LoadFile(self):
     """ loads a file to show """
     oFn = cFileName('').ImportFullPath(uFnFullName=ReplaceVars(self.uShowFileName))
     Logger.debug("Reading File:"+oFn)
     self.uCaption=LoadFile(oFileName=oFn)
Ejemplo n.º 9
0
 def ReadFromFile(self, uFileName):
     self.SetText(LoadFile(uFileName))