From 6679aae47555c1914b34b1bb1c9b51cb09cdc805 Mon Sep 17 00:00:00 2001 From: Dima Gerasimov Date: Mon, 18 Feb 2019 20:24:32 +0000 Subject: [PATCH] some adjustments to notes provider --- notes/__init__.py | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/notes/__init__.py b/notes/__init__.py index 91ef5bc..d10a62c 100644 --- a/notes/__init__.py +++ b/notes/__init__.py @@ -3,24 +3,44 @@ from typing import List from porg import Org # typing: ignore +# TODO enc stuff? +def get_org_paths(): + return [ + '***REMOVED***', + '***REMOVED***', + ] + +def _get_org_files_in(path, archived: bool=False) -> List[str]: + res = [] + res.extend(glob(path + '/**/*.org', recursive=True)) + if archived: + res.extend(glob(path + '/**/*.org_archive', recursive=True)) + return res + + +def get_org_files(archived: bool = False) -> List[str]: + res = [] + for p in get_org_paths(): + res.extend(_get_org_files_in(p, archived=archived)) + return res + + # TODO move to porg? class PorgAll: def __init__(self, paths: List[str]) -> None: self.paths = paths + def get_all(self): + return self.query_all(lambda x: x.xpath_all('//*')) + def query_all(self, query): res = [] for p in self.paths: - ofiles = glob(p + '/**/*.org', recursive=True) - for of in ofiles: + for of in _get_org_files_in(p): org = Org.from_file(of) res.extend(query(org)) return res def get_notes(): - ORG_PATHS = [ - '***REMOVED***', - '***REMOVED***', - ] - return PorgAll(ORG_PATHS) + return PorgAll(get_org_paths())