support for caching every MIMETYPE

This commit is contained in:
Lionel Dricot 2021-12-15 11:45:55 +01:00
parent 3d6c702fda
commit 502668c3c6
2 changed files with 16 additions and 18 deletions

View File

@ -7,11 +7,9 @@ While offline, only content cached in .cache/av-98/ is accessed.
Use "av-98.py --sync" to build a cache containing your bookmarks and all links in your bookmarks. It might be quite slow the first time, be patient.
* FIXME1: doesnt handle MIME other than text/gemini
* FIXME2: consider root file is always index.gmi
* FIXME4: certificates error are not handled in --synconly
* FIXME5: offline web browser use os.system because its the only one that understands the ">> file.txt"
* FIXME6: sync-only always tries to download "uncachable" content (such as XML, forms, gopher…) This is somewhat related to FIXME1 and FIXME2.
* TODO: number of cache updated in blackbox
* TODO: dont add to tour when sync from tour/to_fetch

32
av98.py
View File

@ -423,6 +423,7 @@ you'll be able to transparently follow links to Gopherspace!""")
else:
cached = gi.cache_path
if os.path.isfile(cached):
tmpfile = cached
mime,encoding = mimetypes.guess_type(cached,strict=False)
#gmi Mimetype is not recognized yet
if not mime and cached.endswith('.gmi'):
@ -441,22 +442,21 @@ you'll be able to transparently follow links to Gopherspace!""")
else:
try:
gi, mime, body, tmpfile = self._fetch_over_network(gi)
## We create the permanent cache for "text/gemini"
## FIXME : try caching everything eles ?
if mime == "text/gemini":
cache_dir = os.path.dirname(gi.cache_path)
os.makedirs(cache_dir,exist_ok=True)
#write cache only if content has been modified
# in order to preserve the last modified date
write_cache = False
if not os.path.exists(gi.cache_path):
write_cache = True
elif not filecmp.cmp(gi.cache_path,tmpfile):
write_cache = True
if write_cache:
with open(gi.cache_path,'w') as file:
file.write(body)
file.close()
## We create the permanent cache
cache_dir = os.path.dirname(gi.cache_path)
os.makedirs(cache_dir,exist_ok=True)
shutil.copyfile(tmpfile,gi.cache_path)
# The following is an attempt to
#write cache only if content has been modified
# in order to preserve the last modified date
# It is commented out because not useful (yet?)
#write_cache = False
#if not os.path.exists(gi.cache_path):
# write_cache = True
#elif not filecmp.cmp(gi.cache_path,tmpfile):
# write_cache = True
#if write_cache:
# shutil.copyfile(tmpfile,gi.cache_path)
except UserAbortException:
return
except Exception as err: