Solve accessing url without trailing / and add online command
This commit is contained in:
parent
ce38b49ba6
commit
de840bdf9f
12
README.md
12
README.md
|
@ -1,14 +1,20 @@
|
||||||
# AV-98
|
# AV-98
|
||||||
|
|
||||||
This fork is an experiment by Ploum ( gemini://rawtext.club/~ploum) to add offline capabilities to AV-98.
|
This fork is an experiment by Ploum ( gemini://rawtext.club/~ploum) to add offline capabilities to AV-98, including a persistent "tour" option.
|
||||||
|
|
||||||
In AV-98, use the command "offline" to switch between offline/online.
|
In AV-98, use the commands "online" and "offline" to switch between offline/online.
|
||||||
While offline, only content cached in .cache/av-98/ is accessed.
|
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.
|
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.
|
||||||
|
|
||||||
|
Uncached ressources tentatively accessed offline will be accessed with the next --sync, including reload of already cached ressources.
|
||||||
|
|
||||||
|
New ressources discovered while --sync will be added to your tour.
|
||||||
|
|
||||||
|
|
||||||
|
Known issues in the code:
|
||||||
* FIXME2: consider root file is always index.gmi
|
* FIXME2: consider root file is always index.gmi
|
||||||
* FIXME4: certificates error are not handled in --synconly
|
* FIXME4: certificates error are not handled in --sync
|
||||||
* FIXME5: offline web browser use os.system because it’s the only one that understands the ">> file.txt"
|
* FIXME5: offline web browser use os.system because it’s the only one that understands the ">> file.txt"
|
||||||
|
|
||||||
* TODO: number of cache updated in blackbox
|
* TODO: number of cache updated in blackbox
|
||||||
|
|
25
av98.py
25
av98.py
|
@ -155,7 +155,10 @@ class GeminiItem():
|
||||||
# FIXME : this is a gross hack to give a name to
|
# FIXME : this is a gross hack to give a name to
|
||||||
# index files. This will break if the index is not
|
# index files. This will break if the index is not
|
||||||
# index.gmi. I don’t know how to know the real name
|
# index.gmi. I don’t know how to know the real name
|
||||||
# of the file.
|
# of the file. But first, we need to ensure that the domain name
|
||||||
|
# finish by "/". Else, the cache with create a file, not a folder.
|
||||||
|
if self.path == "":
|
||||||
|
self.cache_path += "/"
|
||||||
if self.cache_path.endswith("/"):
|
if self.cache_path.endswith("/"):
|
||||||
self.cache_path += "index.gmi"
|
self.cache_path += "index.gmi"
|
||||||
|
|
||||||
|
@ -444,6 +447,8 @@ you'll be able to transparently follow links to Gopherspace!""")
|
||||||
gi, mime, body, tmpfile = self._fetch_over_network(gi)
|
gi, mime, body, tmpfile = self._fetch_over_network(gi)
|
||||||
## We create the permanent cache
|
## We create the permanent cache
|
||||||
cache_dir = os.path.dirname(gi.cache_path)
|
cache_dir = os.path.dirname(gi.cache_path)
|
||||||
|
if os.path.isfile(cache_dir):
|
||||||
|
os.remove(cache_dir)
|
||||||
os.makedirs(cache_dir,exist_ok=True)
|
os.makedirs(cache_dir,exist_ok=True)
|
||||||
shutil.copyfile(tmpfile,gi.cache_path)
|
shutil.copyfile(tmpfile,gi.cache_path)
|
||||||
# The following is an attempt to
|
# The following is an attempt to
|
||||||
|
@ -479,6 +484,10 @@ you'll be able to transparently follow links to Gopherspace!""")
|
||||||
if print_error:
|
if print_error:
|
||||||
print("""ERROR3: Connection timed out!
|
print("""ERROR3: Connection timed out!
|
||||||
Slow internet connection? Use 'set timeout' to be more patient.""")
|
Slow internet connection? Use 'set timeout' to be more patient.""")
|
||||||
|
elif isinstance(err, FileExistsError):
|
||||||
|
print("""ERROR5: Trying to create a directory which already exists
|
||||||
|
in the cache : """)
|
||||||
|
print(err)
|
||||||
else:
|
else:
|
||||||
# we fail silently when sync_only
|
# we fail silently when sync_only
|
||||||
if print_error:
|
if print_error:
|
||||||
|
@ -1326,13 +1335,19 @@ you'll be able to transparently follow links to Gopherspace!""")
|
||||||
def do_offline(self, *args):
|
def do_offline(self, *args):
|
||||||
"""Use AV-98 offline by only accessing cached content"""
|
"""Use AV-98 offline by only accessing cached content"""
|
||||||
if self.offline_only:
|
if self.offline_only:
|
||||||
self.offline_only = False
|
print("Offline and undisturbed.")
|
||||||
self.prompt = self.no_cert_prompt
|
|
||||||
print("AV-98 is online and will access the network")
|
|
||||||
else:
|
else:
|
||||||
self.offline_only = True
|
self.offline_only = True
|
||||||
self.prompt = self.offline_prompt
|
self.prompt = self.offline_prompt
|
||||||
print("AV-98 is now offline and will only access cached content")
|
print("AV-98 is now offline and will only access cached content")
|
||||||
|
|
||||||
|
def do_online(self, *args):
|
||||||
|
if self.offline_only:
|
||||||
|
self.offline_only = False
|
||||||
|
self.prompt = self.no_cert_prompt
|
||||||
|
print("AV-98 is online and will access the network")
|
||||||
|
else:
|
||||||
|
print("Already online. Try offline.")
|
||||||
|
|
||||||
### Stuff for getting around
|
### Stuff for getting around
|
||||||
def do_go(self, line):
|
def do_go(self, line):
|
||||||
|
@ -1823,7 +1838,7 @@ def main():
|
||||||
print("[%s/%s] Fetch "%(count,end),j.url)
|
print("[%s/%s] Fetch "%(count,end),j.url)
|
||||||
gc.onecmd("go %s" %j.url)
|
gc.onecmd("go %s" %j.url)
|
||||||
# Depth = 1
|
# Depth = 1
|
||||||
temp_lookup = gc.lookup
|
temp_lookup = set(gc.lookup)
|
||||||
#temp_lookup = []
|
#temp_lookup = []
|
||||||
sec_count = 0
|
sec_count = 0
|
||||||
sec_end = len(temp_lookup)
|
sec_end = len(temp_lookup)
|
||||||
|
|
Loading…
Reference in New Issue