Changeset 173
- Timestamp:
- 02/04/07 13:17:30 (2 years ago)
- Files:
-
- trunk/cheesecake/cheesecake_index.py (modified) (4 diffs)
- trunk/cheesecake/util.py (modified) (2 diffs)
- trunk/tests/unit/test_index_class.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/cheesecake/cheesecake_index.py
r172 r173 432 432 """Iterate over each subindex and yield their values. 433 433 """ 434 for index in self.subindices: 435 # Pass Cheesecake instance to other indices. 436 yield index.compute_with(self.cheesecake) 437 # Print index info after computing. 438 if not self.cheesecake.quiet: 439 index.print_info() 434 for index in self.subindices[:]: 435 try: 436 # Pass Cheesecake instance to a subindex. 437 yield index.compute_with(self.cheesecake) 438 # Print index info after computing. 439 if not self.cheesecake.quiet: 440 index.print_info() 441 except: 442 # When exception is thrown, silence it 443 # and remove this subindex from the list. 444 self.subindices.remove(index) 440 445 441 446 def compute_with(self, cheesecake): … … 1049 1054 pylint_args = ' '.join(map(lambda x: '--disable-msg=%s' % x, disabled_messages)) 1050 1055 1056 max_execution_time = 60 1057 1051 1058 def compute(self, files_list, package_dir): 1052 1059 # See if pylint script location is set via environment variable … … 1080 1087 self.cheesecake.log.debug("Running pylint on files: %s." % filenames) 1081 1088 1082 rc, output = run_cmd("%s %s --persistent=n %s" % (pylint_location, filenames, self.pylint_args)) 1089 # Run pylint, but don't allow it to work longer than one minute. 1090 rc, output = run_cmd("%s %s --persistent=n %s" % (pylint_location, filenames, self.pylint_args), 1091 max_timeout=self.max_execution_time) 1083 1092 if rc: 1093 if output == 'Time exceeded': 1094 # Raise and exception what will cause PyLint to be removed from list of indices 1095 # and thus won't affect the score. 1096 self.cheesecake.log.debug("pylint exceeded maximum execution time of %d seconds and was terminated." % \ 1097 self.max_execution_time) 1098 raise OSError 1084 1099 self.cheesecake.log.debug("encountered an error (%d):\n***\n%s\n***\n" % (rc, output)) 1085 1100 error_count += 1 … … 1735 1750 specific indexes. 1736 1751 """ 1737 # Recursively compute all indices.1738 max_cheesecake_index = self.index.max_value1739 1740 1752 # Pass Cheesecake instance to the main Index object. 1741 1753 cheesecake_index = self.index.compute_with(self) 1754 1755 # Get max value *after* computing indices, because computing 1756 # process can remove some indices from the list. 1757 max_cheesecake_index = self.index.max_value 1758 1742 1759 percentage = (cheesecake_index * 100) / max_cheesecake_index 1743 1760 trunk/cheesecake/util.py
r150 r173 4 4 import os 5 5 import shutil 6 import signal 6 7 import sys 7 8 import tarfile … … 14 15 PAD_VALUE = 4 15 16 16 def run_cmd(cmd, env=None ):17 def run_cmd(cmd, env=None, max_timeout=None): 17 18 """Run command and return its return code and its output. 18 19 19 20 >>> run_cmd('/bin/true') 20 21 (0, '') 22 23 >>> run_cmd('/bin/cat', max_timeout=0.2) 24 (1, 'Time exceeded') 21 25 """ 22 26 arglist = cmd.split() 23 27 try: 24 28 p = Popen(arglist, stdout=PIPE, stderr=STDOUT, env=env) 25 except ProcessError, e:29 except Exception, e: 26 30 return 1, e 31 32 # Wait only max_timeout seconds. 33 if max_timeout: 34 start = time.time() 35 while p.poll() is None: 36 time.sleep(0.1) 37 if time.time() - start > max_timeout: 38 os.kill(p.pid, signal.SIGINT) 39 p.wait() 40 return 1, "Time exceeded" 41 27 42 output = p.communicate()[0] 28 43 return p.returncode, output trunk/tests/unit/test_index_class.py
r159 r173 3 3 >>> import _path_cheesecake 4 4 >>> from cheesecake.cheesecake_index import Index 5 >>> from _helper_cheesecake import Glutton 5 6 6 7 ***** … … 84 85 >>> new.requirements 85 86 ['one', 'two', 'three', 'four'] 87 88 ***** 89 90 Index which throws an Exception during computation will 91 get removed from the list of subindices. 92 >>> class BadIndex(Index): 93 ... max_value = 10 94 ... def compute(self): 95 ... raise Exception("No reason.") 96 >>> bad_index = BadIndex() 97 >>> index = Index(bad_index) 98 >>> bad_index in index.subindices 99 True 100 >>> index.compute_with(Glutton()) 101 0 102 >>> bad_index in index.subindices 103 False 104 >>> index.max_value 105 0 86 106 """
