MCPcopy
hub / github.com/ArchiveBox/ArchiveBox / config

Function config

archivebox/main.py:1068–1160  ·  view source on GitHub ↗

Get and set your ArchiveBox project configuration values

(config_options_str: Optional[str]=None,
           config_options: Optional[List[str]]=None,
           get: bool=False,
           set: bool=False,
           reset: bool=False,
           out_dir: Path=OUTPUT_DIR)

Source from the content-addressed store, hash-verified

1066
1067@enforce_types
1068def config(config_options_str: Optional[str]=None,
1069 config_options: Optional[List[str]]=None,
1070 get: bool=False,
1071 set: bool=False,
1072 reset: bool=False,
1073 out_dir: Path=OUTPUT_DIR) -> None:
1074 """Get and set your ArchiveBox project configuration values"""
1075
1076 check_data_folder(out_dir=out_dir)
1077
1078 if config_options and config_options_str:
1079 stderr(
1080 '[X] You should either pass config values as an arguments '
1081 'or via stdin, but not both.\n',
1082 color='red',
1083 )
1084 raise SystemExit(2)
1085 elif config_options_str:
1086 config_options = config_options_str.split('\n')
1087
1088 config_options = config_options or []
1089
1090 no_args = not (get or set or reset or config_options)
1091
1092 matching_config: ConfigDict = {}
1093 if get or no_args:
1094 if config_options:
1095 config_options = [get_real_name(key) for key in config_options]
1096 matching_config = {key: CONFIG[key] for key in config_options if key in CONFIG}
1097 failed_config = [key for key in config_options if key not in CONFIG]
1098 if failed_config:
1099 stderr()
1100 stderr('[X] These options failed to get', color='red')
1101 stderr(' {}'.format('\n '.join(config_options)))
1102 raise SystemExit(1)
1103 else:
1104 matching_config = CONFIG
1105
1106 print(printable_config(matching_config))
1107 raise SystemExit(not matching_config)
1108 elif set:
1109 new_config = {}
1110 failed_options = []
1111 for line in config_options:
1112 if line.startswith('#') or not line.strip():
1113 continue
1114 if '=' not in line:
1115 stderr('[X] Config KEY=VALUE must have an = sign in it', color='red')
1116 stderr(f' {line}')
1117 raise SystemExit(2)
1118
1119 raw_key, val = line.split('=', 1)
1120 raw_key = raw_key.upper().strip()
1121 key = get_real_name(raw_key)
1122 if key != raw_key:
1123 stderr(f'[i] Note: The config option {raw_key} has been renamed to {key}, please use the new name going forwards.', color='lightyellow')
1124
1125 if key in CONFIG:

Callers 2

setupFunction · 0.85
mainFunction · 0.85

Calls 6

check_data_folderFunction · 0.85
stderrFunction · 0.85
get_real_nameFunction · 0.85
printable_configFunction · 0.85
write_config_fileFunction · 0.85
load_all_configFunction · 0.85

Tested by

no test coverage detected