diff --git a/export.py b/export.py index 3bca659a3..9eca3fdc4 100644 --- a/export.py +++ b/export.py @@ -9,6 +9,9 @@ app = create_app() with app.app_context(): + print( + "This file will be deleted in CTFd v4.0. Switch to using `python manage.py export_ctf`" + ) backup = export_ctf() if len(sys.argv) > 1: diff --git a/import.py b/import.py index fa59abb69..c0f0ba8b6 100644 --- a/import.py +++ b/import.py @@ -8,4 +8,7 @@ app = create_app() with app.app_context(): + print( + "This file will be deleted in CTFd v4.0. Switch to using `python manage.py import_ctf`" + ) import_ctf(sys.argv[1]) diff --git a/manage.py b/manage.py index 0e8e8cd5f..e061d9cdb 100644 --- a/manage.py +++ b/manage.py @@ -1,10 +1,15 @@ -from flask import Flask -from flask_sqlalchemy import SQLAlchemy +import datetime +import shutil + +from flask_migrate import MigrateCommand from flask_script import Manager -from flask_migrate import Migrate, MigrateCommand + from CTFd import create_app -from CTFd.utils import get_config as get_config_util, set_config as set_config_util -from CTFd.models import * +from CTFd.utils import get_config as get_config_util +from CTFd.utils import set_config as set_config_util +from CTFd.utils.config import ctf_name +from CTFd.utils.exports import export_ctf as export_ctf_util +from CTFd.utils.exports import import_ctf as import_ctf_util app = create_app() @@ -46,5 +51,30 @@ def build(cmd): cmd() +@manager.command +def export_ctf(path=None): + with app.app_context(): + backup = export_ctf_util() + + if path: + with open(path, "wb") as target: + shutil.copyfileobj(backup, target) + else: + name = ctf_name() + day = datetime.datetime.now().strftime("%Y-%m-%d") + full_name = f"{name}.{day}.zip" + + with open(full_name, "wb") as target: + shutil.copyfileobj(backup, target) + + print(f"Exported {full_name}") + + +@manager.command +def import_ctf(path): + with app.app_context(): + import_ctf_util(path) + + if __name__ == "__main__": manager.run()