From e7c42fa1b4826c32839bf16bf5f38b3c0bdde692 Mon Sep 17 00:00:00 2001 From: Christian Heller Date: Sun, 24 Nov 2024 18:55:31 +0100 Subject: [PATCH] Replace install.py by a short shell script. --- install.py | 16 ---------------- install.sh | 7 +++++++ .../migrations}/init_0.sql | 0 .../templates}/_base.tmpl | 0 .../templates}/_macros.tmpl | 0 .../templates}/playlist.tmpl | 0 .../templates}/queries.tmpl | 0 .../templates}/results.tmpl | 0 .../templates}/video.tmpl | 0 .../templates}/videos.tmpl | 0 .../templates}/yt_video.tmpl | 0 ytplom/misc.py | 11 +++++++---- 12 files changed, 14 insertions(+), 20 deletions(-) delete mode 100755 install.py create mode 100755 install.sh rename {migrations => install_to_share/migrations}/init_0.sql (100%) rename {templates => install_to_share/templates}/_base.tmpl (100%) rename {templates => install_to_share/templates}/_macros.tmpl (100%) rename {templates => install_to_share/templates}/playlist.tmpl (100%) rename {templates => install_to_share/templates}/queries.tmpl (100%) rename {templates => install_to_share/templates}/results.tmpl (100%) rename {templates => install_to_share/templates}/video.tmpl (100%) rename {templates => install_to_share/templates}/videos.tmpl (100%) rename {templates => install_to_share/templates}/yt_video.tmpl (100%) diff --git a/install.py b/install.py deleted file mode 100755 index 991ef5f..0000000 --- a/install.py +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/env python3 -'''Ensure expected directories, files for app to work exist.''' -from shutil import copyfile -from os import makedirs, scandir -from os.path import basename, join as path_join -from ytplom.misc import PATH_APP_DATA, PATH_MIGRATIONS, PATH_TEMPLATES - -for path in (PATH_APP_DATA, PATH_TEMPLATES, PATH_MIGRATIONS): - print(f'ensuring {path}') - makedirs(path) -for path_dir in (PATH_MIGRATIONS, PATH_TEMPLATES): - for entry in scandir(basename(path_dir)): - target_path = path_join(path_dir, basename(entry.path)) - print(f'copying {entry.path} to {target_path}') - copyfile(entry.path, target_path) -print('installation finished') diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..0661178 --- /dev/null +++ b/install.sh @@ -0,0 +1,7 @@ +#!/usr/bin/sh +set -e +set -x + +PATH_APP_SHARE=~/.local/share/ytplom +mkdir -p "${PATH_APP_SHARE}" +cp -r ./install_to_share/* "${PATH_APP_SHARE}/" diff --git a/migrations/init_0.sql b/install_to_share/migrations/init_0.sql similarity index 100% rename from migrations/init_0.sql rename to install_to_share/migrations/init_0.sql diff --git a/templates/_base.tmpl b/install_to_share/templates/_base.tmpl similarity index 100% rename from templates/_base.tmpl rename to install_to_share/templates/_base.tmpl diff --git a/templates/_macros.tmpl b/install_to_share/templates/_macros.tmpl similarity index 100% rename from templates/_macros.tmpl rename to install_to_share/templates/_macros.tmpl diff --git a/templates/playlist.tmpl b/install_to_share/templates/playlist.tmpl similarity index 100% rename from templates/playlist.tmpl rename to install_to_share/templates/playlist.tmpl diff --git a/templates/queries.tmpl b/install_to_share/templates/queries.tmpl similarity index 100% rename from templates/queries.tmpl rename to install_to_share/templates/queries.tmpl diff --git a/templates/results.tmpl b/install_to_share/templates/results.tmpl similarity index 100% rename from templates/results.tmpl rename to install_to_share/templates/results.tmpl diff --git a/templates/video.tmpl b/install_to_share/templates/video.tmpl similarity index 100% rename from templates/video.tmpl rename to install_to_share/templates/video.tmpl diff --git a/templates/videos.tmpl b/install_to_share/templates/videos.tmpl similarity index 100% rename from templates/videos.tmpl rename to install_to_share/templates/videos.tmpl diff --git a/templates/yt_video.tmpl b/install_to_share/templates/yt_video.tmpl similarity index 100% rename from templates/yt_video.tmpl rename to install_to_share/templates/yt_video.tmpl diff --git a/ytplom/misc.py b/ytplom/misc.py index 9e46c82..647ad39 100644 --- a/ytplom/misc.py +++ b/ytplom/misc.py @@ -82,9 +82,6 @@ QUOTA_COST_YOUTUBE_DETAILS = QuotaCost(1) # local expectations TIMESTAMP_FMT = '%Y-%m-%d %H:%M:%S.%f' LEGAL_EXTENSIONS = {'webm', 'mp4', 'mkv'} -VIDEO_FLAGS: dict[FlagName, FlagsInt] = { - FlagName('delete'): FlagsInt(1 << 62) -} # tables to create database with EXPECTED_DB_VERSION = 0 @@ -93,6 +90,12 @@ PATH_MIGRATIONS = PathStr(path_join(PATH_APP_DATA, 'migrations')) PATH_DB_SCHEMA = PathStr(path_join(PATH_MIGRATIONS, f'init_{EXPECTED_DB_VERSION}.sql')) +# other +NAME_INSTALLER = 'install.sh' +VIDEO_FLAGS: dict[FlagName, FlagsInt] = { + FlagName('delete'): FlagsInt(1 << 62) +} + class NotFoundException(Exception): """Raise on expected data missing, e.g. DB fetches finding nothing.""" @@ -126,7 +129,7 @@ class DatabaseConnection: if not isdir(path_db_dir): raise NotFoundException( f'cannot find {path_db_dir} as directory to put DB ' - 'into, did you run install.py?') + f'into, did you run {NAME_INSTALLER}?') with sql_connect(self._path) as conn: with open(PATH_DB_SCHEMA, 'r', encoding='utf8') as f: conn.executescript(f.read()) -- 2.30.2