diff -ur trac.o/ModPythonHandler.py trac/ModPythonHandler.py
|
old
|
new
|
|
| 122 | 122 | def get(self, key, default=''): |
| 123 | 123 | return util.FieldStorage.get(self, key, default) |
| 124 | 124 | |
| | 125 | sql_user = "SELECT COUNT(*) FROM ticket WHERE owner='%s' AND status <> 'closed'" |
| | 126 | sql_open = "SELECT COUNT(*) FROM ticket WHERE status <> 'closed'" |
| | 127 | |
| | 128 | def get_tickets(mpr, dir, project): |
| | 129 | t_env = cache_get_environment(dir + "/" + project, mpr) |
| | 130 | t_db = t_env.get_db_cnx() |
| | 131 | t_cur = t_db.cursor() |
| | 132 | t_cur.execute(sql_open) |
| | 133 | t_open = t_cur.fetchall()[0][0] |
| | 134 | if (mpr.remote_user): |
| | 135 | t_cur.execute(sql_user % mpr.remote_user) |
| | 136 | t_user = t_cur.fetchall()[0][0] |
| | 137 | else: |
| | 138 | t_user = 0 |
| | 139 | return (t_user, t_open) |
| 125 | 140 | |
| 126 | 141 | def send_project_index(req, mpr, dir): |
| 127 | 142 | req.content_type = 'text/html' |
| 128 | 143 | req.write('<html><head><title>Available Projects</title></head>') |
| 129 | 144 | req.write('<body><h1>Available Projects</h1><ul>') |
| 130 | 145 | for project in os.listdir(dir): |
| 131 | | req.write('<li><a href="%s">%s</a></li>' |
| | 146 | (u, o) = get_tickets(mpr, dir, project) |
| | 147 | req.write('<li><a href="%s">%s</a>' |
| 132 | 148 | % (href_join(mpr.idx_location, project), project)) |
| | 149 | if o > 0: |
| | 150 | req.write(': <a href="%s">%d</a> open' |
| | 151 | % (href_join(mpr.idx_location, project, 'report', '1'), o)) |
| | 152 | if u > 0: |
| | 153 | req.write(', <a href="%s">%d</a> yours' |
| | 154 | % (href_join(mpr.idx_location, project, 'report', '7'), u)) |
| | 155 | req.write('</li>') |
| 133 | 156 | req.write('</ul></body><html>') |
| 134 | 157 | |
| 135 | 158 | def open_environment(env_path, mpr): |
| … |
… |
|
| 149 | 172 | env_cache = {} |
| 150 | 173 | env_cache_lock = threading.Lock() |
| 151 | 174 | |
| | 175 | def cache_get_environment(env_path, mpr): |
| | 176 | env = None |
| | 177 | try: |
| | 178 | env_cache_lock.acquire() |
| | 179 | if not env_path in env_cache: |
| | 180 | env_cache[env_path] = open_environment(env_path, mpr) |
| | 181 | env = env_cache[env_path] |
| | 182 | finally: |
| | 183 | env_cache_lock.release() |
| | 184 | return env |
| | 185 | |
| 152 | 186 | def get_environment(req, mpr): |
| 153 | 187 | global env_cache, env_cache_lock |
| 154 | 188 | options = req.get_options() |
| … |
… |
|
| 169 | 203 | send_project_index(req, mpr, env_parent_dir) |
| 170 | 204 | return None |
| 171 | 205 | |
| 172 | | try: |
| 173 | | env = None |
| 174 | | env_cache_lock.acquire() |
| 175 | | if not env_path in env_cache: |
| 176 | | env_cache[env_path] = open_environment(env_path, mpr) |
| 177 | | env = env_cache[env_path] |
| 178 | | finally: |
| 179 | | env_cache_lock.release() |
| 180 | | return env |
| | 206 | return cache_get_environment(env_path, mpr) |
| 181 | 207 | |
| 182 | 208 | def handler(req): |
| 183 | 209 | mpr = ModPythonRequest(req) |