예제 #1
0
def run_files(args, verbose=0, inspect=False):
    sys.argv = args
    filename = args[0]
    args = args[1:]

    import java.io.File as File
    abspath = File(filename).getAbsolutePath()
    path = str(abspath[0:abspath.rindex(File.separator)])
    sys.path.insert(0, path)

    program=open(filename).read()
    from pysoc import compiler
    src = compiler.compile(program)

    from impSocialite import addMod, loadMod, setSocialiteVars
    sys.modules.pop("__main__", None)

    class FakeConsole:
        def __init__(self):
            self.locals = None

    console = FakeConsole()
    adapter = PythonInterpAdapter(console)
    import socialite.functions.PyInterp as PyInterp
    PyInterp.set(adapter)

    mod = addMod("__main__")
    setSocialiteVars(mod.__dict__)
    console.locals = mod.__dict__
    try:
        import java.lang.System as Sys
        mod = loadMod("__main__", src, filename)
        #exec src in locals
    except SystemExit:
        sys.exit(0)
    except:
        # adapted from code.py::InteractiveInterpreter::showtraceback
        import traceback
        try:
            tp, value, tb = sys.exc_info()
            sys.last_type = tp
            sys.last_value = value
            sys.last_traceback = tb
            tblist = traceback.extract_tb(tb)
            del tblist[:1]
            list = traceback.format_list(tblist)
            if list:
                list.insert(0, "Traceback (most recent call last):\n")
            list[len(list):] = traceback.format_exception_only(tp, value)
        finally:
            tblist = tb = None
        map(sys.stderr.write, list)
        sys.exit(1)
 
    if inspect:
        console = SociaLiteConsole(verbose=verbose)
        console.initLocals(mod.__dict__)
        console.interact("")
예제 #2
0
def run_files(args, verbose=0, inspect=False):
    sys.argv = args
    filename = args[0]
    args = args[1:]

    import java.io.File as File
    abspath = File(filename).getAbsolutePath()
    path = str(abspath[0:abspath.rindex(File.separator)])
    sys.path.insert(0, path)

    program = open(filename).read()
    from pysoc import compiler
    src = compiler.compile(program)

    from impSocialite import addMod, loadMod, setSocialiteVars
    sys.modules.pop("__main__", None)

    class FakeConsole:
        def __init__(self):
            self.locals = None

    console = FakeConsole()
    adapter = PythonInterpAdapter(console)
    import socialite.functions.PyInterp as PyInterp
    PyInterp.set(adapter)

    mod = addMod("__main__")
    setSocialiteVars(mod.__dict__)
    console.locals = mod.__dict__
    try:
        import java.lang.System as Sys
        mod = loadMod("__main__", src, filename)
        #exec src in locals
    except SystemExit:
        sys.exit(0)
    except:
        # adapted from code.py::InteractiveInterpreter::showtraceback
        import traceback
        try:
            tp, value, tb = sys.exc_info()
            sys.last_type = tp
            sys.last_value = value
            sys.last_traceback = tb
            tblist = traceback.extract_tb(tb)
            del tblist[:1]
            list = traceback.format_list(tblist)
            if list:
                list.insert(0, "Traceback (most recent call last):\n")
            list[len(list):] = traceback.format_exception_only(tp, value)
        finally:
            tblist = tb = None
        map(sys.stderr.write, list)
        sys.exit(1)

    if inspect:
        console = SociaLiteConsole(verbose=verbose)
        console.initLocals(mod.__dict__)
        console.interact("")
예제 #3
0
    def __init__(self, cpu=None, verbose=False):
        InteractiveConsole.__init__(self)
        self.filename="<stdin>"

        self.inQuery = False # True if the shell is in SociaLite query
        self.compiler = None

        self.declBegin = None
        self.declEnd = None

        self.locals={}

        from impSocialite import setSocialiteVars
        setSocialiteVars(self.locals)
        self.locals["__name__"] = "__main__"

        self.adapter = PythonInterpAdapter(self)
        import socialite.functions.PyInterp as PyInterp
        PyInterp.set(self.adapter)
예제 #4
0
    def __init__(self, cpu=None, verbose=False):
        InteractiveConsole.__init__(self)
        self.filename = "<stdin>"

        self.inQuery = False  # True if the shell is in SociaLite query
        self.compiler = None

        self.declBegin = None
        self.declEnd = None

        self.locals = {}

        from impSocialite import setSocialiteVars
        setSocialiteVars(self.locals)
        self.locals["__name__"] = "__main__"

        self.adapter = PythonInterpAdapter(self)
        import socialite.functions.PyInterp as PyInterp
        PyInterp.set(self.adapter)
예제 #5
0
    def __init__(self, cpu=None, verbose=False):
        InteractiveConsole.__init__(self)
        self.filename="<stdin>"

        self.inQuery = False # True if the shell is in SociaLite query
        self.compiler = compiler

        self.declBegin = p.stringStart+p.Literal("`")
        self.declBegin.ignore(p.pythonStyleComment)
        self.declBegin.ignore(p.quotedString)

        self.declEnd = p.Literal("`") + p.stringEnd
        self.declEnd.ignore(p.pythonStyleComment)
        self.declEnd.ignore(p.quotedString)

        self.locals={}

        from impSocialite import setSocialiteVars
        setSocialiteVars(self.locals)
        self.locals["__name__"] = "__main__"

        self.adapter = PythonInterpAdapter(self)
        import socialite.functions.PyInterp as PyInterp
        PyInterp.set(self.adapter)
예제 #6
0
@returns(int)             # annotates function return type 
def randInt(s, e):        # to access it from SociaLite queries
    import random as r
    return r.randint(s, e)

# Computes average friend counts for randomly selected samples.
`SampleAvg(int i:0..0, Avg avg).
 SampleAvg(0, $avg(cnt)) :- i=$randInt(0,100), FriendCnt(i, cnt).`

"""


double = float
import sys
try: PyInterp.set(sys._jy_interpreter)
except:
    sys.stderr.write("Cannot access interpreter object via sys._jy_interpreter\n")

def internal(f):
    f.internal = True
    return f
internal.internal = True

isClusterEngine = False
engine = None
@internal
def init(cpu=None, dist=False, interactive=False, verbose=0):
    global engine, isClusterEngine
    if engine==None:
        if dist: