Change the Gopher index filename to gophermap

This seems to be the most common convention among gopher servers (e.g.
Gophernicus, go-gopher).

Added a script to migrate the cache to the new format. Alternatively the
following command can be used for migration in a POSIX system:

find ~/.cache/offpunk/gopher/ -type f -name 'index.txt' -exec sh -c 'mv {} "$(dirname {})/gophermap"' \;
This commit is contained in:
Sotiris Papatheodorou - sotiris at papatheodorou.xyz 2023-04-12 01:14:28 +03:00 committed by Lionel Dricot
parent a73790f0fb
commit 2cc599afdd
3 changed files with 51 additions and 1 deletions

View File

@ -2,6 +2,7 @@
## 1.10 - unreleased
- IMPORTANT : new optional dependency : python-chardet
- IMPORTANT : Gopher directory index filename changed from "index.txt" to "gophermap". To update the cache to the new format run the `migrate-offpunk-cache` script (Sotiris Papatheodorou)
- "set accept_bad_ssl_certificates True" now also used for Gemini expired certificates
- Add missing chardet module (Sotiris Papatheodorou)
- Fix merging dictionaries with common keys (Sotiris Papatheodorou)

47
migrate-offpunk-cache Executable file
View File

@ -0,0 +1,47 @@
#!/usr/bin/env python3
# SPDX-FileCopyrightText: 2023 Sotiris Papatheodorou
# SPDX-License-Identifier: BSD-2-Clause
"""
A script to migrate the offpunk cache to the newest version.
For each new version of offpunk that requires changes to the cache a migration
function should be written. The name of the function should have the format
v<major-version>_<minor-version>_<patch-version> and it should accept the
offpunk cache directory as a string. The function should perform a migration
from the immediately previous cache format. All migration functions must be
called at the end of this script from oldest to newest.
"""
import argparse
import os
import os.path
def v1_10_0(cache_dir: str) -> None:
"""
Rename index.txt to gophermap in the Gopher protocol cache.
"""
for root, _, files in os.walk(os.path.join(cache_dir, 'gopher')):
for f in files:
if f == 'index.txt':
src = os.path.join(root, f)
dst = os.path.join(root, 'gophermap')
os.rename(src, dst)
if __name__ == '__main__':
# Compute the default offpunk cache directory.
xdg_cache_home = os.environ.get('XDG_CACHE_HOME')
if xdg_cache_home:
default_cache_dir = os.path.join(xdg_cache_home, 'offpunk')
else:
default_cache_dir = os.path.join(os.path.expanduser('~'), '.cache/offpunk')
# Parse command line arguments.
parser = argparse.ArgumentParser(
description='Migrate the offpunk cache to a newer version.')
parser.add_argument('cache_dir', metavar='CACHE_DIR', nargs='?',
default=default_cache_dir, help='the path to the cache')
args = parser.parse_args()
# Run the cache migration functions from the oldest to the newest version.
v1_10_0(args.cache_dir)

View File

@ -1439,8 +1439,10 @@ class GeminiItem():
# finish by "/". Else, the cache will create a file, not a folder.
if self.scheme.startswith("http"):
index = "index.html"
elif self.scheme in ["gopher", "finger"]:
elif self.scheme == "finger":
index = "index.txt"
elif self.scheme == "gopher":
index = "gophermap"
else:
index = "index.gmi"
if self.path == "" or os.path.isdir(self._cache_path):