--- /dev/null
+#!/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 NAME_TEMPLATES_DIR, PATH_APP_DATA, PATH_TEMPLATES
+
+print(f'ensuring {PATH_APP_DATA}')
+makedirs(PATH_APP_DATA)
+print(f'ensuring {PATH_TEMPLATES}')
+makedirs(PATH_TEMPLATES)
+for e in scandir(NAME_TEMPLATES_DIR):
+ target_path = path_join(PATH_TEMPLATES, basename(e.path))
+ print(f'copying {e.path} to {target_path}')
+ copyfile(e.path, target_path)
+print(f'installation finished')
# included libs
from typing import TypeAlias, Optional, NewType, Callable, Self, Any
from os import chdir, environ, getcwd, makedirs, scandir, remove as os_remove
-from os.path import (isdir, isfile, exists as path_exists, join as path_join,
- splitext, basename)
+from os.path import (dirname, isdir, isfile, exists as path_exists,
+ join as path_join, splitext, basename)
from random import shuffle
from time import time, sleep
from datetime import datetime, timedelta
| list['YoutubeVideo'] | list['YoutubeQuery']
| list[tuple[YoutubeId, PathStr]] | list[tuple[PathStr, PathStr]]]
-# local data reasonably expected to be in user home directory
+# major expected directories
PATH_HOME = PathStr(environ.get('HOME', ''))
-PATH_WORKDIR = PathStr(path_join(PATH_HOME, 'ytplom'))
-PATH_THUMBNAILS = PathStr(path_join(PATH_WORKDIR, 'thumbnails'))
-PATH_DB = PathStr(path_join(PATH_WORKDIR, 'db.sql'))
-PATH_DOWNLOADS = PathStr(path_join(PATH_WORKDIR, 'downloads'))
-PATH_TEMP = PathStr(path_join(PATH_WORKDIR, 'temp'))
-
-# template paths; might move outside PATH_WORKDIR in the future
-PATH_TEMPLATES = PathStr(path_join(PATH_WORKDIR, 'templates'))
+PATH_APP_DATA = PathStr(path_join(PATH_HOME, '.local/share/ytplom'))
+PATH_CACHE = PathStr(path_join(PATH_HOME, '.cache/ytplom'))
+
+# paths for rather dynamic data
+PATH_DOWNLOADS = PathStr(path_join(PATH_HOME, 'ytplom_downloads'))
+PATH_DB = PathStr(path_join(PATH_APP_DATA, 'db.sql'))
+PATH_TEMP = PathStr(path_join(PATH_CACHE, 'temp'))
+PATH_THUMBNAILS = PathStr(path_join(PATH_CACHE, 'thumbnails'))
+
+# template paths
+NAME_TEMPLATES_DIR = 'templates'
+PATH_TEMPLATES = PathStr(path_join(PATH_APP_DATA, NAME_TEMPLATES_DIR))
NAME_TEMPLATE_QUERIES = PathStr('queries.tmpl')
NAME_TEMPLATE_RESULTS = PathStr('results.tmpl')
NAME_TEMPLATE_VIDEOS = PathStr('videos.tmpl')
NAME_TEMPLATE_VIDEO = PathStr('video.tmpl')
NAME_TEMPLATE_YT_VIDEO = PathStr('yt_video.tmpl')
NAME_TEMPLATE_PLAYLIST = PathStr('playlist.tmpl')
-PATH_TEMPLATE_QUERIES = PathStr(path_join(PATH_TEMPLATES,
- NAME_TEMPLATE_QUERIES))
# yt_dlp config
YT_DOWNLOAD_FORMAT = 'bestvideo[height<=1080][width<=1920]+bestaudio'\
CREATE TABLE files (
rel_path TEXT PRIMARY KEY,
yt_id TEXT NOT NULL DEFAULT "",
- flags INTEGER NOT NULL DEFAULT 0;
+ flags INTEGER NOT NULL DEFAULT 0,
FOREIGN KEY (yt_id) REFERENCES yt_videos(id)
);
'''
if path_exists(self._path):
raise CantWriteException(f'no DB at {self._path}; would create'
', but something\'s already there?')
+ path_db_dir = dirname(self._path)
+ 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?')
with sql_connect(self._path) as conn:
conn.executescript(SCRIPT_INIT_DB)
self._conn = sql_connect(self._path)