better org notes retrieval
This commit is contained in:
parent
4206353d7b
commit
e5165246e0
1 changed files with 20 additions and 6 deletions
|
@ -1,8 +1,12 @@
|
|||
from glob import glob
|
||||
from typing import List
|
||||
from typing import List, Sequence
|
||||
from pathlib import Path
|
||||
|
||||
from kython.ktyping import PathIsh
|
||||
|
||||
from porg import Org # type: ignore
|
||||
|
||||
|
||||
# TODO enc stuff?
|
||||
def get_org_paths():
|
||||
return [
|
||||
|
@ -10,7 +14,14 @@ def get_org_paths():
|
|||
'***REMOVED***',
|
||||
]
|
||||
|
||||
def _get_org_files_in(path, archived: bool=False) -> List[str]:
|
||||
def _get_org_files_in(path, archived: bool=False) -> List[PathIsh]:
|
||||
ppp = Path(path)
|
||||
assert ppp.exists()
|
||||
# TODO try/catch??
|
||||
if ppp.is_file():
|
||||
return [ppp]
|
||||
|
||||
path = str(path) # TODO FIXME use pathlib
|
||||
res = []
|
||||
res.extend(glob(path + '/**/*.org', recursive=True))
|
||||
if archived:
|
||||
|
@ -18,7 +29,7 @@ def _get_org_files_in(path, archived: bool=False) -> List[str]:
|
|||
return res
|
||||
|
||||
|
||||
def get_org_files(archived: bool = False) -> List[str]:
|
||||
def get_org_files(archived: bool = False) -> List[PathIsh]:
|
||||
res = []
|
||||
for p in get_org_paths():
|
||||
res.extend(_get_org_files_in(p, archived=archived))
|
||||
|
@ -27,11 +38,14 @@ def get_org_files(archived: bool = False) -> List[str]:
|
|||
|
||||
# TODO move to porg?
|
||||
class PorgAll:
|
||||
def __init__(self, paths: List[str]) -> None:
|
||||
self.paths = paths
|
||||
def __init__(self, paths: Sequence[PathIsh]) -> None:
|
||||
self.paths = [Path(p) for p in paths]
|
||||
|
||||
def xpath_all(self, query: str):
|
||||
return self.query_all(lambda x: x.xpath_all(query))
|
||||
|
||||
def get_all(self):
|
||||
return self.query_all(lambda x: x.xpath_all('//*'))
|
||||
return self.xpath_all('//*')
|
||||
|
||||
def query_all(self, query):
|
||||
res: List[Org] = []
|
||||
|
|
Loading…
Add table
Reference in a new issue