mirror of
https://github.com/ArchiveBox/ArchiveBox.git
synced 2025-05-13 22:54:27 -04:00
fix cli loading edge case where setup_django wasnt running when it should
This commit is contained in:
parent
6b47510f70
commit
b852951c58
1 changed files with 17 additions and 5 deletions
|
@ -51,6 +51,10 @@ class ArchiveBoxGroup(click.Group):
|
||||||
'export': 'search',
|
'export': 'search',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_canonical_name(cls, cmd_name):
|
||||||
|
return cls.renamed_commands.get(cmd_name, cmd_name)
|
||||||
|
|
||||||
|
|
||||||
def get_command(self, ctx, cmd_name):
|
def get_command(self, ctx, cmd_name):
|
||||||
# handle renamed commands
|
# handle renamed commands
|
||||||
|
@ -92,18 +96,26 @@ class ArchiveBoxGroup(click.Group):
|
||||||
def cli(ctx, help=False):
|
def cli(ctx, help=False):
|
||||||
"""ArchiveBox: The self-hosted internet archive"""
|
"""ArchiveBox: The self-hosted internet archive"""
|
||||||
|
|
||||||
|
subcommand = ArchiveBoxGroup.get_canonical_name(ctx.invoked_subcommand)
|
||||||
|
|
||||||
# if --help is passed or no subcommand is given, show custom help message
|
# if --help is passed or no subcommand is given, show custom help message
|
||||||
if help or ctx.invoked_subcommand is None:
|
if help or ctx.invoked_subcommand is None:
|
||||||
ctx.invoke(ctx.command.get_command(ctx, 'help'))
|
ctx.invoke(ctx.command.get_command(ctx, 'help'))
|
||||||
|
|
||||||
# if the subcommand is in the archive_commands dict and is not 'manage',
|
# if the subcommand is in the archive_commands dict and is not 'manage',
|
||||||
# then we need to set up the django environment and check that we're in a valid data folder
|
# then we need to set up the django environment and check that we're in a valid data folder
|
||||||
if ctx.invoked_subcommand in ArchiveBoxGroup.archive_commands and ctx.invoked_subcommand != 'manage':
|
if subcommand in ArchiveBoxGroup.archive_commands:
|
||||||
# print('SETUP DJANGO AND CHECK DATA FOLDER')
|
# print('SETUP DJANGO AND CHECK DATA FOLDER')
|
||||||
from archivebox.config.django import setup_django
|
try:
|
||||||
from archivebox.misc.checks import check_data_folder
|
from archivebox.config.django import setup_django
|
||||||
setup_django()
|
from archivebox.misc.checks import check_data_folder
|
||||||
check_data_folder()
|
setup_django()
|
||||||
|
check_data_folder()
|
||||||
|
except Exception as e:
|
||||||
|
print(f'[red][X] Error setting up Django or checking data folder: {e}[/red]', file=sys.stderr)
|
||||||
|
if subcommand not in ('manage', 'shell'): # not all management commands need django to be setup beforehand
|
||||||
|
raise
|
||||||
|
|
||||||
|
|
||||||
def main(args=None, prog_name=None):
|
def main(args=None, prog_name=None):
|
||||||
# show `docker run archivebox xyz` in help messages if running in docker
|
# show `docker run archivebox xyz` in help messages if running in docker
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue