|
46 | 46 | } |
47 | 47 |
|
48 | 48 |
|
| 49 | +class CacheNotExist(Exception): |
| 50 | + pass |
| 51 | + |
| 52 | + |
49 | 53 | def get_language_code(language): |
50 | 54 | language = language.split('.')[0] |
51 | 55 | if language in ['pt_PT', 'pt_BR', 'zh_TW']: |
@@ -129,10 +133,15 @@ def get_page_url(command, platform, remote, language): |
129 | 133 | return remote + language + "/" + platform + "/" + quote(command) + ".md" |
130 | 134 |
|
131 | 135 |
|
132 | | -def get_page_for_platform(command, platform, remote, language): |
| 136 | +def get_page_for_platform(command, platform, remote, language, only_use_cache=False): |
133 | 137 | data_downloaded = False |
134 | 138 | if USE_CACHE and have_recent_cache(command, platform, language): |
135 | 139 | data = load_page_from_cache(command, platform, language) |
| 140 | + elif only_use_cache: |
| 141 | + raise CacheNotExist("Cache for {} in {} not Found".format( |
| 142 | + command, |
| 143 | + platform, |
| 144 | + )) |
136 | 145 | else: |
137 | 146 | page_url = get_page_url(command, platform, remote, language) |
138 | 147 | try: |
@@ -196,6 +205,22 @@ def get_page(command, remote=None, platforms=None, languages=None): |
196 | 205 | platforms = get_platform_list() |
197 | 206 | if languages is None: |
198 | 207 | languages = get_language_list() |
| 208 | + # only use cache |
| 209 | + if USE_CACHE: |
| 210 | + for platform in platforms: |
| 211 | + for language in languages: |
| 212 | + if platform is None: |
| 213 | + continue |
| 214 | + try: |
| 215 | + return get_page_for_platform( |
| 216 | + command, |
| 217 | + platform, |
| 218 | + remote, |
| 219 | + language, |
| 220 | + only_use_cache=True, |
| 221 | + ) |
| 222 | + except CacheNotExist: |
| 223 | + continue |
199 | 224 | for platform in platforms: |
200 | 225 | for language in languages: |
201 | 226 | if platform is None: |
|
0 commit comments