From 821eb47c936385a42785af43be9a02d3a4640997 Mon Sep 17 00:00:00 2001 From: Dima Gerasimov Date: Thu, 4 Jun 2020 22:43:10 +0100 Subject: [PATCH] kobo: BREAKING changes. Use kobuddy module directly, rename export_dir to export_path. Hopefully this makes a lot of sense in the first place, and not that many users, so deserves breaking. --- doc/MODULES.org | 14 ++++++++++++++ my/books/__init__.py | 0 my/books/kobo.py | 5 +++++ my/coding/github.py | 3 ++- my/kobo.py | 35 ++++++++++++++++++++++++++++------- my/kython/kompress.py | 3 ++- 6 files changed, 51 insertions(+), 9 deletions(-) delete mode 100644 my/books/__init__.py create mode 100644 my/books/kobo.py diff --git a/doc/MODULES.org b/doc/MODULES.org index 4b33143..5011cae 100644 --- a/doc/MODULES.org +++ b/doc/MODULES.org @@ -27,6 +27,7 @@ If you have some issues with the setup, see [[file:SETUP.org::#troubleshooting][ - [[#myinstapaper][my.instapaper]] - [[#mygithubgdpr][my.github.gdpr]] - [[#mygithubghexport][my.github.ghexport]] + - [[#mykobo][my.kobo]] :END: * Intro @@ -80,6 +81,7 @@ modules = [ ('instapaper' , 'my.instapaper' ), ('github' , 'my.github.gdpr' ), ('github' , 'my.github.ghexport' ), + ('kobo' , 'my.kobo' ), ] def indent(s, spaces=4): @@ -261,3 +263,15 @@ for cls, p in modules: # if omitted, will use /tmp cache_dir: Optional[PathIsh] = None #+end_src +** [[file:../my/kobo.py][my.kobo]] + + [[https://uk.kobobooks.com/products/kobo-aura-one][Kobo]] e-ink reader: annotations and reading stats + + #+begin_src python + class kobo: + ''' + Uses [[https://github.com/karlicoss/kobuddy#as-a-backup-tool][kobuddy]] outputs. + ''' + # path[s]/glob to the exported databases + export_path: Paths + #+end_src diff --git a/my/books/__init__.py b/my/books/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/my/books/kobo.py b/my/books/kobo.py new file mode 100644 index 0000000..10b0352 --- /dev/null +++ b/my/books/kobo.py @@ -0,0 +1,5 @@ +import warnings + +warnings.warn('my.books.kobo is deprecated! Please use my.kobo instead!') + +from ..kobo import * diff --git a/my/coding/github.py b/my/coding/github.py index e1e0d77..9358b04 100644 --- a/my/coding/github.py +++ b/my/coding/github.py @@ -1,6 +1,7 @@ import warnings -warnings.warn('my.coding.github is deprecated! Please use my.github.all instead!', DeprecationWarning) +warnings.warn('my.coding.github is deprecated! Please use my.github.all instead!') +# todo why aren't DeprecationWarning shown by default?? from ..github.all import events, get_events diff --git a/my/kobo.py b/my/kobo.py index 9b27642..51a86f1 100644 --- a/my/kobo.py +++ b/my/kobo.py @@ -1,18 +1,38 @@ """ [[https://uk.kobobooks.com/products/kobo-aura-one][Kobo]] e-ink reader: annotations and reading stats """ -from typing import Callable, Union, List -from my.config import kobo as config -from my.config.repos.kobuddy.src.kobuddy import * -# hmm, explicit imports make pylint a bit happier.. -from my.config.repos.kobuddy.src.kobuddy import Highlight, set_databases, get_highlights +# TODO require installing kobuddy, need to upload to pypi as well? +from dataclasses import dataclass +from .core import Paths +from my.config import kobo as user_config +@dataclass +class kobo(user_config): + ''' + Uses [[https://github.com/karlicoss/kobuddy#as-a-backup-tool][kobuddy]] outputs. + ''' + # path[s]/glob to the exported databases + export_path: Paths + + +from .core.cfg import make_config +config = make_config(kobo) + +from .core import get_files +import kobuddy +# todo not sure about this glob.. +kobuddy.DATABASES = list(get_files(config.export_path, glob='*.sqlite')) + +######################### + +# hmm, explicit imports make pylint a bit happier? +from kobuddy import Highlight, get_highlights +from kobuddy import * -set_databases(config.export_dir) def stats(): - from ..core import stat + from .core import stat return { **stat(get_highlights), } @@ -20,6 +40,7 @@ def stats(): ## TODO hmm. not sure if all this really belongs here?... perhaps orger? +from typing import Callable, Union, List # TODO maybe type over T? _Predicate = Callable[[str], bool] Predicatish = Union[str, _Predicate] diff --git a/my/kython/kompress.py b/my/kython/kompress.py index 057627a..df49bcc 100644 --- a/my/kython/kompress.py +++ b/my/kython/kompress.py @@ -43,7 +43,8 @@ def kopen(path: PathIsh, *args, mode: str='rt', **kwargs) -> IO[str]: ifile.seekable = lambda: False # type: ignore ifile.read1 = ifile.read # type: ignore # TODO pass all kwargs here?? - return io.TextIOWrapper(ifile, encoding=encoding) + # todo 'expected "BinaryIO"'?? + return io.TextIOWrapper(ifile, encoding=encoding) # type: ignore[arg-type] elif suf in {'.lz4'}: import lz4.frame # type: ignore return lz4.frame.open(str(pp), mode, *args, **kwargs)