from model_visitor import ModelVisitor
from compiler import main as do_compile
import os
import urllib2
import urllib
import json

def empty(s):
    return None

class ModelObjectVisitor(ModelVisitor):
    def __init__(self, args):
        ModelVisitor.__init__(self, args)
        self.username = args[0]
        self.obj_file = args[1]
        self.real_file = args[2]
        self.address = args[3]

    def dump(self):
        v = ModelVisitor.dump(self)
        data = [4] + v + ["exit"]

        # Wait for kernel to signal that it finished
        data.append(2)

        urllib2.urlopen(urllib2.Request(self.address, urllib.urlencode({"op": "set_input", "data": json.dumps(data), "username": self.username}))).read()
        v = urllib2.urlopen(urllib2.Request(self.address, urllib.urlencode({"op": "get_output", "username": self.username}))).read()
        v = json.loads(v)
        if v == "DONE":
            return True
        else:
            return False
