comparison mercurial/ui.py @ 3123:70e62df12704

Merge with mainline
author Benoit Boissinot <benoit.boissinot@ens-lyon.org>
date Mon, 18 Sep 2006 11:55:38 +0200
parents 09e8aecd8016
children 1b6d0fa84e0d
comparison
equal deleted inserted replaced
3094:8e8deb8035a4 3123:70e62df12704
16 self.overlay = {} 16 self.overlay = {}
17 if parentui is None: 17 if parentui is None:
18 # this is the parent of all ui children 18 # this is the parent of all ui children
19 self.parentui = None 19 self.parentui = None
20 self.readhooks = [] 20 self.readhooks = []
21 self.trusted_users = {}
22 self.trusted_groups = {}
23 self.cdata = ConfigParser.SafeConfigParser() 21 self.cdata = ConfigParser.SafeConfigParser()
24 self.readconfig(util.rcpath()) 22 self.readconfig(util.rcpath())
25 23
26 self.quiet = self.configbool("ui", "quiet") 24 self.quiet = self.configbool("ui", "quiet")
27 self.verbose = self.configbool("ui", "verbose") 25 self.verbose = self.configbool("ui", "verbose")
36 self.revlogopts = self.configrevlog() 34 self.revlogopts = self.configrevlog()
37 else: 35 else:
38 # parentui may point to an ui object which is already a child 36 # parentui may point to an ui object which is already a child
39 self.parentui = parentui.parentui or parentui 37 self.parentui = parentui.parentui or parentui
40 self.readhooks = parentui.readhooks[:] 38 self.readhooks = parentui.readhooks[:]
41 self.trusted_users = parentui.trusted_users.copy()
42 self.trusted_groups = parentui.trusted_groups.copy()
43 parent_cdata = self.parentui.cdata 39 parent_cdata = self.parentui.cdata
44 self.cdata = ConfigParser.SafeConfigParser(parent_cdata.defaults()) 40 self.cdata = ConfigParser.SafeConfigParser(parent_cdata.defaults())
45 # make interpolation work 41 # make interpolation work
46 for section in parent_cdata.sections(): 42 for section in parent_cdata.sections():
47 self.cdata.add_section(section) 43 self.cdata.add_section(section)
73 def readconfig(self, fn, root=None): 69 def readconfig(self, fn, root=None):
74 if isinstance(fn, basestring): 70 if isinstance(fn, basestring):
75 fn = [fn] 71 fn = [fn]
76 for f in fn: 72 for f in fn:
77 try: 73 try:
78 fp = open(f) 74 self.cdata.read(f)
79 except IOError:
80 continue
81 if ((self.trusted_users or self.trusted_groups) and
82 '*' not in self.trusted_users and
83 '*' not in self.trusted_groups):
84 st = util.fstat(fp)
85 user = util.username(st.st_uid)
86 group = util.groupname(st.st_gid)
87 if (user not in self.trusted_users and
88 group not in self.trusted_groups):
89 self.warn(_('not reading file %s from untrusted '
90 'user %s, group %s\n') % (f, user, group))
91 continue
92 try:
93 self.cdata.readfp(fp, f)
94 except ConfigParser.ParsingError, inst: 75 except ConfigParser.ParsingError, inst:
95 raise util.Abort(_("Failed to parse %s\n%s") % (f, inst)) 76 raise util.Abort(_("Failed to parse %s\n%s") % (f, inst))
96 # translate paths relative to root (or home) into absolute paths 77 # translate paths relative to root (or home) into absolute paths
97 if root is None: 78 if root is None:
98 root = os.path.expanduser('~') 79 root = os.path.expanduser('~')
99 for name, path in self.configitems("paths"): 80 for name, path in self.configitems("paths"):
100 if path and "://" not in path and not os.path.isabs(path): 81 if path and "://" not in path and not os.path.isabs(path):
101 self.cdata.set("paths", name, os.path.join(root, path)) 82 self.cdata.set("paths", name, os.path.join(root, path))
102 user = util.username()
103 if user is not None:
104 self.trusted_users[user] = 1
105 for user in self.configlist('trusted', 'users'):
106 self.trusted_users[user] = 1
107 for group in self.configlist('trusted', 'groups'):
108 self.trusted_groups[group] = 1
109 for hook in self.readhooks: 83 for hook in self.readhooks:
110 hook(self) 84 hook(self)
111 85
112 def addreadhook(self, hook): 86 def addreadhook(self, hook):
113 self.readhooks.append(hook) 87 self.readhooks.append(hook)