Changeset 100

Show
Ignore:
Timestamp:
07/21/06 17:30:39 (2 years ago)
Author:
mk
Message:

Use verbose to display notes for package being scored (like which files it is missing).

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/mk/cheesecake/cheesecake_index.py

    r99 r100  
    352352    value = -1 
    353353    details = "" 
     354    advices = "" 
    354355 
    355356    def __init__(self, *indices): 
     
    496497        return self._indices_dict[name] 
    497498 
     499    def get_advices(self): 
     500        if self.subindices: 
     501            return ''.join(map(lambda index: index.get_advices(), self.subindices)) 
     502        return self.advices 
     503 
    498504################################################################################ 
    499505## Index that computes scores based on files and directories. 
     
    504510        self.possibilities = possibilities 
    505511    def __str__(self): 
    506         return 'one of %s' % (self.possibilities,
     512        return '/'.join(map(lambda x: str(x), self.possibilities)
    507513 
    508514def WithOptionalExt(name, extensions): 
     
    552558 
    553559        return 0 
     560 
     561    def get_not_used(self, files_rules): 
     562        """Get only these of files_rules that didn't match during computation. 
     563 
     564        >>> rules = { 
     565        ...     Doc('readme'): 30, 
     566        ...     OneOf(Doc('license'), Doc('copying')): 30, 
     567        ...     'demo': 10, 
     568        ... } 
     569        >>> index = FilesIndex() 
     570        >>> index._used_rules.append('demo') 
     571        >>> map(lambda x: str(x), index.get_not_used(rules.keys())) 
     572        ['license/license.html/license.txt/copying/copying.html/copying.txt', 'readme/readme.html/readme.txt'] 
     573        """ 
     574        return filter(lambda rule: rule not in self._used_rules, 
     575                      files_rules) 
    554576 
    555577    def match_filename(self, name, rule): 
     
    769791                       (files_count, dirs_count) 
    770792 
     793        # Inform user of files and directories the package is missing. 
     794        def make_advices(dictionary, what): 
     795            missing = self.get_not_used(dictionary.keys()) 
     796            importance = {30: ' critical', 20: ' important', 10: ''} 
     797            return ''.join(map(lambda miss: "Package don't have%s %s: %s.\n" % \ 
     798                                 (importance[dictionary[miss]], what, str(miss)), 
     799                                 missing)) 
     800 
     801        self.advices = make_advices(self.cheese_files, 'file') +\ 
     802                       make_advices(self.cheese_dirs, 'directory') 
     803 
    771804        return self.value 
    772805 
     
    11861219        logger.setconsumer('null', None) 
    11871220 
    1188         if self.verbose: 
    1189             self.log = logger.MultipleProducer('cheesecake console') 
    1190         else: 
    1191             self.log = logger.MultipleProducer('cheesecake logfile') 
    1192  
     1221        self.log = logger.MultipleProducer('cheesecake logfile') 
    11931222        self.log.info = logger.MultipleProducer('cheesecake logfile') 
    11941223        self.log.debug = logger.MultipleProducer('cheesecake logfile') 
     
    15051534                   max_cheesecake_index, 
    15061535                   percentage) 
     1536 
     1537            if self.verbose: 
     1538                print 
     1539                print self.index.get_advices(), 
    15071540 
    15081541        return cheesecake_index