From d5ed7b7b5c2e55a6c243fa3d48fca472fedec415 Mon Sep 17 00:00:00 2001 From: Alex Myers Date: Fri, 26 Jan 2024 10:08:46 -0600 Subject: [PATCH] reckless: add installation metadata The metadata includes an original retrieval source, timestamp, and commit hash. This will allow a future update command to more easily evaluate the status of the existing installation. --- tools/reckless | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/tools/reckless b/tools/reckless index f22bc810e..625a99478 100755 --- a/tools/reckless +++ b/tools/reckless @@ -1,19 +1,21 @@ #!/usr/bin/env python3 -from subprocess import Popen, PIPE, TimeoutExpired, run import sys -import json -import os import argparse +import copy +import datetime +from enum import Enum +import json +import logging +import os from pathlib import Path, PosixPath import shutil +from subprocess import Popen, PIPE, TimeoutExpired, run import tempfile +import time from typing import Union from urllib.parse import urlparse from urllib.request import urlopen -import logging -import copy -from enum import Enum logging.basicConfig( @@ -654,6 +656,26 @@ def get_temp_reckless_dir() -> PosixPath: return new_path +def add_installation_metadata(installed: InstInfo, + original_request: InstInfo): + """Document the install request and installation details for use when + updating the plugin.""" + install_dir = Path(installed.source_loc) + assert install_dir.is_dir() + data = ('installation date\n' + f'{datetime.date.today().isoformat()}\n' + 'installation time\n' + f'{int(time.time())}\n' + 'original source\n' + f'{original_request.source_loc}\n' + 'requested commit\n' + f'{original_request.commit}\n' + 'installed commit\n' + f'{installed.commit}\n') + with open(install_dir / '.metadata', 'w') as metadata: + metadata.write(data) + + def _install_plugin(src: InstInfo) -> Union[InstInfo, None]: """make sure the repo exists and clone it.""" logging.debug(f'Install requested from {src}.') @@ -777,6 +799,7 @@ def _install_plugin(src: InstInfo) -> Union[InstInfo, None]: # Find this cute little plugin a forever home shutil.copytree(str(staging_path), inst_path) + add_installation_metadata(staged_src, src) print(f'plugin installed: {inst_path}') remove_dir(clone_path) return staged_src