From aa3155ff409a04a8349460fc72c07fca8ba4e92d Mon Sep 17 00:00:00 2001 From: Dima Gerasimov Date: Tue, 13 Nov 2018 20:24:49 +0000 Subject: [PATCH 1/6] notes provider --- notes/__init__.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 notes/__init__.py diff --git a/notes/__init__.py b/notes/__init__.py new file mode 100644 index 0000000..91ef5bc --- /dev/null +++ b/notes/__init__.py @@ -0,0 +1,26 @@ +from glob import glob +from typing import List + +from porg import Org # typing: ignore + +# TODO move to porg? +class PorgAll: + def __init__(self, paths: List[str]) -> None: + self.paths = paths + + def query_all(self, query): + res = [] + for p in self.paths: + ofiles = glob(p + '/**/*.org', recursive=True) + for of in ofiles: + org = Org.from_file(of) + res.extend(query(org)) + return res + + +def get_notes(): + ORG_PATHS = [ + '***REMOVED***', + '***REMOVED***', + ] + return PorgAll(ORG_PATHS) From 6679aae47555c1914b34b1bb1c9b51cb09cdc805 Mon Sep 17 00:00:00 2001 From: Dima Gerasimov Date: Mon, 18 Feb 2019 20:24:32 +0000 Subject: [PATCH 2/6] 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()) From 4206353d7b76bd20a8f0e3b9e95ab88742416744 Mon Sep 17 00:00:00 2001 From: Dima Gerasimov Date: Mon, 11 Mar 2019 23:23:03 +0000 Subject: [PATCH 3/6] Fix ruci --- notes/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/notes/__init__.py b/notes/__init__.py index d10a62c..e67dc9e 100644 --- a/notes/__init__.py +++ b/notes/__init__.py @@ -1,7 +1,7 @@ from glob import glob from typing import List -from porg import Org # typing: ignore +from porg import Org # type: ignore # TODO enc stuff? def get_org_paths(): @@ -34,7 +34,7 @@ class PorgAll: return self.query_all(lambda x: x.xpath_all('//*')) def query_all(self, query): - res = [] + res: List[Org] = [] for p in self.paths: for of in _get_org_files_in(p): org = Org.from_file(of) From e5165246e0a9a76c5e334778dd9a0b29a903c1c7 Mon Sep 17 00:00:00 2001 From: Dima Gerasimov Date: Thu, 11 Apr 2019 17:34:00 +0100 Subject: [PATCH 4/6] better org notes retrieval --- notes/__init__.py | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/notes/__init__.py b/notes/__init__.py index e67dc9e..f05c894 100644 --- a/notes/__init__.py +++ b/notes/__init__.py @@ -1,8 +1,12 @@ from glob import glob -from typing import List +from typing import List, Sequence +from pathlib import Path + +from kython.ktyping import PathIsh from porg import Org # type: ignore + # TODO enc stuff? def get_org_paths(): return [ @@ -10,7 +14,14 @@ def get_org_paths(): '***REMOVED***', ] -def _get_org_files_in(path, archived: bool=False) -> List[str]: +def _get_org_files_in(path, archived: bool=False) -> List[PathIsh]: + ppp = Path(path) + assert ppp.exists() + # TODO try/catch?? + if ppp.is_file(): + return [ppp] + + path = str(path) # TODO FIXME use pathlib res = [] res.extend(glob(path + '/**/*.org', recursive=True)) if archived: @@ -18,7 +29,7 @@ def _get_org_files_in(path, archived: bool=False) -> List[str]: return res -def get_org_files(archived: bool = False) -> List[str]: +def get_org_files(archived: bool = False) -> List[PathIsh]: res = [] for p in get_org_paths(): res.extend(_get_org_files_in(p, archived=archived)) @@ -27,11 +38,14 @@ def get_org_files(archived: bool = False) -> List[str]: # TODO move to porg? class PorgAll: - def __init__(self, paths: List[str]) -> None: - self.paths = paths + def __init__(self, paths: Sequence[PathIsh]) -> None: + self.paths = [Path(p) for p in paths] + + def xpath_all(self, query: str): + return self.query_all(lambda x: x.xpath_all(query)) def get_all(self): - return self.query_all(lambda x: x.xpath_all('//*')) + return self.xpath_all('//*') def query_all(self, query): res: List[Org] = [] From b1a816e5048e2561de082fd4ee0a998c6697d026 Mon Sep 17 00:00:00 2001 From: Dima Gerasimov Date: Sat, 29 Jun 2019 13:43:09 +0100 Subject: [PATCH 5/6] fix mypy --- notes/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/notes/__init__.py b/notes/__init__.py index f05c894..319605f 100644 --- a/notes/__init__.py +++ b/notes/__init__.py @@ -51,7 +51,7 @@ class PorgAll: res: List[Org] = [] for p in self.paths: for of in _get_org_files_in(p): - org = Org.from_file(of) + org = Org.from_file(str(of)) res.extend(query(org)) return res From 82ec0e95778d59e5b5b6d638940ca353bfd7123f Mon Sep 17 00:00:00 2001 From: Dima Gerasimov Date: Tue, 13 Aug 2019 21:39:28 +0100 Subject: [PATCH 6/6] imdb provider --- notes/__init__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/notes/__init__.py b/notes/__init__.py index 319605f..76a3893 100644 --- a/notes/__init__.py +++ b/notes/__init__.py @@ -14,7 +14,7 @@ def get_org_paths(): '***REMOVED***', ] -def _get_org_files_in(path, archived: bool=False) -> List[PathIsh]: +def _get_org_files_in(path, archived: bool=False) -> List[Path]: ppp = Path(path) assert ppp.exists() # TODO try/catch?? @@ -26,10 +26,10 @@ def _get_org_files_in(path, archived: bool=False) -> List[PathIsh]: res.extend(glob(path + '/**/*.org', recursive=True)) if archived: res.extend(glob(path + '/**/*.org_archive', recursive=True)) - return res + return list(map(Path, res)) -def get_org_files(archived: bool = False) -> List[PathIsh]: +def get_org_files(archived: bool = False) -> List[Path]: res = [] for p in get_org_paths(): res.extend(_get_org_files_in(p, archived=archived))