Permalink
Browse files

cleanups, make coqd not require json by default. add code to interp

  • Loading branch information...
1 parent 66d09f2 commit 093cedff81319fd59565240cbab7a8b28347dda5 @dcolish committed Sep 13, 2010
View
@@ -2,7 +2,6 @@ include README
include LICENSE
recursive-include tests *
recursive-exclude tests *.pyc
-recursive-exclude tests *.pyc
recursive-include docs *
recursive-exclude docs *.pyc
recursive-exclude docs *.pyo
@@ -5,11 +5,14 @@
<head>
<title>Cockerel Logic Checker - {% block title %}{% endblock %}</title>
<link rel="stylesheet" type="text/css" href="/static/site.css" />
- <script type="text/javascript" src="http://www.google.com/jsapi?key=ABQIAAAA8Iq3w1LF6TgIDgZx7RQ_cRT7g5bZECU_gqoByQmzcFSTeCxKshRn_ZMRy-gSPjQ8nSSldSReJClRvA"></script>
+ <script type="text/javascript"
+ src="http://www.google.com/jsapi?key=ABQIAAAA8Iq3w1LF6TgIDgZx7RQ_cRT7g5bZECU_gqoByQmzcFSTeCxKshRn_ZMRy-gSPjQ8nSSldSReJClRvA"></script>
<script>
google.load('jquery', '1.4.2');
</script>
- <script type="text/javascript" language="javascript" src="http://colishcloud.appspot.com/static/codemirror/js/codemirror.js" ></script>
+ <script type="text/javascript"
+ language="javascript"
+ src="http://colishcloud.appspot.com/static/codemirror/js/codemirror.js" ></script>
<!-- <script type="text/javascript" language="javascript" src="/static/cockerel.js"></script> -->
</head>
<body>
@@ -39,8 +42,14 @@
<div id="footer">
{% block footer %}
{% endblock %}
- <p>Copyright 2010 by Dan Colish</p>
+ <a href="http://flask.pocoo.org/">
+ <img
+ src="http://flask.pocoo.org/static/badges/powered-by-flask-s.png"
+ border="0"
+ alt="powered by Flask"
+ title="powered by Flask" />
+ </a>
+ <p>Copyright 2010 by Dan Colish</p>
</div>
-
</body>
</html>
@@ -6,7 +6,6 @@
<p><a href="{{ url_for('classes.register', class_id=class_section.id) }}">Register</a></p>
{% else %}
<p>Lessons</p>
-
<ul>
{% for lesson in lessons %}
<li><a href="{{ url_for('lessons.view', lesson_id=lesson.id) }}">{{ lesson.lesson_name }}</a></li>
@@ -10,7 +10,7 @@
Goal True -> True.
>>>
"""
-from urllib import urlencode
+
import re
import markdown
View
@@ -66,6 +66,9 @@ def quit(self):
active_conns = {}
+ def connectionMade(self):
+ self.serialize = self.factory.serialize
+
def dataReceived(self, data):
"""
Parse data we've recieved and send to proof engine
@@ -76,8 +79,14 @@ def dataReceived(self, data):
command = req_data.get('command')
userid = req_data.get('userid')
resp_data = self.handle_command(userid, command)
- resp_data['response'] = self.do_parse(resp_data['response'])
- self.transport.write(JSONEncoder().encode(resp_data))
+
+ data = resp_data['response']
+
+ if self.serialize:
+ resp_data['response'] = self.do_parse(resp_data['response'])
+ data = JSONEncoder().encode(resp_data)
+
+ self.transport.write(data)
self.transport.loseConnection()
def do_parse(self, output):
View
@@ -1,24 +1,48 @@
-from code import InteractiveConsole
+from argparse import ArgumentParser
from json import JSONDecoder, JSONEncoder
import readline
import logging
+from sys import argv
import telnetlib
-def send(command):
+def send(command, serialize):
try:
tn = telnetlib.Telnet('localhost', 8003)
tn.write(JSONEncoder().encode(dict(userid=0,
command=command)))
- proofst = JSONDecoder().decode(tn.read_all())
- proofst = proofst.get('response', None)
+ if serialize:
+ proofst = JSONDecoder().decode(tn.read_all())
+ proofst = proofst.get('response', None)
+ else:
+ proofst = tn.read_all()
print proofst
except Exception:
logging.error("Connection to coqd failed")
-while True:
- try:
- prompt = raw_input(">>> ")
- send(prompt)
- except:
- pass
+
+def options(parser):
+ parser.add_argument("--serialize", action="store_true",
+ default=False,
+ help="Serialize output to JSON")
+ return parser
+
+
+def main():
+ """
+ Setup and run coqd
+ """
+ parser = ArgumentParser(prog="Coqd", description="Options for Coqd",
+ version="Coqd 0.1")
+ parser = options(parser)
+ opts = parser.parse_args(argv[1:])
+
+ while True:
+ try:
+ prompt = raw_input(">>> ")
+ send(prompt, opts.serialize)
+ except:
+ pass
+
+if __name__ == '__main__':
+ main()
View
@@ -3,14 +3,14 @@
~~~~~~
Main entry points for coqd
"""
-# from argparse import ArgumentParser
-from optparse import OptionParser
+from argparse import ArgumentParser
+# from optparse import OptionParser
from ConfigParser import SafeConfigParser
import logging
from sys import argv
from twisted.internet import reactor
-from twisted.internet.protocol import Factory
+from twisted.internet.protocol import ServerFactory
from connserv import CoqProtocol
@@ -22,36 +22,41 @@ def __init__(self, config_files):
self.conf.read(config_files)
+class CoqFactory(ServerFactory):
+ protocol = CoqProtocol
+
+ def __init__(self, serialize):
+ self.serialize = serialize
+
+
def options(parser):
- parser.add_option("--module", dest="modules", action="append",
+ parser.add_argument("--module", dest="modules", action="append",
default=[],
help="load modules into coqd, more than one "
"can be specified",
)
- parser.add_option("--serialize", action="store_true",
- default=False,
- help="Serialize output to JSON")
+ parser.add_argument("--serialize", action="store_true",
+ default=False,
+ help="Serialize output to JSON")
return parser
def main():
"""
Setup and run coqd
"""
- parser = OptionParser(prog="Coqd", description="Options for Coqd",
- version="Coqd 0.1")
+ parser = ArgumentParser(prog="Coqd", description="Options for Coqd",
+ version="Coqd 0.1")
parser = options(parser)
- opts, args = parser.parse_args(argv[1:])
+ opts = parser.parse_args(argv[1:])
if opts.modules:
# XXX: actual module loading occurs here
pass
logging.info("Coq is starting... hold on")
-
- f = Factory()
- f.protocol = CoqProtocol
- reactor.listenTCP(8003, f)
+ factory = CoqFactory(opts.serialize)
+ reactor.listenTCP(8003, factory)
reactor.run()
if __name__ == '__main__':

0 comments on commit 093cedf

Please sign in to comment.