|
1 |
| -from flask import Flask |
2 |
| -from flask_sqlalchemy import SQLAlchemy |
| 1 | +import datetime |
| 2 | +import shutil |
| 3 | + |
| 4 | +from flask_migrate import MigrateCommand |
3 | 5 | from flask_script import Manager
|
4 |
| -from flask_migrate import Migrate, MigrateCommand |
| 6 | + |
5 | 7 | from CTFd import create_app
|
6 |
| -from CTFd.utils import get_config as get_config_util, set_config as set_config_util |
7 |
| -from CTFd.models import * |
| 8 | +from CTFd.utils import get_config as get_config_util |
| 9 | +from CTFd.utils import set_config as set_config_util |
| 10 | +from CTFd.utils.config import ctf_name |
| 11 | +from CTFd.utils.exports import export_ctf as export_ctf_util |
| 12 | +from CTFd.utils.exports import import_ctf as import_ctf_util |
8 | 13 |
|
9 | 14 | app = create_app()
|
10 | 15 |
|
@@ -46,5 +51,30 @@ def build(cmd):
|
46 | 51 | cmd()
|
47 | 52 |
|
48 | 53 |
|
| 54 | +@manager.command |
| 55 | +def export_ctf(path=None): |
| 56 | + with app.app_context(): |
| 57 | + backup = export_ctf_util() |
| 58 | + |
| 59 | + if path: |
| 60 | + with open(path, "wb") as target: |
| 61 | + shutil.copyfileobj(backup, target) |
| 62 | + else: |
| 63 | + name = ctf_name() |
| 64 | + day = datetime.datetime.now().strftime("%Y-%m-%d") |
| 65 | + full_name = f"{name}.{day}.zip" |
| 66 | + |
| 67 | + with open(full_name, "wb") as target: |
| 68 | + shutil.copyfileobj(backup, target) |
| 69 | + |
| 70 | + print(f"Exported {full_name}") |
| 71 | + |
| 72 | + |
| 73 | +@manager.command |
| 74 | +def import_ctf(path): |
| 75 | + with app.app_context(): |
| 76 | + import_ctf_util(path) |
| 77 | + |
| 78 | + |
49 | 79 | if __name__ == "__main__":
|
50 | 80 | manager.run()
|
0 commit comments