Files
CTFd/export.py
Kevin Chung 66ff9c0b91 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
2020-11-16 20:24:42 -05:00

29 lines
767 B
Python

from CTFd import create_app
from CTFd.utils import config
from CTFd.utils.exports import export_ctf
import datetime
import sys
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:
with open(sys.argv[1], "wb") as target:
shutil.copyfileobj(backup, target)
else:
ctf_name = config.ctf_name()
day = datetime.datetime.now().strftime("%Y-%m-%d")
full_name = "{}.{}.zip".format(ctf_name, day)
with open(full_name, "wb") as target:
shutil.copyfileobj(backup, target)
print("Exported {filename}".format(filename=full_name))