コード例 #1
0
 def _get_plus_paths( self, path:DocPath) -> List[DocPath]:
     lines = path.split(self._plus)
     if len(lines) == 0:
         return lines
     first = lines[0]
     lines = lines[1:]
     mark = first.find(self._hashmark)
     if mark > -1:
         first = first[0:mark+1]
     else:
         first += self._hashmark
     lines = [ DocPath(first+line) for line in lines]
     return lines
コード例 #2
0
ファイル: context.py プロジェクト: dk107dk/cdocs
 def get_doc_from_roots(self,
                        rootnames: List[str],
                        path: DocPath,
                        notfound: Optional[bool] = True,
                        splitplus: Optional[bool] = True) -> Optional[Doc]:
     """
         rootnames: a list of named roots to search
         path: the docpath. may have hash and plusses
         notfound: if true, return a default notfound if no results
         splitplus: if true, plus concats can be on different roots.
                    i.e. for /x/y/z+a+b /x/y/z, /x/y/z/a, /x/y/z/b
                    can all be on different roots.
     """
     logging.info(
         f"Context.get_doc_from_roots: first match wins. rootnames: {rootnames}, path: {path}, notfound: {notfound}, splitplus: {splitplus}"
     )
     plusmark = self._metadata.config.get("filenames", "plus")
     plus = path.find(plusmark)
     if plus > -1 and splitplus:
         if self._nosplitplus is None:
             nsp = self._metadata.config.get("defaults", "nosplitplus", "")
             self._nosplitplus = nsp.split(',')
         if len(self._nosplitplus) > 0:
             rootnames = [
                 name for name in rootnames if not name in self._nosplitplus
             ]
             logging.info(
                 f"Context.get_doc_from_roots: nsp filtered rootnames: {rootnames}"
             )
         # split into paths and call get_doc_from_roots on each, then concat
         #
         #  /r/o/o/t.html#fish
         # needs to become /r/o/o
         #
         #  /r/o/o/t#fish
         # needs to become /r/o/o/t
         #
         #  /r/o/o/t
         # needs to become /r/o/o/t
         #
         logging.info(f"Context.get_doc_from_roots: path: {path}")
         logging.info(f"Context.get_doc_from_roots: rootnames: {rootnames}")
         logging.info(f"Context.get_doc_from_roots: notfound: {notfound}")
         logging.info(f"Context.get_doc_from_roots: splitplus: {splitplus}")
         paths = path.split(plusmark)
         logging.info(f"Context.get_doc_from_roots: paths: {paths}")
         rootpath = paths[0]
         logging.info(f"Context.get_doc_from_roots: rootpath: {rootpath}")
         hashmark = self._metadata.config.get("filenames", "hashmark")
         logging.info(f"Context.get_doc_from_roots: hashmark: {hashmark}")
         rootpath = rootpath.split(hashmark)[0]
         logging.info(f"Context.get_doc_from_roots: rootpath: {rootpath}")
         paths = [
             p if p.find(rootpath) > -1 else rootpath + "/" + p
             for p in paths
         ]
         logging.info(f"Context.get_doc_from_roots: paths: {paths}")
         result = []
         for path in paths:
             logging.info(
                 f"Context.get_doc_from_roots: .... next path: {path}")
             r = self.get_doc_from_roots(rootnames, path, notfound)
             if r is not None:
                 result.append(r)
         if len(result) == 0 and notfound:
             return self._get_default_not_found()
         return "".join(result)
     else:
         rootnames = self.filter_root_names_for_path(rootnames, path)
         logging.info(
             f"Context.get_doc_from_roots: rootnames: {rootnames} - not spliting pluses, first root locks in the pluses"
         )
         for _ in rootnames:
             cdocs = self.keyed_cdocs[_]
             logging.info(
                 f"Context.get_doc_from_roots: cdocs: {_} -> {cdocs.get_doc_root()}"
             )
             doc = cdocs.get_doc(path, False)
             logging.info(f"found doc: {type(doc)}")
             if doc is not None:
                 return doc
         if notfound:
             return self._get_default_not_found()