Changeset 1089

Show
Ignore:
Timestamp:
08/06/06 12:43:09 (2 years ago)
Author:
eblot
Message:

SvnCcHelpersScript:

Fix up cache management

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • svncchelpersscript/0.10/revtree/revtree/web_ui.py

    r1083 r1089  
    221221        # Cache directory (reuses graphviz dir) 
    222222        self.cache_dir = self.config.get('graphviz', 'cache_dir') 
     223        self.prefix_url = self.config.get('graphviz', 'prefix_url') 
    223224        if not self.cache_dir or not os.path.exists(self.cache_dir): 
    224225            raise TracError, "cache directory is not valid" 
     226        if not self.prefix_url: 
     227            raise TracError, "prefix URL not defined" 
    225228        # Repository proxy 
    226229        if self.config.get('trac', 'repository_type') != 'svn': 
     
    286289        return periods 
    287290 
    288     def _get_cache_name(self, revtree): 
     291    def _get_cache_name(self, revtree, img_kind): 
    289292        """Generates a unique filename for the current revtree""" 
    290         id = "%d-%d-%s-%s-%d-%d" % (revtree.revrange[0], \ 
    291                                     revtree.revrange[1], \ 
    292                                     revtree['branch'] or ' ', \ 
    293                                     revtree['author'] or ' ', \ 
    294                                     revtree['btup'] != '0' and 1 or 0, \ 
    295                                     revtree['hideterm'] != '0' and 1 or 0) 
     293        id = "%s-%d-%d-%s-%s-%d-%d" % (img_kind, 
     294                                       revtree.revrange[0], \ 
     295                                       revtree.revrange[1], \ 
     296                                       revtree['branch'] or ' ', \ 
     297                                       revtree['author'] or ' ', \ 
     298                                       revtree['btup'] != '0' and 1 or 0, \ 
     299                                       revtree['hideterm'] != '0' and 1 or 0) 
    296300        sha_key  = sha.new(id).hexdigest() 
    297301        img_name = '%s.revtree' % (sha_key) 
     
    322326        """Renders revtree graph (tests cache status and generates a new image 
    323327           if not found)""" 
    324         cache_file = self._get_cache_name(revtree
     328        cache_file = self._get_cache_name(revtree, img_kind
    325329        create = True 
    326330        headers = ['revisions', 'branches', 'authors', 'image' ] 
     
    340344                content = '\n'.join(cache.readlines()) 
    341345                cache.close() 
    342                 image = os.path.join(self.cache_dir, "%s.%s.%s" % \ 
    343                                       (props['image'][0], self.image_engine, 
    344                                        img_kind)) 
     346                image = os.path.join(self.cache_dir, props['image'][0]) 
    345347                if os.path.exists(image): 
    346348                    create = False 
     
    363365            props['branches'] = branches 
    364366            props['authors'] = authors 
    365             image_re = re.compile('<object data="(.*?)"') 
    366             mo = image_re.search(content) 
    367             if mo: 
    368                 props['image'] = (mo.group(1), ) 
     367            if img_kind == 'svg': 
     368                image_re = re.compile(r'<object data="(.*?)\.'+  
     369                                      self.image_engine + r'\.svg"') 
     370                mo = image_re.search(content) 
     371                if mo: 
     372                    props['image'] = ("%s.%s.svg" % \ 
     373                                      (mo.group(1)[len(self.prefix_url)+1:], \ 
     374                                       self.image_engine), ) 
     375                else: 
     376                    self.env.log.warn('Unable to find image uid in graphviz ' \ 
     377                                      'content: %s...' % content[0:160]) 
     378                    props['image'] = None 
    369379            else: 
    370                 self.env.log.warn('Unable to find image uid in graphviz ' \ 
    371                                   'content: %s' % content) 
    372                 props['image'] = None 
     380                image_re = re.compile(r'<img\sid="(.*?)"') 
     381                image_suffix = 'png' 
     382                mo = image_re.search(content) 
     383                if mo: 
     384                    props['image'] = ("%s.%s.png" % \ 
     385                                      (mo.group(1), self.image_engine), ) 
     386                else: 
     387                    self.env.log.warn('Unable to find image uid in graphviz ' \ 
     388                                      'content: %s...' % content[0:160]) 
     389                    props['image'] = None 
    373390            try: 
    374391                cache = open(cache_file, 'w') 
     
    387404                raise TracError, \ 
    388405                      "Error rendering the rev tree (type: %s)" % header 
     406        else: 
     407            self.env.log.debug("Using cached file %s" % props['image'][0]) 
    389408        return (content, props) 
    390409