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 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
|
from porg import Org # type: ignore
|
||||||
|
|
||||||
|
|
||||||
# TODO enc stuff?
|
# TODO enc stuff?
|
||||||
def get_org_paths():
|
def get_org_paths():
|
||||||
return [
|
return [
|
||||||
|
@ -10,7 +14,14 @@ def get_org_paths():
|
||||||
'***REMOVED***',
|
'***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 = []
|
||||||
res.extend(glob(path + '/**/*.org', recursive=True))
|
res.extend(glob(path + '/**/*.org', recursive=True))
|
||||||
if archived:
|
if archived:
|
||||||
|
@ -18,7 +29,7 @@ def _get_org_files_in(path, archived: bool=False) -> List[str]:
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
|
||||||
def get_org_files(archived: bool = False) -> List[str]:
|
def get_org_files(archived: bool = False) -> List[PathIsh]:
|
||||||
res = []
|
res = []
|
||||||
for p in get_org_paths():
|
for p in get_org_paths():
|
||||||
res.extend(_get_org_files_in(p, archived=archived))
|
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?
|
# TODO move to porg?
|
||||||
class PorgAll:
|
class PorgAll:
|
||||||
def __init__(self, paths: List[str]) -> None:
|
def __init__(self, paths: Sequence[PathIsh]) -> None:
|
||||||
self.paths = paths
|
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):
|
def get_all(self):
|
||||||
return self.query_all(lambda x: x.xpath_all('//*'))
|
return self.xpath_all('//*')
|
||||||
|
|
||||||
def query_all(self, query):
|
def query_all(self, query):
|
||||||
res: List[Org] = []
|
res: List[Org] = []
|
||||||
|
|
Loading…
Add table
Reference in a new issue