Merge branch 'c-agents'
[progcomp10.git] / src / link / bundle-agent.sh
diff --git a/src/link/bundle-agent.sh b/src/link/bundle-agent.sh
new file mode 100755 (executable)
index 0000000..edf55ee
--- /dev/null
@@ -0,0 +1,120 @@
+#!/bin/bash
+
+# bundle-agent.sh
+# progcomp
+#
+# Written by Daniel Axtens <[email protected]> for the UCC Programming Competition in 2010.
+# Licensed under an MIT-style license: see the LICENSE file for details.
+
+# a candidate for porting to python.
+
+# put ourselves in SRCROOT - src/
+# this assumes we are in the src/link directory.
+cd `dirname $0`/..
+
+# begin script
+cat << __EOF__
+This script takes the code that you have written for UCC::ProgComp 2010 and
+bundles it up as an agent that you can test. This script is not needed for code
+written in Python.
+__EOF__
+
+
+# select language
+lang=0
+
+while ([ $lang != 1 ] && [ $lang != 2 ]) do {
+
+    cat << __EOF__
+Is your agent written in:
+(1) C
+(2) another language (UNSUPPORTED)
+__EOF__
+
+    read -p "Enter 1 or 2: " lang
+
+} done;
+
+# C bots
+if ([ $lang == 1 ]) then 
+    echo
+    echo "Preparing a C bot."
+    echo
+
+    echo "Where is your .c file?"
+    echo "Provide the full path, including the agent file and the .c"
+    echo "Give paths relative to the src/ directory."
+    echo "WARNING: will overwrite \'agent name\'.py if it exists" 
+    
+    read -p "Path: " path
+
+    location=`dirname $path`
+    name=`basename $path .c`
+    
+    cat > ${location}/${name}.py << __EOF__
+# ${name}.py - a C bot shell generated by `basename $0` for UCC::ProgComp 2010
+
+from link.cAgent import cAgent
+
+class ${name} (cAgent):
+       def __init__ (self):
+               cAgent.__init__(self, "${location}/${name}")
+__EOF__
+
+    
+
+# Custom bots
+elif ([ $lang == 2 ]) then
+    echo
+    echo "Preparing a custom bot."
+    echo
+
+    echo "What is the name of your bot?"
+    
+    read -p "Name: " name
+
+    echo
+    echo "Enter the command required to spawn your bot."
+    echo "Give paths relative to the src/ directory."
+
+    read -p "Command: " cmd
+    
+    echo
+    echo "Into which directory should I put the resultant python module?"
+    echo "(again, give paths relative to src/)"
+    echo "WARNING: will overwrite ${name}.py if it exists" 
+    
+    read -p "Location: " location
+    
+    cat > ${location}/${name}.py << __EOF__
+# ${name}.py - a custom bot shell generated by `basename $0` for UCC::ProgComp 2010
+# calls "${cmd}" to invoke the bot
+
+from link.externAgent import externAgent
+
+class ${name} (externAgent):
+       def __init__ (self):
+               externAgent.__init__(self, "${cmd}")
+__EOF__
+
+    
+fi
+
+### Finish up
+echo
+echo "${name}.py created."
+echo
+echo "Include your bot with:"
+
+#there must be a nicer way to do this. possibly by using python
+#part of the horror is trying to deal with location possibly having a trailing
+#slash, and possibly not having one. *sigh*
+pythonpath=`sed 's:/:.:g' << __EOF__
+$(dirname ${location}/${name}).${name}
+__EOF__
+`
+
+echo "   from ${pythonpath} import ${name}"
+echo "Then make sure the Agents list includes ${name}"
+echo
+echo "Good luck!"
\ No newline at end of file

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