prettify orgmode module
This commit is contained in:
parent
78bebaa71a
commit
d795787ffd
1 changed files with 17 additions and 27 deletions
|
@ -1,39 +1,29 @@
|
||||||
from glob import glob
|
from glob import glob
|
||||||
from typing import List, Sequence
|
from typing import List, Sequence, Iterator
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from kython.ktyping import PathIsh
|
from ..common import PathIsh
|
||||||
|
|
||||||
from porg import Org # type: ignore
|
from mycfg import orgmode as config
|
||||||
|
|
||||||
|
from porg import Org
|
||||||
|
|
||||||
|
|
||||||
# TODO enc stuff?
|
# TODO not sure about symlinks?
|
||||||
def get_org_paths():
|
def _org_files_in(ppp: Path, archived: bool=False) -> Iterator[Path]:
|
||||||
return [
|
assert ppp.exists(), ppp
|
||||||
'***REMOVED***',
|
# TODO reuse get_files somehow?
|
||||||
'***REMOVED***',
|
|
||||||
]
|
|
||||||
|
|
||||||
def _get_org_files_in(path, archived: bool=False) -> List[Path]:
|
|
||||||
ppp = Path(path)
|
|
||||||
assert ppp.exists()
|
|
||||||
# TODO try/catch??
|
|
||||||
if ppp.is_file():
|
if ppp.is_file():
|
||||||
return [ppp]
|
return [ppp]
|
||||||
|
|
||||||
path = str(path) # TODO FIXME use pathlib
|
yield from ppp.rglob('*.org')
|
||||||
res = []
|
|
||||||
res.extend(glob(path + '/**/*.org', recursive=True))
|
|
||||||
if archived:
|
if archived:
|
||||||
res.extend(glob(path + '/**/*.org_archive', recursive=True))
|
yield from ppp.rglob('*.org_archive')
|
||||||
return list(map(Path, res))
|
|
||||||
|
|
||||||
|
|
||||||
def get_org_files(archived: bool = False) -> List[Path]:
|
def org_files(archived: bool=False) -> Iterator[Path]:
|
||||||
res = []
|
for p in config.roots:
|
||||||
for p in get_org_paths():
|
yield from _org_files_in(Path(p), archived=archived)
|
||||||
res.extend(_get_org_files_in(p, archived=archived))
|
|
||||||
return res
|
|
||||||
|
|
||||||
|
|
||||||
# TODO move to porg?
|
# TODO move to porg?
|
||||||
|
@ -50,11 +40,11 @@ class PorgAll:
|
||||||
def query_all(self, query):
|
def query_all(self, query):
|
||||||
res: List[Org] = []
|
res: List[Org] = []
|
||||||
for p in self.paths:
|
for p in self.paths:
|
||||||
for of in _get_org_files_in(p):
|
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 get_notes():
|
def notes():
|
||||||
return PorgAll(get_org_paths())
|
return PorgAll(org_files())
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue