set constants in conf.py properly
[progcomp10.git] / src / link / bundle-agent.sh
1 #!/bin/bash
2
3 # bundle-agent.sh
4 # progcomp
5 #
6 # Written by Daniel Axtens <[email protected]> for the UCC Programming Competition in 2010.
7 # Licensed under an MIT-style license: see the LICENSE file for details.
8
9 # a candidate for porting to python.
10
11 # put ourselves in SRCROOT - src/
12 # this assumes we are in the src/link directory.
13 cd `dirname $0`/..
14
15 # begin script
16 cat << __EOF__
17 This script takes the code that you have written for UCC::ProgComp 2010 and
18 bundles it up as an agent that you can test. This script is not needed for code
19 written in Python.
20 __EOF__
21
22
23 # select language
24 lang=0
25
26 while ([ $lang != 1 ] && [ $lang != 2 ]) do {
27
28     cat << __EOF__
29 Is your agent written in:
30 (1) C
31 (2) another language (UNSUPPORTED)
32 __EOF__
33
34     read -p "Enter 1 or 2: " lang
35
36 } done;
37
38 # C bots
39 if ([ $lang == 1 ]) then 
40     echo
41     echo "Preparing a C bot."
42     echo
43
44     echo "Where is your .c file?"
45     echo "Provide the full path, including the agent file and the .c"
46     echo "Give paths relative to the src/ directory."
47     echo "WARNING: will overwrite \'agent name\'.py if it exists" 
48     
49     read -p "Path: " path
50
51     location=`dirname $path`
52     name=`basename $path .c`
53     
54     cat > ${location}/${name}.py << __EOF__
55 # ${name}.py - a C bot shell generated by `basename $0` for UCC::ProgComp 2010
56
57 from link.cAgent import cAgent
58
59 class ${name} (cAgent):
60         def __init__ (self):
61                 cAgent.__init__(self, "${location}/${name}")
62 __EOF__
63
64     
65
66 # Custom bots
67 elif ([ $lang == 2 ]) then
68     echo
69     echo "Preparing a custom bot."
70     echo
71
72     echo "What is the name of your bot?"
73     
74     read -p "Name: " name
75
76     echo
77     echo "Enter the command required to spawn your bot."
78     echo "Give paths relative to the src/ directory."
79
80     read -p "Command: " cmd
81     
82     echo
83     echo "Into which directory should I put the resultant python module?"
84     echo "(again, give paths relative to src/)"
85     echo "WARNING: will overwrite ${name}.py if it exists" 
86     
87     read -p "Location: " location
88     
89     cat > ${location}/${name}.py << __EOF__
90 # ${name}.py - a custom bot shell generated by `basename $0` for UCC::ProgComp 2010
91 # calls "${cmd}" to invoke the bot
92
93 from link.externAgent import externAgent
94
95 class ${name} (externAgent):
96         def __init__ (self):
97                 externAgent.__init__(self, "${cmd}")
98 __EOF__
99
100     
101 fi
102
103 ### Finish up
104 echo
105 echo "${name}.py created."
106 echo
107 echo "Include your bot with:"
108
109 #there must be a nicer way to do this. possibly by using python
110 #part of the horror is trying to deal with location possibly having a trailing
111 #slash, and possibly not having one. *sigh*
112 pythonpath=`sed 's:/:.:g' << __EOF__
113 $(dirname ${location}/${name}).${name}
114 __EOF__
115 `
116
117 echo "   from ${pythonpath} import ${name}"
118 echo "Then make sure the Agents list includes ${name}"
119 echo
120 echo "Good luck!"

UCC git Repository :: git.ucc.asn.au