##// END OF EJS Templates
ui: represent paths as classes...
Gregory Szorc -
r24250:9c32eea2 default
parent child Browse files
Show More
@@ -531,10 +531,14 b' class ui(object):'
531 if util.hasscheme(loc) or os.path.isdir(os.path.join(loc, '.hg')):
531 if util.hasscheme(loc) or os.path.isdir(os.path.join(loc, '.hg')):
532 return loc
532 return loc
533
533
534 path = self.config('paths', loc)
534 p = self.paths.getpath(loc, default=default)
535 if not path and default is not None:
535 if p:
536 path = self.config('paths', default)
536 return p.loc
537 return path or loc
537 return loc
538
539 @util.propertycache
540 def paths(self):
541 return paths(self)
538
542
539 def pushbuffer(self, error=False):
543 def pushbuffer(self, error=False):
540 """install a buffer to capture standard output of the ui object
544 """install a buffer to capture standard output of the ui object
@@ -923,3 +927,48 b' class ui(object):'
923 ui.write(ui.label(s, 'label')).
927 ui.write(ui.label(s, 'label')).
924 '''
928 '''
925 return msg
929 return msg
930
931 class paths(dict):
932 """Represents a collection of paths and their configs.
933
934 Data is initially derived from ui instances and the config files they have
935 loaded.
936 """
937 def __init__(self, ui):
938 dict.__init__(self)
939
940 for name, loc in ui.configitems('paths'):
941 # No location is the same as not existing.
942 if not loc:
943 continue
944 self[name] = path(name, rawloc=loc)
945
946 def getpath(self, name, default=None):
947 """Return a ``path`` for the specified name, falling back to a default.
948
949 Returns the first of ``name`` or ``default`` that is present, or None
950 if neither is present.
951 """
952 try:
953 return self[name]
954 except KeyError:
955 if default is not None:
956 try:
957 return self[default]
958 except KeyError:
959 pass
960
961 return None
962
963 class path(object):
964 """Represents an individual path and its configuration."""
965
966 def __init__(self, name, rawloc=None):
967 """Construct a path from its config options.
968
969 ``name`` is the symbolic name of the path.
970 ``rawloc`` is the raw location, as defined in the config.
971 """
972 self.name = name
973 # We'll do more intelligent things with rawloc in the future.
974 self.loc = rawloc
General Comments 0
You need to be logged in to leave comments. Login now