David Anderson avatar David Anderson committed c1527af

Build up a nice-looking little test.

Comments (0)

Files changed (3)

lol.py

-hello = "hello reassembled world!"
     assert basename[-3:] == '.py'
     source = zlib.compress(_readfile(filename))
     out.append('%s\n%d\n%s' % (basename[:-3], len(source), source))
-  for name, source in literal_modules:
+  for name, source in literal_modules.iteritems():
     source = zlib.compress(source)
     out.append('%s\n%d\n%s' % (name, len(source), source))
   out.append('\n%s\n' % main_func)
   return ''.join(out)
 
 def _get_assembler():
-  source = _readfile(__file__)
-  assembler = source.split('# ' + 'BEGIN ASSEMBLER\n')[1]
-  assembler = assembler.split('# ' + 'END ASSEMBLER\n')[0]
+  filename = __file__
+  if filename.endswith('.pyc'):
+    filename = filename[:-1]
+  source = _readfile(filename)
+  assembler = source.split('# BEGIN ASSEMBLER\n')[1]
+  assembler = assembler.split('# END ASSEMBLER\n')[0]
   return assembler + '_load()\n'
 
 # BEGIN ASSEMBLER
 def _load():
+  def __log(s):
+    print s
+    sys.stdout.flush()
   import imp
   import zlib
   import sys
     n = int(sys.stdin.readline())
     files[name] = zlib.decompress(sys.stdin.read(n))
   while files:
+    l = len(files)
     for name in list(files.keys()):
       code = compile(files[name], name, 'exec')
       d = {}
       mod.__dict__.update(d)
       sys.modules[name] = mod
       del files[name]
+    if len(files) == l:
+      print 'Infinite compile loop'
+      sys.stdout.flush()
+      exit(1)
   del sys.modules[__name__].__dict__['_load']
   sys.stdout.flush()
   sys.stderr.flush()
   s2.sendall(stage2)
   s2.sendall(main)
   p.wait()
-
-remote_exec(hostname='localhost',
-            module_filenames=['lol.py', 'test.py'],
-            main_func='test.hello')
-import lol
+#!/usr/bin/env python
 
-def hello():
-  print 'LOL'
-  print lol.hello
+import socket
+import sys
+
+mods = {
+    'test1': '\n'.join([
+        'import test',
+        'import test2',
+        'def print_stuff():',
+        '  print "Hello from test1"',
+        '  print test2.hello',
+        '  print test.mods',
+        '  test.hostname()',
+        ]),
+    'test2': '\n'.join([
+        'hello = "Hello from test2"',
+        ]),
+    }
+
+def hostname():
+  print socket.gethostname()
+
+if __name__ == '__main__':
+  import pycomp
+  pycomp.remote_exec(hostname=sys.argv[1],
+                     module_filenames=['test.py', 'pycomp.py'],
+                     literal_modules=mods,
+                     main_func='test1.print_stuff')
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.