1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- import sys
- import urllib
- import urllib2
- import json
- def flush_data(address, data, username):
- if data:
- urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": "set_input", "data": json.dumps(data), "username": username})), timeout=10).read()
- return []
- def link(address, username, objects):
- # Read out all symbol tables that are to be linked
- definers = {}
- users = {}
- data = []
- data.append(("V", '3'))
- data.append(("V", '"check_symbols"'))
- for obj in objects:
- data.append(("V", '"%s"' % obj))
- data.append(("V", '""'))
- data = flush_data(address, data, username)
- v = urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": "get_output", "username": username}))).read()
- if "False" in v:
- raise Exception("Linking error")
- # Ok, we know that all symbols can be defined with this set of files, now link their initializers together
- initializers = []
- for obj in objects:
- data.append(("V", '3'))
- data.append(("V", '"read_initializers"'))
- data.append(("V", '"%s"' % obj))
- data = flush_data(address, data, username)
- for obj in objects:
- print("[LINK] %s" % (obj))
- v = urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": "get_output", "username": username}))).read()
- start = str(v.split("&", 1)[0].split("=")[1])
- initializers.append(start)
- # Bind all initializers together
- if definers:
- print("[LOAD] %s:main()" % definers["main"])
- else:
- print("[LOAD] main()")
- # Set interface to constructors
- commands = [("V", '1')]
- # Link all initializers together
- for init in initializers:
- commands.extend([
- ("V", '"call"'),
- ("V", '"access"'),
- ("V", '"resolve"'),
- ("V", '"exec"'),
- ("V", '1'),
- ("V", '"const"'),
- ("R", str(init)),
- ("V", 'true'),
- ])
- # Load main function
- commands.extend([
- ("V", '"return"'),
- ("V", 'true'),
- ("V", '"call"'),
- ("V", '"access"'),
- ("V", '"resolve"'),
- ("V", '"main"'),
- ("V", '0'),
- ("V", 'false'),
- ])
- import json
- urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": "set_input", "data": json.dumps(commands), "username": username}))).read()
- if __name__ == "__main__":
- if len(sys.argv) == 1:
- print("No username defined")
- else:
- address = sys.argv[1]
- username = sys.argv[2]
- objects = set(sys.argv[3:])
- if objects:
- link(address, username, objects)
- else:
- print("No files to link defined")
|