mirror of
https://github.com/ArchiveBox/ArchiveBox.git
synced 2025-05-18 00:54:26 -04:00
simplify archivebox.constants to just use benedict instead of kludgy NamedTuple
This commit is contained in:
parent
80d3def206
commit
45736036e0
1 changed files with 222 additions and 229 deletions
|
@ -2,8 +2,8 @@ __package__ = 'archivebox'
|
|||
|
||||
|
||||
import os
|
||||
from types import MappingProxyType
|
||||
from typing import Set, Dict, NamedTuple, Tuple
|
||||
import re
|
||||
from typing import Dict
|
||||
from pathlib import Path
|
||||
|
||||
from benedict import benedict
|
||||
|
@ -14,10 +14,10 @@ from .misc.logging import DEFAULT_CLI_COLORS
|
|||
|
||||
###################### Config ##########################
|
||||
|
||||
class ConstantsConfig(NamedTuple):
|
||||
|
||||
VERSION: str = archivebox.__version__
|
||||
VERSION: str = archivebox.VERSION
|
||||
|
||||
TIMEZONE: str = 'UTC'
|
||||
DEFAULT_CLI_COLORS: Dict[str, str] = DEFAULT_CLI_COLORS
|
||||
DISABLED_CLI_COLORS: Dict[str, str] = benedict({k: '' for k in DEFAULT_CLI_COLORS})
|
||||
|
||||
|
@ -29,7 +29,6 @@ class ConstantsConfig(NamedTuple):
|
|||
USER_PLUGINS_DIR_NAME: str = 'user_plugins'
|
||||
CUSTOM_TEMPLATES_DIR_NAME: str = 'user_templates'
|
||||
|
||||
DATA_DIR: Path = archivebox.DATA_DIR
|
||||
ARCHIVE_DIR_NAME: str = 'archive'
|
||||
SOURCES_DIR_NAME: str = 'sources'
|
||||
PERSONAS_DIR_NAME: str = 'personas'
|
||||
|
@ -67,7 +66,9 @@ class ConstantsConfig(NamedTuple):
|
|||
ROBOTS_TXT_FILENAME: str = 'robots.txt'
|
||||
FAVICON_FILENAME: str = 'favicon.ico'
|
||||
|
||||
STATICFILE_EXTENSIONSSTATICFILE_EXTENSIONS: frozenset[str] = frozenset((
|
||||
ALLOWDENYLIST_REGEX_FLAGS: int = re.IGNORECASE | re.UNICODE | re.MULTILINE
|
||||
|
||||
STATICFILE_EXTENSIONS: frozenset[str] = frozenset((
|
||||
# 99.999% of the time, URLs ending in these extensions are static files
|
||||
# that can be downloaded as-is, not html pages that need to be rendered
|
||||
'gif', 'jpeg', 'jpg', 'png', 'tif', 'tiff', 'wbmp', 'ico', 'jng', 'bmp',
|
||||
|
@ -155,7 +156,7 @@ class ConstantsConfig(NamedTuple):
|
|||
"sonic", # created by docker bind mount
|
||||
))
|
||||
|
||||
CODE_LOCATIONS = MappingProxyType(benedict({
|
||||
CODE_LOCATIONS = benedict({
|
||||
'PACKAGE_DIR': {
|
||||
'path': (archivebox.PACKAGE_DIR).resolve(),
|
||||
'enabled': True,
|
||||
|
@ -181,9 +182,9 @@ class ConstantsConfig(NamedTuple):
|
|||
'enabled': True,
|
||||
'is_valid': CUSTOM_TEMPLATES_DIR.is_dir(),
|
||||
},
|
||||
}))
|
||||
})
|
||||
|
||||
DATA_LOCATIONS = MappingProxyType(benedict({
|
||||
DATA_LOCATIONS = benedict({
|
||||
"OUTPUT_DIR": {
|
||||
"path": archivebox.DATA_DIR.resolve(),
|
||||
"enabled": True,
|
||||
|
@ -233,17 +234,9 @@ class ConstantsConfig(NamedTuple):
|
|||
"enabled": True,
|
||||
"is_valid": CACHE_DIR.is_dir(),
|
||||
},
|
||||
}))
|
||||
|
||||
def items(self):
|
||||
return self._asdict().items()
|
||||
|
||||
def keys(self):
|
||||
return self._asdict().keys()
|
||||
|
||||
def values(self):
|
||||
return self._asdict().values()
|
||||
})
|
||||
|
||||
|
||||
CONSTANTS = ConstantsConfig()
|
||||
|
||||
CONSTANTS = benedict({key: value for key, value in globals().items() if key.isupper()})
|
||||
CONSTANTS_CONFIG = CONSTANTS
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue