Add orgmode test

This commit is contained in:
Dima Gerasimov 2020-03-14 18:15:52 +00:00
parent d795787ffd
commit d38c6f8b36
2 changed files with 21 additions and 10 deletions

View file

@ -1,3 +1,7 @@
'''
Programmatic access and queries to org-mode files on the filesystem
'''
from glob import glob from glob import glob
from typing import List, Sequence, Iterator from typing import List, Sequence, Iterator
from pathlib import Path from pathlib import Path
@ -21,30 +25,30 @@ def _org_files_in(ppp: Path, archived: bool=False) -> Iterator[Path]:
yield from ppp.rglob('*.org_archive') yield from ppp.rglob('*.org_archive')
def org_files(archived: bool=False) -> Iterator[Path]: def org_files(roots=config.roots, archived: bool=False) -> Iterator[Path]:
for p in config.roots: for p in config.roots:
yield from _org_files_in(Path(p), archived=archived) yield from _org_files_in(Path(p), archived=archived)
# TODO move to porg? # TODO move to porg?
class PorgAll: class PorgAll:
def __init__(self, paths: Sequence[PathIsh]) -> None: # TODO *roots?
self.paths = [Path(p) for p in paths] def __init__(self, roots: Sequence[PathIsh]) -> None:
self.files = org_files(roots=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))
def get_all(self): def get_all(self):
return self.xpath_all('//*') return self.xpath_all('/')
def query_all(self, query): def query_all(self, query):
res: List[Org] = [] res: List[Org] = []
for p in self.paths: for of in self.files:
for of in _org_files_in(p): org = Org.from_file(str(of))
org = Org.from_file(str(of)) res.extend(query(org))
res.extend(query(org))
return res return res
def notes(): def query():
return PorgAll(org_files()) return PorgAll(roots=config.roots)

7
tests/orgmode.py Normal file
View file

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