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
|
#!/bin/bash
#
# Usage
# compile-python.sh source_file [output_name]
#
# Default paremeters
# output_name = "./jail/name"
#
# Standard example
# compile-python.sh test/something.py jail/2259
#
source_file="$1"
if [ -z "$2" ]
then
output_name="jail/main"
else
output_name="$2"
fi
# Get the "jail" directory
jail_dir=${output_name%/*}
#echo "Jail Dir: $jail_dir"
# Copy the source to the jail_dir
cp "$source_file" "$jail_dir/"
# Get the real file name
file_name=${source_file#*/}
file_name=${file_name%.*}
file_name="$jail_dir/$file_name"
#echo "Filename: $file_name"
compile_command="import py_compile; py_compile.compile('$file_name.py');"
#echo $compile_command
/usr/bin/env python -c "$compile_command" && mv "$file_name.pyc" "$output_name"
|