| 1 | # svntrac
|
|---|
| 2 | #
|
|---|
| 3 | # Copyright (C) 2003 Jonas Borgström <jonas@xyche.com>
|
|---|
| 4 | #
|
|---|
| 5 | # svntrac is free software; you can redistribute it and/or
|
|---|
| 6 | # modify it under the terms of the GNU General Public License as
|
|---|
| 7 | # published by the Free Software Foundation; either version 2 of the
|
|---|
| 8 | # License, or (at your option) any later version.
|
|---|
| 9 | #
|
|---|
| 10 | # svntrac is distributed in the hope that it will be useful,
|
|---|
| 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|---|
| 13 | # General Public License for more details.
|
|---|
| 14 | #
|
|---|
| 15 | # You should have received a copy of the GNU General Public License
|
|---|
| 16 | # along with this program; if not, write to the Free Software
|
|---|
| 17 | # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|---|
| 18 | #
|
|---|
| 19 | # Author: Jonas Borgström <jonas@xyche.com>
|
|---|
| 20 |
|
|---|
| 21 | import sys
|
|---|
| 22 | import time
|
|---|
| 23 | import StringIO
|
|---|
| 24 | from svn import util
|
|---|
| 25 | from db import get_connection
|
|---|
| 26 | from xml.sax.saxutils import escape
|
|---|
| 27 |
|
|---|
| 28 | def time_to_string(date):
|
|---|
| 29 | date = time.asctime(time.localtime(date))
|
|---|
| 30 | return date[4:-8]
|
|---|
| 31 |
|
|---|
| 32 | def format_date(date, pool):
|
|---|
| 33 | date = util.svn_time_from_cstring(date, pool)
|
|---|
| 34 | return time_to_string (date / 1000000)
|
|---|
| 35 |
|
|---|
| 36 | def log_href (path, rev = None):
|
|---|
| 37 | if not rev:
|
|---|
| 38 | return 'svntrac.cgi?mode=log&path=%s' % path
|
|---|
| 39 | else:
|
|---|
| 40 | return 'svntrac.cgi?mode=log&path=%s&rev=%s' % (path, rev)
|
|---|
| 41 |
|
|---|
| 42 | def file_href (path, rev):
|
|---|
| 43 | return 'svntrac.cgi?mode=file&path=%s&rev=%s' % (path, rev)
|
|---|
| 44 |
|
|---|
| 45 | def browser_href (path):
|
|---|
| 46 | return 'svntrac.cgi?mode=browser&path=%s' % path
|
|---|
| 47 |
|
|---|
| 48 | def login_href ():
|
|---|
| 49 | return 'svntrac_auth.cgi'
|
|---|
| 50 |
|
|---|
| 51 | def timeline_href ():
|
|---|
| 52 | return 'svntrac.cgi?mode=timeline'
|
|---|
| 53 |
|
|---|
| 54 | def changeset_href (rev):
|
|---|
| 55 | return 'svntrac.cgi?mode=changeset&rev=%s' % rev
|
|---|
| 56 |
|
|---|
| 57 | def ticket_href (ticket):
|
|---|
| 58 | return 'svntrac.cgi?mode=ticket&id=%s' % ticket
|
|---|
| 59 |
|
|---|
| 60 | def menu_href ():
|
|---|
| 61 | return 'svntrac.cgi?mode=menu'
|
|---|
| 62 |
|
|---|
| 63 | def newticket_href ():
|
|---|
| 64 | return 'svntrac.cgi?mode=newticket'
|
|---|
| 65 |
|
|---|
| 66 | def wiki_href (page = None, version=None):
|
|---|
| 67 | if page and version:
|
|---|
| 68 | return 'svntrac.cgi?mode=wiki&page=%s&version=%s' % (page, version)
|
|---|
| 69 | if page:
|
|---|
| 70 | return 'svntrac.cgi?mode=wiki&page=%s' % page
|
|---|
| 71 | else:
|
|---|
| 72 | return 'svntrac.cgi?mode=wiki'
|
|---|
| 73 |
|
|---|
| 74 | def report_href (report=None, action=None):
|
|---|
| 75 | if report and action:
|
|---|
| 76 | return 'svntrac.cgi?mode=report&id=%s&action=%s' % (report, action)
|
|---|
| 77 | if report:
|
|---|
| 78 | return 'svntrac.cgi?mode=report&id=%s' % report
|
|---|
| 79 | elif action:
|
|---|
| 80 | return 'svntrac.cgi?mode=report&action=%s' % action
|
|---|
| 81 | else:
|
|---|
| 82 | return 'svntrac.cgi?mode=report'
|
|---|
| 83 |
|
|---|
| 84 | def redirect (url):
|
|---|
| 85 | """
|
|---|
| 86 | redirects the user agent to a different url
|
|---|
| 87 | """
|
|---|
| 88 | print 'Location: %s\r\n\r\n' % url
|
|---|
| 89 | sys.exit(0)
|
|---|
| 90 |
|
|---|
| 91 | def enum_selector (sql, name, selected=None,default_empty=0):
|
|---|
| 92 | out = StringIO.StringIO()
|
|---|
| 93 | out.write ('<select size="1" name="%s">' % name)
|
|---|
| 94 |
|
|---|
| 95 | cnx = get_connection()
|
|---|
| 96 | cursor = cnx.cursor ()
|
|---|
| 97 | cursor.execute (sql)
|
|---|
| 98 |
|
|---|
| 99 | if default_empty:
|
|---|
| 100 | out.write ('<option></option>')
|
|---|
| 101 | while 1:
|
|---|
| 102 | row = cursor.fetchone()
|
|---|
| 103 | if not row:
|
|---|
| 104 | break
|
|---|
| 105 | if selected == row[0]:
|
|---|
| 106 | out.write ('<option selected>%s</option>' % row[0])
|
|---|
| 107 | else:
|
|---|
| 108 | out.write ('<option>%s</option>' % row[0])
|
|---|
| 109 |
|
|---|
| 110 | out.write ('</select>')
|
|---|
| 111 | return out.getvalue()
|
|---|
| 112 |
|
|---|
| 113 | def get_first_line(text, maxlen):
|
|---|
| 114 | """
|
|---|
| 115 | returns the first line of text. If the line is longer then
|
|---|
| 116 | maxlen characters it is truncated. The line is also html escaped.
|
|---|
| 117 | """
|
|---|
| 118 | lines = text.splitlines()
|
|---|
| 119 | line = lines[0]
|
|---|
| 120 | if len(lines) > 1:
|
|---|
| 121 | return escape(line[:maxlen] + '...')
|
|---|
| 122 | elif len(line) > maxlen-3:
|
|---|
| 123 | return escape(line[:maxlen] + '...')
|
|---|
| 124 | else:
|
|---|
| 125 | return escape(line)
|
|---|