my.notes.orgmode: make a bit more iterative

This commit is contained in:
Dima Gerasimov 2020-10-10 23:43:12 +01:00 committed by karlicoss
parent 6a1a006202
commit 649537deca
2 changed files with 10 additions and 6 deletions

View file

@ -35,20 +35,24 @@ def org_files(roots=config.roots, archived: bool=False) -> Iterator[Path]:
class PorgAll: class PorgAll:
# TODO *roots? # TODO *roots?
def __init__(self, roots: Sequence[PathIsh]) -> None: def __init__(self, roots: Sequence[PathIsh]) -> None:
self.files = org_files(roots=roots) self.roots = roots
@property
def files(self):
yield from org_files(roots=self.roots)
def xpath_all(self, query: str): def xpath_all(self, query: str):
return self.query_all(lambda x: x.xpath_all(query)) return self.query_all(lambda x: x.xpath_all(query))
# TODO very confusing names...
# TODO careful... maybe use orgparse iterate instead?? ugh.
def get_all(self): def get_all(self):
return self.xpath_all('/') return self.xpath_all('//org')
def query_all(self, query): def query_all(self, query):
res: List[Org] = []
for of in self.files: for of in self.files:
org = Org.from_file(str(of)) org = Org.from_file(str(of))
res.extend(query(org)) yield from query(org)
return res
def query(): def query():

View file

@ -3,5 +3,5 @@ import my.notes.orgmode as orgmode
def test(): def test():
# meh # meh
results = orgmode.query().query_all(lambda x: x.with_tag('python')) results = list(orgmode.query().query_all(lambda x: x.with_tag('python')))
assert len(results) > 5 assert len(results) > 5