working archivebox update CLI cmd

This commit is contained in:
Nick Sweeting 2024-11-19 02:31:59 -08:00
parent a0edf218e8
commit c9a05c9d94
No known key found for this signature in database
7 changed files with 61 additions and 114 deletions
archivebox/base_models

View file

@ -21,6 +21,8 @@ from django.urls import reverse_lazy
from django_stubs_ext.db.models import TypedModelMeta
from archivebox.index.json import to_json
from .abid import (
ABID,
ABID_LEN,
@ -438,7 +440,7 @@ class ModelWithOutputDir(ABIDModel):
def write_indexes(self):
"""Write the Snapshot json, html, and merkle indexes to its output dir"""
print(f'{self}.write_indexes()')
print(f'{type(self).__name__}[{self.ABID}].write_indexes()')
self.OUTPUT_DIR.mkdir(parents=True, exist_ok=True)
self.migrate_output_dir()
self.save_merkle_index()
@ -447,14 +449,14 @@ class ModelWithOutputDir(ABIDModel):
def migrate_output_dir(self):
"""Move the output files to the new folder structure if needed"""
print(f'{self}.migrate_output_dir()')
print(f'{type(self).__name__}[{self.ABID}].migrate_output_dir()')
self.migrate_from_0_7_2()
self.migrate_from_0_8_6()
# ... future migrations here
def migrate_from_0_7_2(self) -> None:
"""Migrate output_dir generated by ArchiveBox <= 0.7.2 to current version"""
print(f'{self}.migrate_from_0_7_2()')
print(f'{type(self).__name__}[{self.ABID}].migrate_from_0_7_2()')
# move /data/archive/<timestamp> -> /data/archive/snapshots/<abid>
# update self.output_path = /data/archive/snapshots/<abid>
pass
@ -462,27 +464,28 @@ class ModelWithOutputDir(ABIDModel):
def migrate_from_0_8_6(self) -> None:
"""Migrate output_dir generated by ArchiveBox <= 0.8.6 to current version"""
# ... future migration code here ...
print(f'{self}.migrate_from_0_8_6()')
print(f'{type(self).__name__}[{self.ABID}].migrate_from_0_8_6()')
pass
def save_merkle_index(self, **kwargs) -> None:
"""Write the ./.index.merkle file to the output dir"""
# write self.generate_merkle_tree() to self.output_dir / '.index.merkle'
print(f'{self}.save_merkle_index()')
print(f'{type(self).__name__}[{self.ABID}].save_merkle_index()')
pass
def save_html_index(self, **kwargs) -> None:
# write self.as_html() to self.output_dir / 'index.html'
print(f'{self}.save_html_index()')
print(f'{type(self).__name__}[{self.ABID}].save_html_index()')
pass
def save_json_index(self, **kwargs) -> None:
print(f'{self}.save_json_index()')
print(f'{type(self).__name__}[{self.ABID}].save_json_index()')
# write self.as_json() to self.output_dir / 'index.json'
(self.OUTPUT_DIR / 'index.json').write_text(to_json(self.as_json()))
pass
def save_symlinks_index(self) -> None:
print(f'{self}.save_symlinks_index()')
print(f'{type(self).__name__}[{self.ABID}].save_symlinks_index()')
# ln -s ../../../../self.output_dir data/index/snapshots_by_date/2024-01-01/example.com/<abid>
# ln -s ../../../../self.output_dir data/index/snapshots_by_domain/example.com/2024-01-01/<abid>
# ln -s self.output_dir data/archive/1453452234234.21445