Advertisement
Guest User

Untitled

a guest
Apr 30th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. import os
  4. import subprocess
  5. import urllib
  6. import json
  7. import sys
  8. import StringIO
  9. import zipfile
  10.  
  11. import urllib2
  12. req = urllib2.Request('http://metadata.google.internal/computeMetadata/v1/instance/hostname')
  13. req.add_header('Metadata-Flavor', 'Google')
  14. resp = urllib2.urlopen(req)
  15. content = resp.read()
  16. hostname = content.split(".")[0]
  17.  
  18. while True:
  19. u = urllib.urlopen("http://chrisplaysgames.com:8000/fetch?owner=%s" % hostname)
  20. data = json.load(u)
  21. task_id = data['task_id']
  22. d = "stuff-%s" % task_id
  23. if not os.path.exists(d):
  24. os.mkdir(d)
  25. zfd = open("%s/%s.zip" % (d,d), "w")
  26. zfd.write(urllib.urlopen("http://chrisplaysgames.com:8000/zip?task=%s" % task_id).read())
  27. zfd.close()
  28. zf = zipfile.ZipFile("%s/%s.zip" % (d, d))
  29. zf.extractall(d)
  30.  
  31. os.chdir(d)
  32. file = data['task']
  33. dir, fname = os.path.split(file)
  34. clock = data['clock']
  35. image_id = str(clock).zfill(4)
  36. image = file.strip(".pov") + image_id + ".png"
  37. print image
  38. return_code = subprocess.call("povray +a +I%s +KFI1 +KFF1000 Subset_Start_Frame=%s Subset_End_Frame=%s +W4000 +H2000" % (fname, clock, clock), cwd=dir, shell=True)
  39. copy_command = "/usr/local/bin/gsutil cp %s gs://crschmidt-povrayexperiments/" % image
  40. return_code = subprocess.call(copy_command, shell=True)
  41. os.unlink(image)
  42. u = urllib.urlopen("http://chrisplaysgames.com:8000/complete?task=%s&clock=%s" % (task_id, clock))
  43. os.chdir("/tmp")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement