def __init__(self, repo, name=None): if isinstance(repo, str): u = ui.ui() u.setconfig('ui', 'report_untrusted', 'off') u.setconfig('ui', 'interactive', 'off') self.repo = hg.repository(u, repo) else: self.repo = repo hook.redirect(True) self.mtime = -1 self.reponame = name self.archives = 'zip', 'gz', 'bz2' self.stripecount = 1 # a repo owner may set web.templates in .hg/hgrc to get any file # readable by the user running the CGI script self.templatepath = self.config('web', 'templates')
def refresh(self): if self.lastrefresh + self.refreshinterval > time.time(): return if self.baseui: self.ui = self.baseui.copy() else: self.ui = ui.ui() self.ui.setconfig('ui', 'report_untrusted', 'off') self.ui.setconfig('ui', 'interactive', 'off') if not isinstance(self.conf, (dict, list, tuple)): map = {'paths': 'hgweb-paths'} self.ui.readconfig(self.conf, remap=map, trust=True) paths = self.ui.configitems('hgweb-paths') elif isinstance(self.conf, (list, tuple)): paths = self.conf elif isinstance(self.conf, dict): paths = self.conf.items() encoding.encoding = self.ui.config('web', 'encoding', encoding.encoding) self.motd = self.ui.config('web', 'motd') self.style = self.ui.config('web', 'style', 'paper') self.stripecount = self.ui.config('web', 'stripes', 1) if self.stripecount: self.stripecount = int(self.stripecount) self._baseurl = self.ui.config('web', 'baseurl') self.repos = findrepos(paths) for prefix, root in self.ui.configitems('collections'): prefix = util.pconvert(prefix) for path in util.walkrepos(root, followsym=True): repo = os.path.normpath(path) name = util.pconvert(repo) if name.startswith(prefix): name = name[len(prefix):] self.repos.append((name.lstrip('/'), repo)) self.repos.sort() self.lastrefresh = time.time()