1
0
Fork 0

move SYSTEM_USER call to get_system_user func

This commit is contained in:
Nick Sweeting 2024-01-02 17:09:31 -08:00
parent a0c16ecae0
commit 73993d26c0
2 changed files with 29 additions and 26 deletions

View file

@ -52,26 +52,6 @@ from .config_stubs import (
) )
### Pre-Fetch Minimal System Config
TIMEZONE = 'UTC'
SYSTEM_USER = getpass.getuser() or os.getlogin()
try:
import pwd
SYSTEM_USER = pwd.getpwuid(os.geteuid()).pw_name or SYSTEM_USER
except KeyError:
# Process' UID might not map to a user in cases such as running the Docker image
# (where `archivebox` is 999) as a different UID.
pass
except ModuleNotFoundError:
# pwd is only needed for some linux systems, doesn't exist on windows
pass
except Exception:
# this should never happen, uncomment to debug
# raise
pass
############################### Config Schema ################################## ############################### Config Schema ##################################
CONFIG_SCHEMA: Dict[str, ConfigDefaultDict] = { CONFIG_SCHEMA: Dict[str, ConfigDefaultDict] = {
@ -377,7 +357,32 @@ ALLOWED_IN_OUTPUT_DIR = {
'static_index.json', 'static_index.json',
} }
def get_version(config) -> str:
ALLOWDENYLIST_REGEX_FLAGS: int = re.IGNORECASE | re.UNICODE | re.MULTILINE
############################## Version Config ##################################
def get_system_user():
SYSTEM_USER = getpass.getuser() or os.getlogin()
try:
import pwd
return pwd.getpwuid(os.geteuid()).pw_name or SYSTEM_USER
except KeyError:
# Process' UID might not map to a user in cases such as running the Docker image
# (where `archivebox` is 999) as a different UID.
pass
except ModuleNotFoundError:
# pwd doesn't exist on windows
pass
except Exception:
# this should never happen, uncomment to debug
# raise
pass
return SYSTEM_USER
def get_version(config):
try: try:
return importlib.metadata.version(__package__ or 'archivebox') return importlib.metadata.version(__package__ or 'archivebox')
except importlib.metadata.PackageNotFoundError: except importlib.metadata.PackageNotFoundError:
@ -467,14 +472,11 @@ def can_upgrade(config):
############################## Derived Config ################################## ############################## Derived Config ##################################
ALLOWDENYLIST_REGEX_FLAGS: int = re.IGNORECASE | re.UNICODE | re.MULTILINE
# These are derived/computed values calculated *after* all user-provided config values are ingested # These are derived/computed values calculated *after* all user-provided config values are ingested
# they appear in `archivebox config` output and are intended to be read-only for the user # they appear in `archivebox config` output and are intended to be read-only for the user
DYNAMIC_CONFIG_SCHEMA: ConfigDefaultDict = { DYNAMIC_CONFIG_SCHEMA: ConfigDefaultDict = {
'TERM_WIDTH': {'default': lambda c: lambda: shutil.get_terminal_size((100, 10)).columns}, 'TERM_WIDTH': {'default': lambda c: lambda: shutil.get_terminal_size((100, 10)).columns},
'USER': {'default': lambda c: SYSTEM_USER}, 'USER': {'default': lambda c: get_system_user()},
'ANSI': {'default': lambda c: DEFAULT_CLI_COLORS if c['USE_COLOR'] else {k: '' for k in DEFAULT_CLI_COLORS.keys()}}, 'ANSI': {'default': lambda c: DEFAULT_CLI_COLORS if c['USE_COLOR'] else {k: '' for k in DEFAULT_CLI_COLORS.keys()}},
'PACKAGE_DIR': {'default': lambda c: Path(__file__).resolve().parent}, 'PACKAGE_DIR': {'default': lambda c: Path(__file__).resolve().parent},

View file

@ -12,7 +12,8 @@ version: '3.9'
services: services:
archivebox: archivebox:
image: ${DOCKER_IMAGE:-archivebox/archivebox:dev} #image: ${DOCKER_IMAGE:-archivebox/archivebox:dev}
image: archivebox:dev
command: server --quick-init 0.0.0.0:8000 command: server --quick-init 0.0.0.0:8000
ports: ports:
- 8000:8000 - 8000:8000