def _render_editor(self, req, db, id, copy=False): if id == -1: req.perm.assert_permission('REPORT_CREATE') title = sql = description = '' else: req.perm.assert_permission('REPORT_MODIFY') cursor = db.cursor() cursor.execute("SELECT title,description,sql FROM report " "WHERE id=%s", (id,)) row = cursor.fetchone() if not row: raise util.TracError('Report %s does not exist.' % id, 'Invalid Report Number') title = row[0] or '' description = row[1] or '' sql = row[2] or '' if copy: title += ' (copy)' if copy or id == -1: req.hdf['title'] = 'Create New Report' req.hdf['report.href'] = self.env.href.report() req.hdf['report.action'] = 'new' else: req.hdf['title'] = 'Edit Report {%d} %s' % (id, title) req.hdf['report.href'] = self.env.href.report(id) req.hdf['report.action'] = 'edit' req.hdf['report.id'] = id req.hdf['report.mode'] = 'edit' req.hdf['report.title'] = util.escape(title) req.hdf['report.sql'] = util.escape(sql) req.hdf['report.description'] = util.escape(description)
def process_request(self, req): # This method is based on _render_view() in ReportModule # --- BugReporter commands --- if re.compile ("^/autotrac/ping/?$").match (req.path_info, 0): self.reply_to_ping(req) elif re.compile ("^/autotrac/newreport/?$").match(req.path_info,0)\ and req.method == "POST": self.bug_reporters_post(req) # --- User commands --- elif re.compile (r'^/autotrac/?$').match (req.path_info): db = self.env.get_db_cnx() id = 1 resp = self.display_report_page (req, db, id) add_stylesheet (req, 'common/css/report.css') return 'autotracreport.cs', None elif re.compile (r'/autotrac/ticket(/[1-9][0-9]*)').match (req.path_info): ticketId = re.sub (".*ticket/", "", req.path_info) return self.display_ticket_page (req, int(ticketId)) # -- Redirect an unspecified ticket to view report -- elif re.match (r"/autotrac/ticket/?$", req.path_info): req.redirect(self.env.href.autotrac()) else: raise util.TracError('No handler matched request to %s' % req.path_info)
def repl(match): aname = match.group()[1:] try: arg = args[aname] except KeyError: raise util.TracError("Dynamic variable '$%s' not defined." % aname) req.hdf['report.var.' + aname] = arg return arg
def _do_trac_req(self): if self.path == '/': path_info = '/' req = TracHTTPRequest(self, '', '') self.server.send_project_index(req) return m = self.url_re.findall(self.path) if not m: self.send_error(400, 'Bad Request') return project_name, path_info, query_string = m[0] project_name = urllib.unquote(project_name) path_info = urllib.unquote(path_info) req = TracHTTPRequest(self, project_name, query_string) try: opts = self.server.get_env_opts(project_name) except KeyError: # unrecognized project self.server.send_project_index(req) return env = get_environment(req, opts) if not env: self.server.send_project_index(req) return req.remote_user = None if path_info == '/login': auth = self.server.auths.get(project_name) if not auth: raise util.TracError('Authentication not enabled. ' 'Please use the tracd --auth option.\n') req.remote_user = auth.do_auth(self) if not req.remote_user: return try: start = time.time() dispatch_request(path_info, req, env) env.log.debug('Total request time: %f s', time.time() - start) except socket.error, (code, msg): if code == errno.EPIPE or code == 10053: # Windows env.log.info('Lost connection to client: %s' % self.address_string()) else: raise
def _render_confirm_delete(self, req, db, id): req.perm.assert_permission('REPORT_DELETE') cursor = db.cursor() cursor.execute("SELECT title FROM report WHERE id = %s", (id,)) row = cursor.fetchone() if not row: raise util.TracError('Report %s does not exist.' % id, 'Invalid Report Number') req.hdf['title'] = 'Delete Report {%s} %s' % (id, row[0]) req.hdf['report'] = { 'id': id, 'mode': 'delete', 'title': util.escape(row[0]), 'href': self.env.href.report(id) }
def execute_report(self, req, db, id, sql, args): sql = self.sql_sub_vars(req, sql, args) if not sql: raise util.TracError('Report %s has no SQL query.' % id) if sql.find('__group__') == -1: req.hdf['report.sorting.enabled'] = 1 cursor = db.cursor() cursor.execute(sql) # FIXME: fetchall should probably not be used. info = cursor.fetchall() or [] cols = cursor.description or [] db.rollback() return cols, info
def get_info(self, db, id, args): if id == -1: # If no particular report was requested, display # a list of available reports instead title = 'Available Reports' sql = 'SELECT id AS report, title FROM report ORDER BY report' description = 'This is a list of reports available.' else: cursor = db.cursor() cursor.execute("SELECT title,sql,description from report " "WHERE id=%s", (id,)) row = cursor.fetchone() if not row: raise util.TracError('Report %d does not exist.' % id, 'Invalid Report Number') title = row[0] or '' sql = row[1] description = row[2] or '' return [title, description, sql]
def execute(hdf, args, env): # Args seperated by commas: # url, formatter # # url is the url to go get. # Formatter is which formatter if any to parse. Default: None _href = env.abs_href or env.href formatter = None url = None regex = None argstring = '' match_seperator = ' ' dotall = '' db = env.get_db_cnx() cursor = db.cursor() cs = db.cursor() buf = StringIO() currentpage = hdf.getValue('wiki.page_name', '') + '/' if args: # Get regex's - last argument try: regex = re.search('^(?:.+?,)+?(\'.*)', args).group(1) except: regex = '' argstring = argstring.join( [',', args, ',']) #Add trailing and tailing comma for easy matching args = args.replace('\'', '\'\'') #Split args args = args.split(',') if regex != '': regex = regex.split('\',\'') #Get URL if args[0] != 'None': url = args[0] #Get formatter if args[1] != 'None': formatter = args[1] if url[:5] == 'trunk': # we need to get the file from the svn repo. #http://financial.trac.yumaed.org/trac.cgi/file/trunk/needs_document/Employee/employee_file.txt?format=raw url = 'http://' + os.getenv( 'HTTP_HOST') + env.href.base + '/file/' + url + '?format=raw' if (url[:7] != 'http://') and (url[:5] != 'wiki:'): #We are getting local file url = '/tmp/trac_include/' + url.replace('/', '_') #url = 'http://' + os.getenv('HTTP_HOST') + env.href.base + '/file/' + url + '?format=raw' authname = hdf.getValue("trac.authname", "anonymous") # control options #------------------------ #If arg no_dotall is set, disable DOTALL usage try: argstring.index(',no_dotall,') except: re.DOTALL #Aparantly this doesnt always work.. dotall = '(?s)' # So we use this regex equivilant #buf.write('DOTALL') #Should we only include pages for authenticated users? try: argstring.index(',no_anon,') if authname == "anonymous": return buf.getvalue() except: 1 #Sorry.. Dont know python at all, and this was the only way i could solve that except: requires at least 1 line #Should we only include pages for authenticated users? if re.search(',match_seperator(?:=[^,]+)?,', argstring): match_seperator = re.search(',match_seperator(?:=([^,]+))?,', argstring).group(1) #Or allow the match seperator to be in quotes if re.search(',match_seperator="[^"]+?"?,', argstring): match_seperator = re.search(',match_seperator="([^"]+?)"?,', argstring).group(1) #Should we replace $USER with logged-in username, in URL? if re.search(',use_vars(?:=\w+)?,', argstring): sub_arg = re.search(',use_vars(?:=(\w+))?,', argstring).group(1) if sub_arg == 'lower': authname = authname.lower() if sub_arg == 'upper': authname = authname.upper() if sub_arg == 'ucfirst': authname = authname.capitalize() url = url.replace('$USER', authname) #----------------------------- #Fetch the included page if url[:5] == 'wiki:': #Wiki url url = url[5:] sql = "SELECT text from wiki where name = '%s' order by version desc limit 1" % url cs = db.cursor() cs.execute(sql) row = cs.fetchone() if row == None: return '' txt = row[0] else: # Normal URL try: f = urllib.urlopen(url) except: raise util.TracError( 'The "%s" argument doesnt seem to be a valid link' % (url)) txt = f.read() #Do the regex replacements for ex in regex: #Detect replace or search ex = ex.strip("'") try: ex.index("'/'") #Check If this is a replacement ex = ex.split('\'/\'') txt = re.sub(dotall + ex[0], ex[1], txt) except: #If this is a search tmp = '' for m in re.finditer(dotall + ex, txt): tmp = "".join([tmp, match_seperator, m.group(1)]) txt = tmp[1:] if formatter == 'wiki': txt = wiki_to_html(txt, env, hdf, db, 0) buf.write(txt) # buf.write(env) #DEBUG return buf.getvalue()