1
0
Fork 0

new setup flag on init command to autosetup on init

This commit is contained in:
Nick Sweeting 2021-04-05 21:15:32 -04:00
parent 5c181532b5
commit 8b4f84959a
3 changed files with 26 additions and 13 deletions

View file

@ -15,10 +15,10 @@ from importlib import import_module
CLI_DIR = Path(__file__).resolve().parent CLI_DIR = Path(__file__).resolve().parent
# 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') # dont require existing db present main_cmds = ('init', 'config', 'setup') # dont require existing db present
archive_cmds = ('add', 'remove', 'update', 'list', 'status', 'setup') # 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
display_first = (*meta_cmds, *main_cmds, *archive_cmds) display_first = (*meta_cmds, *main_cmds, *archive_cmds)

View file

@ -32,12 +32,18 @@ def main(args: Optional[List[str]]=None, stdin: Optional[IO]=None, pwd: Optional
action='store_true', action='store_true',
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(
'--setup', #'-s',
action='store_true',
help='Automatically install dependencies and extras used for archiving',
)
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,
out_dir=pwd or OUTPUT_DIR, out_dir=pwd or OUTPUT_DIR,
) )

View file

@ -101,6 +101,11 @@ from .config import (
USE_CHROME, USE_CHROME,
CHROME_BINARY, CHROME_BINARY,
CHROME_VERSION, CHROME_VERSION,
YOUTUBEDL_BINARY,
YOUTUBEDL_VERSION,
SINGLEFILE_VERSION,
READABILITY_VERSION,
MERCURY_VERSION,
USE_YOUTUBEDL, USE_YOUTUBEDL,
USE_NODE, USE_NODE,
NODE_VERSION, NODE_VERSION,
@ -108,6 +113,7 @@ from .config import (
CONFIG, CONFIG,
USER_CONFIG, USER_CONFIG,
get_real_name, get_real_name,
setup_django,
) )
from .logging_util import ( from .logging_util import (
TERM_WIDTH, TERM_WIDTH,
@ -295,19 +301,19 @@ def run(subcommand: str,
@enforce_types @enforce_types
def init(force: bool=False, quick: bool=False, out_dir: Path=OUTPUT_DIR) -> None: def init(force: bool=False, quick: bool=False, setup: bool=False, out_dir: Path=OUTPUT_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
Path(out_dir).mkdir(exist_ok=True) out_dir.mkdir(exist_ok=True)
is_empty = not len(set(os.listdir(out_dir)) - ALLOWED_IN_OUTPUT_DIR) is_empty = not len(set(os.listdir(out_dir)) - ALLOWED_IN_OUTPUT_DIR)
if (Path(out_dir) / JSON_INDEX_FILENAME).exists(): if (out_dir / JSON_INDEX_FILENAME).exists():
stderr("[!] This folder contains a JSON index. It is deprecated, and will no longer be kept up to date automatically.", color="lightyellow") stderr("[!] This folder contains a JSON index. It is deprecated, and will no longer be kept up to date automatically.", color="lightyellow")
stderr(" You can run `archivebox list --json --with-headers > index.json` to manually generate it.", color="lightyellow") stderr(" You can run `archivebox list --json --with-headers > index.json` to manually generate it.", color="lightyellow")
existing_index = (Path(out_dir) / SQL_INDEX_FILENAME).exists() existing_index = (out_dir / SQL_INDEX_FILENAME).exists()
if is_empty and not existing_index: if is_empty and not existing_index:
print('{green}[+] Initializing a new ArchiveBox v{} collection...{reset}'.format(VERSION, **ANSI)) print('{green}[+] Initializing a new ArchiveBox v{} collection...{reset}'.format(VERSION, **ANSI))
@ -343,12 +349,12 @@ def init(force: bool=False, quick: bool=False, out_dir: Path=OUTPUT_DIR) -> None
print(f' + ./{CONFIG_FILE.relative_to(OUTPUT_DIR)}...') print(f' + ./{CONFIG_FILE.relative_to(OUTPUT_DIR)}...')
write_config_file({}, out_dir=out_dir) write_config_file({}, out_dir=out_dir)
if (Path(out_dir) / SQL_INDEX_FILENAME).exists(): if (out_dir / SQL_INDEX_FILENAME).exists():
print('\n{green}[*] Verifying main SQL index and running any migrations needed...{reset}'.format(**ANSI)) print('\n{green}[*] Verifying main SQL index and running any migrations needed...{reset}'.format(**ANSI))
else: else:
print('\n{green}[+] Building main SQL index and running initial migrations...{reset}'.format(**ANSI)) print('\n{green}[+] Building main SQL index and running initial migrations...{reset}'.format(**ANSI))
DATABASE_FILE = Path(out_dir) / SQL_INDEX_FILENAME DATABASE_FILE = out_dir / SQL_INDEX_FILENAME
for migration_line in apply_migrations(out_dir): for migration_line in apply_migrations(out_dir):
print(f' {migration_line}') print(f' {migration_line}')
@ -443,15 +449,16 @@ def init(force: bool=False, quick: bool=False, out_dir: Path=OUTPUT_DIR) -> None
print(' For more usage and examples, run:') print(' For more usage and examples, run:')
print(' archivebox help') print(' archivebox help')
json_index = Path(out_dir) / JSON_INDEX_FILENAME json_index = out_dir / JSON_INDEX_FILENAME
html_index = Path(out_dir) / HTML_INDEX_FILENAME html_index = out_dir / HTML_INDEX_FILENAME
index_name = f"{date.today()}_index_old" index_name = f"{date.today()}_index_old"
if json_index.exists(): if json_index.exists():
json_index.rename(f"{index_name}.json") json_index.rename(f"{index_name}.json")
if html_index.exists(): if html_index.exists():
html_index.rename(f"{index_name}.html") html_index.rename(f"{index_name}.html")
if setup:
run_subcommand('setup', pwd=out_dir)
@enforce_types @enforce_types
def status(out_dir: Path=OUTPUT_DIR) -> None: def status(out_dir: Path=OUTPUT_DIR) -> None: