From 72f2b5f91cf69bd616df4e2d42a0e46491739b7e Mon Sep 17 00:00:00 2001 From: Lionel Dricot Date: Tue, 14 Dec 2021 14:06:07 +0100 Subject: [PATCH] --synconly is now --sync and has a fancy output --- README.md | 15 +++++++++------ av98.py | 34 +++++++++++++++------------------- 2 files changed, 24 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index ecc5d21..20a5780 100644 --- a/README.md +++ b/README.md @@ -5,15 +5,18 @@ This fork is an experiment by Ploum ( gemini://rawtext.club/~ploum) to add offli In AV-98, use the command "offline" to switch between offline/online. While offline, only content cached in .cache/av-98/ is accessed. -Use "av-98.py --synconly" 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. -* FIXME: doesn’t handle MIME other than text/gemini -* FIXME: consider root file is always index.gmi -* FIXME: if a file exists in the cache where it should have been a folder, it fails (should instead remove the file) -* FIXME: certificates error are not handled in --synconly -* FIXME: offline web browser use os.system because it’s the only one that understands the ">> file.txt" +* FIXME1: doesn’t handle MIME other than text/gemini +* FIXME2: consider root file is always index.gmi +* FIXME3: if a file exists in the cache where it should have been a folder, it fails (should instead remove the file) +* FIXME4: certificates error are not handled in --synconly +* FIXME5: offline web browser use os.system because it’s 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. * TODO: handle request done offline and retrieve them later +* TODO: reload while offline should mark the url for syncing +* TODO: number of cache updated in blackbox This is a fork of the original [AV-98](https://tildegit.org/solderpunk/AV-98) by Solderpunk. diff --git a/av98.py b/av98.py index cf69b8b..b6096ab 100755 --- a/av98.py +++ b/av98.py @@ -1318,15 +1318,6 @@ you'll be able to transparently follow links to Gopherspace!""") self.prompt = self.offline_prompt print("AV-98 is now offline and will only access cached content") - def do_sync_only(self, *args): - """No output for non-interactive use""" - if self.sync_only: - self.sync_only = False - print("AV-98 will display output") - else: - self.sync_only = True - print("AV-98 is in non-interactive mode. No output") - ### Stuff for getting around def do_go(self, line): """Go to a gemini URL or marked item.""" @@ -1711,8 +1702,8 @@ def main(): parser.add_argument('--tls-cert', metavar='FILE', help='TLS client certificate file') parser.add_argument('--tls-key', metavar='FILE', help='TLS client certificate private key file') parser.add_argument('--restricted', action="store_true", help='Disallow shell, add, and save commands') - parser.add_argument('--synconly', action='store_true', - help='run non-interactively to build cache') + parser.add_argument('--sync', action='store_true', + help='run non-interactively to build cache by exploring bookmarks') parser.add_argument('--version', action='store_true', help='display version information and quit') parser.add_argument('url', metavar='URL', nargs='*', @@ -1725,7 +1716,7 @@ def main(): sys.exit() # Instantiate client - gc = GeminiClient(restricted=args.restricted,synconly=args.synconly) + gc = GeminiClient(restricted=args.restricted,synconly=args.sync) # Process config file rcfile = os.path.join(gc.config_dir, "av98rc") @@ -1745,7 +1736,7 @@ def main(): gc.cmdqueue.append(line) # Say hi - if not args.synconly: + if not args.sync: print("Welcome to AV-98!") if args.restricted: print("Restricted mode engaged!") @@ -1768,24 +1759,29 @@ def main(): gc.cmdqueue.append("tour") # Endless interpret loop - if args.synconly: + if args.sync: #TODO : synconly should run only every XX hours, no more - gc.onecmd("sync_only") + gc.sync_only = True gc.onecmd("bm") #gc.onecmd("go rawtext.club/~ploum/") - original_lookup = gc.lookup[0:1] + original_lookup = gc.lookup + count = 0 + end = len(original_lookup) for j in original_lookup: - print("Caching bookmark: ",j.url) + count += 1 + print("[%s/%s] Get bookmark "%(count,end),j.url) gc.onecmd("go %s" %j.url) # Depth = 1 temp_lookup = gc.lookup #temp_lookup = [] + sec_count = 0 + sec_end = len(temp_lookup) for k in temp_lookup: - print(" --",k.url,k.is_cache_valid()) + sec_count += 1 if not k.is_cache_valid(): #if not cached, we download #and add to offline tour - print(" new -> ",k.url) + print(" -> [%s/%s] "%(sec_count,sec_end),k.url,end='\r') gc.onecmd("go %s" %k.url) # TODO: add to offline tour gc.onecmd("blackbox")