forked from alem0lars/ctfs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtasks.py
executable file
·51 lines (41 loc) · 1.97 KB
/
tasks.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# ------------------------------------------------------------------------------
# IMPORTS ----------------------------------------------------------------------
from os import system
from os import listdir as list_dir
from os.path import basename as base_name
from os.path import dirname as dir_name
from os.path import realpath as real_path
from os.path import relpath as rel_path
from os.path import isfile as is_file
from os.path import join as join_path
from invoke import task
# ------------------------------------------------------------------------------
# CONFIGURATION ----------------------------------------------------------------
ROOT_DIR = dir_name(real_path(__file__))
SHARED_DIR = join_path(ROOT_DIR, 'shared')
TEST_DIR = join_path(ROOT_DIR, 'test')
# ------------------------------------------------------------------------------
# TASKS ------------------------------------------------------------------------
@task(help={'ctf_name': 'CTF name', 'challenge_name': 'Challenge name'})
def create_challenge(ctf_name, challenge_name):
"""Prepare the storage for a CTF challenge."""
challenge_dir = join_path(ROOT_DIR, ctf_name, challenge_name)
shared_link = rel_path(SHARED_DIR, challenge_dir)
print('Preparing {storage} for challenge {challenge} of CTF {ctf}'.format(
storage=challenge_dir, challenge=challenge_name, ctf=ctf_name))
os.makedirs(challenge_dir)
os.symlink(shared_link, join_path(challenge_dir, 'shared'))
@task
def test():
for file_rel_path in list_dir(TEST_DIR):
file_path = join_path(TEST_DIR, file_rel_path)
file_name = base_name(file_path)
if (is_file(file_path)
and file_name.startswith('test_')
and file_name.endswith('.py')):
system('python {}'.format(file_path))
@task
def cleanup():
system('find . -name "*.pyc" -exec rm {} \;')
# ------------------------------------------------------------------------------
# vim: set filetype=python :