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 typing import List, Sequence, Iterator
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')
def org_files(archived: bool=False) -> Iterator[Path]:
def org_files(roots=config.roots, archived: bool=False) -> Iterator[Path]:
for p in config.roots:
yield from _org_files_in(Path(p), archived=archived)
# TODO move to porg?
class PorgAll:
def __init__(self, paths: Sequence[PathIsh]) -> None:
self.paths = [Path(p) for p in paths]
# TODO *roots?
def __init__(self, roots: Sequence[PathIsh]) -> None:
self.files = org_files(roots=roots)
def xpath_all(self, query: str):
return self.query_all(lambda x: x.xpath_all(query))
def get_all(self):
return self.xpath_all('//*')
return self.xpath_all('/')
def query_all(self, query):
res: List[Org] = []
for p in self.paths:
for of in _org_files_in(p):
org = Org.from_file(str(of))
res.extend(query(org))
for of in self.files:
org = Org.from_file(str(of))
res.extend(query(org))
return res
def notes():
return PorgAll(org_files())
def query():
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