PageRenderTime 102ms CodeModel.GetById 37ms RepoModel.GetById 0ms app.codeStats 0ms

/qooxdoo/tool/pylib/generator/runtime/Generatord.py

https://github.com/Wkasel/qooxdoo
Python | 134 lines | 75 code | 26 blank | 33 comment | 1 complexity | 213b6baac2e0ef2dc3c6bf0993c0a3a3 MD5 | raw file
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. ################################################################################
  4. #
  5. # qooxdoo - the new era of web development
  6. #
  7. # http://qooxdoo.org
  8. #
  9. # Copyright:
  10. # 2006-2011 1&1 Internet AG, Germany, http://www.1und1.de
  11. #
  12. # License:
  13. # LGPL: http://www.gnu.org/licenses/lgpl.html
  14. # EPL: http://www.eclipse.org/org/documents/epl-v10.php
  15. # See the LICENSE file in the project's top-level directory for details.
  16. #
  17. # Authors:
  18. # * Thomas Herchenroeder (thron7)
  19. #
  20. ################################################################################
  21. ##
  22. # Generatord -- Generator Daemon Module
  23. #
  24. # Allows to run generator.py in daemon mode.
  25. ##
  26. import sys, os, re, string, types, copy
  27. from generator import Context
  28. from generator.Generator import Generator
  29. from generator.code.Class import Class
  30. from generator.runtime.Cache import Cache
  31. # -- BaseHTTPServer stuff ----
  32. import BaseHTTPServer, cgi
  33. # -- Pyro stuff ----
  34. import Pyro.core, Pyro.naming
  35. generator_context = None
  36. class Generatord(object):
  37. def __init__(self, context, num=0):
  38. global generator_context
  39. generator_context = context
  40. self.num = num
  41. generator_context['cache'] = Cache("/tmp/qx1.5/cache", **generator_context) # TODO: cache path
  42. #self.servAddr = ('',8008)
  43. #self.serv = BaseHTTPServer.HTTPServer(self.servAddr, httpServerHandler)
  44. generator_context['interruptRegistry'].register(self.shut_down)
  45. def serve(self):
  46. #self.serv.serve_forever()
  47. daemon = Pyro.core.Daemon()
  48. self.daemon = daemon
  49. ns = Pyro.naming.NameServerLocator().getNS()
  50. daemon.useNameServer(ns)
  51. uri = daemon.connect(GeneratordWorker(self.num), "genworker"+str(self.num))
  52. daemon.requestLoop()
  53. def shut_down(self):
  54. self.daemon.shutdown(True)
  55. # This is adopted from the standard Pyro example
  56. class GeneratordWorker(Pyro.core.ObjBase):
  57. def __init__(self, num):
  58. Pyro.core.ObjBase.__init__(self)
  59. self.num = num
  60. self.job = generator_context['jobconf']
  61. self.classList = self._scanLibs(self.job)
  62. def _scanLibs(self, job):
  63. genobj = Generator(generator_context)
  64. (ns,classes,d,tr,lib) = genobj.scanLibrary(job.get("library", []))
  65. return classes
  66. def joke(self,name):
  67. return "sorry "+name+", I don't know any jokes!"
  68. def tree(self, classId, classPath, variantSet):
  69. c = Class(classId, classPath, None, generator_context, {})
  70. t = c.tree(variantSet)
  71. return t
  72. def dependencies(self, classId, classPath, variantSet, force=False):
  73. print "\nrunning on Pyro server", str(self.num)
  74. c = Class(classId, classPath, None, generator_context, self.classList)
  75. d, cached = c.dependencies(variantSet, force)
  76. return d, cached
  77. def run(self, jobname):
  78. print "\nrunning on Pyro server", str(self.num), ":", jobname
  79. config = generator_context['config']
  80. console = generator_context['console']
  81. expjobs = config.resolveExtendsAndRuns([jobname])
  82. config.includeSystemDefaults(expjobs)
  83. config.resolveMacros(expjobs)
  84. config.resolveLibs(expjobs)
  85. config.checkSchema(expjobs, checkJobTypes=True)
  86. config.cleanUpJobs(expjobs)
  87. console.resetFilter()
  88. for jobn in expjobs:
  89. console.head("Executing: %s" % jobn, True)
  90. job = generator_context['config'].getJob(jobn)
  91. assert job is not None
  92. job_context = copy.copy(generator_context)
  93. job_context.update({'jobconf':job})
  94. genobj = Generator(job_context)
  95. genobj.run()
  96. # This is from B.Dayley's "Python Phrasebook"
  97. class httpServerHandler(BaseHTTPServer.BaseHTTPRequestHandler):
  98. def do_POST(self):
  99. self.query_string = self.rfile.read(int(self.headers['Content-Length']))
  100. self.args = dict(cgi.parse_qsl(self.query_string))
  101. self.send_response(200)
  102. self.send_header('Content-type', 'text/html')
  103. self.end_headers()
  104. sys.stdout = self.wfile
  105. self.wfile.write("<h2>Handling Post</h2><p>")
  106. self.wfile.write("<li>Location: <b>%s</b>" % (self.path,))
  107. self.wfile.write("<li>Arguments: <b>%s</b><hr>" % (self.args,))
  108. #execfile(self.path, self.args)