diff --git a/archivebox/logging_util.py b/archivebox/logging_util.py index 2fbcbb35..0a41fe5f 100644 --- a/archivebox/logging_util.py +++ b/archivebox/logging_util.py @@ -3,6 +3,7 @@ __package__ = 'archivebox' import re import os import sys +import stat import time import argparse from math import log @@ -11,7 +12,7 @@ from pathlib import Path from datetime import datetime from dataclasses import dataclass -from typing import Optional, List, Dict, Union, IO, TYPE_CHECKING +from typing import Any, Optional, List, Dict, Union, IO, TYPE_CHECKING if TYPE_CHECKING: from .index.schema import Link, ArchiveResult @@ -21,8 +22,10 @@ from .config import ( ConfigDict, OUTPUT_DIR, PYTHON_ENCODING, + VERSION, ANSI, IS_TTY, + IN_DOCKER, TERM_WIDTH, SHOW_PROGRESS, SOURCES_DIR_NAME, @@ -50,6 +53,32 @@ class RuntimeStats: _LAST_RUN_STATS = RuntimeStats() +def debug_dict_summary(obj: Dict[Any, Any]) -> None: + stderr(' '.join(f'{key}={str(val).ljust(6)}' for key, val in obj.items())) + + +def get_fd_info(fd) -> Dict[str, Any]: + NAME = fd.name[1:-1] + FILENO = fd.fileno() + MODE = os.fstat(FILENO).st_mode + IS_TTY = hasattr(fd, 'isatty') and fd.isatty() + IS_PIPE = stat.S_ISFIFO(MODE) + IS_FILE = stat.S_ISREG(MODE) + IS_TERMINAL = not (IS_PIPE or IS_FILE) + IS_LINE_BUFFERED = fd.line_buffering + IS_READABLE = fd.readable() + return {key: val for key, val in locals().items() if val is not fd} + + +# # Log debug information about stdin, stdout, and stderr +# sys.stdout.write('[>&1] this is python stdout\n') +# sys.stderr.write('[>&2] this is python stderr\n') + +# debug_dict_summary(get_fd_info(sys.stdin)) +# debug_dict_summary(get_fd_info(sys.stdout)) +# debug_dict_summary(get_fd_info(sys.stderr)) + + class SmartFormatter(argparse.HelpFormatter): """Patched formatter that prints newlines in argparse help strings""" diff --git a/archivebox/main.py b/archivebox/main.py index 8a823597..05c501c0 100644 --- a/archivebox/main.py +++ b/archivebox/main.py @@ -67,7 +67,9 @@ from .config import ( ConfigDict, ANSI, IS_TTY, + DEBUG, IN_DOCKER, + SHOW_PROGRESS, USER, ARCHIVEBOX_BINARY, ONLY_NEW, @@ -85,6 +87,7 @@ from .config import ( SQL_INDEX_FILENAME, ROBOTS_TXT_FILENAME, FAVICON_FILENAME, + SEARCH_BACKEND_ENGINE, check_dependencies, check_data_folder, write_config_file, @@ -220,9 +223,23 @@ def version(quiet: bool=False, if quiet: print(VERSION) else: + # ArchiveBox v0.5.6 + # Cpython Linux Linux-4.19.121-linuxkit-x86_64-with-glibc2.28 x86_64 (in Docker) (in TTY) print('ArchiveBox v{}'.format(VERSION)) p = platform.uname() - print(sys.implementation.name.title(), p.system, platform.platform(), p.machine, '(in Docker)' if IN_DOCKER else '(not in Docker)') + print( + sys.implementation.name.title(), + p.system, + platform.platform(), + p.machine, + ) + print( + f'IN_DOCKER={IN_DOCKER}', + f'DEBUG={DEBUG}', + f'IS_TTY={IS_TTY}', + f'TZ={os.environ.get("TZ", "UTC")}', + f'SEARCH_BACKEND_ENGINE={SEARCH_BACKEND_ENGINE}', + ) print() print('{white}[i] Dependency versions:{reset}'.format(**ANSI))