Mercurial > public > mercurial-scm > hg
comparison mercurial/templater.py @ 22634:e48a5d3996c2
templater: introduce templatepaths for getting paths searched for templates
Avoid function with different return types depending on parameters.
author | Mads Kiilerich <madski@unity3d.com> |
---|---|
date | Sun, 28 Sep 2014 16:57:37 +0200 |
parents | 92b54547ac5d |
children | 660861a6fad4 |
comparison
equal
deleted
inserted
replaced
22633:92b54547ac5d | 22634:e48a5d3996c2 |
---|---|
623 return _flatten(runtemplate(self, mapping, self._load(t))) | 623 return _flatten(runtemplate(self, mapping, self._load(t))) |
624 | 624 |
625 engines = {'default': engine} | 625 engines = {'default': engine} |
626 | 626 |
627 def stylelist(): | 627 def stylelist(): |
628 paths = templatepath() | 628 paths = templatepaths() |
629 if not paths: | 629 if not paths: |
630 return _('no templates found, try `hg debuginstall` for more info') | 630 return _('no templates found, try `hg debuginstall` for more info') |
631 dirlist = os.listdir(paths[0]) | 631 dirlist = os.listdir(paths[0]) |
632 stylelist = [] | 632 stylelist = [] |
633 for file in dirlist: | 633 for file in dirlist: |
708 if self.minchunk: | 708 if self.minchunk: |
709 stream = util.increasingchunks(stream, min=self.minchunk, | 709 stream = util.increasingchunks(stream, min=self.minchunk, |
710 max=self.maxchunk) | 710 max=self.maxchunk) |
711 return stream | 711 return stream |
712 | 712 |
713 def templatepath(name=None): | 713 def templatepaths(): |
714 '''return location of template file or directory (if no name). | 714 '''return locations used for template files.''' |
715 returns None if not found.''' | |
716 normpaths = [] | 715 normpaths = [] |
717 | |
718 for f in path: | 716 for f in path: |
719 if f.startswith('/'): | 717 if f.startswith('/'): |
720 p = f | 718 p = f |
721 else: | 719 else: |
722 fl = f.split('/') | 720 fl = f.split('/') |
723 p = os.path.join(util.datapath, *fl) | 721 p = os.path.join(util.datapath, *fl) |
724 if name: | 722 if os.path.isdir(p): |
725 p = os.path.join(p, name) | |
726 if name and os.path.exists(p): | |
727 return os.path.normpath(p) | |
728 elif os.path.isdir(p): | |
729 normpaths.append(os.path.normpath(p)) | 723 normpaths.append(os.path.normpath(p)) |
730 | |
731 return normpaths | 724 return normpaths |
725 | |
726 def templatepath(name): | |
727 '''return location of template file. returns None if not found.''' | |
728 for p in templatepaths(): | |
729 f = os.path.join(p, name) | |
730 if os.path.exists(f): | |
731 return f | |
732 return None | |
732 | 733 |
733 def stylemap(styles, paths=None): | 734 def stylemap(styles, paths=None): |
734 """Return path to mapfile for a given style. | 735 """Return path to mapfile for a given style. |
735 | 736 |
736 Searches mapfile in the following locations: | 737 Searches mapfile in the following locations: |
738 2. templatepath/map-style | 739 2. templatepath/map-style |
739 3. templatepath/map | 740 3. templatepath/map |
740 """ | 741 """ |
741 | 742 |
742 if paths is None: | 743 if paths is None: |
743 paths = templatepath() | 744 paths = templatepaths() |
744 elif isinstance(paths, str): | 745 elif isinstance(paths, str): |
745 paths = [paths] | 746 paths = [paths] |
746 | 747 |
747 if isinstance(styles, str): | 748 if isinstance(styles, str): |
748 styles = [styles] | 749 styles = [styles] |