From 13eb5cad5dedf0cc7a01f7f8d50812b14288e71d Mon Sep 17 00:00:00 2001 From: Daniel Axtens Date: Tue, 29 Jun 2010 17:08:21 +0800 Subject: [PATCH] split off c agents into cAgent.py. created a script to churn out a python module for an external agent. --- src/link/C/README | 5 + src/link/C/c_agents.py | 18 ++-- src/link/bundle-agent.sh | 120 ++++++++++++++++++++++++ src/link/cAgent.py | 17 ++++ src/progcomp.xcodeproj/project.pbxproj | 125 +------------------------ 5 files changed, 155 insertions(+), 130 deletions(-) create mode 100755 src/link/bundle-agent.sh create mode 100644 src/link/cAgent.py diff --git a/src/link/C/README b/src/link/C/README index 7f0a970..9afcc16 100644 --- a/src/link/C/README +++ b/src/link/C/README @@ -1,5 +1,7 @@ Welcome to the C SDK and link library. +If you want to enter in C, you've come to the right place. + == Compiling and testing the sample bots == Run "make" in this directory. To include them in the @@ -7,6 +9,9 @@ Run "make" in this directory. To include them in the == Making your own agent == See wiki page. +Also, use the link/bundle-agent.sh shell script - it will take your agent file +and make a python module that you can include. + = Testing your own agent = Edit src/simulate.py. Your agents live in link.C.c_agents diff --git a/src/link/C/c_agents.py b/src/link/C/c_agents.py index ae64410..dfc1393 100644 --- a/src/link/C/c_agents.py +++ b/src/link/C/c_agents.py @@ -1,20 +1,20 @@ # add your agents to this file by copying the definition and adjusting # you then need to modify simulate.py -from link.externAgent import externAgent +from link.cAgent import cAgent -class c_angel (externAgent): +class c_angel (cAgent): def __init__ (self): - externAgent.__init__(self, "./link/C/agents/c_angel") + cAgent.__init__(self, "./link/C/agents/c_angel") -class c_lucifer (externAgent): +class c_lucifer (cAgent): def __init__ (self): - externAgent.__init__(self, "./link/C/agents/c_lucifer") + cAgent.__init__(self, "./link/C/agents/c_lucifer") -class c_streetfighter (externAgent): +class c_streetfighter (cAgent): def __init__ (self): - externAgent.__init__(self, "./link/C/agents/c_streetfighter") + cAgent.__init__(self, "./link/C/agents/c_streetfighter") -class c_frenchie (externAgent): +class c_frenchie (cAgent): def __init__ (self): - externAgent.__init__(self, "./link/C/agents/c_frenchie") + cAgent.__init__(self, "./link/C/agents/c_frenchie") diff --git a/src/link/bundle-agent.sh b/src/link/bundle-agent.sh new file mode 100755 index 0000000..edf55ee --- /dev/null +++ b/src/link/bundle-agent.sh @@ -0,0 +1,120 @@ +#!/bin/bash + +# bundle-agent.sh +# progcomp +# +# Written by Daniel Axtens 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 diff --git a/src/link/cAgent.py b/src/link/cAgent.py new file mode 100644 index 0000000..5d445aa --- /dev/null +++ b/src/link/cAgent.py @@ -0,0 +1,17 @@ +'''cAgent.py - a bot shell for talking to C bots. +Written by Daniel Axtens for the UCC Programming Competition in 2010. + +This is a separate class to externAgent so that changes can be made +without requiring C agents to have their wrapper scripts rewritten. + +Licensed under an MIT-style license: see the LICENSE file for details. +''' + +from link.externAgent import externAgent + +class cAgent (externAgent): + """A class for handling agents in C. + A subclass of externAgent so that changes can be made to how all external + agents are handled, or how all C agents are handled, without requiring C + agents to have their wrapper scripts rewritten. Use this in preference to + externAgent for C agents.""" \ No newline at end of file diff --git a/src/progcomp.xcodeproj/project.pbxproj b/src/progcomp.xcodeproj/project.pbxproj index eaf32af..36086a8 100644 --- a/src/progcomp.xcodeproj/project.pbxproj +++ b/src/progcomp.xcodeproj/project.pbxproj @@ -7,6 +7,8 @@ objects = { /* Begin PBXFileReference section */ + 22CA010611D9BD51001ECDEF /* bundle-agent.sh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; name = "bundle-agent.sh"; path = "link/bundle-agent.sh"; sourceTree = ""; }; + 22CA010711D9C52B001ECDEF /* cAgent.py */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.python; name = cAgent.py; path = link/cAgent.py; sourceTree = ""; }; 22CAFEEA11D84076001ECDEF /* LICENSE */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = LICENSE; sourceTree = ""; }; 22CAFEEB11D84076001ECDEF /* README */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = README; sourceTree = ""; }; 22CAFEEC11D84076001ECDEF /* rpsconst.py */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.python; path = rpsconst.py; sourceTree = ""; }; @@ -16,54 +18,6 @@ 22CAFEF011D84076001ECDEF /* uccProgComp.py */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.python; path = uccProgComp.py; sourceTree = ""; }; 22CAFF7B11D840E3001ECDEF /* __init__.py */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.python; name = __init__.py; path = link/__init__.py; sourceTree = ""; }; 22CAFF7C11D840E3001ECDEF /* externAgent.py */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.python; name = externAgent.py; path = link/externAgent.py; sourceTree = ""; }; - 22CAFF7E11D840E3001ECDEF /* __init__.py */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.python; path = __init__.py; sourceTree = ""; }; - 22CAFF8011D840E3001ECDEF /* ANSI.py */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.python; path = ANSI.py; sourceTree = ""; }; - 22CAFF8211D840E3001ECDEF /* ANSI.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = ANSI.html; sourceTree = ""; }; - 22CAFF8311D840E3001ECDEF /* clean.css */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.css; path = clean.css; sourceTree = ""; }; - 22CAFF8411D840E3001ECDEF /* email.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = email.png; sourceTree = ""; }; - 22CAFF8511D840E3001ECDEF /* examples.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = examples.html; sourceTree = ""; }; - 22CAFF8611D840E3001ECDEF /* fdpexpect.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = fdpexpect.html; sourceTree = ""; }; - 22CAFF8711D840E3001ECDEF /* FSM.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = FSM.html; sourceTree = ""; }; - 22CAFF8811D840E3001ECDEF /* index.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = index.html; sourceTree = ""; }; - 22CAFF8911D840E3001ECDEF /* index.template.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = index.template.html; sourceTree = ""; }; - 22CAFF8A11D840E3001ECDEF /* pexpect.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = pexpect.html; sourceTree = ""; }; - 22CAFF8B11D840E3001ECDEF /* pxssh.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = pxssh.html; sourceTree = ""; }; - 22CAFF8C11D840E3001ECDEF /* screen.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = screen.html; sourceTree = ""; }; - 22CAFF8E11D840E3001ECDEF /* astat.py */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.python; path = astat.py; sourceTree = ""; }; - 22CAFF8F11D840E3001ECDEF /* bd_client.py */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.python; path = bd_client.py; sourceTree = ""; }; - 22CAFF9011D840E3001ECDEF /* bd_serv.py */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.python; path = bd_serv.py; sourceTree = ""; }; - 22CAFF9111D840E3001ECDEF /* cgishell.cgi */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.python; path = cgishell.cgi; sourceTree = ""; }; - 22CAFF9211D840E3001ECDEF /* chess.py */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.python; path = chess.py; sourceTree = ""; }; - 22CAFF9311D840E3001ECDEF /* chess2.py */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.python; path = chess2.py; sourceTree = ""; }; - 22CAFF9411D840E3001ECDEF /* chess3.py */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.python; path = chess3.py; sourceTree = ""; }; - 22CAFF9511D840E3001ECDEF /* df.py */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.python; path = df.py; sourceTree = ""; }; - 22CAFF9611D840E3001ECDEF /* fix_cvs_files.py */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.python; path = fix_cvs_files.py; sourceTree = ""; }; - 22CAFF9711D840E3001ECDEF /* ftp.py */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.python; path = ftp.py; sourceTree = ""; }; - 22CAFF9811D840E3001ECDEF /* hive.py */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.python; path = hive.py; sourceTree = ""; }; - 22CAFF9911D840E3001ECDEF /* log_69.80.212.10 */ = {isa = PBXFileReference; lastKnownFileType = file; path = log_69.80.212.10; sourceTree = ""; }; - 22CAFF9A11D840E3001ECDEF /* log_69.80.212.11 */ = {isa = PBXFileReference; lastKnownFileType = file; path = log_69.80.212.11; sourceTree = ""; }; - 22CAFF9B11D840E3001ECDEF /* monitor.py */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.python; path = monitor.py; sourceTree = ""; }; - 22CAFF9C11D840E3001ECDEF /* passmass.py */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.python; path = passmass.py; sourceTree = ""; }; - 22CAFF9D11D840E3001ECDEF /* python.py */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.python; path = python.py; sourceTree = ""; }; - 22CAFF9E11D840E3001ECDEF /* README */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = README; sourceTree = ""; }; - 22CAFF9F11D840E3001ECDEF /* rippy.py */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.python; path = rippy.py; sourceTree = ""; }; - 22CAFFA011D840E3001ECDEF /* script.py */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.python; path = script.py; sourceTree = ""; }; - 22CAFFA111D840E3001ECDEF /* ssh_session.py */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.python; path = ssh_session.py; sourceTree = ""; }; - 22CAFFA211D840E3001ECDEF /* ssh_tunnel.py */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.python; path = ssh_tunnel.py; sourceTree = ""; }; - 22CAFFA311D840E3001ECDEF /* sshls.py */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.python; path = sshls.py; sourceTree = ""; }; - 22CAFFA411D840E3001ECDEF /* table_test.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = table_test.html; sourceTree = ""; }; - 22CAFFA511D840E3001ECDEF /* topip.py */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.python; path = topip.py; sourceTree = ""; }; - 22CAFFA611D840E3001ECDEF /* uptime.py */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.python; path = uptime.py; sourceTree = ""; }; - 22CAFFA711D840E3001ECDEF /* fdpexpect.py */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.python; path = fdpexpect.py; sourceTree = ""; }; - 22CAFFA811D840E3001ECDEF /* FSM.py */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.python; path = FSM.py; sourceTree = ""; }; - 22CAFFA911D840E3001ECDEF /* INSTALL */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = INSTALL; sourceTree = ""; }; - 22CAFFAA11D840E3001ECDEF /* LICENSE */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = LICENSE; sourceTree = ""; }; - 22CAFFAB11D840E3001ECDEF /* pexpect.py */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.python; path = pexpect.py; sourceTree = ""; }; - 22CAFFAD11D840E3001ECDEF /* PKG-INFO */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "PKG-INFO"; sourceTree = ""; }; - 22CAFFAE11D840E3001ECDEF /* pxssh.py */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.python; path = pxssh.py; sourceTree = ""; }; - 22CAFFAF11D840E3001ECDEF /* README */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = README; sourceTree = ""; }; - 22CAFFB011D840E3001ECDEF /* screen.py */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.python; path = screen.py; sourceTree = ""; }; - 22CAFFB111D840E3001ECDEF /* setup.py */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.python; path = setup.py; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXGroup section */ @@ -85,85 +39,14 @@ 22CAFF7711D840CB001ECDEF /* link */ = { isa = PBXGroup; children = ( + 22CA010711D9C52B001ECDEF /* cAgent.py */, 22CAFF7B11D840E3001ECDEF /* __init__.py */, 22CAFF7C11D840E3001ECDEF /* externAgent.py */, - 22CAFF7D11D840E3001ECDEF /* pexpect */, + 22CA010611D9BD51001ECDEF /* bundle-agent.sh */, ); name = link; sourceTree = ""; }; - 22CAFF7D11D840E3001ECDEF /* pexpect */ = { - isa = PBXGroup; - children = ( - 22CAFF7E11D840E3001ECDEF /* __init__.py */, - 22CAFF8011D840E3001ECDEF /* ANSI.py */, - 22CAFF8111D840E3001ECDEF /* doc */, - 22CAFF8D11D840E3001ECDEF /* examples */, - 22CAFFA711D840E3001ECDEF /* fdpexpect.py */, - 22CAFFA811D840E3001ECDEF /* FSM.py */, - 22CAFFA911D840E3001ECDEF /* INSTALL */, - 22CAFFAA11D840E3001ECDEF /* LICENSE */, - 22CAFFAB11D840E3001ECDEF /* pexpect.py */, - 22CAFFAD11D840E3001ECDEF /* PKG-INFO */, - 22CAFFAE11D840E3001ECDEF /* pxssh.py */, - 22CAFFAF11D840E3001ECDEF /* README */, - 22CAFFB011D840E3001ECDEF /* screen.py */, - 22CAFFB111D840E3001ECDEF /* setup.py */, - ); - name = pexpect; - path = link/pexpect; - sourceTree = ""; - }; - 22CAFF8111D840E3001ECDEF /* doc */ = { - isa = PBXGroup; - children = ( - 22CAFF8211D840E3001ECDEF /* ANSI.html */, - 22CAFF8311D840E3001ECDEF /* clean.css */, - 22CAFF8411D840E3001ECDEF /* email.png */, - 22CAFF8511D840E3001ECDEF /* examples.html */, - 22CAFF8611D840E3001ECDEF /* fdpexpect.html */, - 22CAFF8711D840E3001ECDEF /* FSM.html */, - 22CAFF8811D840E3001ECDEF /* index.html */, - 22CAFF8911D840E3001ECDEF /* index.template.html */, - 22CAFF8A11D840E3001ECDEF /* pexpect.html */, - 22CAFF8B11D840E3001ECDEF /* pxssh.html */, - 22CAFF8C11D840E3001ECDEF /* screen.html */, - ); - path = doc; - sourceTree = ""; - }; - 22CAFF8D11D840E3001ECDEF /* examples */ = { - isa = PBXGroup; - children = ( - 22CAFF8E11D840E3001ECDEF /* astat.py */, - 22CAFF8F11D840E3001ECDEF /* bd_client.py */, - 22CAFF9011D840E3001ECDEF /* bd_serv.py */, - 22CAFF9111D840E3001ECDEF /* cgishell.cgi */, - 22CAFF9211D840E3001ECDEF /* chess.py */, - 22CAFF9311D840E3001ECDEF /* chess2.py */, - 22CAFF9411D840E3001ECDEF /* chess3.py */, - 22CAFF9511D840E3001ECDEF /* df.py */, - 22CAFF9611D840E3001ECDEF /* fix_cvs_files.py */, - 22CAFF9711D840E3001ECDEF /* ftp.py */, - 22CAFF9811D840E3001ECDEF /* hive.py */, - 22CAFF9911D840E3001ECDEF /* log_69.80.212.10 */, - 22CAFF9A11D840E3001ECDEF /* log_69.80.212.11 */, - 22CAFF9B11D840E3001ECDEF /* monitor.py */, - 22CAFF9C11D840E3001ECDEF /* passmass.py */, - 22CAFF9D11D840E3001ECDEF /* python.py */, - 22CAFF9E11D840E3001ECDEF /* README */, - 22CAFF9F11D840E3001ECDEF /* rippy.py */, - 22CAFFA011D840E3001ECDEF /* script.py */, - 22CAFFA111D840E3001ECDEF /* ssh_session.py */, - 22CAFFA211D840E3001ECDEF /* ssh_tunnel.py */, - 22CAFFA311D840E3001ECDEF /* sshls.py */, - 22CAFFA411D840E3001ECDEF /* table_test.html */, - 22CAFFA511D840E3001ECDEF /* topip.py */, - 22CAFFA611D840E3001ECDEF /* uptime.py */, - ); - path = examples; - sourceTree = ""; - }; /* End PBXGroup section */ /* Begin PBXLegacyTarget section */ -- 2.20.1