# # # patch "fileinbranch.psp" # from [b5303538fa3fc8a567d758d257de52f79004414f] # to [669d559abf0b0033333d01735993bf1f93da56bb] # # patch "headofbranch.psp" # from [5949f4c3976c2860d25028f005f6f5e19a4995d3] # to [4202c80defa38112c39ecbf17c26e9bf97a640ff] # # patch "index.psp" # from [91b20f95e6c81b15fa20307e27ab590700ea8200] # to [4c4e48057137b7128ae152fd020212363d2c7b56] # # patch "monotone.py" # from [7e27870203771c7919ff8cbfc50977f029c16ac7] # to [e2fa7b49375e3a5448d0c657d0087a8cf571184b] # # patch "revision.psp" # from [51027eadc7443245e40030623274abe7202eef2b] # to [0d4ef551870068ee14ccf17cc0908f012920a933] # # patch "tags.psp" # from [ebf8689665678fbcb9a90537d5f1fae8c2da73b8] # to [82170afbb360ce8d7586aa1166fcb5777d7a8bf3] # # patch "tarofbranch.psp" # from [a213fcbd0ade73bb588d5d4b37bc9174b24299a4] # to [feadce980ebd565f2994099f01bd7baa58ee57b9] # # patch "wrapper.py" # from [256d3e8f34c5959c8ec24602f639cc0c04e53ae3] # to [b9277f3e8636318e0aa6cda2f6c2c8d9e195bce9] # ============================================================ --- fileinbranch.psp b5303538fa3fc8a567d758d257de52f79004414f +++ fileinbranch.psp 669d559abf0b0033333d01735993bf1f93da56bb @@ -6,7 +6,6 @@ import urllib import template from template import header,footer -from monotone import Monotone from common import link psp.set_error_page("error.psp") @@ -24,8 +23,6 @@ # in a branch (and present a choice iff there # are multiple heads and the files difer in them) -mt = Monotone(config.monotone, config.dbfile) - heads = mt.heads(branch) if len(heads) == 0: raise Exception("No head ID can be determined for this branch.") ============================================================ --- headofbranch.psp 5949f4c3976c2860d25028f005f6f5e19a4995d3 +++ headofbranch.psp 4202c80defa38112c39ecbf17c26e9bf97a640ff @@ -6,7 +6,6 @@ import urllib import template from template import header,footer -from monotone import Monotone from common import link psp.set_error_page("error.psp") @@ -25,8 +24,6 @@ # otherwise, redirect to revision.psp and show that # ID. -mt = Monotone(config.monotone, config.dbfile) - heads = mt.heads(branch) if len(heads) == 0: raise Exception("No head ID can be determined for this branch.") ============================================================ --- index.psp 91b20f95e6c81b15fa20307e27ab590700ea8200 +++ index.psp 4c4e48057137b7128ae152fd020212363d2c7b56 @@ -6,7 +6,6 @@ import urllib import template from template import header,footer -from monotone import Monotone from common import link psp.set_error_page("error.psp") @@ -14,9 +13,7 @@ req.write(header(info)) hq = common.html_escape() -mt = Monotone(config.monotone, config.dbfile) branches = mt.branches() -del mt %> ============================================================ --- monotone.py 7e27870203771c7919ff8cbfc50977f029c16ac7 +++ monotone.py e2fa7b49375e3a5448d0c657d0087a8cf571184b @@ -1,6 +1,5 @@ import utility -import syslog import string import urllib import pipes @@ -35,25 +34,22 @@ return ''.join(map(lambda x: "%.2x" % int(x * 256), hls_to_rgb(hue, li, sat))) class Automation: - def __init__(self, mt, dbfile): - self.mt = mt - self.dbfile = dbfile - self.command = "%s --db=%s automate stdio" % (self.mt, pipes.quote(self.dbfile)) + def __init__(self, base_command): + self.command = "%s automate stdio" % (base_command) self.process = None def __del__(self): - syslog.syslog("%d - stopping automation child" % os.getpid()) - if self.process: - try: - self.process.tochild.close() - self.process.fromchild.close() - self.process.wait() - except: pass - syslog.syslog("%d - completed automation child" % os.getpid()) + self.stop() self.process = None def start(self): self.process = popen2.Popen3(self.command) set_nonblocking(self.process.fromchild) - syslog.syslog("%d - starting automation child" % os.getpid()) + def stop(self): + if not self.process: return + try: + self.process.tochild.close() + self.process.fromchild.close() + self.process.wait() + except: pass def run(self, command, args): if self.process == None: self.start() enc = "l%d:%s" % (len(command), command) @@ -90,7 +86,7 @@ self.mt = mt self.dbfile = dbfile self.base_command = "%s --db=%s" % (self.mt, pipes.quote(self.dbfile)) - self.automate = Automation(self.mt, self.dbfile) + self.automate = Automation(self.base_command) def branches(self): result = utility.run_command(self.base_command + " ls branches") if result['exitcode'] != 0: ============================================================ --- revision.psp 51027eadc7443245e40030623274abe7202eef2b +++ revision.psp 0d4ef551870068ee14ccf17cc0908f012920a933 @@ -6,8 +6,6 @@ import urllib import template from template import header,footer -from monotone import Monotone -reload(monotone) from common import link # @@ -26,8 +24,6 @@ if not monotone.is_valid_id(id): raise Exception("Specified revision ID is not valid.") -mt = Monotone(config.monotone, config.dbfile) - hq = common.html_escape() info = {'title' : "Revision %s" % (hq(id))} req.write(header(info)) ============================================================ --- tags.psp ebf8689665678fbcb9a90537d5f1fae8c2da73b8 +++ tags.psp 82170afbb360ce8d7586aa1166fcb5777d7a8bf3 @@ -6,7 +6,6 @@ import urllib import template from template import header,footer -from monotone import Monotone from common import link psp.set_error_page("error.psp") @@ -14,8 +13,6 @@ req.write(header(info)) hq = common.html_escape() -mt = Monotone(config.monotone, config.dbfile) - tags = mt.tags() %> ============================================================ --- tarofbranch.psp a213fcbd0ade73bb588d5d4b37bc9174b24299a4 +++ tarofbranch.psp feadce980ebd565f2994099f01bd7baa58ee57b9 @@ -6,7 +6,6 @@ import urllib import template from template import header,footer -from monotone import Monotone from common import link psp.set_error_page("error.psp") @@ -21,8 +20,6 @@ # HEAD of a branch. If there are multiple heads, # present a choice. -mt = Monotone(config.monotone, config.dbfile) - heads = mt.heads(branch) if len(heads) == 0: raise Exception("No head ID can be determined for this branch.") ============================================================ --- wrapper.py 256d3e8f34c5959c8ec24602f639cc0c04e53ae3 +++ wrapper.py b9277f3e8636318e0aa6cda2f6c2c8d9e195bce9 @@ -8,7 +8,6 @@ from monotone import Monotone import template import tarfile -import syslog import os import re @@ -94,6 +93,13 @@ 'gettar.py' : get_tar } +def cleanup(req, vars): + req.log_error("testing: %s" % (str(vars))) + mt = vars['mt'] + mt.automate.stop() + req.log_error("survived deletion") + del mt + def handler(req): req.content_type = "text/plain" uri = req.uri @@ -109,26 +115,17 @@ return handlers[uri](req) # - # if we're here, then we're doing something PSP-ish (or - # it's a 404) + # PSP or 404 # - rv = apache.HTTP_NOT_FOUND - template = None try: if uri.endswith('.psp') and sane_uri_re.match(uri[:-4]): req.content_type = "text/html" - syslog.syslog("%d - starting template" % os.getpid()) - template = psp.PSP(req, filename=uri) + vars = { 'mt' : Monotone(config.monotone, config.dbfile) } + req.register_cleanup(cleanup, (req, vars)) + mt = Monotone(config.monotone, config.dbfile) + template = psp.PSP(req, filename=uri, vars={'mt':mt}) template.run() - syslog.syslog("%d - stopping template" % os.getpid()) - rv = apache.OK - except IOError: - rv = apache.HTTP_INTERNAL_SERVER_ERROR - syslog.syslog("%d - IOError" % os.getpid()) + return apache.OK except ValueError: - rv = apache.HTTP_NOT_FOUND - syslog.syslog("%d - ValueError" % os.getpid()) - del template - syslog.syslog("%d - unreffed template" % os.getpid()) - return rv + return apache.HTTP_NOT_FOUND