|
30 | 30 | 'https://tldr-pages.github.io/assets/tldr.zip'
|
31 | 31 | )
|
32 | 32 |
|
| 33 | +USE_NETWORK = int(os.environ.get('TLDR_NETWORK_ENABLED', '1')) > 0 |
33 | 34 | USE_CACHE = int(os.environ.get('TLDR_CACHE_ENABLED', '1')) > 0
|
34 | 35 | MAX_CACHE_AGE = int(os.environ.get('TLDR_CACHE_MAX_AGE', 24))
|
35 | 36 |
|
@@ -75,11 +76,11 @@ def get_default_language() -> str:
|
75 | 76 |
|
76 | 77 |
|
77 | 78 | def get_cache_dir() -> str:
|
78 |
| - if not os.environ.get('XDG_CACHE_HOME', False): |
79 |
| - if not os.environ.get('HOME', False): |
80 |
| - return os.path.join(os.path.expanduser("~"), ".cache", "tldr") |
| 79 | + if os.environ.get('XDG_CACHE_HOME', False): |
| 80 | + return os.path.join(os.environ.get('XDG_CACHE_HOME'), 'tldr') |
| 81 | + if os.environ.get('HOME', False): |
81 | 82 | return os.path.join(os.environ.get('HOME'), '.cache', 'tldr')
|
82 |
| - return os.path.join(os.environ.get('XDG_CACHE_HOME'), 'tldr') |
| 83 | + return os.path.join(os.path.expanduser("~"), ".cache", "tldr") |
83 | 84 |
|
84 | 85 |
|
85 | 86 | def get_cache_file_path(command: str, platform: str, language: str) -> str:
|
@@ -163,10 +164,12 @@ def get_page_for_platform(
|
163 | 164 | ).read()
|
164 | 165 | data_downloaded = True
|
165 | 166 | except Exception:
|
| 167 | + if not USE_CACHE: |
| 168 | + raise |
166 | 169 | data = load_page_from_cache(command, platform, language)
|
167 | 170 | if data is None:
|
168 | 171 | raise
|
169 |
| - if data_downloaded: |
| 172 | + if data_downloaded and USE_CACHE: |
170 | 173 | store_page_to_cache(data, command, platform, language)
|
171 | 174 | return data.splitlines()
|
172 | 175 |
|
|
0 commit comments