Mercurial > caja-test
comparison pavement.py @ 4:cf673c093b61 default tip
paver runserver now shows errors if cajoling failed.
author | Atul Varma <varmaa@toolness.com> |
---|---|
date | Sun, 07 Jun 2009 20:44:44 -0700 |
parents | 6737bc744b46 |
children |
comparison
equal
deleted
inserted
replaced
3:8ca68c2a7217 | 4:cf673c093b61 |
---|---|
17 contents = open(filename).read() | 17 contents = open(filename).read() |
18 hash = md5.md5(contents).hexdigest() | 18 hash = md5.md5(contents).hexdigest() |
19 if hash not in self.cache: | 19 if hash not in self.cache: |
20 # TODO: This isn't threadsafe. | 20 # TODO: This isn't threadsafe. |
21 # TODO: There's no way to evict entries from the cache. | 21 # TODO: There's no way to evict entries from the cache. |
22 output_filename = "output.co.js" | 22 cajoled_filename = "output.co.js" |
23 retval = subprocess.call([self.cajoler_path, | 23 output_filename = "output.txt" |
24 popen = subprocess.Popen([self.cajoler_path, | |
24 "-i", filename, | 25 "-i", filename, |
25 "-o", output_filename]) | 26 "-o", cajoled_filename], |
26 if retval == 0: | 27 stdout=open(output_filename, 'w'), |
27 self.cache[hash] = open(output_filename).read() | 28 stderr=subprocess.STDOUT) |
28 os.remove(output_filename) | 29 popen.wait() |
30 if popen.returncode == 0: | |
31 content = open(cajoled_filename).read() | |
32 self.cache[hash] = Bunch(success = True, | |
33 content = content) | |
34 os.remove(cajoled_filename) | |
29 else: | 35 else: |
30 self.cache[hash] = None | 36 output = open(output_filename).read() |
37 self.cache[hash] = Bunch(success = False, | |
38 content = output) | |
39 os.remove(output_filename) | |
31 return self.cache[hash] | 40 return self.cache[hash] |
32 | 41 |
33 def app(self, env, start_response): | 42 def app(self, env, start_response): |
34 path = env['PATH_INFO'] | 43 path = env['PATH_INFO'] |
35 parts = path.split('/')[1:] | 44 parts = path.split('/')[1:] |
36 if len(parts) == 1: | 45 if len(parts) == 1: |
37 filename = os.path.join('caja-js', parts[0]) | 46 filename = os.path.join('caja-js', parts[0]) |
38 if os.path.exists(filename) and not os.path.isdir(filename): | 47 if os.path.exists(filename) and not os.path.isdir(filename): |
39 cajoled = self.cajole(filename) | 48 result = self.cajole(filename) |
40 if cajoled is None: | 49 if not result.success: |
41 start_response('500 Internal Server Error', | 50 start_response('500 Internal Server Error', |
42 [('Content-type', 'text/plain')]) | 51 [('Content-type', 'text/plain')]) |
43 return ["Cajoling failed."] | 52 return ["Cajoling failed:\n\n%s" % result.content] |
44 start_response('200 OK', | 53 start_response('200 OK', |
45 [('Content-type', 'text/javascript')]) | 54 [('Content-type', 'text/javascript')]) |
46 return [cajoled] | 55 return [result.content] |
47 start_response('404 Not Found', | 56 start_response('404 Not Found', |
48 [('Content-type', 'text/plain')]) | 57 [('Content-type', 'text/plain')]) |
49 return ['Not found: %s' % path] | 58 return ['Not found: %s' % path] |
50 | 59 |
51 @task | 60 @task |