[cheesecake-users] output question

will guaraldi willg at bluesock.org
Fri Jul 21 20:46:52 PDT 2006


I skimmed the code and I see what Grig is talking about.

I found some time to tinker with the code and attached a patch that 
changes the behavior to something more like what I was hoping for.

I changed it so that advice (though I'm not sure that's the word that we 
should use--I think I'm now using it less like advice and more like, "oh, 
by the way--this is the verbose explanation of what I'm thinking while I'm 
calculating the score for this index" which I think is more in line with 
"verbose") is printed along with the index it relates to.  The Cheesecake 
instance is passed into the Index instances, so the Index instances know 
whether we're in verbose mode or not.  Then I adjusted _print_info_one so 
that if we're in verbose mode, it prints get_advice() in addition to 
printing out the test results.

Then there was a minor issue in the existing advice for the 
files/directories index.  _used_rules gets reset when you call 
_compute_from_rules.  The problem there being that at the point we figured 
out the advice from the missing files and directories, _used_rules only 
had the used directories.  So I adjusted the order of things in the 
compute method so that we capture used files and used directories.

This is more like what I was looking for, though I don't know if it's what 
you guys have in mind.  Figured it was easier to code it up than to bumble 
through more explanations of what's in me head.  ;)

Rock on!
/will
-------------- next part --------------
Index: cheesecake_index.py
===================================================================
--- cheesecake_index.py	(revision 100)
+++ cheesecake_index.py	(working copy)
@@ -351,7 +351,7 @@
     name = "unnamed"
     value = -1
     details = ""
-    advices = ""
+    advice = ""
 
     def __init__(self, *indices):
         # When indices are given explicitly they override the default.
@@ -467,6 +467,8 @@
         del self._indices_dict[index_name]
 
     def _print_info_one(self):
+        if self.cheesecake.verbose:
+            print self.get_advice(),
         print "%s  (%s)" % (pad_msg(index_class_to_name(self.name), self.value), self.details)
 
     def _print_info_many(self):
@@ -496,10 +498,10 @@
     def __getitem__(self, name):
         return self._indices_dict[name]
 
-    def get_advices(self):
+    def get_advice(self):
         if self.subindices:
-            return ''.join(map(lambda index: index.get_advices(), self.subindices))
-        return self.advices
+            return ''.join(map(lambda index: index.get_advice(), self.subindices))
+        return self.advice
 
 ################################################################################
 ## Index that computes scores based on files and directories.
@@ -782,25 +784,35 @@
     max_value = sum(cheese_files.values() + cheese_dirs.values())
 
     def compute(self, files_list, dirs_list, package_dir):
+        # Inform user of files and directories the package is missing.
+        def make_advice(dictionary, what):
+            msg = "Package has%s %s: %s."
+            mmsg = "Package doesn't have%s %s: %s."
+
+            advice = []
+            missing = self.get_not_used(dictionary.keys())
+            importance = {30: ' critical', 20: ' important', 10: ''}
+
+            for mem in dictionary.keys():
+                if mem in missing:
+                    advice.append(mmsg % (importance[dictionary[mem]], what, str(mem)))
+                else:
+                    advice.append(msg % (importance[dictionary[mem]], what, str(mem)))
+            return "\n".join(advice) + "\n"
+
+        # compute required files
         files_count, files_value = self._compute_from_rules(files_list, package_dir, self.cheese_files)
+        self.advice = make_advice(self.cheese_files, 'file')
+
+        # compute required directories
         dirs_count, dirs_value = self._compute_from_rules(dirs_list, package_dir, self.cheese_dirs)
+        self.advice += make_advice(self.cheese_dirs, 'directory')
 
         self.value = files_value + dirs_value
 
         self.details = "%d files and %d required directories found" % \
                        (files_count, dirs_count)
 
-        # Inform user of files and directories the package is missing.
-        def make_advices(dictionary, what):
-            missing = self.get_not_used(dictionary.keys())
-            importance = {30: ' critical', 20: ' important', 10: ''}
-            return ''.join(map(lambda miss: "Package don't have%s %s: %s.\n" % \
-                                 (importance[dictionary[miss]], what, str(miss)),
-                                 missing))
-
-        self.advices = make_advices(self.cheese_files, 'file') +\
-                       make_advices(self.cheese_dirs, 'directory')
-
         return self.value
 
 class IndexDocstrings(Index):
@@ -1534,10 +1546,6 @@
                    max_cheesecake_index,
                    percentage)
 
-            if self.verbose:
-                print
-                print self.index.get_advices(),
-
         return cheesecake_index
 
 ################################################################################


More information about the cheesecake-users mailing list