mirror of
https://github.com/ArchiveBox/ArchiveBox
synced 2024-11-25 21:50:21 +00:00
add init flag to server and fix SHOW_PROGRESS config being ignored
This commit is contained in:
parent
55a237a435
commit
9e7330cc14
3 changed files with 37 additions and 13 deletions
|
@ -39,6 +39,11 @@ def main(args: Optional[List[str]]=None, stdin: Optional[IO]=None, pwd: Optional
|
||||||
action='store_true',
|
action='store_true',
|
||||||
help='Enable DEBUG=True mode with more verbose errors',
|
help='Enable DEBUG=True mode with more verbose errors',
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'--init',
|
||||||
|
action='store_true',
|
||||||
|
help='Run archivebox init before starting the server',
|
||||||
|
)
|
||||||
command = parser.parse_args(args or ())
|
command = parser.parse_args(args or ())
|
||||||
reject_stdin(__command__, stdin)
|
reject_stdin(__command__, stdin)
|
||||||
|
|
||||||
|
@ -46,6 +51,7 @@ def main(args: Optional[List[str]]=None, stdin: Optional[IO]=None, pwd: Optional
|
||||||
runserver_args=command.runserver_args,
|
runserver_args=command.runserver_args,
|
||||||
reload=command.reload,
|
reload=command.reload,
|
||||||
debug=command.debug,
|
debug=command.debug,
|
||||||
|
init=command.init,
|
||||||
out_dir=pwd or OUTPUT_DIR,
|
out_dir=pwd or OUTPUT_DIR,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -84,7 +84,9 @@ class TimedProgress:
|
||||||
"""Show a progress bar and measure elapsed time until .end() is called"""
|
"""Show a progress bar and measure elapsed time until .end() is called"""
|
||||||
|
|
||||||
def __init__(self, seconds, prefix=''):
|
def __init__(self, seconds, prefix=''):
|
||||||
if SHOW_PROGRESS:
|
from .config import SHOW_PROGRESS
|
||||||
|
self.SHOW_PROGRESS = SHOW_PROGRESS
|
||||||
|
if self.SHOW_PROGRESS:
|
||||||
self.p = Process(target=progress_bar, args=(seconds, prefix))
|
self.p = Process(target=progress_bar, args=(seconds, prefix))
|
||||||
self.p.start()
|
self.p.start()
|
||||||
|
|
||||||
|
@ -96,7 +98,7 @@ class TimedProgress:
|
||||||
end_ts = datetime.now()
|
end_ts = datetime.now()
|
||||||
self.stats['end_ts'] = end_ts
|
self.stats['end_ts'] = end_ts
|
||||||
|
|
||||||
if SHOW_PROGRESS:
|
if self.SHOW_PROGRESS:
|
||||||
# terminate if we havent already terminated
|
# terminate if we havent already terminated
|
||||||
self.p.terminate()
|
self.p.terminate()
|
||||||
self.p.join()
|
self.p.join()
|
||||||
|
|
|
@ -987,38 +987,54 @@ def schedule(add: bool=False,
|
||||||
def server(runserver_args: Optional[List[str]]=None,
|
def server(runserver_args: Optional[List[str]]=None,
|
||||||
reload: bool=False,
|
reload: bool=False,
|
||||||
debug: bool=False,
|
debug: bool=False,
|
||||||
|
init: bool=False,
|
||||||
out_dir: str=OUTPUT_DIR) -> None:
|
out_dir: str=OUTPUT_DIR) -> None:
|
||||||
"""Run the ArchiveBox HTTP server"""
|
"""Run the ArchiveBox HTTP server"""
|
||||||
|
|
||||||
runserver_args = runserver_args or []
|
runserver_args = runserver_args or []
|
||||||
|
|
||||||
|
if init:
|
||||||
|
run_subcommand('init', stdin=None, pwd=out_dir)
|
||||||
|
|
||||||
|
# setup config for django runserver
|
||||||
from . import config
|
from . import config
|
||||||
config.SHOW_PROGRESS = False
|
config.SHOW_PROGRESS = False
|
||||||
|
config.DEBUG = config.DEBUG or debug
|
||||||
if debug:
|
|
||||||
# if --debug is passed, patch config.DEBUG to be True for this run
|
|
||||||
config.DEBUG = True
|
|
||||||
else:
|
|
||||||
# force staticfiles to be served when DEBUG=False
|
|
||||||
# TODO: do this using nginx or another server instead of django?
|
|
||||||
runserver_args.append('--insecure')
|
|
||||||
|
|
||||||
check_data_folder(out_dir=out_dir)
|
check_data_folder(out_dir=out_dir)
|
||||||
setup_django(out_dir)
|
setup_django(out_dir)
|
||||||
|
|
||||||
from django.core.management import call_command
|
from django.core.management import call_command
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
|
|
||||||
if IS_TTY and not User.objects.filter(is_superuser=True).exists():
|
admin_user = User.objects.filter(is_superuser=True).order_by('date_joined').only('username').last()
|
||||||
|
|
||||||
|
print('{green}[+] Starting ArchiveBox webserver...{reset}'.format(**ANSI))
|
||||||
|
if admin_user:
|
||||||
|
print("{lightred}[i] The admin username is:{lightblue} {}{reset}".format(admin_user.username, **ANSI))
|
||||||
|
else:
|
||||||
print('{lightyellow}[!] No admin users exist yet, you will not be able to edit links in the UI.{reset}'.format(**ANSI))
|
print('{lightyellow}[!] No admin users exist yet, you will not be able to edit links in the UI.{reset}'.format(**ANSI))
|
||||||
print()
|
print()
|
||||||
print(' To create an admin user, run:')
|
print(' To create an admin user, run:')
|
||||||
print(' archivebox manage createsuperuser')
|
print(' archivebox manage createsuperuser')
|
||||||
print()
|
print()
|
||||||
|
|
||||||
print('{green}[+] Starting ArchiveBox webserver...{reset}'.format(**ANSI))
|
# fallback to serving staticfiles insecurely with django when DEBUG=False
|
||||||
if not reload:
|
if config.DEBUG:
|
||||||
|
print('DEBUG=True')
|
||||||
|
else:
|
||||||
|
runserver_args.append('--insecure') # TODO: serve statics w/ nginx instead
|
||||||
|
|
||||||
|
# toggle autoreloading when archivebox code changes (it's on by default)
|
||||||
|
if reload:
|
||||||
|
print('AUTORELOAD=True')
|
||||||
|
else:
|
||||||
runserver_args.append('--noreload')
|
runserver_args.append('--noreload')
|
||||||
|
|
||||||
|
config.SHOW_PROGRESS = False
|
||||||
|
config.DEBUG = config.DEBUG or debug
|
||||||
|
|
||||||
|
|
||||||
call_command("runserver", *runserver_args)
|
call_command("runserver", *runserver_args)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue