wrolpi/wrolpi/cmd.py
Roland abb0b49315
Checking for icesheet table as current user.
Importing maps as wrolpi user, then changing ownership to _renderd.

Changing ownership of /opt/wrolpi as well.

Creating pgpass for wrolpi user in debian 11.

Install specific version of serve.

Not echoing the echo.

Updating cache directory in create_db.sh.

Use python binary to run db upgrade.

Install renderd.conf to /etc on RPi OS.

Fetching DC map from wrolpi.org to avoid broken daily PBFs.

Only get latest dc map if it doesn't exist.

carto switched again??

Changing mod_tile directory to /var/cache/renderd/tiles for RPi OS.

Copying renderd configs for RPi OS.

Installing postgres 13 for RPi OS map.

Changing title of feature matrix.

Moving download link up in readme.

Changing mod_tile to _renderd.

Using unix socket rather than host connection.

Getting openstreetmap-carto as _renderd user.

Assigning ownership of gis db to _renderd in reset_map.sh.

Creating _renderd db user.

Using _renderd to run renderd on debian 11.

Installing python modules that map requires globally.

Upgrading db using venv.

Installing nodejs which installs npm.

Install npm/node after other dependencies.

Updating apt so nodejs can be installed.

Upgrading PyYAML in new venv.

Installing pip via apt.

Including bash binary for portability.

Moving images link out of list.

Moving download up on Readme.

Removing map installation from readme.

Installing specific version of carto.

Creating venv for wrolpi project.  Using venv to install requirements and run wrolpi's main.py.

Logging upgrade script.

Including upgrade script in Upgrade readme.

Moving upgrade logic into separate script.  This is necessary so and repo update will take immediate effect on the upgrade.

Modifying and unifying Debian installation with RPi OS installation.
2023-02-24 16:16:13 -07:00

90 lines
3 KiB
Python

"""Paths for third-party commands that WROLPi may require."""
import os
import shutil
from pathlib import Path
from typing import Optional
from wrolpi import flags
from wrolpi.common import logger
from wrolpi.vars import PYTEST, DOCKERIZED
logger = logger.getChild(__name__)
def is_executable(path: Path) -> bool:
"""Returns True if the file is executable."""
return path.is_file() and os.access(path, os.X_OK)
def which(*possible_paths: str, warn: bool = False, flag: str = None) -> Optional[Path]:
"""
Find an executable in the system $PATH. If the executable cannot be found in $PATH, then return the first
executable found in possible_paths.
Returns None if no executable can be found.
"""
found = None
possible_paths = list(map(Path, possible_paths))
for path in possible_paths:
if is_executable(path):
# `path` was an absolute file which is executable.
found = path
break
path = shutil.which(path)
if path and (path := Path(path).absolute()) and is_executable(path):
# `path` was a name or relative path.
found = path
if not found and warn and not PYTEST and not DOCKERIZED:
logger.warning(f'Cannot find executable {possible_paths[0]}')
return
elif found:
if flag:
# Mark the command as installed.
try:
getattr(flags, flag).set()
except AttributeError as e:
logger.error(f'Unable to set flag {flag}', exc_info=e)
return found.absolute()
# Admin
SUDO_BIN = which('sudo', '/usr/bin/sudo')
NMCLI_BIN = which('nmcli', '/usr/bin/nmcli', flag='nmcli_installed')
CPUFREQ_INFO_BIN = which('cpufreq-info', '/usr/bin/cpufreq-info')
CPUFREQ_SET_BIN = which('cpufreq-set', '/usr/bin/cpufreq-set')
# Map
BASH_BIN = which('bash', '/bin/bash', warn=True)
# Archive
SINGLE_FILE_BIN = which('single-file',
'/usr/bin/single-file', # rpi os
'/usr/local/bin/single-file', # debian
warn=True,
flag='singlefile_installed',
)
CHROMIUM = which('chromium-browser', 'chromium',
'/usr/bin/chromium-browser', # rpi os
'/usr/bin/chromium', # debian
warn=True,
flag='chromium_installed',
)
READABILITY_BIN = which('readability-extractor',
'/usr/bin/readability-extractor', # rpi os
'/usr/local/bin/readability-extractor', # debian
warn=True,
flag='readability_installed',
)
# Videos
YT_DLP_BIN = which(
'yt-dlp',
'/usr/local/bin/yt-dlp', # Location in docker container
'/opt/wrolpi/venv/bin/yt-dlp', # Use virtual environment location
warn=True,
flag='yt_dlp_installed',
)
FFPROBE_BIN = which('ffprobe', '/usr/bin/ffprobe', warn=True, flag='ffprobe_installed')
FFMPEG_BIN = which('ffmpeg', '/usr/bin/ffmpeg', flag='ffmpeg_installed')