def process_request(self, req): modname, attrname = str(req.args['name']).split(':') try: module = __import__(modname, {}, {}, filter(None, [attrname])) obj = getattr(module, attrname) except (ImportError, AttributeError), e: raise HTTPNotFound(e)
def process_request(self,req): options = get_options(self.config) build_type_match = re.match('/builds/history/(bt\d+)?$',req.path_info) if build_type_match is None: query_string = "&".join(['buildTypeId=%s' % id for id in options['builds']]) else: build_type_id = build_type_match.groups()[0] query_string = 'buildTypeId=%s' % build_type_id add_stylesheet(req, 'teamcity/css/teamcity.css') query_string += '&sinceDate=-%d' % options['limit'] feed_url = "%s/feed.html?%s" % (options['base_url'], query_string) tc = TeamCityQuery(self.options) feed = TeamCityQuery.xml_query(feed_url) if feed is None: raise HTTPNotFound("Can't load feed") data = {'entries': []} for entry in feed.iterfind('{http://www.w3.org/2005/Atom}entry'): title = entry.find('{http://www.w3.org/2005/Atom}title').text link = entry.find('{http://www.w3.org/2005/Atom}link').attrib['href'] date = entry.find('{http://www.w3.org/2005/Atom}published').text date = datetime.strptime(date, '%Y-%m-%dT%H:%M:%SZ') summary = entry.find('{http://www.w3.org/2005/Atom}summary').text summary = summary.split('<a href')[0] build_id_match = re.search('buildId=(\d+)', link) if build_id_match: summary += "<br/><a href='%s'>Build Log</a>" % \ req.href.builds('download', build_id_match.groups()[0]) data['entries'].append({ 'title': title, 'link': link, 'date': date, 'summary': summary, }) return 'teamcity_status.html', data, None
def _render_view(self, req, db, page): page_name = self._set_title(req, page, '') if page.name == 'WikiStart': req.hdf['title'] = '' version = req.args.get('version') if version: # Ask web spiders to not index old versions req.hdf['html.norobots'] = 1 # Add registered converters for conversion in Mimeview( self.env).get_supported_conversions('text/x-trac-wiki'): conversion_href = req.href.wiki(page.name, version=version, format=conversion[0]) add_link(req, 'alternate', conversion_href, conversion[1], conversion[3]) latest_page = WikiPage(self.env, page.name) req.hdf['wiki'] = { 'exists': page.exists, 'version': page.version, 'latest_version': latest_page.version, 'readonly': page.readonly } if page.exists: req.hdf['wiki'] = { 'page_html': wiki_to_html(page.text, self.env, req), 'history_href': req.href.wiki(page.name, action='history'), 'last_change_href': req.href.wiki(page.name, action='diff', version=page.version) } if version: req.hdf['wiki'] = { 'comment_html': wiki_to_oneliner(page.comment or '--', self.env, db), 'author': page.author, 'age': pretty_timedelta(page.time) } else: if not req.perm.has_permission('WIKI_CREATE'): raise HTTPNotFound('Page %s not found', page.name) req.hdf['wiki.page_html'] = html.P('Describe "%s" here' % page_name) # Show attachments req.hdf['wiki.attachments'] = attachments_to_hdf( self.env, req, db, 'wiki', page.name) if req.perm.has_permission('WIKI_MODIFY'): attach_href = req.href.attachment('wiki', page.name) req.hdf['wiki.attach_href'] = attach_href
def process_request(self,req): try: path = req.path_info.split('/builds/proxy/')[1] except IndexError: # no trailing slash ex. raise HTTPNotFound("Invalid proxy url, no trailing slash") t_url = "%s/httpAuth/%s?%s" % (self.options['base_url'], path,req.environ['QUERY_STRING']) tc = TeamCityQuery(self.options) try: response = tc.http_query(t_url) except TeamCityError, e: raise HTTPBadGateway('An error occured during proxy request to %s: %s' % (t_url, e))
def process_request(self, req): header = req.get_header('X-Requested-With') if not header or header.lower() != 'xmlhttprequest': # Not an XHR request from the debugger, so send a help page add_stylesheet(req, 'common/css/code.css') return 'developer/debug_help.html', {}, None path = req.args['path'] token = req.args['token'] assert path is not None and token is not None key = token + ':' + path.split(':', 1)[0] data = self._cache.get(key) if not data: raise HTTPNotFound("Not found '%s'" % path) node = data.lookup(path) data = {'node': node, 'drillable': self._is_drillable(req)} return 'developer/debug_node.html', data, None
def process_request(self, req): panel_id = req.args['panel_id'] panels = [] chosen_provider = None for provider in self.panel_providers: for name, label in provider.get_preference_panels(req) or []: if name == panel_id or None: chosen_provider = provider panels.append((name, label)) if not chosen_provider: self.log.warn('Unknown preference panel %r', panel_id) raise HTTPNotFound(_('Unknown preference panel')) template, data = chosen_provider.render_preference_panel(req, panel_id) data.update({'active_panel': panel_id, 'panels': panels}) add_stylesheet(req, 'common/css/prefs.css') return template, data, None
def process_request(self, req): xhr = req.get_header('X-Requested-With') == 'XMLHttpRequest' if xhr and req.method == 'POST' and 'save_prefs' in req.args: self._do_save_xhr(req) panel_id = req.args['panel_id'] panels = [] chosen_provider = None for provider in self.panel_providers: for name, label in provider.get_preference_panels(req) or []: if name == panel_id or None: chosen_provider = provider panels.append((name, label)) if not chosen_provider: self.log.warn('Unknown preference panel %r', panel_id) raise HTTPNotFound(_('Unknown preference panel')) template, data = chosen_provider.render_preference_panel(req, panel_id) data.update({'active_panel': panel_id, 'panels': panels}) add_stylesheet(req, 'common/css/prefs.css') return template, data, None
def process_request(self, req): panels, providers = self._get_panels(req) if not panels: raise HTTPNotFound(_('No administration panels available')) def _panel_order(p1, p2): if p1[::2] == ('general', 'basics'): return -1 elif p2[::2] == ('general', 'basics'): return 1 elif p1[0] == 'general': if p2[0] == 'general': return cmp(p1[1:], p2[1:]) return -1 elif p2[0] == 'general': if p1[0] == 'general': return cmp(p1[1:], p2[1:]) return 1 return cmp(p1, p2) panels.sort(_panel_order) cat_id = req.args.get('cat_id') or panels[0][0] panel_id = req.args.get('panel_id') path_info = req.args.get('path_info') if not panel_id: try: panel_id = filter(lambda panel: panel[0] == cat_id, panels)[0][2] except IndexError: raise HTTPNotFound(_('Unknown administration panel')) provider = providers.get((cat_id, panel_id), None) if not provider: raise HTTPNotFound(_('Unknown administration panel')) if hasattr(provider, 'render_admin_panel'): template, data = provider.render_admin_panel( req, cat_id, panel_id, path_info) else: # support for legacy WebAdmin panels data = {} cstmpl, ct = provider.process_admin_request( req, cat_id, panel_id, path_info) output = cstmpl.render() title = _("Untitled") for panel in panels: if (panel[0], panel[2]) == (cat_id, panel_id): title = panel[3] data.update({'page_title': title, 'page_body': HTML(output)}) template = 'admin_legacy.html' data.update({ 'active_cat': cat_id, 'active_panel': panel_id, 'panel_href': partial(req.href, 'admin', cat_id, panel_id), 'panels': [{ 'category': { 'id': panel[0], 'label': panel[1] }, 'panel': { 'id': panel[2], 'label': panel[3] } } for panel in panels] }) add_stylesheet(req, 'common/css/admin.css') return template, data, None
def process_request(self, req): req.perm.require('BUILD_VIEW') db = self.env.get_db_cnx() build_id = int(req.args.get('id')) build = Build.fetch(self.env, build_id, db=db) if not build: raise HTTPNotFound("Build '%s' does not exist." \ % build_id) if req.method == 'POST': if req.args.get('action') == 'invalidate': self._do_invalidate(req, build, db) req.redirect(req.href.build(build.config, build.id)) add_link(req, 'up', req.href.build(build.config), 'Build Configuration') data = { 'title': 'Build %s - %s' % (build_id, _status_title[build.status]), 'page_mode': 'view_build', 'build': {} } config = BuildConfig.fetch(self.env, build.config, db=db) data['build']['config'] = { 'name': config.label or config.name, 'href': req.href.build(config.name) } context = Context.from_request(req, build.resource) data['context'] = context data['build']['attachments'] = AttachmentModule( self.env).attachment_data(context) formatters = [] for formatter in self.log_formatters: formatters.append(formatter.get_formatter(req, build)) summarizers = {} # keyed by report type for summarizer in self.report_summarizers: categories = summarizer.get_supported_categories() summarizers.update(dict([(cat, summarizer) for cat in categories])) data['build'].update(_get_build_data(self.env, req, build)) steps = [] for step in BuildStep.select(self.env, build=build.id, db=db): steps.append({ 'name': step.name, 'description': step.description, 'duration': pretty_timedelta(step.started, step.stopped), 'failed': step.status == BuildStep.FAILURE, 'errors': step.errors, 'log': self._render_log(req, build, formatters, step), 'reports': self._render_reports(req, config, build, summarizers, step) }) data['build']['steps'] = steps data['build']['can_delete'] = ('BUILD_DELETE' in req.perm \ and build.status != build.PENDING) repos = self.env.get_repository(req.authname) repos.authz.assert_permission(config.branch) chgset = repos.get_changeset(build.rev) data['build']['chgset_author'] = chgset.author add_script(req, 'common/js/folding.js') add_script(req, 'bitten/tabset.js') add_stylesheet(req, 'bitten/bitten.css') return 'bitten_build.html', data, None
def _render_config(self, req, config_name): db = self.env.get_db_cnx() config = BuildConfig.fetch(self.env, config_name, db=db) if not config: raise HTTPNotFound("Build configuration '%s' does not exist." \ % config_name) repos = self.env.get_repository(req.authname) repos.authz.assert_permission(config.branch) data = {'title': 'Build Configuration "%s"' \ % config.label or config.name, 'page_mode': 'view_config'} add_link(req, 'up', req.href.build(), 'Build Status') description = config.description if description: description = wiki_to_html(description, self.env, req) pending_builds = list( Build.select(self.env, config=config.name, status=Build.PENDING)) inprogress_builds = list( Build.select(self.env, config=config.name, status=Build.IN_PROGRESS)) rev = '' for b in repos.git.get_branches(): if b[0] == config.branch: rev = b[1] break data['config'] = { 'name': config.name, 'label': config.label, 'branch': config.branch, 'active': config.active, 'description': description, 'browser_href': req.href.browser(rev=rev), 'builds_pending': len(pending_builds), 'builds_inprogress': len(inprogress_builds) } context = Context.from_request(req, config.resource) data['context'] = context data['config']['attachments'] = AttachmentModule( self.env).attachment_data(context) platforms = list( TargetPlatform.select(self.env, config=config_name, db=db)) data['config']['platforms'] = [{ 'name': platform.name, 'id': platform.id, 'builds_pending': len( list( Build.select(self.env, config=config.name, status=Build.PENDING, platform=platform.id))), 'builds_inprogress': len( list( Build.select(self.env, config=config.name, status=Build.IN_PROGRESS, platform=platform.id))) } for platform in platforms] has_reports = False for report in Report.select(self.env, config=config.name, db=db): has_reports = True break if has_reports: chart_generators = [] for generator in ReportChartController(self.env).generators: for category in generator.get_supported_categories(): chart_generators.append({ 'href': req.href.build(config.name, 'chart/' + category) }) data['config']['charts'] = chart_generators charts_license = self.config.get('bitten', 'charts_license') if charts_license: data['config']['charts_license'] = charts_license page = max(1, int(req.args.get('page', 1))) more = False data['page_number'] = page repos = self.env.get_repository(req.authname) builds_per_page = 12 * len(platforms) idx = 0 builds = {} for platform, rev, build in collect_changes(repos, config): if idx >= page * builds_per_page: more = True break elif idx >= (page - 1) * builds_per_page: builds.setdefault(rev, {}) builds[rev].setdefault('href', req.href.changeset(rev)) if build and build.status != Build.PENDING: build_data = _get_build_data(self.env, req, build) build_data['steps'] = [] for step in BuildStep.select(self.env, build=build.id, db=db): build_data['steps'].append({ 'name': step.name, 'description': step.description, 'duration': to_datetime(step.stopped, utc) - \ to_datetime(step.started, utc), 'failed': not step.successful, 'errors': step.errors, 'href': build_data['href'] + '#step_' + step.name }) builds[rev][platform.id] = build_data idx += 1 data['config']['builds'] = builds if page > 1: if page == 2: prev_href = req.href.build(config.name) else: prev_href = req.href.build(config.name, page=page - 1) add_link(req, 'prev', prev_href, 'Previous Page') if more: next_href = req.href.build(config.name, page=page + 1) add_link(req, 'next', next_href, 'Next Page') prevnext_nav(req, 'Page') return data
def _render_config(self, req, config_name): db = self.env.get_db_cnx() config = BuildConfig.fetch(self.env, config_name, db=db) if not config: raise HTTPNotFound("Build configuration '%s' does not exist." \ % config_name) repos = self.env.get_repository(authname=req.authname) assert repos, 'No "(default)" Repository: Add a repository or alias ' \ 'named "(default)" to Trac.' rev = config.max_rev or repos.youngest_rev try: _has_permission(req.perm, repos, config.path, rev=rev, raise_error=True) except NoSuchNode: raise TracError("Permission checking against repository path %s " "at revision %s failed." % (config.path, rev)) data = {'title': 'Build Configuration "%s"' \ % config.label or config.name, 'page_mode': 'view_config'} add_link(req, 'up', req.href.build(), 'Build Status') description = config.description if description: description = wiki_to_html(description, self.env, req) pending_builds = list( Build.select(self.env, config=config.name, status=Build.PENDING)) inprogress_builds = list( Build.select(self.env, config=config.name, status=Build.IN_PROGRESS)) data['config'] = { 'name': config.name, 'label': config.label, 'path': config.path, 'min_rev': config.min_rev, 'min_rev_href': req.href.changeset(config.min_rev), 'max_rev': config.max_rev, 'max_rev_href': req.href.changeset(config.max_rev), 'active': config.active, 'description': description, 'browser_href': req.href.browser(config.path), 'builds_pending': len(pending_builds), 'builds_inprogress': len(inprogress_builds) } context = Context.from_request(req, config.resource) data['context'] = context data['config']['attachments'] = AttachmentModule( self.env).attachment_data(context) platforms = list( TargetPlatform.select(self.env, config=config_name, db=db)) data['config']['platforms'] = [{ 'name': platform.name, 'id': platform.id, 'builds_pending': len( list( Build.select(self.env, config=config.name, status=Build.PENDING, platform=platform.id))), 'builds_inprogress': len( list( Build.select(self.env, config=config.name, status=Build.IN_PROGRESS, platform=platform.id))) } for platform in platforms] has_reports = False for report in Report.select(self.env, config=config.name, db=db): has_reports = True break if has_reports: chart_generators = [] report_categories = list( self._report_categories_for_config(config)) for generator in ReportChartController(self.env).generators: for category in generator.get_supported_categories(): if category in report_categories: chart_generators.append({ 'href': req.href.build(config.name, 'chart/' + category), 'category': category, 'style': self.config.get('bitten', 'chart_style'), }) data['config']['charts'] = chart_generators page = max(1, int(req.args.get('page', 1))) more = False data['page_number'] = page repos = self.env.get_repository(authname=req.authname) assert repos, 'No "(default)" Repository: Add a repository or alias ' \ 'named "(default)" to Trac.' builds_per_page = 12 * len(platforms) idx = 0 builds = {} revisions = [] for platform, rev, build in collect_changes(repos, config): if idx >= page * builds_per_page: more = True break elif idx >= (page - 1) * builds_per_page: if rev not in builds: revisions.append(rev) builds.setdefault(rev, {}) builds[rev].setdefault('href', req.href.changeset(rev)) builds[rev].setdefault('display_rev', repos.normalize_rev(rev)) if build and build.status != Build.PENDING: build_data = _get_build_data(self.env, req, build) build_data['steps'] = [] for step in BuildStep.select(self.env, build=build.id, db=db): build_data['steps'].append({ 'name': step.name, 'description': step.description, 'duration': to_datetime(step.stopped or int(time.time()), utc) - \ to_datetime(step.started, utc), 'status': _step_status_label[step.status], 'cls': _step_status_label[step.status].replace(' ', '-'), 'errors': step.errors, 'href': build_data['href'] + '#step_' + step.name }) builds[rev][platform.id] = build_data idx += 1 data['config']['builds'] = builds data['config']['revisions'] = revisions if page > 1: if page == 2: prev_href = req.href.build(config.name) else: prev_href = req.href.build(config.name, page=page - 1) add_link(req, 'prev', prev_href, 'Previous Page') if more: next_href = req.href.build(config.name, page=page + 1) add_link(req, 'next', next_href, 'Next Page') if arity(prevnext_nav) == 4: # Trac 0.12 compat, see #450 prevnext_nav(req, 'Previous Page', 'Next Page') else: prevnext_nav(req, 'Page') return data
def process_request(self, req): if req.path_info + '/' == '/user/': qs = '' else: [qs] = req.path_info.split('/user/', 1)[1:] qs = [item for item in qs.split('/') if len(item) > 0] content = u"" if len(qs) == 0: content += u"= User Whitepages List =\n[[BR]]\n" r = self._ldap.search_s(self._user_rdn, ldap.SCOPE_ONELEVEL, "objectclass=posixAccount", ['uid', 'sn', 'givenName']) r = [(data['uid'][0], data['sn'][0], data['givenName'][0]) for dn, data in r] r.sort() content += u"|| `uid` || '''given name''' || '''surname''' ||\n" for uid, sn, gn in r: content += u"|| %s || %s || %s ||\n" % (uid, gn, sn) req.hdf['wp.text'] = wiki_to_html(content, self.env, req) req.hdf['title'] = u'Whitepages List' return 'wp.cs', 'text/html' elif len(qs) == 1: uid = qs[0] data = self.get_info(uid) if not data: raise HTTPNotFound("uid %s not found" % uid) content += (u'= Whitepages Entry for %s =\n' % uid) content += u'''{{{ #!html <table style="border: none; padding: 15px; margin: 0px"> <tr><td style="vertical-align: top"> }}} ''' if True or ('jpegPhoto' in data): content += (u'[[FaceImg(%s)]]\n' % uid) content += u'''{{{ #!html </td><td style="vertical-align: top; width: 40px;"> </td><td style="vertical-align: top"> }}} ''' content += (u'== %s, %s ==\n' % (data['sn'][0], data['givenName'][0])) content += (u" '''Username''':: %s[[BR]]\n" % uid) if 'mail' in data: content += (u" '''Email''':: [mailto:%s %s][[BR]]\n" % (data['mail'][0], data['mail'][0])) if 'telephoneNumber' in data: content += (u" '''Phone''':: %s[[BR]]\n" % data['telephoneNumber'][0]) if 'birthDate' in data: birthDate = data['birthDate'][0] bday = datetime.date( *time.strptime(birthDate, "%Y-%m-%d")[0:3]) tday = datetime.date.today() age = tday.year - bday.year ofs = (tday - datetime.date(tday.year, bday.month, bday.day)).days if ofs < 0: days = (datetime.date(tday.year, bday.month, bday.day) - datetime.date(tday.year - 1, bday.month, bday.day)).days else: days = ( datetime.date(tday.year + 1, bday.month, bday.day) - datetime.date(tday.year, bday.month, bday.day)).days age = float(age) + (float(ofs) / float(days)) content += (u" '''Age''':: %.2f years[[BR]]\n" % age) content += (u" '''Birthdate''':: %s[[BR]]\n" % birthDate) content += u'''{{{ #!html </td></tr> </table> }}} ''' req.hdf['wp.text'] = wiki_to_html(content, self.env, req) req.hdf['title'] = (u'Whitepages Entry for %s' % uid) return 'wp.cs', 'text/html' elif len(qs) == 2: uid = qs[0] if qs[1] == 'jpegPhoto': jpegPhoto = self.get_jpegPhoto(uid) if jpegPhoto: req.send_response(200) req.send_header('Content-Type', 'image/jpeg') req.send_header('Content-Length', len(jpegPhoto)) req.end_headers() if req.method != 'HEAD': req.write(jpegPhoto) raise RequestDone raise HTTPNotFound("File not found")