فهرست منبع

Added gitignore file and removed some more useless files

Yentl Van Tendeloo 9 سال پیش
والد
کامیت
4e70c41c7e
7فایلهای تغییر یافته به همراه3 افزوده شده و 386 حذف شده
  1. 2 0
      .gitignore
  2. 1 1
      hybrid_server/server.py
  3. 0 78
      prompt.py
  4. 0 10
      request.sh
  5. 0 2
      set_value.sh
  6. BIN
      techreport/demonstration.pdf
  7. 0 295
      test1.py

+ 2 - 0
.gitignore

@@ -0,0 +1,2 @@
+*.pyc
+*.pickle

+ 1 - 1
hybrid_server/server.py

@@ -1,7 +1,7 @@
 """
 Generated by Statechart compiler by Glenn De Jonghe and Joeri Exelmans
 
-Date:   Wed Jul 27 14:52:25 2016
+Date:   Wed Jul 27 14:53:33 2016
 
 Model author: Yentl Van Tendeloo
 Model name:   MvK Server

+ 0 - 78
prompt.py

@@ -1,78 +0,0 @@
-import urllib
-import urllib2
-import threading
-import subprocess
-import os
-
-def local_print(string):
-    print("\033[92m%s\033[0m" % string)
-
-def remote_print(string):
-    print("\033[94m%s\033[0m" % string)
-
-def execute(scriptname, parameters=[], wait=False):
-    if os.name == "nt":
-        command = ["%s.bat" % scriptname] + parameters
-    elif os.name == "posix":
-        command = ["./%s.sh" % scriptname] + parameters
-    else:
-        raise Exception("Unknown OS: " + str(os.name))
-
-    if wait:
-        return subprocess.call(command, shell=False)
-        return subprocess.call(command, shell=False, stdout=open('/tmp/output', 'w'), stderr=open('/tmp/output', 'w'))
-    else:
-        return subprocess.Popen(command, shell=False, stdout=open('/tmp/output', 'w'))
-
-local_print("Welcome to the local shell!")
-local_print("Please specify Modelverse location (default: localhost:8001)")
-
-location = raw_input()
-if location == "":
-    address = "localhost"
-    port = 8001
-else:
-    address, port = location.strip().split(":")
-
-local_print("Username (default: test)")
-username = raw_input()
-if username == "":
-    username = "test"
-else:
-    username = username.strip()
-
-local_print("Switching context to Modelverse: all data is piped.")
-local_print("To quit: execute command 'quit'")
-
-def print_output():
-    while 1:
-        output = urllib2.urlopen(urllib2.Request("http://%s:%s/" % (address, port), urllib.urlencode({"op": "get_output", "username": username}))).read()
-        l, r = output.split("&", 1)
-        if "value" in l:
-            output = l
-        else:
-            output = r
-        _, output = output.split("=", 1)
-        remote_print("%s" % str(output))
-
-thrd = threading.Thread(target=print_output)
-thrd.daemon = True
-thrd.start()
-
-while 1:
-    command = raw_input()
-    if command == "quit":
-        local_print("Received quit: breaking connection to Modelverse immediately!")
-        break
-    try:
-        # Could be a number
-        _ = float(command)
-        command = str(command)
-        local_print("Interpreting value as a number")
-    except:
-        if len(command) > 0 and command[0] == "\\":
-            command = '{"value": "%s"}' % command[1:]
-        else:
-            command = '"%s"' % command
-        local_print("Got command string: " + str(command))
-    urllib2.urlopen(urllib2.Request("http://%s:%s/" % (address, port), urllib.urlencode({"op": "set_input", "element_type": "V", "value": command, "username": username}))).read()

+ 0 - 10
request.sh

@@ -1,10 +0,0 @@
-#!/bin/bash
-set -e
-
-curl http://localhost:8001 -d "op=set_input&username=user_manager&element_type=V&value=\"test\""
-sleep 0.5
-while true
-do
-    echo ""
-    curl http://localhost:8001 -d "op=get_output&username=test&element_type=V&value="
-done

+ 0 - 2
set_value.sh

@@ -1,2 +0,0 @@
-curl http://localhost:8001 -d "op=set_input&username=test&element_type=V&value=${1}"
-echo

BIN
techreport/demonstration.pdf


+ 0 - 295
test1.py

@@ -1,295 +0,0 @@
-import json
-import os
-import pexpect
-import sys
-import threading
-import time
-import urllib
-import urllib2
-
-sys.path.append("interface/HUTN")
-
-from hutn_compiler.compiler import main
-
-
-# CONSTANTS
-user = 'test'
-timeout = 10
-grammar_file = 'interface/HUTN/grammars/actionlanguage.g'
-
-
-# Consumes output of some subprocess in a background thread
-class OutletThread(threading.Thread):
-    # obj:   pexpect.spawn object
-    # delay: time (in seconds) to wait between two reads
-    def __init__(self, obj, delay = 1):
-        threading.Thread.__init__(self)
-        self.obj = obj
-        self.on = True
-        self.delay = delay
-
-    # main
-    def run(self):
-        while self.on:
-            try:
-                x = self.obj.read_nonblocking(size=2048, timeout=0)
-                sys.stdout.write(x)
-                sys.stdout.flush()
-            except pexpect.TIMEOUT:
-                pass
-            time.sleep(self.delay)
-
-    # utils
-    def join(self, timeout=None):
-        self.on = False
-        threading.Thread.join(self, timeout)
-
-    def pause(self):
-        self.on = False
-
-    def resume(self):
-        self.on = True
-
-
-# do obj.expect(s) and print the output of the spawned process
-def pp(obj, s):
-    obj.expect(s)
-    print obj.before + obj.after
-
-
-def execute(scriptname, parameters=[]):
-    if os.name == "nt":
-        command = "%s.bat" % scriptname
-    elif os.name == "posix":
-        command = "./%s.sh" % scriptname
-    else:
-        raise Exception("Unknown OS: " + str(os.name))
-
-    ok = False
-    proc = None
-    while not ok:
-        try:
-            proc = pexpect.spawn(command, parameters)
-            ok = True
-        except:
-            pass
-
-    return proc
-
-
-def set_input(value, user=user, timeout=timeout):
-    if isinstance(value, tuple):
-        for v in value:
-            set_input(v)
-    else:
-        args = {"op": "set_input",
-                "element_type": "V",
-                "value": json.dumps(value),
-                "username": user}
-        urllib2.urlopen(
-            urllib2.Request("http://localhost:8001/", urllib.urlencode(args)),
-            timeout=timeout).read()
-
-
-def flush_data(data, user=user, timeout=timeout):
-    args = {"op": "set_input",
-            "data": json.dumps(data),
-            "username": user}
-    urllib2.urlopen(
-        urllib2.Request("http://localhost:8001/", urllib.urlencode(args)),
-        timeout=timeout).read()
-    return []
-
-
-def get_output(user=user, timeout=timeout):
-    return urllib2.urlopen(
-        urllib2.Request("http://localhost:8001/",
-                        urllib.urlencode({"op": "get_output",
-                                          "username": user})),
-        timeout=timeout).read()
-
-
-def create_user(user):
-    ok = False
-    while not ok:
-        try:
-            set_input(user, "user_manager")
-            ok = True
-        except:
-            pass
-
-
-def run_file(input_file, test_input, test_output, mode="PS"):
-    # Resolve file
-    input_file = "integration/code/%s" % input_file
-
-    # Run Modelverse server
-    mv = execute("run_local_modelverse", ["bootstrap/bootstrap.m"])
-
-    # consume output of MvK and print it in the main thread
-    mvo = OutletThread(mv)
-    mvo.start()
-
-    # determine the interface
-    if mode == "CS":
-        interface = 1
-    elif mode == "PS":
-        interface = 0
-    else:
-        raise RuntimeError("Mode be either PS or CS")
-
-    # compile to code
-    code = main(input_file, grammar_file, mode)
-
-    create_user(user)
-
-    # set interface
-    set_input(interface)
-
-    try:
-        # send code
-        if mode == "CS":
-            var_list = {}
-            data = []
-            for p in code:
-                if isinstance(p, int):
-                    if p not in var_list:
-                        data = flush_data(data)
-                        data = []
-                        val = get_output()
-                        val = val.split("=", 2)[1].split("&", 1)[0]
-                        var_list[p] = val
-                        continue
-                    else:
-                        val = var_list[p]
-                        t = "R"
-                else:
-                    val = p
-                    t = "V"
-                data.append([t, val])
-            data = flush_data(data)
-        elif mode == "PS":
-            set_input(code)
-
-        # set input and get output
-        for i in range(len(test_input)):
-            set_input(test_input[i])
-            val = get_output()
-            val = val.split("=", 2)[2]
-            print("For input %s, got output %s, expected %s" % (test_input[i], val, test_output[i]))
-            assert str(val) == test_output[i]
-            if str(val) != test_output[i]:
-                return False
-    finally:
-        mvo.join()
-        mv.sendintr()
-
-    # All passed!
-    return True
-
-
-def run_barebone(constructors_and_test_input, test_output, interface):
-    # Run Modelverse server
-    mv = execute("run_local_modelverse", ["bootstrap/bootstrap.m"])
-
-    # consume output of MvK and print it in the main thread
-    mvo = OutletThread(mv)
-    mvo.start()
-
-    create_user(user)
-
-    # set interface
-    set_input(interface)
-
-    # send constructors and inpout
-    var_list = {}
-    data = []
-    for p in constructors_and_test_input:
-        if isinstance(p, int):
-            if p not in var_list:
-                data = flush_data(data)
-                val = get_output()
-                val = val.split("=", 2)[1].split("&", 1)[0]
-                var_list[p] = val
-                continue
-            else:
-                val = var_list[p]
-                t = "R"
-        else:
-            val = p
-            t = "V"
-        data.append([t, val])
-    data = flush_data(data)
-
-    for e in test_output:
-        val = get_output()
-        val = val.split("=", 2)[2]
-        print("Got %s, expected %s" % (val, e))
-        assert str(val) == e
-        if str(val) != e:
-            mvo.join()
-            mv.sendintr()
-            return False
-
-    # for e in test_output:
-    #     c = len(e) if isinstance(e, set) else 1
-    #     for _ in range(c):
-    #         val = get_output(user)
-    #         val = val.split("=", 2)[2]
-    #
-    #         print("Got %s, expected %s" % (val, e))
-    #         if isinstance(e, set):
-    #             assert str(val) in e
-    #             if str(val) not in e:
-    #                 mvo.join()
-    #                 mv.sendintr()
-    #                 return False
-    #         else:
-    #             assert str(val) == e
-    #             if str(val) != e:
-    #                 mvo.join()
-    #                 mv.sendintr()
-    #                 return False
-
-    # All passed!
-    mvo.join()
-    mv.sendintr()
-    return True
-# assert(run_file("binary_to_decimal.al",
-#             ["1", "10", "11", "100", "001", "1100111101"],
-#             ["1", "2", "3", "4", "1", "829"],
-#             "PS"))
-assert(run_file("binary_to_decimal.al",
-            ["1", "10", "11", "100", "001", "1100111101"],
-            ["1", "2", "3", "4", "1", "829"],
-            "CS"))
-# assert(run_file("fibonacci.al", [1, 2, 3, 4], ["1", "1", "2", "3"]))
-# assert(run_file("fibonacci.al", [1, 2, 3, 4], ["1", "1", "2", "3"], mode="CS"))
-# assert(run_file("power.al", [(1, 0), (2, 1), (5, 0), (2, 2), (3, 2), (10, 2), (10, 10)], ["1", "2", "1", "4", "9", "100", "10000000000"]))
-# assert(run_file("binary_to_decimal.al", ["1", "10", "11", "100", "001", "1100111101"], ["1", "2", "3", "4", "1", "829"]))
-# assert(run_file("leap_year.al", [  2016,    2015,    2014,    2013,   2012,    2001,    2000,    1999],
-#                                 ["True", "False", "False", "False", "True", "False", "False", "False"]))
-#
-#
-# def flatten(lst):
-#     new_lst = []
-#     for f in lst:
-#         if isinstance(f, (list, tuple)):
-#             new_lst.extend(flatten(f))
-#         else:
-#             new_lst.append(f)
-#     return new_lst
-#
-#
-# commands = [('"output"',  # Output
-#              ('"const"', 'true'),
-#              'true',  # (has next)
-#              ('"return"',  # Return
-#               'true',  # (has value)
-#               ('"const"', 'true'),
-#               ),
-#              )
-#             ]
-#
-#
-# assert(run_barebone(flatten(commands), ["True"], 1))