Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: sitescripts/extensions/web/downloads.py

Issue 5747446760079360: Issue 402 - Use a redirector script for downloads, not a direct link (Closed)
Patch Set: Got rid of polling Created Sept. 16, 2014, 7:13 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « sitescripts/extensions/web/__init__.py ('k') | sitescripts/web.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 # coding: utf-8
2
3 # This file is part of the Adblock Plus web scripts,
4 # Copyright (C) 2006-2014 Eyeo GmbH
5 #
6 # Adblock Plus is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License version 3 as
8 # published by the Free Software Foundation.
9 #
10 # Adblock Plus 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
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
17
18 import re
19 import time
20 import posixpath
21 import urlparse
22 import multiprocessing
23 import threading
24 from ConfigParser import SafeConfigParser
25 from sitescripts.web import url_handler
26 from sitescripts.extensions.utils import getDownloadLinks
27
28 links = {}
29 UPDATE_INTERVAL = 10 * 60 # 10 minutes
30
31 @url_handler('/latest/')
32 def handle_request(environ, start_response):
33 request = urlparse.urlparse(environ.get('REQUEST_URI', ''))
34 basename = posixpath.splitext(posixpath.basename(request.path))[0]
35 if basename in links:
36 start_response('302 Found', [('Location', links[basename].encode("utf-8"))])
37 else:
38 start_response('404 Not Found', [])
39 return []
40
41 def update_links():
Sebastian Noack 2014/09/17 13:32:11 Since you are apparently fine with keeping a threa
Wladimir Palant 2014/09/17 17:45:44 That was the idea originally. However, https://sta
Sebastian Noack 2014/09/17 17:53:42 That is correct, but IMO not an issue here: 1. Th
Sebastian Noack 2014/09/17 18:13:53 Note that CPU time is distributed across all threa
42 try:
43 pool = multiprocessing.Pool(1)
44 pool.apply_async(_update_links, callback=_set_links)
45 pool.close()
46 finally:
47 t = threading.Timer(UPDATE_INTERVAL, update_links)
48 t.daemon = True
49 t.start()
50
51 def _update_links():
52 parser = SafeConfigParser()
53 getDownloadLinks(parser)
54 result = {}
55 for section in parser.sections():
56 result[section] = parser.get(section, "downloadURL")
57 return result
58
59 def _set_links(newlinks):
60 global links
61 links = newlinks
62
63 update_links()
OLDNEW
« no previous file with comments | « sitescripts/extensions/web/__init__.py ('k') | sitescripts/web.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld