mirror of
https://github.com/aljazceru/CTFd.git
synced 2025-12-17 05:54:19 +01:00
Add import export commands to manage.py (#1723)
* Add `import_ctf` and `export_ctf` commands to `manage.py` * Deprecate `import.py` and `export.py` * Works on #1629
This commit is contained in:
@@ -9,6 +9,9 @@ import shutil
|
||||
|
||||
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:
|
||||
|
||||
@@ -8,4 +8,7 @@ import sys
|
||||
|
||||
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])
|
||||
|
||||
40
manage.py
40
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()
|
||||
|
||||
Reference in New Issue
Block a user