rename archivebox setup to archivebox install

This commit is contained in:
Nick Sweeting 2024-09-30 23:19:11 -07:00
parent 4334c74548
commit 8c3342afe5
No known key found for this signature in database
5 changed files with 26 additions and 27 deletions

View file

@ -12,8 +12,7 @@ from typing import Optional, List, IO, Union, Iterable
from pathlib import Path from pathlib import Path
from archivebox.config import DATA_DIR from archivebox.config import DATA_DIR
from ..misc.checks import check_data_folder, check_migrations from archivebox.misc.logging import stderr
from ..misc.logging import stderr
from importlib import import_module from importlib import import_module
@ -21,6 +20,10 @@ BUILTIN_LIST = list
CLI_DIR = Path(__file__).resolve().parent CLI_DIR = Path(__file__).resolve().parent
# rewrite setup -> install for backwards compatibility
if sys.argv[1] == 'setup':
sys.argv[1] = 'install'
# def list_subcommands() -> Dict[str, str]: # def list_subcommands() -> Dict[str, str]:
# """find and import all valid archivebox_<subcommand>.py files in CLI_DIR""" # """find and import all valid archivebox_<subcommand>.py files in CLI_DIR"""
@ -46,7 +49,7 @@ SUBCOMMAND_MODULES = {
'init': 'archivebox_init', 'init': 'archivebox_init',
'config': 'archivebox_config', 'config': 'archivebox_config',
'setup': 'archivebox_setup', 'install': 'archivebox_install',
'add': 'archivebox_add', 'add': 'archivebox_add',
'remove': 'archivebox_remove', 'remove': 'archivebox_remove',
@ -98,7 +101,7 @@ CLI_SUBCOMMANDS = LazySubcommands()
# these common commands will appear sorted before any others for ease-of-use # these common commands will appear sorted before any others for ease-of-use
meta_cmds = ('help', 'version') # dont require valid data folder at all meta_cmds = ('help', 'version') # dont require valid data folder at all
main_cmds = ('init', 'config', 'setup') # dont require existing db present main_cmds = ('init', 'config', 'setup', 'install') # dont require existing db present
archive_cmds = ('add', 'remove', 'update', 'list', 'status') # require existing db present archive_cmds = ('add', 'remove', 'update', 'list', 'status') # require existing db present
fake_db = ("oneshot",) # use fake in-memory db fake_db = ("oneshot",) # use fake in-memory db

View file

@ -8,10 +8,10 @@ import argparse
from typing import Optional, List, IO from typing import Optional, List, IO
from ..main import init
from archivebox.misc.util import docstring from archivebox.misc.util import docstring
from archivebox.config import DATA_DIR from archivebox.config import DATA_DIR
from ..logging_util import SmartFormatter, reject_stdin from ..logging_util import SmartFormatter, reject_stdin
from ..main import init
@docstring(init.__doc__) @docstring(init.__doc__)
@ -33,17 +33,22 @@ def main(args: Optional[List[str]]=None, stdin: Optional[IO]=None, pwd: Optional
help='Run any updates or migrations without rechecking all snapshot dirs', help='Run any updates or migrations without rechecking all snapshot dirs',
) )
parser.add_argument( parser.add_argument(
'--setup', #'-s', '--install', #'-s',
action='store_true', action='store_true',
help='Automatically install dependencies and extras used for archiving', help='Automatically install dependencies and extras used for archiving',
) )
parser.add_argument(
'--setup', #'-s',
action='store_true',
help='DEPRECATED: equivalent to --install',
)
command = parser.parse_args(args or ()) command = parser.parse_args(args or ())
reject_stdin(__command__, stdin) reject_stdin(__command__, stdin)
init( init(
force=command.force, force=command.force,
quick=command.quick, quick=command.quick,
setup=command.setup, install=command.install or command.setup,
out_dir=pwd or DATA_DIR, out_dir=pwd or DATA_DIR,
) )

View file

@ -1,7 +1,7 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
__package__ = 'archivebox.cli' __package__ = 'archivebox.cli'
__command__ = 'archivebox setup' __command__ = 'archivebox install'
import sys import sys
import argparse import argparse
@ -11,14 +11,14 @@ from typing import Optional, List, IO
from archivebox.misc.util import docstring from archivebox.misc.util import docstring
from archivebox.config import DATA_DIR from archivebox.config import DATA_DIR
from ..logging_util import SmartFormatter, reject_stdin from ..logging_util import SmartFormatter, reject_stdin
from ..main import setup from ..main import install
@docstring(setup.__doc__) @docstring(install.__doc__)
def main(args: Optional[List[str]]=None, stdin: Optional[IO]=None, pwd: Optional[str]=None) -> None: def main(args: Optional[List[str]]=None, stdin: Optional[IO]=None, pwd: Optional[str]=None) -> None:
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
prog=__command__, prog=__command__,
description=setup.__doc__, description=install.__doc__,
add_help=True, add_help=True,
formatter_class=SmartFormatter, formatter_class=SmartFormatter,
) )
@ -30,7 +30,7 @@ def main(args: Optional[List[str]]=None, stdin: Optional[IO]=None, pwd: Optional
command = parser.parse_args(args or ()) # noqa command = parser.parse_args(args or ()) # noqa
reject_stdin(__command__, stdin) reject_stdin(__command__, stdin)
setup( install(
# force=command.force, # force=command.force,
out_dir=Path(pwd) if pwd else DATA_DIR, out_dir=Path(pwd) if pwd else DATA_DIR,
) )

View file

@ -81,7 +81,7 @@ class ShellConfig(BaseConfigSet):
@model_validator(mode='after') @model_validator(mode='after')
def validate_not_running_as_root(self): def validate_not_running_as_root(self):
attempted_command = ' '.join(sys.argv[:3]) attempted_command = ' '.join(sys.argv[:3])
if self.PUID == 0 and attempted_command != 'setup': if self.PUID == 0 and attempted_command not in ('setup', 'install'):
# stderr('[!] ArchiveBox should never be run as root!', color='red') # stderr('[!] ArchiveBox should never be run as root!', color='red')
# stderr(' For more information, see the security overview documentation:') # stderr(' For more information, see the security overview documentation:')
# stderr(' https://github.com/ArchiveBox/ArchiveBox/wiki/Security-Overview#do-not-run-as-root') # stderr(' https://github.com/ArchiveBox/ArchiveBox/wiki/Security-Overview#do-not-run-as-root')

View file

@ -68,7 +68,6 @@ from archivebox.misc.logging import stderr, hint
from archivebox.misc.checks import check_data_folder from archivebox.misc.checks import check_data_folder
from archivebox.config.legacy import ( from archivebox.config.legacy import (
write_config_file, write_config_file,
DEPENDENCIES,
load_all_config, load_all_config,
CONFIG, CONFIG,
USER_CONFIG, USER_CONFIG,
@ -129,7 +128,7 @@ def help(out_dir: Path=DATA_DIR) -> None:
{lightred}Example Use:{reset} {lightred}Example Use:{reset}
mkdir -p ~/archivebox/data; cd ~/archivebox/data mkdir -p ~/archivebox/data; cd ~/archivebox/data
archivebox init archivebox init
archivebox setup archivebox install
archivebox version archivebox version
archivebox status archivebox status
@ -214,16 +213,8 @@ def version(quiet: bool=False,
) )
print() print()
print('[pale_green3][i] Old dependency versions:[/pale_green3]')
for name, dependency in DEPENDENCIES.items():
print(printable_dependency_version(name, dependency))
# add a newline between core dependencies and extractor dependencies for easier reading
if name == 'ARCHIVEBOX_BINARY':
print()
print() print()
print('[pale_green1][i] New dependency versions:[/pale_green1]') print('[pale_green1][i] Dependency versions:[/pale_green1]')
for name, binary in reversed(list(settings.BINARIES.items())): for name, binary in reversed(list(settings.BINARIES.items())):
if binary.name == 'archivebox': if binary.name == 'archivebox':
continue continue
@ -270,7 +261,7 @@ def run(subcommand: str,
@enforce_types @enforce_types
def init(force: bool=False, quick: bool=False, setup: bool=False, out_dir: Path=DATA_DIR) -> None: def init(force: bool=False, quick: bool=False, install: bool=False, out_dir: Path=DATA_DIR) -> None:
"""Initialize a new ArchiveBox collection in the current directory""" """Initialize a new ArchiveBox collection in the current directory"""
from core.models import Snapshot from core.models import Snapshot
@ -421,8 +412,8 @@ def init(force: bool=False, quick: bool=False, setup: bool=False, out_dir: Path=
if html_index.exists(): if html_index.exists():
html_index.rename(f"{index_name}.html") html_index.rename(f"{index_name}.html")
if setup: if install:
run_subcommand('setup', pwd=out_dir) run_subcommand('install', pwd=out_dir)
if Snapshot.objects.count() < 25: # hide the hints for experienced users if Snapshot.objects.count() < 25: # hide the hints for experienced users
print() print()