netcache_migration.py 1.1 KB

1234567891011121314151617181920212223242526272829303132
  1. #!/usr/bin/env python3
  2. # SPDX-FileCopyrightText: 2023 Sotiris Papatheodorou
  3. # SPDX-License-Identifier: BSD-2-Clause
  4. """
  5. A script to migrate the offpunk cache to the newest version.
  6. For each new version of offpunk that requires changes to the cache a migration
  7. function should be written. The name of the function should have the format
  8. v<major-version>_<minor-version>_<patch-version> and it should accept the
  9. offpunk cache directory as a string. The function should perform a migration
  10. from the immediately previous cache format. All migration functions must be
  11. called at the end of this script from oldest to newest.
  12. """
  13. import argparse
  14. import os
  15. import os.path
  16. def upgrade_to_1(cache_dir: str) -> None:
  17. """
  18. Rename index.txt to gophermap in the Gopher protocol cache.
  19. """
  20. print("Upgrading cache to version 1: migrating index.txt to gophermap")
  21. for root, _, files in os.walk(os.path.join(cache_dir, 'gopher')):
  22. for f in files:
  23. if f == 'index.txt':
  24. src = os.path.join(root, f)
  25. dst = os.path.join(root, 'gophermap')
  26. os.rename(src, dst)