add disable_cachew helper
This commit is contained in:
parent
121ed58c17
commit
21e82f0cd6
3 changed files with 36 additions and 12 deletions
29
my/core/cachew.py
Normal file
29
my/core/cachew.py
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
'''
|
||||||
|
# TODO this probably belongs to cachew? or cachew.experimental
|
||||||
|
'''
|
||||||
|
from contextlib import contextmanager
|
||||||
|
|
||||||
|
|
||||||
|
def disable_cachew():
|
||||||
|
'''
|
||||||
|
NOTE: you need to use it before importing any function using @cachew.cachew
|
||||||
|
'''
|
||||||
|
# TODO not sure... maybe it should instead use some hook.. it's a ibt ugly do
|
||||||
|
import cachew
|
||||||
|
|
||||||
|
@cachew.doublewrap
|
||||||
|
def cachew_off(func=None, *args, **kwargs):
|
||||||
|
return func
|
||||||
|
old = cachew.cachew
|
||||||
|
cachew.cachew = cachew_off
|
||||||
|
return old
|
||||||
|
|
||||||
|
|
||||||
|
@contextmanager
|
||||||
|
def disabled_cachew():
|
||||||
|
import cachew
|
||||||
|
old = disable_cachew()
|
||||||
|
try:
|
||||||
|
yield
|
||||||
|
finally:
|
||||||
|
cachew.cachew = old
|
|
@ -11,6 +11,6 @@ tz_lookup = {
|
||||||
tz_lookup['UTC'] = pytz.utc # ugh. otherwise it'z Zulu...
|
tz_lookup['UTC'] = pytz.utc # ugh. otherwise it'z Zulu...
|
||||||
|
|
||||||
|
|
||||||
@lru_cache(-1)
|
@lru_cache(None)
|
||||||
def abbr_to_timezone(abbr: str):
|
def abbr_to_timezone(abbr: str):
|
||||||
return tz_lookup[abbr]
|
return tz_lookup[abbr]
|
||||||
|
|
|
@ -2,30 +2,25 @@ from pathlib import Path
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
from .common import get_files
|
from .common import get_files
|
||||||
|
from .kython.kompress import kopen, kexists
|
||||||
|
|
||||||
from my.config import google as config
|
from my.config import google as config
|
||||||
|
|
||||||
from .kython.kompress import kopen
|
|
||||||
|
|
||||||
def get_last_takeout(*, path: Optional[str]=None) -> Path:
|
def get_last_takeout(*, path: Optional[str]=None) -> Path:
|
||||||
"""
|
"""
|
||||||
Ok, sometimes google splits takeout into two zip archives
|
Ok, sometimes google splits takeout into two zip archives
|
||||||
I guess I could detect it (they've got 001/002 etc suffixes), but fornow that works fine..
|
I guess I could detect it (they've got 001/002 etc suffixes), but fornow that works fine..
|
||||||
"""
|
"""
|
||||||
|
# TODO FIXME zip is not great..
|
||||||
|
# allow a lambda expression? that way the user could restrict it
|
||||||
for takeout in reversed(get_files(config.takeout_path, glob='*.zip')):
|
for takeout in reversed(get_files(config.takeout_path, glob='*.zip')):
|
||||||
if path is None:
|
if path is None or kexists(takeout, path):
|
||||||
return takeout
|
return takeout
|
||||||
else:
|
else:
|
||||||
try:
|
continue
|
||||||
kopen(takeout, path)
|
|
||||||
return takeout
|
|
||||||
except:
|
|
||||||
# TODO eh, a bit horrible, but works for now..
|
|
||||||
# TODO move ot kompress? 'kexists'?
|
|
||||||
continue
|
|
||||||
raise RuntimeError(f'Not found: {path}')
|
raise RuntimeError(f'Not found: {path}')
|
||||||
|
|
||||||
# TODO might be a good idea to merge across multiple taekouts...
|
# TODO might be a good idea to merge across multiple takeouts...
|
||||||
# perhaps even a special takeout module that deals with all of this automatically?
|
# perhaps even a special takeout module that deals with all of this automatically?
|
||||||
# e.g. accumulate, filter and maybe report useless takeouts?
|
# e.g. accumulate, filter and maybe report useless takeouts?
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue